Repository navigation
[Feat/#319] 챗봇 추천 질문(FAQ) 관리 API 추가 #320
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
319354c
feat: 챗봇 추천 질문 테이블과 저장소 추가
sangrae2325 694f501
feat: 챗봇 추천 질문 관리자 API 추가
sangrae2325 9ab9225
feat: 챗봇 추천 질문 앱 조회 API 추가
sangrae2325 70cc61f
refactor: 챗봇 추천 질문 리뷰 반영
sangrae2325 d96b75b
refactor: 챗봇 추천 질문 도메인에 동등성 비교 추가
sangrae2325 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
39 changes: 39 additions & 0 deletions
39
api/admin-api/src/main/java/kr/ac/kookmin/stream/api/admin/welfare/chat/AdminChatFaqApi.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,39 @@ | ||
| package kr.ac.kookmin.stream.api.admin.welfare.chat; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import java.util.List; | ||
| import kr.ac.kookmin.stream.api.admin.AdminApiUser; | ||
| import kr.ac.kookmin.stream.api.admin.welfare.chat.request.AdminChatFaqWriteRequest; | ||
| import kr.ac.kookmin.stream.api.admin.welfare.chat.response.AdminChatFaqResponse; | ||
| import kr.ac.kookmin.stream.api.common.dto.ApiResponse; | ||
| import kr.ac.kookmin.stream.api.common.openapi.ApiErrorCode; | ||
| import kr.ac.kookmin.stream.common.CommonErrorCode; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatErrorCode; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
|
|
||
| /** | ||
| * 운영진 챗봇 추천 질문 API의 문서 명세. 구현은 {@link AdminChatFaqController}가 맡는다. | ||
| */ | ||
| @Tag(name = "챗봇 추천 질문 관리", description = "운영진 챗봇 추천 질문(FAQ) 조회·등록·수정·삭제") | ||
| public interface AdminChatFaqApi { | ||
|
|
||
| @Operation(summary = "추천 질문 목록 조회", description = "등록 순서대로 전부 조회한다. 최대 " + ChatFaq.MAX_COUNT + "개라 페이지로 자르지 않는다.") | ||
| ApiResponse<List<AdminChatFaqResponse>> getFaqs(AdminApiUser apiUser); | ||
|
|
||
| @Operation(summary = "추천 질문 등록", | ||
| description = "질문을 등록하고 목록 맨 뒤에 붙인다. 이미 " + ChatFaq.MAX_COUNT + "개면 거부한다. " | ||
| + "다른 운영진과 동시에 등록해 부딪히면 한쪽만 들어가고 다른 쪽은 CHAT_FAQ_ADD_CONFLICT를 받는다.") | ||
| @ApiErrorCode(type = CommonErrorCode.class, codes = {"INVALID_INPUT"}) | ||
| @ApiErrorCode(type = ChatErrorCode.class, codes = {"CHAT_FAQ_LIMIT_EXCEEDED", "CHAT_FAQ_ADD_CONFLICT"}) | ||
| ApiResponse<Void> createFaq(AdminApiUser apiUser, AdminChatFaqWriteRequest request); | ||
|
|
||
| @Operation(summary = "추천 질문 수정", description = "질문 문구를 바꾼다. 목록 순서는 그대로다.") | ||
| @ApiErrorCode(type = CommonErrorCode.class, codes = {"INVALID_INPUT"}) | ||
| @ApiErrorCode(type = ChatErrorCode.class, codes = {"CHAT_FAQ_NOT_FOUND"}) | ||
| ApiResponse<Void> updateFaq(AdminApiUser apiUser, Long faqId, AdminChatFaqWriteRequest request); | ||
|
|
||
| @Operation(summary = "추천 질문 삭제", description = "질문을 삭제한다. 데이터는 남기고 목록과 앱에서만 보이지 않게 한다.") | ||
| @ApiErrorCode(type = ChatErrorCode.class, codes = {"CHAT_FAQ_NOT_FOUND"}) | ||
| ApiResponse<Void> deleteFaq(AdminApiUser apiUser, Long faqId); | ||
| } |
59 changes: 59 additions & 0 deletions
59
...api/src/main/java/kr/ac/kookmin/stream/api/admin/welfare/chat/AdminChatFaqController.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,59 @@ | ||
| package kr.ac.kookmin.stream.api.admin.welfare.chat; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import java.util.List; | ||
| import kr.ac.kookmin.stream.api.admin.AdminApiUser; | ||
| import kr.ac.kookmin.stream.api.admin.welfare.chat.request.AdminChatFaqWriteRequest; | ||
| import kr.ac.kookmin.stream.api.admin.welfare.chat.response.AdminChatFaqResponse; | ||
| import kr.ac.kookmin.stream.api.common.dto.ApiResponse; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.service.AdminChatFaqService; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.service.ChatFaqService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/v1/admin/chat/faqs") | ||
| @RequiredArgsConstructor | ||
| public class AdminChatFaqController implements AdminChatFaqApi { | ||
|
|
||
| private final AdminChatFaqService adminChatFaqService; | ||
| private final ChatFaqService chatFaqService; | ||
|
|
||
| @Override | ||
| @GetMapping | ||
| public ApiResponse<List<AdminChatFaqResponse>> getFaqs(AdminApiUser apiUser) { | ||
| return ApiResponse.success(chatFaqService.getFaqs().stream().map(AdminChatFaqResponse::from).toList()); | ||
| } | ||
|
|
||
| @Override | ||
| @PostMapping | ||
| public ApiResponse<Void> createFaq(AdminApiUser apiUser, @Valid @RequestBody AdminChatFaqWriteRequest request) { | ||
| adminChatFaqService.create(request.question()); | ||
| return ApiResponse.success(); | ||
| } | ||
|
|
||
| @Override | ||
| @PutMapping("/{faqId}") | ||
| public ApiResponse<Void> updateFaq( | ||
| AdminApiUser apiUser, | ||
| @PathVariable Long faqId, | ||
| @Valid @RequestBody AdminChatFaqWriteRequest request | ||
| ) { | ||
| adminChatFaqService.updateQuestion(faqId, request.question()); | ||
| return ApiResponse.success(); | ||
| } | ||
|
|
||
| @Override | ||
| @DeleteMapping("/{faqId}") | ||
| public ApiResponse<Void> deleteFaq(AdminApiUser apiUser, @PathVariable Long faqId) { | ||
| adminChatFaqService.delete(faqId); | ||
| return ApiResponse.success(); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...in/java/kr/ac/kookmin/stream/api/admin/welfare/chat/request/AdminChatFaqWriteRequest.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 kr.ac.kookmin.stream.api.admin.welfare.chat.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| /** | ||
| * @param question 누르면 그대로 챗봇에 가므로 챗봇 질문 상한(500자)보다 짧아야 한다 | ||
| */ | ||
| public record AdminChatFaqWriteRequest( | ||
|
|
||
| @Schema(description = "추천 질문", example = "사물함 신청은 어떻게 하나요?") | ||
| @NotBlank(message = "질문을 입력해 주세요.") | ||
| @Size(max = 100, message = "질문은 100자까지 입력할 수 있습니다.") | ||
| String question | ||
| ) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
.../main/java/kr/ac/kookmin/stream/api/admin/welfare/chat/response/AdminChatFaqResponse.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,10 @@ | ||
| package kr.ac.kookmin.stream.api.admin.welfare.chat.response; | ||
|
|
||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
|
|
||
| public record AdminChatFaqResponse(Long faqId, String question) { | ||
|
|
||
| public static AdminChatFaqResponse from(ChatFaq faq) { | ||
| return new AdminChatFaqResponse(faq.getId(), faq.getQuestion()); | ||
| } | ||
| } |
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
10 changes: 10 additions & 0 deletions
10
...api/src/main/java/kr/ac/kookmin/stream/api/app/welfare/chat/response/ChatFaqResponse.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,10 @@ | ||
| package kr.ac.kookmin.stream.api.app.welfare.chat.response; | ||
|
|
||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
|
|
||
| public record ChatFaqResponse(Long faqId, String question) { | ||
|
|
||
| public static ChatFaqResponse from(ChatFaq faq) { | ||
| return new ChatFaqResponse(faq.getId(), faq.getQuestion()); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
.../welfare/src/main/java/kr/ac/kookmin/stream/welfare/domain/chat/domain/ChatErrorCode.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,20 @@ | ||
| package kr.ac.kookmin.stream.welfare.domain.chat.domain; | ||
|
|
||
| import kr.ac.kookmin.stream.common.ErrorCode; | ||
| import kr.ac.kookmin.stream.common.ErrorStatus; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| @Getter | ||
| @Accessors(fluent = true) | ||
| @AllArgsConstructor | ||
| public enum ChatErrorCode implements ErrorCode { | ||
|
|
||
| CHAT_FAQ_NOT_FOUND(ErrorStatus.NOT_FOUND, "존재하지 않는 추천 질문입니다."), | ||
| CHAT_FAQ_LIMIT_EXCEEDED(ErrorStatus.BAD_REQUEST, "추천 질문은 " + ChatFaq.MAX_COUNT + "개까지 등록할 수 있습니다."), | ||
| CHAT_FAQ_ADD_CONFLICT(ErrorStatus.CONFLICT, "다른 운영진이 동시에 질문을 추가해 저장하지 못했습니다. 새로고침한 뒤 다시 시도해 주세요."); | ||
|
|
||
| private final int status; | ||
| private final String message; | ||
| } |
44 changes: 44 additions & 0 deletions
44
...domain/welfare/src/main/java/kr/ac/kookmin/stream/welfare/domain/chat/domain/ChatFaq.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,44 @@ | ||
| package kr.ac.kookmin.stream.welfare.domain.chat.domain; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import kr.ac.kookmin.stream.common.BusinessException; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * {@code slot}은 개수 상한을 DB 유니크로 지키려는 자리라 노출 순서와 무관하다. 순서로 겸하면 삭제마다 뒤를 당겨야 하고, | ||
| * 동시에 지우면 빈칸이 남아 상한까지 채우지 못하게 된다. | ||
| */ | ||
| @Getter | ||
| @EqualsAndHashCode | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class ChatFaq { | ||
|
|
||
| public static final int MAX_COUNT = 5; | ||
|
|
||
| private Long id; | ||
| private String question; | ||
| private int slot; | ||
|
sangrae2325 marked this conversation as resolved.
Resolved
|
||
|
|
||
| public static ChatFaq of(Long id, String question, int slot) { | ||
| return new ChatFaq(id, question, slot); | ||
| } | ||
|
|
||
| public static ChatFaq create(String question, List<ChatFaq> activeFaqs) { | ||
| Set<Integer> usedSlots = activeFaqs.stream().map(ChatFaq::getSlot).collect(Collectors.toSet()); | ||
| int slot = IntStream.range(0, MAX_COUNT) | ||
| .filter(candidate -> !usedSlots.contains(candidate)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new BusinessException(ChatErrorCode.CHAT_FAQ_LIMIT_EXCEEDED)); | ||
| return new ChatFaq(null, question, slot); | ||
| } | ||
|
|
||
| public void changeQuestion(String question) { | ||
| this.question = question; | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
.../src/main/java/kr/ac/kookmin/stream/welfare/domain/chat/repository/ChatFaqRepository.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 kr.ac.kookmin.stream.welfare.domain.chat.repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
|
|
||
| public interface ChatFaqRepository { | ||
|
|
||
| /** 등록 순서대로. */ | ||
| List<ChatFaq> findAll(); | ||
|
|
||
| Optional<ChatFaq> findById(Long id); | ||
|
|
||
| /** 동시 추가로 같은 자리를 잡았으면 {@code CHAT_FAQ_ADD_CONFLICT}를 던진다. */ | ||
| ChatFaq save(ChatFaq faq); | ||
|
|
||
| boolean delete(Long id); | ||
| } |
13 changes: 13 additions & 0 deletions
13
...e/src/main/java/kr/ac/kookmin/stream/welfare/domain/chat/service/AdminChatFaqService.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,13 @@ | ||
| package kr.ac.kookmin.stream.welfare.domain.chat.service; | ||
|
|
||
| /** | ||
| * 운영진용 추천 질문 서비스. 등록·수정·삭제를 맡고, 목록 조회는 운영진도 {@link ChatFaqService}를 쓴다. | ||
| */ | ||
| public interface AdminChatFaqService { | ||
|
|
||
| void create(String question); | ||
|
|
||
| void updateQuestion(Long id, String question); | ||
|
|
||
| void delete(Long id); | ||
| } |
10 changes: 10 additions & 0 deletions
10
...elfare/src/main/java/kr/ac/kookmin/stream/welfare/domain/chat/service/ChatFaqService.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,10 @@ | ||
| package kr.ac.kookmin.stream.welfare.domain.chat.service; | ||
|
|
||
| import java.util.List; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
|
|
||
| public interface ChatFaqService { | ||
|
|
||
| /** 등록 순서대로. */ | ||
| List<ChatFaq> getFaqs(); | ||
| } |
40 changes: 40 additions & 0 deletions
40
...n/java/kr/ac/kookmin/stream/welfare/domain/chat/service/impl/AdminChatFaqServiceImpl.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,40 @@ | ||
| package kr.ac.kookmin.stream.welfare.domain.chat.service.impl; | ||
|
|
||
| import kr.ac.kookmin.stream.common.BusinessException; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatErrorCode; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.repository.ChatFaqRepository; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.service.AdminChatFaqService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| class AdminChatFaqServiceImpl implements AdminChatFaqService { | ||
|
|
||
| private final ChatFaqRepository chatFaqRepository; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void create(String question) { | ||
| chatFaqRepository.save(ChatFaq.create(question, chatFaqRepository.findAll())); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void updateQuestion(Long id, String question) { | ||
| ChatFaq faq = chatFaqRepository.findById(id) | ||
| .orElseThrow(() -> new BusinessException(ChatErrorCode.CHAT_FAQ_NOT_FOUND)); | ||
| faq.changeQuestion(question); | ||
| chatFaqRepository.save(faq); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void delete(Long id) { | ||
| if (!chatFaqRepository.delete(id)) { | ||
| throw new BusinessException(ChatErrorCode.CHAT_FAQ_NOT_FOUND); | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...c/main/java/kr/ac/kookmin/stream/welfare/domain/chat/service/impl/ChatFaqServiceImpl.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,20 @@ | ||
| package kr.ac.kookmin.stream.welfare.domain.chat.service.impl; | ||
|
|
||
| import java.util.List; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.domain.ChatFaq; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.repository.ChatFaqRepository; | ||
| import kr.ac.kookmin.stream.welfare.domain.chat.service.ChatFaqService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| class ChatFaqServiceImpl implements ChatFaqService { | ||
|
|
||
| private final ChatFaqRepository chatFaqRepository; | ||
|
|
||
| @Override | ||
| public List<ChatFaq> getFaqs() { | ||
| return chatFaqRepository.findAll(); | ||
| } | ||
| } |
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.