-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Team-Shaka/feature/33-reaction
Feature/33-반응 추가/삭제
- Loading branch information
Showing
20 changed files
with
412 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/example/tree/domain/reaction/controller/ReactionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,52 @@ | ||
package org.example.tree.domain.reaction.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.tree.domain.reaction.dto.ReactionRequestDTO; | ||
import org.example.tree.domain.reaction.service.ReactionService; | ||
import org.example.tree.global.common.ApiResponse; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping | ||
public class ReactionController { | ||
private final ReactionService reactionService; | ||
|
||
@PostMapping("/trees/{treeId}/feed/posts/{postId}/reaction") | ||
public ApiResponse createPostReaction( | ||
@PathVariable Long treeId, | ||
@PathVariable Long postId, | ||
@RequestHeader("Authorization") String header, | ||
@RequestBody ReactionRequestDTO.createReaction request | ||
) { | ||
String token = header.replace("Bearer ", ""); | ||
reactionService.reactToPost(treeId, postId, request, token); | ||
return ApiResponse.onSuccess(""); | ||
} | ||
|
||
@PostMapping("/trees/{treeId}/feed/comments/{commentId}/reaction") | ||
public ApiResponse createCommentReaction( | ||
@PathVariable Long treeId, | ||
@PathVariable Long commentId, | ||
@RequestHeader("Authorization") String header, | ||
@RequestBody ReactionRequestDTO.createReaction request | ||
) { | ||
String token = header.replace("Bearer ", ""); | ||
reactionService.reactToComment(treeId, commentId, request, token); | ||
return ApiResponse.onSuccess(""); | ||
} | ||
|
||
@PostMapping("/trees/{treeId}/feed/replies/{replyId}/reaction") | ||
public ApiResponse createReplyReaction( | ||
@PathVariable Long treeId, | ||
@PathVariable Long replyId, | ||
@RequestHeader("Authorization") String header, | ||
@RequestBody ReactionRequestDTO.createReaction request | ||
) { | ||
String token = header.replace("Bearer ", ""); | ||
reactionService.reactToReply(treeId, replyId, request, token); | ||
return ApiResponse.onSuccess(""); | ||
} | ||
|
||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/example/tree/domain/reaction/converter/ReactionConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.example.tree.domain.reaction.converter; | ||
|
||
import org.example.tree.domain.profile.entity.Profile; | ||
import org.example.tree.domain.reaction.dto.ReactionResponseDTO; | ||
import org.example.tree.domain.reaction.entity.Reaction; | ||
import org.example.tree.domain.reaction.entity.ReactionType; | ||
import org.example.tree.domain.reaction.entity.TargetType; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ReactionConverter { | ||
public Reaction toPostReaction(Profile profile, Long postId, ReactionType type) { | ||
return Reaction.builder() | ||
.profile(profile) | ||
.type(type) | ||
.targetId(postId) | ||
.targetType(TargetType.POST) | ||
.build(); | ||
} | ||
|
||
public Reaction toCommentReaction(Profile profile, Long commentId, ReactionType type) { | ||
return Reaction.builder() | ||
.profile(profile) | ||
.type(type) | ||
.targetId(commentId) | ||
.targetType(TargetType.COMMENT) | ||
.build(); | ||
} | ||
|
||
public Reaction toReplyReaction(Profile profile, Long replyId, ReactionType type) { | ||
return Reaction.builder() | ||
.profile(profile) | ||
.type(type) | ||
.targetId(replyId) | ||
.targetType(TargetType.REPLY) | ||
.build(); | ||
} | ||
|
||
public ReactionResponseDTO.getReaction toGetReaction(ReactionType type, Integer count, Boolean isPushed) { | ||
return ReactionResponseDTO.getReaction.builder() | ||
.content(type.name()) | ||
.number(count) | ||
.isPushed(isPushed) | ||
.build(); | ||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/example/tree/domain/reaction/dto/ReactionRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
package org.example.tree.domain.reaction.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.tree.domain.reaction.entity.ReactionType; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
|
||
public class ReactionRequestDTO { | ||
|
||
@Getter | ||
public static class createReaction { | ||
private ReactionType type; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/example/tree/domain/reaction/dto/ReactionResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
package org.example.tree.domain.reaction.dto; | ||
|
||
import lombok.*; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
|
||
public class ReactionResponseDTO { | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class getReaction { | ||
private String content; | ||
private Integer number; | ||
private Boolean isPushed; | ||
} | ||
} |
Oops, something went wrong.