-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 유저 질문 및 답변 관련 API #864
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
Open
dev-Crayon
wants to merge
15
commits into
develop
Choose a base branch
from
feature/#861-ask
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7a3e612
[Feat]: 멤버 질문 & 답변 Entity 클래스 구현
dev-Crayon 3c64fad
[Feat]: 멤버 질문 | 답변 리액션 테이블 및 질문 신고 테이블 구현
dev-Crayon 5aebbf7
[Feat]: 질문 생성 request body & repository 코드 구현
dev-Crayon 8e2e578
[Feat]: 질문 조회 및 생성 로직 구현
dev-Crayon 42710dc
[Feat]: 질문 및 답변 관련 API 구현
dev-Crayon 41fd705
[Feat]: 질문 및 답변 관련 API DTO deprecated 코드 제거
dev-Crayon 0773f01
[Delete]: SQL 스크립트 삭제
dev-Crayon fa34c81
[Fix]: 페이지네이션으로 인한 빌드 오류 제거
dev-Crayon 6c40b48
[Feat]: 익명 질문시 사용자 최신기수 정보 저장
dev-Crayon da90db8
[Feat]: 익명 질문 수정 가능하게 변경
dev-Crayon 6250ee0
[Feat]: 질문 삭제 로직 수정
dev-Crayon 760d642
[Feat]: 답변시 질문자에게 푸시알림 발송 로직 추가
dev-Crayon dac2f04
[Feat]: 질문 리스트 로직 수정
dev-Crayon abc2aa1
[Feat]: 질문 익명으로 작성시 랜덤 닉네임 및 프로필 이미지 생성
dev-Crayon 5007cac
[Feat]: 질문 익명으로 작성시 랜덤 닉네임 및 프로필 이미지 생성
dev-Crayon 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
25 changes: 25 additions & 0 deletions
25
src/main/java/org/sopt/makers/internal/common/util/PaginationUtil.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,25 @@ | ||
| package org.sopt.makers.internal.common.util; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class PaginationUtil { | ||
|
|
||
| private static final int DEFAULT_LIMIT = 20; | ||
| private static final int MAX_LIMIT = 100; | ||
|
|
||
| public static int validateAndGetLimit(Integer limit) { | ||
| if (limit == null || limit <= 0) { | ||
| return DEFAULT_LIMIT; | ||
| } | ||
| return Math.min(limit, MAX_LIMIT); | ||
| } | ||
|
|
||
| public static int validateAndGetLimit(Integer limit, int defaultLimit, int maxLimit) { | ||
| if (limit == null || limit <= 0) { | ||
| return defaultLimit; | ||
| } | ||
| return Math.min(limit, maxLimit); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
...t/makers/internal/external/pushNotification/message/member/AnswerNotificationMessage.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,51 @@ | ||
| package org.sopt.makers.internal.external.pushNotification.message.member; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.sopt.makers.internal.external.pushNotification.message.PushNotificationMessageBuilder; | ||
|
|
||
| import static org.sopt.makers.internal.external.pushNotification.message.member.MemberPushConstants.*; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class AnswerNotificationMessage implements PushNotificationMessageBuilder { | ||
|
|
||
| private final Long questionAskerId; | ||
| private final String answerWriterName; | ||
| private final String answerContent; | ||
| private final String webLink; | ||
|
|
||
| @Override | ||
| public String buildTitle() { | ||
| return ANSWER_NOTIFICATION_TITLE; | ||
| } | ||
|
|
||
| @Override | ||
| public String buildContent() { | ||
| String abbreviatedContent = StringUtils.abbreviate(answerContent, CONTENT_MAX_LENGTH); | ||
| return String.format(ANSWER_CONTENT_FORMAT, answerWriterName, abbreviatedContent); | ||
| } | ||
|
|
||
| @Override | ||
| public Long[] getRecipientIds() { | ||
| return new Long[]{questionAskerId}; | ||
| } | ||
|
|
||
| @Override | ||
| public String getWebLink() { | ||
| return webLink; | ||
| } | ||
|
|
||
| public static AnswerNotificationMessage of( | ||
| Long questionAskerId, | ||
| String answerWriterName, | ||
| String answerContent, | ||
| String webLink | ||
| ) { | ||
| return new AnswerNotificationMessage( | ||
| questionAskerId, | ||
| answerWriterName, | ||
| answerContent, | ||
| webLink | ||
| ); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...rg/sopt/makers/internal/external/pushNotification/message/member/MemberPushConstants.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 org.sopt.makers.internal.external.pushNotification.message.member; | ||
|
|
||
| public final class MemberPushConstants { | ||
|
|
||
| private MemberPushConstants() { | ||
| throw new UnsupportedOperationException("유틸 클래스는 인스턴스화 할 수 없습니다."); | ||
| } | ||
|
|
||
| // 에스크 답변 알림 | ||
| public static final String ANSWER_NOTIFICATION_TITLE = "💬나의 에스크에 답변이 달렸어요."; | ||
| public static final String ANSWER_CONTENT_FORMAT = "[%s의 댓글] : \"%s\""; | ||
|
|
||
| // 답변 내용 최대 길이 | ||
| public static final int CONTENT_MAX_LENGTH = 100; | ||
| } |
183 changes: 183 additions & 0 deletions
183
src/main/java/org/sopt/makers/internal/member/controller/MemberQuestionController.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,183 @@ | ||
| package org.sopt.makers.internal.member.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.sopt.makers.internal.member.domain.QuestionTab; | ||
| import org.sopt.makers.internal.member.dto.request.*; | ||
| import org.sopt.makers.internal.member.dto.response.*; | ||
| import org.sopt.makers.internal.member.service.MemberQuestionService; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/members") | ||
| @SecurityRequirement(name = "Authorization") | ||
| @Tag(name = "Member Question 관련 API", description = "회원 질문/답변 관련 API List") | ||
| public class MemberQuestionController { | ||
|
|
||
| private final MemberQuestionService memberQuestionService; | ||
|
|
||
| @Operation( | ||
| summary = "질문 작성 API", | ||
| description = """ | ||
| 다른 사용자에게 질문을 작성합니다. | ||
| 익명으로 작성할 경우 asker 정보가 숨겨집니다. | ||
| """ | ||
| ) | ||
| @PostMapping("/questions/{receiverId}") | ||
| public ResponseEntity<Map<String, Long>> createQuestion( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long receiverId, | ||
| @RequestBody @Valid QuestionSaveRequest request | ||
| ) { | ||
| Long questionId = memberQuestionService.createQuestion(userId, receiverId, request); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(Map.of("questionId", questionId)); | ||
| } | ||
|
|
||
| @Operation(summary = "질문 수정 API", description = "답변이 달리기 전에만 수정 가능합니다.") | ||
| @PutMapping("/questions/{questionId}") | ||
| public ResponseEntity<Map<String, Boolean>> updateQuestion( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long questionId, | ||
| @RequestBody @Valid QuestionUpdateRequest request | ||
| ) { | ||
| memberQuestionService.updateQuestion(userId, questionId, request); | ||
| return ResponseEntity.status(HttpStatus.OK).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "질문 삭제 API", | ||
| description = """ | ||
| 질문 삭제 규칙: | ||
| - 답변 전: 질문 작성자만 삭제 가능 | ||
| - 항상: 질문 받은 사람은 삭제 가능 | ||
| """ | ||
| ) | ||
| @DeleteMapping("/questions/{questionId}") | ||
| public ResponseEntity<Map<String, Boolean>> deleteQuestion( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long questionId | ||
| ) { | ||
| memberQuestionService.deleteQuestion(userId, questionId); | ||
| return ResponseEntity.status(HttpStatus.OK).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation(summary = "답변 작성 API", description = "질문을 받은 사람만 답변을 작성할 수 있습니다.") | ||
| @PostMapping("/questions/{questionId}/answer") | ||
| public ResponseEntity<Map<String, Long>> createAnswer( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long questionId, | ||
| @RequestBody @Valid AnswerSaveRequest request | ||
| ) { | ||
| Long answerId = memberQuestionService.createAnswer(userId, questionId, request); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(Map.of("answerId", answerId)); | ||
| } | ||
|
|
||
| @Operation(summary = "답변 수정 API", description = "답변 작성자만 수정 가능합니다.") | ||
| @PutMapping("/answers/{answerId}") | ||
| public ResponseEntity<Map<String, Boolean>> updateAnswer( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long answerId, | ||
| @RequestBody @Valid AnswerUpdateRequest request | ||
| ) { | ||
| memberQuestionService.updateAnswer(userId, answerId, request); | ||
| return ResponseEntity.status(HttpStatus.OK).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation(summary = "답변 삭제 API", description = "답변 작성자만 삭제 가능합니다.") | ||
| @DeleteMapping("/answers/{answerId}") | ||
| public ResponseEntity<Map<String, Boolean>> deleteAnswer( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long answerId | ||
| ) { | ||
| memberQuestionService.deleteAnswer(userId, answerId); | ||
| return ResponseEntity.status(HttpStatus.OK).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "나도 궁금해요 토글 API", | ||
| description = """ | ||
| 답변이 달리기 전 질문에 '나도 궁금해요' 반응을 토글합니다. | ||
| 이미 반응을 누른 경우 취소되고, 누르지 않은 경우 반응이 추가됩니다. | ||
| 질문을 받은 사람은 반응을 누를 수 없습니다. | ||
| """ | ||
| ) | ||
| @PostMapping("/questions/{questionId}/reactions") | ||
| public ResponseEntity<Map<String, Boolean>> toggleQuestionReaction( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long questionId | ||
| ) { | ||
| memberQuestionService.toggleQuestionReaction(userId, questionId); | ||
| return ResponseEntity.status(HttpStatus.OK).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "도움돼요 토글 API", | ||
| description = """ | ||
| 답변에 '도움돼요' 반응을 토글합니다. | ||
| 이미 반응을 누른 경우 취소되고, 누르지 않은 경우 반응이 추가됩니다. | ||
| 답변 작성자는 반응을 누를 수 없습니다. | ||
| """ | ||
| ) | ||
| @PostMapping("/answers/{answerId}/reactions") | ||
| public ResponseEntity<Map<String, Boolean>> toggleAnswerReaction( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long answerId | ||
| ) { | ||
| memberQuestionService.toggleAnswerReaction(userId, answerId); | ||
| return ResponseEntity.status(HttpStatus.OK).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation(summary = "질문 신고 API") | ||
| @PostMapping("/questions/{questionId}/report") | ||
| public ResponseEntity<Map<String, Boolean>> reportQuestion( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long questionId, | ||
| @RequestBody QuestionReportRequest request | ||
| ) { | ||
| memberQuestionService.reportQuestion(userId, questionId, request); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(Map.of("success", true)); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "질문 목록 조회 API", | ||
| description = """ | ||
| 특정 사용자의 질문 목록을 조회합니다. | ||
| tab: answered (답변 완료), unanswered (새질문) | ||
| page: 페이지 번호 (0부터 시작, 기본값 0) | ||
| size: 페이지 크기 (기본 10, 최대 100) | ||
| """ | ||
| ) | ||
| @GetMapping("/{memberId}/questions") | ||
| public ResponseEntity<QuestionsResponse> getQuestions( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId, | ||
| @PathVariable Long memberId, | ||
| @RequestParam(value = "tab", defaultValue = "answered") QuestionTab tab, | ||
| @RequestParam(value = "page", required = false) Integer page, | ||
| @RequestParam(value = "size", required = false) Integer size | ||
| ) { | ||
| QuestionsResponse response = memberQuestionService.getQuestions(userId, memberId, tab, page, size); | ||
| return ResponseEntity.status(HttpStatus.OK).body(response); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "답변 대기 중인 질문 개수 조회 API", | ||
| description = "현재 로그인한 사용자에게 달린 답변 대기 중인 질문의 개수를 조회합니다." | ||
| ) | ||
| @GetMapping("/me/questions/unanswered-count") | ||
| public ResponseEntity<UnansweredCountResponse> getUnansweredCount( | ||
| @Parameter(hidden = true) @AuthenticationPrincipal Long userId | ||
| ) { | ||
| UnansweredCountResponse response = memberQuestionService.getUnansweredCount(userId); | ||
| return ResponseEntity.status(HttpStatus.OK).body(response); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/sopt/makers/internal/member/converter/StringToQuestionTabConverter.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,14 @@ | ||
| package org.sopt.makers.internal.member.converter; | ||
|
|
||
| import org.sopt.makers.internal.member.domain.QuestionTab; | ||
| import org.springframework.core.convert.converter.Converter; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class StringToQuestionTabConverter implements Converter<String, QuestionTab> { | ||
|
|
||
| @Override | ||
| public QuestionTab convert(String source) { | ||
| return QuestionTab.from(source); | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/sopt/makers/internal/member/domain/AnswerReaction.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,42 @@ | ||
| package org.sopt.makers.internal.member.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.sopt.makers.internal.common.AuditingTimeEntity; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table( | ||
| name = "answer_reaction", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint( | ||
| name = "uk_answer_reaction_answer_member", | ||
| columnNames = {"answer_id", "member_id"} | ||
| ) | ||
| } | ||
| ) | ||
| public class AnswerReaction extends AuditingTimeEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "reaction_id") | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "answer_id", nullable = false) | ||
| private MemberAnswer answer; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "member_id", nullable = false) | ||
| private Member member; | ||
|
|
||
| @Builder | ||
| private AnswerReaction(MemberAnswer answer, Member member) { | ||
| this.answer = answer; | ||
| this.member = member; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/sopt/makers/internal/member/domain/MemberAnswer.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,41 @@ | ||
| package org.sopt.makers.internal.member.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.sopt.makers.internal.common.AuditingTimeEntity; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Builder | ||
| @Table(name = "member_answer") | ||
| public class MemberAnswer extends AuditingTimeEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "answer_id") | ||
| private Long id; | ||
|
|
||
| @OneToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "question_id", nullable = false, unique = true) | ||
| private MemberQuestion question; | ||
|
|
||
| @Column(columnDefinition = "TEXT", nullable = false, length = 2000) | ||
| private String content; | ||
|
|
||
| @Builder.Default | ||
| @OneToMany(mappedBy = "answer", cascade = CascadeType.REMOVE, orphanRemoval = true) | ||
| private List<AnswerReaction> reactions = new ArrayList<>(); | ||
|
|
||
| public void updateContent(String content) { | ||
| this.content = content; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 클래스는 호출이 안되고 있는 것 같은데, 어떤 용도로 쓰이는지 궁금합니다!