Skip to content

Commit

Permalink
Api logic and documentation for favoriting topics
Browse files Browse the repository at this point in the history
  • Loading branch information
tu2463 committed Sep 30, 2024
1 parent 11c4375 commit a5d9dff
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions public/openapi/write.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ paths:
$ref: 'write/topics/tid/follow.yaml'
/topics/{tid}/ignore:
$ref: 'write/topics/tid/ignore.yaml'
/topics/{tid}/favorite:
$ref: 'write/topics/tid/favorite.yaml'
/topics/{tid}/tags:
$ref: 'write/topics/tid/tags.yaml'
/topics/{tid}/thumbs:
Expand Down
53 changes: 53 additions & 0 deletions public/openapi/write/topics/tid/favorite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
put:
tags:
- topics
summary: Add a topic to favorites
description: This operation saves the specified topic to the current user's favorites.
parameters:
- in: path
name: tid
schema:
type: string
required: true
description: A valid topic id
example: 1
responses:
'200':
description: Topic successfully saved to favorites
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}

delete:
tags:
- topics
summary: Remove a topic from favorites
description: This operation removes the specified topic from the current user's favorites.
parameters:
- in: path
name: tid
schema:
type: string
required: true
description: A valid topic ID
example: 1
responses:
'200':
description: Topic successfully removed from favorites
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}
8 changes: 8 additions & 0 deletions src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ topicsAPI.unfollow = async function (caller, data) {
await topics.unfollow(data.tid, caller.uid);
};

topicsAPI.favorite = async function (caller, data) {
await topics.favorite(data.tid, caller.uid);
};

topicsAPI.unfavorite = async function (caller, data) {
await topics.unfavorite(data.tid, caller.uid);
};

topicsAPI.updateTags = async (caller, { tid, tags }) => {
if (!await privileges.topics.canEdit(tid, caller.uid)) {
throw new Error('[[error:no-privileges]]');
Expand Down

0 comments on commit a5d9dff

Please sign in to comment.