Skip to content

Commit

Permalink
Change: add folowed user
Browse files Browse the repository at this point in the history
  • Loading branch information
Voktor Stolenets committed Jan 21, 2025
1 parent fd10935 commit 0b09a5e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
55 changes: 53 additions & 2 deletions src/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ paths:
items:
type: object
properties:
_id:
type: string
address:
type: string
tokenAddress:
Expand Down Expand Up @@ -343,6 +345,8 @@ paths:
items:
type: object
properties:
_id:
type: string
address:
type: string
tokenAddress:
Expand Down Expand Up @@ -392,6 +396,8 @@ paths:
items:
type: object
properties:
_id:
type: string
address:
type: string
tokenAddress:
Expand All @@ -412,11 +418,10 @@ paths:
properties:
error:
type: string
/api/followers:
get:
summary: Get followers
description: Retrieve the list of followers for a specific user.
description: Retrieve the list of followers.
parameters:
- name: userAddress
in: query
Expand Down Expand Up @@ -458,6 +463,52 @@ paths:
properties:
error:
type: string
/api/followed:
get:
summary: Get followers
description: Retrieve the list of followed.
parameters:
- name: address
in: query
required: true
description: The address of the user whose followers are being retrieved.
schema:
type: string
responses:
"200":
description: Successfully retrieved the list of followers.
content:
application/json:
schema:
type: array
items:
type: object
properties:
address:
type: string
description: The address of the follower.
userAddress:
type: string
description: The address of the user being followed.
"400":
description: Invalid query parameter or missing required field.
content:
application/json:
schema:
type: object
properties:
error:
type: string
"500":
description: Server error
content:
application/json:
schema:
type: object
properties:
error:
type: string
/api/token:
get:
summary: Get token by address
Expand Down
17 changes: 17 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const startServer = async () => {
fastify.get("/api/likes", getUserLikes);
fastify.get("/api/secret", getSecret);
fastify.get("/api/followers", getFollowers);
fastify.get("/api/followed", getFollowed);
fastify.get("/api/messagesbyuser", getMessagesByUser);
fastify.get("/api/messagereplies", getMessageReplies);

Expand Down Expand Up @@ -489,4 +490,20 @@ async function getFollowers(request: FastifyRequest, reply: FastifyReply) {
return reply.status(500).send({ error: error.message });
}
}

async function getFollowed(request: FastifyRequest, reply: FastifyReply) {
try {
const { address } = request.query as {
address?: string;
};
const followers = await request.server.mongo.db
?.collection("followers")
.find({ address }, { projection: { _id: 0 } })
.toArray();
return reply.send(followers);
} catch (error) {
request.log.error(error);
return reply.status(500).send({ error: error.message });
}
}
startServer();

0 comments on commit 0b09a5e

Please sign in to comment.