-
Notifications
You must be signed in to change notification settings - Fork 0
메시지 피드백 등록 API 구현 #152
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
Merged
Merged
메시지 피드백 등록 API 구현 #152
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/com/sofa/linkiving/domain/chat/controller/FeedbackApi.java
This file contains hidden or 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,15 @@ | ||
| package com.sofa.linkiving.domain.chat.controller; | ||
|
|
||
| import com.sofa.linkiving.domain.chat.dto.request.AddFeedbackReq; | ||
| import com.sofa.linkiving.domain.chat.dto.response.AddFeedbackRes; | ||
| import com.sofa.linkiving.domain.member.entity.Member; | ||
| import com.sofa.linkiving.global.common.BaseResponse; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
|
||
| @Tag(name = "Feedback", description = "피드백 관리 API") | ||
| public interface FeedbackApi { | ||
| @Operation(summary = "피드백 추가", description = "메세지에 피드백을 추가하고 생성된 피드백 ID를 반환합니다.") | ||
| BaseResponse<AddFeedbackRes> createFeedback(Long messageId, AddFeedbackReq createFeedbackReq, Member member); | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/sofa/linkiving/domain/chat/controller/FeedbackController.java
This file contains hidden or 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,32 @@ | ||
| package com.sofa.linkiving.domain.chat.controller; | ||
|
|
||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.sofa.linkiving.domain.chat.dto.request.AddFeedbackReq; | ||
| import com.sofa.linkiving.domain.chat.dto.response.AddFeedbackRes; | ||
| import com.sofa.linkiving.domain.chat.facade.FeedbackFacade; | ||
| import com.sofa.linkiving.domain.member.entity.Member; | ||
| import com.sofa.linkiving.global.common.BaseResponse; | ||
| import com.sofa.linkiving.security.annotation.AuthMember; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/v1/messages") | ||
| @RequiredArgsConstructor | ||
| public class FeedbackController implements FeedbackApi { | ||
| private final FeedbackFacade feedbackFacade; | ||
|
|
||
| @Override | ||
| @PostMapping("/{messageId}/feedback") | ||
| public BaseResponse<AddFeedbackRes> createFeedback(@PathVariable Long messageId, | ||
| @Valid @RequestBody AddFeedbackReq req, @AuthMember Member member) { | ||
| AddFeedbackRes res = feedbackFacade.createFeedback(member, messageId, req.sentiment(), req.text()); | ||
| return BaseResponse.success(res, "피드백이 등록되었습니다."); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/sofa/linkiving/domain/chat/dto/request/AddFeedbackReq.java
This file contains hidden or 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,17 @@ | ||
| package com.sofa.linkiving.domain.chat.dto.request; | ||
|
|
||
| import com.sofa.linkiving.domain.chat.enums.Sentiment; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record AddFeedbackReq( | ||
| @NotNull(message = "피드백 상태는 필수입니다.") // 필수 값 체크 | ||
| @Schema(description = "피드백 상태 (LIKE, DISLIKE)", example = "LIKE") | ||
| Sentiment sentiment, | ||
| @Schema(description = "피드백 내용 (선택)", example = "도움이 되었습니다.") | ||
| @Size(max = 20, message = "피드백 내용은 20자를 넘을 수 없습니다.") | ||
| String text | ||
| ) { | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
src/main/java/com/sofa/linkiving/domain/chat/dto/response/AddFeedbackRes.java
This file contains hidden or 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,9 @@ | ||
| package com.sofa.linkiving.domain.chat.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record AddFeedbackRes( | ||
| @Schema(description = "피드백 ID") | ||
| Long id | ||
| ) { | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/sofa/linkiving/domain/chat/error/MessageErrorCode.java
This file contains hidden or 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,18 @@ | ||
| package com.sofa.linkiving.domain.chat.error; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import com.sofa.linkiving.global.error.code.ErrorCode; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum MessageErrorCode implements ErrorCode { | ||
| MESSAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "MS-001", "메세지를 찾을 수 없습니다."); | ||
|
|
||
| private final HttpStatus status; | ||
| private final String code; | ||
| private final String message; | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/sofa/linkiving/domain/chat/facade/FeedbackFacade.java
This file contains hidden or 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,28 @@ | ||
| package com.sofa.linkiving.domain.chat.facade; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.sofa.linkiving.domain.chat.dto.response.AddFeedbackRes; | ||
| import com.sofa.linkiving.domain.chat.entity.Message; | ||
| import com.sofa.linkiving.domain.chat.enums.Sentiment; | ||
| import com.sofa.linkiving.domain.chat.service.FeedbackService; | ||
| import com.sofa.linkiving.domain.chat.service.MessageService; | ||
| import com.sofa.linkiving.domain.member.entity.Member; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class FeedbackFacade { | ||
| private final FeedbackService feedbackService; | ||
| private final MessageService messageService; | ||
|
|
||
| public AddFeedbackRes createFeedback(Member member, Long messageId, Sentiment sentiment, String text) { | ||
|
|
||
| Message message = messageService.get(messageId, member); | ||
| Long id = feedbackService.create(message, sentiment, text); | ||
| return new AddFeedbackRes(id); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
src/test/java/com/sofa/linkiving/domain/chat/facade/FeedbackFacadeTest.java
This file contains hidden or 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,56 @@ | ||
| package com.sofa.linkiving.domain.chat.facade; | ||
|
|
||
| import static org.assertj.core.api.Assertions.*; | ||
| import static org.mockito.BDDMockito.*; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import com.sofa.linkiving.domain.chat.dto.response.AddFeedbackRes; | ||
| import com.sofa.linkiving.domain.chat.entity.Message; | ||
| import com.sofa.linkiving.domain.chat.enums.Sentiment; | ||
| import com.sofa.linkiving.domain.chat.service.FeedbackService; | ||
| import com.sofa.linkiving.domain.chat.service.MessageService; | ||
| import com.sofa.linkiving.domain.member.entity.Member; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class FeedbackFacadeTest { | ||
| @InjectMocks | ||
| private FeedbackFacade feedbackFacade; | ||
|
|
||
| @Mock | ||
| private FeedbackService feedbackService; | ||
|
|
||
| @Mock | ||
| private MessageService messageService; | ||
|
|
||
| @Test | ||
| @DisplayName("피드백 생성 요청 시 Message 조회 후 Feedback을 생성하고 결과를 반환함") | ||
| void shouldCreateFeedbackAndReturnRes() { | ||
| // given | ||
| Long messageId = 1L; | ||
| Long feedbackId = 100L; | ||
| Sentiment sentiment = Sentiment.LIKE; | ||
| String text = "도움이 되었어요"; | ||
|
|
||
| Message message = mock(Message.class); | ||
| Member member = mock(Member.class); | ||
|
|
||
| given(messageService.get(messageId, member)).willReturn(message); | ||
| given(feedbackService.create(message, sentiment, text)).willReturn(feedbackId); | ||
|
|
||
| // when | ||
| AddFeedbackRes result = feedbackFacade.createFeedback(member, messageId, sentiment, text); | ||
|
|
||
| // then | ||
| assertThat(result).isNotNull(); | ||
| assertThat(result.id()).isEqualTo(feedbackId); | ||
|
|
||
| verify(messageService).get(messageId, member); | ||
| verify(feedbackService).create(message, sentiment, text); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.