-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat : 피드별 반응 기능 개발 (+통했당)
- Loading branch information
Showing
11 changed files
with
447 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
...main/java/com/web/baebaeBE/domain/reaction/controller/MemberAnswerReactionController.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,40 @@ | ||
package com.web.baebaeBE.domain.reaction.controller; | ||
|
||
import com.web.baebaeBE.domain.reaction.controller.api.MemberAnswerReactionApi; | ||
import com.web.baebaeBE.domain.reaction.dto.ReactionRequest; | ||
import com.web.baebaeBE.domain.reaction.dto.ReactionResponse; | ||
import com.web.baebaeBE.domain.reaction.entity.MemberAnswerReaction; | ||
import com.web.baebaeBE.domain.reaction.service.MemberAnswerReactionService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/reactions") | ||
@RequiredArgsConstructor | ||
public class MemberAnswerReactionController implements MemberAnswerReactionApi { | ||
private final MemberAnswerReactionService memberAnswerReactionService; | ||
|
||
@PostMapping("/{memberId}/{answerId}") | ||
public ResponseEntity<ReactionResponse.ReactionInformationDto> createReaction( | ||
@PathVariable Long memberId, | ||
@PathVariable Long answerId, | ||
@RequestBody ReactionRequest.create reactionDto) { | ||
|
||
return ResponseEntity.ok(memberAnswerReactionService.createReaction(memberId, answerId, reactionDto.getReaction())); | ||
} | ||
|
||
// 통했당~ | ||
@PostMapping("/connection/{memberId}/{answerId}/{destinationMemberId}") | ||
public ResponseEntity<ReactionResponse.ConnectionReactionInformationDto> createClickReaction( | ||
@PathVariable Long memberId, // 자기자신 (통했당 하는 주체) | ||
@PathVariable Long answerId, // 피드정보 | ||
@RequestParam(required = false) Long destinationMemberId // 피드작성자가 통했당 누군지 대상 지정 | ||
) { | ||
// destinationMemberId 파라미터 여부로 체크 | ||
if(destinationMemberId == null) | ||
return ResponseEntity.ok(memberAnswerReactionService.createConnectionReaction(memberId, answerId)); | ||
else | ||
return ResponseEntity.ok(memberAnswerReactionService.connectConnectionReaction(memberId, answerId, destinationMemberId)); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...rc/main/java/com/web/baebaeBE/domain/reaction/controller/api/MemberAnswerReactionApi.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,102 @@ | ||
package com.web.baebaeBE.domain.reaction.controller.api; | ||
|
||
import com.web.baebaeBE.domain.reaction.dto.ReactionRequest; | ||
import com.web.baebaeBE.domain.reaction.dto.ReactionResponse; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
|
||
@Tag(name = "Reaction", description = "피드 반응 API") | ||
@SecurityRequirement(name = "bearerAuth") | ||
@RequestMapping("/api/reactions") | ||
public interface MemberAnswerReactionApi { | ||
|
||
@Operation( | ||
summary = "피드 반응 생성", | ||
description = "피드에 대한 지정된 멤버 ID와 답변 ID에 대한 반응을 생성합니다. " + | ||
"(HEART, CURIOUS, SAD 만 가능합니다.)", | ||
security = @SecurityRequirement(name = "bearerAuth") | ||
) | ||
@Parameter( | ||
in = ParameterIn.HEADER, | ||
name = "Authorization", required = true, | ||
schema = @Schema(type = "string"), | ||
description = "Bearer [Access 토큰]") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "생성 성공", | ||
content = @Content(mediaType = "application/json", | ||
schema = @Schema( | ||
implementation = ReactionResponse.ReactionInformationDto.class | ||
)) | ||
), | ||
@ApiResponse(responseCode = "401", description = "토큰 인증 실패", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{\n" + | ||
" \"errorCode\": \"M-003\",\n" + | ||
" \"message\": \"해당 토큰은 유효한 토큰이 아닙니다.\"\n" + | ||
"}")) | ||
), | ||
@ApiResponse(responseCode = "404", description = "존재하지 않는 회원 또는 답변", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{\n" + | ||
" \"errorCode\": \"M-002\",\n" + | ||
" \"message\": \"존재하지 않는 회원 또는 답변입니다.\"\n" + | ||
"}")) | ||
) | ||
}) | ||
ResponseEntity<ReactionResponse.ReactionInformationDto> createReaction(@Parameter(description = "멤버의 ID", required = true) @PathVariable Long memberId, | ||
@Parameter(description = "답변의 ID", required = true) @PathVariable Long answerId, | ||
@RequestBody ReactionRequest.create reactionDto); | ||
|
||
@Operation( | ||
summary = "통했당 생성", | ||
description = "지정된 멤버 ID, 답변 ID, 대상 멤버 ID에 대한 '통했당'을 생성합니다. " + | ||
"다른 피드에 '통했당'을 남길경우 memberId, answerId만 필요합니다. " + | ||
"또한 피드 주인이 통했당을 완료할 경우 destinationMemberId가 추가적으로 필요합니다." + | ||
"(", | ||
security = @SecurityRequirement(name = "bearerAuth") | ||
) | ||
@Parameter( | ||
in = ParameterIn.HEADER, | ||
name = "Authorization", required = true, | ||
schema = @Schema(type = "string"), | ||
description = "Bearer [Access 토큰]") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "생성 성공", | ||
content = @Content(mediaType = "application/json", | ||
schema = @Schema( | ||
implementation = ReactionResponse.ConnectionReactionInformationDto.class | ||
)) | ||
), | ||
@ApiResponse(responseCode = "401", description = "토큰 인증 실패", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{\n" + | ||
" \"errorCode\": \"M-003\",\n" + | ||
" \"message\": \"해당 토큰은 유효한 토큰이 아닙니다.\"\n" + | ||
"}")) | ||
), | ||
@ApiResponse(responseCode = "404", description = "존재하지 않는 회원 또는 답변", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{\n" + | ||
" \"errorCode\": \"M-002\",\n" + | ||
" \"message\": \"존재하지 않는 회원 또는 답변입니다.\"\n" + | ||
"}")) | ||
) | ||
}) | ||
ResponseEntity<ReactionResponse.ConnectionReactionInformationDto> createClickReaction(@Parameter(description = "멤버의 ID", required = true) @PathVariable Long memberId, | ||
@Parameter(description = "답변의 ID", required = true) @PathVariable Long answerId, | ||
@Parameter(description = "대상 멤버의 ID (피드주인이 통했당 완료할때만 가능)", required = false) @RequestParam(required = false) Long destinationMemberId); | ||
} |
20 changes: 20 additions & 0 deletions
20
baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/dto/ReactionRequest.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,20 @@ | ||
package com.web.baebaeBE.domain.reaction.dto; | ||
|
||
import com.web.baebaeBE.domain.reaction.entity.ReactionValue; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
|
||
public class ReactionRequest { | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class create{ | ||
private ReactionValue reaction; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/dto/ReactionResponse.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,46 @@ | ||
package com.web.baebaeBE.domain.reaction.dto; | ||
|
||
import com.web.baebaeBE.domain.answer.entity.Answer; | ||
import com.web.baebaeBE.domain.reaction.entity.MemberAnswerReaction; | ||
import lombok.*; | ||
|
||
public class ReactionResponse { | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ReactionInformationDto { | ||
private boolean isClicked; | ||
private int heartCount; | ||
private int curiousCount; | ||
private int sadCount; | ||
|
||
public static ReactionInformationDto of(Answer answer, boolean isClicked) { | ||
return ReactionInformationDto.builder() | ||
.isClicked(isClicked) | ||
.heartCount(answer.getHeartCount()) | ||
.curiousCount(answer.getCuriousCount()) | ||
.sadCount(answer.getSadCount()) | ||
.build(); | ||
} | ||
} | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ConnectionReactionInformationDto { | ||
private boolean isClicked; | ||
private boolean isMatched; | ||
|
||
public static ConnectionReactionInformationDto of(boolean isClicked, boolean isMatched) { | ||
return ConnectionReactionInformationDto.builder() | ||
.isClicked(isClicked) | ||
.isMatched(isMatched) | ||
.build(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/entity/MemberAnswerReaction.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,34 @@ | ||
package com.web.baebaeBE.domain.reaction.entity; | ||
|
||
|
||
import com.web.baebaeBE.domain.answer.entity.Answer; | ||
import com.web.baebaeBE.domain.member.entity.Member; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Table(name = "member_answer_reaction") | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Builder | ||
public class MemberAnswerReaction { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id", nullable = false) | ||
private Member member; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "answer_id", nullable = false) | ||
private Answer answer; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "reaction", nullable = false) | ||
private ReactionValue reaction; | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/entity/ReactionValue.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,5 @@ | ||
package com.web.baebaeBE.domain.reaction.entity; | ||
|
||
public enum ReactionValue { | ||
HEART, CURIOUS, SAD, CONNECTION | ||
} |
20 changes: 20 additions & 0 deletions
20
baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/exception/ReactionException.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,20 @@ | ||
package com.web.baebaeBE.domain.reaction.exception; | ||
|
||
import com.web.baebaeBE.global.error.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ReactionException implements ErrorCode { | ||
|
||
NOT_EXIST_CONNECTION_REACTION(HttpStatus.NOT_FOUND, "R-001", "상대방이 통했당을 하지 않았습니다."), | ||
NOT_EXIST_MEMBER(HttpStatus.NOT_FOUND, "R-002", "존재하지 않는 회원입니다."), | ||
NOT_EXIST_ANSWER(HttpStatus.NOT_FOUND, "R-003", "존재하지 않는 답변입니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorCode; | ||
private final String message; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...main/java/com/web/baebaeBE/domain/reaction/repository/MemberAnswerReactionRepository.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,13 @@ | ||
package com.web.baebaeBE.domain.reaction.repository; | ||
|
||
import com.web.baebaeBE.domain.answer.entity.Answer; | ||
import com.web.baebaeBE.domain.member.entity.Member; | ||
import com.web.baebaeBE.domain.reaction.entity.MemberAnswerReaction; | ||
import com.web.baebaeBE.domain.reaction.entity.ReactionValue; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface MemberAnswerReactionRepository extends JpaRepository<MemberAnswerReaction, Long> { | ||
Optional<MemberAnswerReaction> findByMemberAndAnswerAndReaction(Member member, Answer answer, ReactionValue reaction); | ||
} |
Oops, something went wrong.