Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): リアクションの削除ができるように #171

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/server/controller/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ export class PostController {
return new Success(resp);
}

async UndoReaction(userID: string, postID: string) {
const res = await this.createReactionService.Undo(
postID as Snowflake,
userID as Snowflake,
);
if (res.isFailure()) {
return new Failure(res.value);
}
return new Success(res);
}

private convertToCommonResponse(arg: { post: PostData; user: UserData }) {
const resp: CommonPostResponse = {
id: arg.post.id,
Expand Down
10 changes: 10 additions & 0 deletions src/server/handlers/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ export class PostHandler {
}
r.code(200).send(re.value);
};

public UndoReaction: FastifyHandlerMethod<{ Params: { id: string } }> =
async (q, r) => {
const re = await this.controller.UndoReaction("123", q.params.id);
if (re.isFailure()) {
const [code, message] = ErrorConverter(re.value);
return r.code(code).send(message);
}
r.code(204).send();
};
}
1 change: 1 addition & 0 deletions src/server/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export async function StartServer(port: number) {
app.get("/api/v1/posts/:id", postHandler.FindByID);
app.delete("/api/v1/posts/:id", postHandler.DeletePost);
app.post("/api/v1/posts/:id/reaction", postHandler.CreateReaction);
app.delete("/api/v1/posts/:id/reaction", postHandler.UndoReaction);
app.post("/api/v1/posts", postHandler.CreatePost);
app.get("/api/v1/users/:name", userHandler.FindByHandle);
app.get("/api/v1/users/:name/posts", userHandler.FindUserPosts);
Expand Down
8 changes: 8 additions & 0 deletions src/service/post/create_reaction_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class CreateReactionService {
return new Success(data);
}

async Undo(postID: Snowflake, userID: Snowflake): AsyncResult<void, Error> {
const res = await this.repository.Undo(postID, userID);
if (res.isFailure()) {
return new Failure(res.value);
}
return new Success(void "");
}

private async isExists(d: PostReactionEvent): Promise<boolean> {
const res = await this.repository.Find(d.postID, d.userID);
return res.isSuccess();
Expand Down