Skip to content

Commit

Permalink
added new API endpoint for listing answers for a particular question …
Browse files Browse the repository at this point in the history
…/api/posts/{id}/answers
  • Loading branch information
albogdano committed Jun 20, 2024
1 parent dd97aa9 commit 5f1c6c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/erudika/scoold/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ public void downvotePost(@PathVariable String id, @RequestParam(required = false
}
}

@GetMapping("/posts/{id}/answers")
public List<Reply> getPostReplies(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Post post = pc.read(id);
if (post == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
Pager itemcount = utils.getPager("page", req);
return questionController.getAllAnswers(utils.getAuthUser(req), post, itemcount, req);
}

@GetMapping("/posts/{id}/comments")
public List<Comment> getPostComments(@PathVariable String id,
@RequestParam(required = false, defaultValue = "5") String limit,
Expand Down
28 changes: 28 additions & 0 deletions src/main/resources/templates/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,34 @@ paths:
description: vote succeeded
'400':
description: vote failed
/api/posts/{id}/answers:
get:
summary: Returns a page of answers for a given post
description: You can paginate through answers by setting the parameters `sortby`, `desc`, `limit` and `page`.
tags:
- posts
security:
- scoold_auth: []
parameters:
- name: id
in: path
required: true
description: The id of the parent question
schema:
type: string
- $ref: '#/components/parameters/limit'
- $ref: '#/components/parameters/page'
- $ref: '#/components/parameters/sortby'
- $ref: '#/components/parameters/desc'
responses:
'200':
description: A list of answers
content:
application/json:
schema:
$ref: '#/components/schemas/Posts'
'404':
description: Not found
/api/posts/{id}/comments:
get:
summary: Returns a page of comments for a given post
Expand Down

0 comments on commit 5f1c6c5

Please sign in to comment.