Skip to content

Assessment Management — Backend Implementation #8

@adarshm11

Description

@adarshm11

Route stubs are wired up already (internal/handlers/), but they all just return placeholder JSON. Time to make them actually do things.


What needs to happen

1. Define domain structs

Where: internal/core/models/

  • AssessmentTemplate — id, title, description, duration_minutes, timestamps
  • Question — id, assessment_template_id, type (mcq_single/mcq_multi/short_answer/code), prompt, options (JSONB), correct_answer (JSONB), score, language (nullable)
  • TestCase — id, question_id, input, expected_output, is_hidden, score

These should have JSON tags for API responses and db tags for scanning rows. Keep them clean — no methods on these yet.

2. Write repository interfaces

Where: internal/core/repositories/

  • AssessmentRepository interface — Create, GetByID, List, Update, Delete
  • QuestionRepository interface — Create, GetByAssessmentID, Update, Delete
  • TestCaseRepository interface — Create, GetByQuestionID, Delete

Code against the interfaces for now. The actual Postgres implementations can come once the migrations are in (someone else is handling that). If you want to test in the meantime, throw together an in-memory implementation.

3. Implement service layer

Where: internal/core/services/

  • AssessmentService that orchestrates repo calls and handles business logic:
    • Validate that code questions have a language set
    • Validate that MCQ questions have options populated
    • Validate score > 0
    • Handle cascading fetches (get assessment + its questions in one call)

Nothing fancy — just the glue between handlers and repos.

4. Fill in the handler stubs with real logic

Where: internal/handlers/assessments.go

The routes are already wired, these just need actual implementations:

  • CreateAssessment — parse request body, call service, return created template
  • ListAssessments — call service, return list
  • GetAssessment — parse id param, call service, return template + questions
  • AddQuestion — parse body + assessment id, validate question type, call service
  • AddTestCases — parse body + question id, call service

Each handler should: bind JSON -> validate -> call service -> return response or error.

5. Add request validation

  • Add go-playground/validator or manual checks
  • Required fields: title, duration_minutes on assessments; type, prompt, score on questions
  • Enum validation on question type (mcq_single, mcq_multi, short_answer, code)
  • Return consistent { "error": "..." } responses on bad input

Notes

  • The DB migration work is being done by someone else, so don't touch migrations/
  • Route registration in main.go is already done — no need to add new routes
  • When the Postgres repo implementations get written, they just need to satisfy the interfaces from step 2

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions