# Answer

Endpoints for answers

## Get answer by ID

> Retrieves answer details by its ID. Requires access to the answer.

```json
{"openapi":"3.1.0","info":{"title":"Codebattles backend","version":"0.1.0"},"tags":[{"name":"Answer","description":"Endpoints for answers"}],"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"security":[{"JWT":[]}],"components":{"securitySchemes":{"JWT":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"AnswerDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the answer"},"user":{"$ref":"#/components/schemas/UserDto","description":"User who submitted the answer"},"status":{"type":"string","description":"Current status of the answer","enum":["IN_PROGRESS","COMPLETED"]},"score":{"type":"integer","format":"int32","description":"Score awarded for the answer"},"code":{"type":"string","description":"Code submitted by the user"},"result":{"type":"string","description":"Result of the code execution"},"checker":{"$ref":"#/components/schemas/CheckerDto","description":"Checker used to evaluate the answer"},"createdAt":{"type":"string","format":"date-time","description":"Timestamp when the answer was created"},"competitionsProblems":{"$ref":"#/components/schemas/CompetitionsProblemsDto","description":"Details of the competition problem associated with the answer"}},"required":["checker","code","createdAt","status","user"]},"UserDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the user"},"username":{"type":"string","description":"Username of the user"}},"required":["id","username"]},"CheckerDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the checker"},"displayName":{"type":"string","description":"Display name of the checker"},"languageHighlightName":{"type":"string","description":"Programming language used by the checker"}},"required":["displayName","languageHighlightName"]},"CompetitionsProblemsDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the competition problem"},"priority":{"type":"integer","format":"int32","description":"Priority of problem for sorting"},"problem":{"$ref":"#/components/schemas/ProblemDto","description":"Unique identifier of the competition problem"},"slug":{"type":"string","description":"Unique identifier of the competition problem"}},"required":["id","priority","problem","slug"]},"ProblemDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the problem"},"name":{"type":"string","description":"Name of the problem"},"description":{"type":"string","description":"Description of the problem"},"inData":{"type":"string","description":"Input data for the problem"},"outData":{"type":"string","description":"Expected output data for the problem"},"public":{"type":"boolean","description":"Indicates if the problem is public"}},"required":["description","examples","id","inData","name","outData"]},"UnauthorizedResponse":{"type":"object","description":"Response returned when the user is not authenticated.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}},"AccessDeniedResponse":{"type":"object","description":"Response returned when the user does not have permission to access the requested resource.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}},"ConflictResponse":{"type":"object","description":"Response returned when the conflict in data.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}},"InternalServerErrorResponse":{"type":"object","description":"Response returned when an unexpected error occurs on the server.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}}}},"paths":{"/api/answers/{id}":{"get":{"tags":["Answer"],"summary":"Get answer by ID","description":"Retrieves answer details by its ID. Requires access to the answer.","operationId":"getById_3","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/AnswerDto"}}}},"401":{"description":"Unauthorized","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"403":{"description":"Forbidden","content":{"*/*":{"schema":{"$ref":"#/components/schemas/AccessDeniedResponse"}}}},"409":{"description":"Conflict","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ConflictResponse"}}}},"500":{"description":"Internal Server Error","content":{"*/*":{"schema":{"$ref":"#/components/schemas/InternalServerErrorResponse"}}}}}}}}}
```

## \[ADMIN] Get the last answer by problem and user ID

> Retrieves the most recent answer submitted by a specific user for a specific competition problem. Required admin role.

```json
{"openapi":"3.1.0","info":{"title":"Codebattles backend","version":"0.1.0"},"tags":[{"name":"Answer","description":"Endpoints for answers"}],"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"security":[{"JWT":[]}],"components":{"securitySchemes":{"JWT":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"AnswerDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the answer"},"user":{"$ref":"#/components/schemas/UserDto","description":"User who submitted the answer"},"status":{"type":"string","description":"Current status of the answer","enum":["IN_PROGRESS","COMPLETED"]},"score":{"type":"integer","format":"int32","description":"Score awarded for the answer"},"code":{"type":"string","description":"Code submitted by the user"},"result":{"type":"string","description":"Result of the code execution"},"checker":{"$ref":"#/components/schemas/CheckerDto","description":"Checker used to evaluate the answer"},"createdAt":{"type":"string","format":"date-time","description":"Timestamp when the answer was created"},"competitionsProblems":{"$ref":"#/components/schemas/CompetitionsProblemsDto","description":"Details of the competition problem associated with the answer"}},"required":["checker","code","createdAt","status","user"]},"UserDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the user"},"username":{"type":"string","description":"Username of the user"}},"required":["id","username"]},"CheckerDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the checker"},"displayName":{"type":"string","description":"Display name of the checker"},"languageHighlightName":{"type":"string","description":"Programming language used by the checker"}},"required":["displayName","languageHighlightName"]},"CompetitionsProblemsDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the competition problem"},"priority":{"type":"integer","format":"int32","description":"Priority of problem for sorting"},"problem":{"$ref":"#/components/schemas/ProblemDto","description":"Unique identifier of the competition problem"},"slug":{"type":"string","description":"Unique identifier of the competition problem"}},"required":["id","priority","problem","slug"]},"ProblemDto":{"type":"object","properties":{"id":{"type":"integer","format":"int64","description":"Unique identifier of the problem"},"name":{"type":"string","description":"Name of the problem"},"description":{"type":"string","description":"Description of the problem"},"inData":{"type":"string","description":"Input data for the problem"},"outData":{"type":"string","description":"Expected output data for the problem"},"public":{"type":"boolean","description":"Indicates if the problem is public"}},"required":["description","examples","id","inData","name","outData"]},"UnauthorizedResponse":{"type":"object","description":"Response returned when the user is not authenticated.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}},"AccessDeniedResponse":{"type":"object","description":"Response returned when the user does not have permission to access the requested resource.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}},"ConflictResponse":{"type":"object","description":"Response returned when the conflict in data.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}},"InternalServerErrorResponse":{"type":"object","description":"Response returned when an unexpected error occurs on the server.","properties":{"message":{"type":"string","description":"Detailed message about the error."},"code":{"type":"integer","format":"int32","description":"HTTP status code representing the error."}}}}},"paths":{"/api/answers/last":{"get":{"tags":["Answer"],"summary":"[ADMIN] Get the last answer by problem and user ID","description":"Retrieves the most recent answer submitted by a specific user for a specific competition problem. Required admin role.","operationId":"getLastSendByProblemAnswerAndUserId","parameters":[{"name":"compProblemId","in":"query","description":"The ID of CompetitionProblem id","required":true,"schema":{"type":"integer","format":"int64"}},{"name":"userId","in":"query","description":"The ID of the user","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/AnswerDto"}}}},"401":{"description":"Unauthorized","content":{"*/*":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"403":{"description":"Forbidden","content":{"*/*":{"schema":{"$ref":"#/components/schemas/AccessDeniedResponse"}}}},"409":{"description":"Conflict","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ConflictResponse"}}}},"500":{"description":"Internal Server Error","content":{"*/*":{"schema":{"$ref":"#/components/schemas/InternalServerErrorResponse"}}}}}}}}}
```
