diff --git a/src/main/generated/briefing/briefing/domain/QBriefing.java b/src/main/generated/briefing/briefing/domain/QBriefing.java index 3a93bce..1169e07 100644 --- a/src/main/generated/briefing/briefing/domain/QBriefing.java +++ b/src/main/generated/briefing/briefing/domain/QBriefing.java @@ -29,7 +29,7 @@ public class QBriefing extends EntityPathBase { //inherited public final DateTimePath createdAt = _super.createdAt; - public final EnumPath gptModel = createEnum("gptModel", briefing.chatting.domain.GptModel.class); + public final EnumPath gptModel = createEnum("gptModel", briefing.common.enums.GptModel.class); public final NumberPath id = createNumber("id", Long.class); diff --git a/src/main/generated/briefing/chatting/domain/QChatting.java b/src/main/generated/briefing/chatting/domain/QChatting.java deleted file mode 100644 index 0a9ccae..0000000 --- a/src/main/generated/briefing/chatting/domain/QChatting.java +++ /dev/null @@ -1,50 +0,0 @@ -package briefing.chatting.domain; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QChatting is a Querydsl query type for Chatting - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QChatting extends EntityPathBase { - - private static final long serialVersionUID = -1751649618L; - - public static final QChatting chatting = new QChatting("chatting"); - - public final briefing.base.QBaseDateTimeEntity _super = new briefing.base.QBaseDateTimeEntity(this); - - //inherited - public final DateTimePath createdAt = _super.createdAt; - - public final NumberPath id = createNumber("id", Long.class); - - public final ListPath messages = this.createList("messages", Message.class, QMessage.class, PathInits.DIRECT2); - - public final StringPath title = createString("title"); - - //inherited - public final DateTimePath updatedAt = _super.updatedAt; - - public QChatting(String variable) { - super(Chatting.class, forVariable(variable)); - } - - public QChatting(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QChatting(PathMetadata metadata) { - super(Chatting.class, metadata); - } - -} - diff --git a/src/main/generated/briefing/chatting/domain/QMessage.java b/src/main/generated/briefing/chatting/domain/QMessage.java deleted file mode 100644 index d9196c9..0000000 --- a/src/main/generated/briefing/chatting/domain/QMessage.java +++ /dev/null @@ -1,57 +0,0 @@ -package briefing.chatting.domain; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QMessage is a Querydsl query type for Message - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QMessage extends EntityPathBase { - - private static final long serialVersionUID = -1226188129L; - - private static final PathInits INITS = PathInits.DIRECT2; - - public static final QMessage message = new QMessage("message"); - - public final QChatting chatting; - - public final StringPath content = createString("content"); - - public final DateTimePath createdAt = createDateTime("createdAt", java.time.LocalDateTime.class); - - public final NumberPath id = createNumber("id", Long.class); - - public final EnumPath role = createEnum("role", MessageRole.class); - - public QMessage(String variable) { - this(Message.class, forVariable(variable), INITS); - } - - public QMessage(Path path) { - this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); - } - - public QMessage(PathMetadata metadata) { - this(metadata, PathInits.getFor(metadata, INITS)); - } - - public QMessage(PathMetadata metadata, PathInits inits) { - this(Message.class, metadata, inits); - } - - public QMessage(Class type, PathMetadata metadata, PathInits inits) { - super(type, metadata, inits); - this.chatting = inits.isInitialized("chatting") ? new QChatting(forProperty("chatting")) : null; - } - -} - diff --git a/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java b/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java index 45570fc..3daea3b 100644 --- a/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java +++ b/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java @@ -6,7 +6,7 @@ import briefing.briefing.domain.BriefingType; import briefing.briefing.domain.TimeOfDay; -import briefing.chatting.domain.GptModel; +import briefing.common.enums.GptModel; import lombok.Getter; public class BriefingRequestDTO { diff --git a/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java b/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java index 91e5e43..699a329 100644 --- a/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java +++ b/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java @@ -6,7 +6,7 @@ import briefing.briefing.domain.BriefingType; import briefing.briefing.domain.TimeOfDay; -import briefing.chatting.domain.GptModel; +import briefing.common.enums.GptModel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/briefing/briefing/domain/Briefing.java b/src/main/java/briefing/briefing/domain/Briefing.java index 4ed9c20..fed9e6e 100644 --- a/src/main/java/briefing/briefing/domain/Briefing.java +++ b/src/main/java/briefing/briefing/domain/Briefing.java @@ -7,7 +7,7 @@ import jakarta.persistence.*; import briefing.base.BaseDateTimeEntity; -import briefing.chatting.domain.GptModel; +import briefing.common.enums.GptModel; import lombok.*; @Entity diff --git a/src/main/java/briefing/briefing/domain/repository/BriefingCustomRepositoryImpl.java b/src/main/java/briefing/briefing/domain/repository/BriefingCustomRepositoryImpl.java index 5d5bef5..92f48e5 100644 --- a/src/main/java/briefing/briefing/domain/repository/BriefingCustomRepositoryImpl.java +++ b/src/main/java/briefing/briefing/domain/repository/BriefingCustomRepositoryImpl.java @@ -2,9 +2,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; import org.springframework.stereotype.Repository; @@ -79,17 +77,23 @@ public List findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) { .where(briefing.type.eq(type)) .groupBy(briefing) .orderBy(date.desc(), briefing.ranks.asc()) - .limit(10) + .limit(20) .fetch(); - return results.stream() - .map( - tuple -> { - Briefing b = tuple.get(briefing); - b.setScrapCount(Math.toIntExact(tuple.get(scrap.count()))); - return b; - }) - .collect(Collectors.toCollection(ArrayList::new)); + List briefingList = + results.stream() + .map( + tuple -> { + Briefing b = tuple.get(briefing); + b.setScrapCount(Math.toIntExact(tuple.get(scrap.count()))); + return b; + }) + .collect(Collectors.toCollection(ArrayList::new)); + + Map briefingMap = new HashMap<>(); + briefingList.forEach(candidate -> briefingMap.putIfAbsent(candidate.getRanks(), candidate)); + + return briefingMap.values().stream().toList(); } @Override diff --git a/src/main/java/briefing/chatting/api/ChattingApi.java b/src/main/java/briefing/chatting/api/ChattingApi.java deleted file mode 100644 index d2a7e66..0000000 --- a/src/main/java/briefing/chatting/api/ChattingApi.java +++ /dev/null @@ -1,60 +0,0 @@ -package briefing.chatting.api; - -import java.util.List; - -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.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import briefing.chatting.application.ChattingCommandService; -import briefing.chatting.application.ChattingQueryService; -import briefing.chatting.application.dto.*; -import briefing.common.response.CommonResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; - -@Tag(name = "04-Chatting \uD83D\uDCE8", description = "채팅 관련 API") -@RestController -@RequestMapping("/chattings") -@RequiredArgsConstructor -public class ChattingApi { - - private final ChattingQueryService chattingQueryService; - private final ChattingCommandService chattingCommandService; - - @GetMapping - public CommonResponse findChattings( - @RequestParam final List ids) { - return CommonResponse.onSuccess( - ChattingConverter.toChattingListResponseDTO( - chattingQueryService.findChattings(ids))); - } - - @GetMapping("/{id}") - public CommonResponse findChatting( - @PathVariable final Long id) { - return CommonResponse.onSuccess( - ChattingConverter.toChattingDetailResponseDTO( - chattingQueryService.findChatting(id))); - } - - @PostMapping - public CommonResponse createChatting() { - return CommonResponse.onSuccess( - ChattingConverter.toChattingCreateResponseDTO( - chattingCommandService.createChatting())); - } - - @PostMapping("/{id}") - public CommonResponse requestAnswer( - @PathVariable final Long id, - @RequestBody final ChattingRequest.AnswerRequestDTO request) { - return CommonResponse.onSuccess( - ChattingConverter.toAnswerResponseDTO( - chattingCommandService.requestAnswer(id, request))); - } -} diff --git a/src/main/java/briefing/chatting/api/ChattingConverter.java b/src/main/java/briefing/chatting/api/ChattingConverter.java deleted file mode 100644 index d7c6aa5..0000000 --- a/src/main/java/briefing/chatting/api/ChattingConverter.java +++ /dev/null @@ -1,80 +0,0 @@ -package briefing.chatting.api; - -import java.util.List; -import java.util.Optional; - -import briefing.chatting.application.dto.ChattingRequest; -import briefing.chatting.application.dto.ChattingResponse; -import briefing.chatting.domain.Chatting; -import briefing.chatting.domain.Message; - -public class ChattingConverter { - - public static ChattingResponse.AnswerResponseDTO toAnswerResponseDTO(final Message message) { - return ChattingResponse.AnswerResponseDTO.builder() - .id(message.getId()) - .role(message.getRole()) - .content(message.getContent()) - .createdAt(message.getCreatedAt()) - .build(); - } - - public static ChattingResponse.MessageResponseDTO toMessageResponseDTO(final Message message) { - return ChattingResponse.MessageResponseDTO.builder() - .id(message.getId()) - .role(message.getRole()) - .content(message.getContent()) - .createdAt(message.getCreatedAt()) - .build(); - } - - public static ChattingResponse.ChattingDetailResponseDTO toChattingDetailResponseDTO( - Chatting chatting) { - List messageResponseDTOList = - chatting.getMessages().stream() - .map(ChattingConverter::toMessageResponseDTO) - .toList(); - return ChattingResponse.ChattingDetailResponseDTO.builder() - .id(chatting.getId()) - .title(chatting.getTitle()) - .build(); - } - - public static ChattingResponse.ChattingResponseDTO toChattingResponseDTO(Chatting chatting) { - return ChattingResponse.ChattingResponseDTO.builder() - .id(chatting.getId()) - .title(chatting.getTitle()) - .createdAt(chatting.getCreatedAt()) - .build(); - } - - public static ChattingResponse.ChattingListResponseDTO toChattingListResponseDTO( - final List chattingList) { - - List chattingResponseDTOList = - chattingList.stream().map(ChattingConverter::toChattingResponseDTO).toList(); - return ChattingResponse.ChattingListResponseDTO.builder() - .chattings(chattingResponseDTOList) - .build(); - } - - public static ChattingResponse.ChattingCreateResponseDTO toChattingCreateResponseDTO( - Chatting chatting) { - return ChattingResponse.ChattingCreateResponseDTO.builder() - .id(chatting.getId()) - .createdAt(chatting.getCreatedAt()) - .build(); - } - - public static List getMessagesExcludeLast( - List messages) { - return messages.subList(0, messages.size() - 1); - } - - public static Optional getLastMessage( - List messages) { - if (messages.isEmpty()) return Optional.empty(); - final int lastIndex = messages.size() - 1; - return Optional.of(messages.get(lastIndex)); - } -} diff --git a/src/main/java/briefing/chatting/application/ChatGptClient.java b/src/main/java/briefing/chatting/application/ChatGptClient.java deleted file mode 100644 index 7e45895..0000000 --- a/src/main/java/briefing/chatting/application/ChatGptClient.java +++ /dev/null @@ -1,86 +0,0 @@ -package briefing.chatting.application; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - -import briefing.chatting.application.ChatGptClient.GptAnswerResponse.Choice.ChoiceMessage; -import briefing.chatting.application.dto.ChattingRequest; -import briefing.chatting.domain.Chatting; -import briefing.chatting.domain.GptModel; -import briefing.chatting.domain.Message; -import briefing.chatting.domain.MessageRole; -import lombok.RequiredArgsConstructor; - -@Component -@RequiredArgsConstructor -public class ChatGptClient { - - private static final float TEMPERATURE = 1; - - private final RestTemplate restTemplate; - - @Value("${openai.url.chat}") - private String chatUrl; - - @Value("${openai.token}") - private String token; - - public Message requestAnswer( - final Chatting chatting, final ChattingRequest.AnswerRequestDTO request) { - final HttpEntity requestEntity = generateRequestEntity(request); - - final GptAnswerResponse response = - restTemplate - .exchange(chatUrl, HttpMethod.POST, requestEntity, GptAnswerResponse.class) - .getBody(); - - return new Message(chatting, response.getRole(), response.getContent()); - } - - private HttpEntity generateRequestEntity( - final ChattingRequest.AnswerRequestDTO request) { - final HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.setBearerAuth(token); - - final GptAnswerRequest requestBody = GptAnswerRequest.from(request, TEMPERATURE); - - return new HttpEntity<>(requestBody, headers); - } - - record GptAnswerRequest( - GptModel model, float temperature, List messages) { - - public static GptAnswerRequest from( - final ChattingRequest.AnswerRequestDTO request, final float temperature) { - return new GptAnswerRequest(request.getModel(), temperature, request.getMessages()); - } - } - - record GptAnswerResponse(List choices) { - - public MessageRole getRole() { - return getAnswer().role(); - } - - public String getContent() { - return getAnswer().content(); - } - - private ChoiceMessage getAnswer() { - return choices.get(0).message(); - } - - record Choice(ChoiceMessage message) { - - record ChoiceMessage(MessageRole role, String content) {} - } - } -} diff --git a/src/main/java/briefing/chatting/application/ChattingCommandService.java b/src/main/java/briefing/chatting/application/ChattingCommandService.java deleted file mode 100644 index 452702a..0000000 --- a/src/main/java/briefing/chatting/application/ChattingCommandService.java +++ /dev/null @@ -1,92 +0,0 @@ -package briefing.chatting.application; - -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import briefing.chatting.api.ChattingConverter; -import briefing.chatting.application.dto.*; -import briefing.chatting.domain.Chatting; -import briefing.chatting.domain.Message; -import briefing.chatting.domain.repository.ChattingRepository; -import briefing.chatting.domain.repository.MessageRepository; -import briefing.exception.ErrorCode; -import briefing.exception.handler.ChattingException; -import lombok.RequiredArgsConstructor; - -@Service -@Transactional -@RequiredArgsConstructor -public class ChattingCommandService { - - private final ChattingRepository chattingRepository; - private final MessageRepository messageRepository; - private final ChatGptClient chatGptClient; - - public Chatting createChatting() { - final Chatting chatting = chattingRepository.save(new Chatting()); - return chatting; - } - - public Message requestAnswer(final Long id, final ChattingRequest.AnswerRequestDTO request) { - final Chatting chatting = - chattingRepository - .findById(id) - .orElseThrow(() -> new ChattingException(ErrorCode.NOT_FOUND_CHATTING)); - - final ChattingRequest.MessageRequestDTO lastMessage = - ChattingConverter.getLastMessage(request.getMessages()) - .orElseThrow(() -> new ChattingException(ErrorCode.LAST_MESSAGE_NOT_EXIST)); - validateLastMessage(lastMessage); - - final Message question = - Message.builder() - .chatting(chatting) - .role(lastMessage.getRole()) - .content(lastMessage.getContent()) - .build(); - final Message answer = chatGptClient.requestAnswer(chatting, request); - - if (chatting.isNotInitialized()) { - initChatting(request, chatting, question); - } - messageRepository.save(question); - messageRepository.save(answer); - - return answer; - } - - private void initChatting( - final ChattingRequest.AnswerRequestDTO request, - final Chatting chatting, - final Message question) { - chatting.updateTitle(question.getContent()); - - final List messages = - ChattingConverter.getMessagesExcludeLast(request.getMessages()).stream() - .map( - message -> - Message.builder() - .chatting(chatting) - .role(message.getRole()) - .content(message.getContent()) - .build()) - .toList(); - - messageRepository.saveAll(messages); - } - - private void validateLastMessage(final ChattingRequest.MessageRequestDTO questionRequest) { - if (questionRequest.getRole().isNotUser()) { - throw new ChattingException(ErrorCode.BAD_LAST_MESSAGE_ROLE); - } - if (isInvalidContent(questionRequest)) { - throw new ChattingException(ErrorCode.CAN_NOT_EMPTY_CONTENT); - } - } - - private boolean isInvalidContent(final ChattingRequest.MessageRequestDTO message) { - return message.getContent() == null || message.getContent().isBlank(); - } -} diff --git a/src/main/java/briefing/chatting/application/ChattingQueryService.java b/src/main/java/briefing/chatting/application/ChattingQueryService.java deleted file mode 100644 index 0ea741f..0000000 --- a/src/main/java/briefing/chatting/application/ChattingQueryService.java +++ /dev/null @@ -1,35 +0,0 @@ -package briefing.chatting.application; - -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import briefing.chatting.domain.Chatting; -import briefing.chatting.domain.repository.ChattingRepository; -import briefing.exception.ErrorCode; -import briefing.exception.handler.ChattingException; -import lombok.RequiredArgsConstructor; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class ChattingQueryService { - - private final ChattingRepository chattingRepository; - - public List findChattings(final List ids) { - final List chattings = chattingRepository.findAllById(ids); - - return chattings; - } - - public Chatting findChatting(final Long id) { - final Chatting chatting = - chattingRepository - .findById(id) - .orElseThrow(() -> new ChattingException(ErrorCode.NOT_FOUND_CHATTING)); - - return chatting; - } -} diff --git a/src/main/java/briefing/chatting/application/dto/ChattingRequest.java b/src/main/java/briefing/chatting/application/dto/ChattingRequest.java deleted file mode 100644 index 4fe7b2d..0000000 --- a/src/main/java/briefing/chatting/application/dto/ChattingRequest.java +++ /dev/null @@ -1,22 +0,0 @@ -package briefing.chatting.application.dto; - -import java.util.List; - -import briefing.chatting.domain.GptModel; -import briefing.chatting.domain.MessageRole; -import lombok.Getter; - -public class ChattingRequest { - - @Getter - public static class MessageRequestDTO { - MessageRole role; - String content; - } - - @Getter - public static class AnswerRequestDTO { - GptModel model; - List messages; - } -} diff --git a/src/main/java/briefing/chatting/application/dto/ChattingResponse.java b/src/main/java/briefing/chatting/application/dto/ChattingResponse.java deleted file mode 100644 index 4aaf743..0000000 --- a/src/main/java/briefing/chatting/application/dto/ChattingResponse.java +++ /dev/null @@ -1,72 +0,0 @@ -package briefing.chatting.application.dto; - -import java.time.LocalDateTime; -import java.util.List; - -import briefing.chatting.domain.MessageRole; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -public class ChattingResponse { - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class AnswerResponseDTO { - Long id; - MessageRole role; - String content; - LocalDateTime createdAt; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class MessageResponseDTO { - Long id; - MessageRole role; - String content; - LocalDateTime createdAt; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class ChattingDetailResponseDTO { - Long id; - String title; - List messages; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class ChattingResponseDTO { - Long id; - String title; - LocalDateTime createdAt; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class ChattingListResponseDTO { - List chattings; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class ChattingCreateResponseDTO { - Long id; - LocalDateTime createdAt; - } -} diff --git a/src/main/java/briefing/chatting/domain/Chatting.java b/src/main/java/briefing/chatting/domain/Chatting.java deleted file mode 100644 index ed886dd..0000000 --- a/src/main/java/briefing/chatting/domain/Chatting.java +++ /dev/null @@ -1,47 +0,0 @@ -package briefing.chatting.domain; - -import java.util.List; - -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; - -import briefing.base.BaseDateTimeEntity; -import lombok.Getter; - -@Entity -@Getter -public class Chatting extends BaseDateTimeEntity { - - private static final int LIMIT_TITLE_LENGTH = 20; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - private String title; - - @OneToMany(mappedBy = "chatting", fetch = FetchType.LAZY) - private List messages; - - public Chatting() {} - - public boolean isNotInitialized() { - return title == null || title.isBlank(); - } - - public void updateTitle(final String content) { - this.title = convertToTitle(content); - } - - private String convertToTitle(final String content) { - if (content.length() > LIMIT_TITLE_LENGTH) { - final String substring = content.substring(0, LIMIT_TITLE_LENGTH - 3); - return substring + "..."; - } - return content; - } -} diff --git a/src/main/java/briefing/chatting/domain/Message.java b/src/main/java/briefing/chatting/domain/Message.java deleted file mode 100644 index 599da4b..0000000 --- a/src/main/java/briefing/chatting/domain/Message.java +++ /dev/null @@ -1,53 +0,0 @@ -package briefing.chatting.domain; - -import java.time.LocalDateTime; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; - -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import lombok.*; - -@Entity -@EntityListeners(AuditingEntityListener.class) -@Getter -@Builder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -public class Message { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(nullable = false) - private Chatting chatting; - - @Enumerated(EnumType.STRING) - private MessageRole role; - - @Column(nullable = false, length = 1024) - private String content; - - @CreatedDate - @Column(updatable = false) - private LocalDateTime createdAt; - - public Message(final Chatting chatting, final MessageRole role, final String content) { - this.chatting = chatting; - this.role = role; - this.content = content; - } -} diff --git a/src/main/java/briefing/chatting/domain/MessageRole.java b/src/main/java/briefing/chatting/domain/MessageRole.java deleted file mode 100644 index 34e79ce..0000000 --- a/src/main/java/briefing/chatting/domain/MessageRole.java +++ /dev/null @@ -1,33 +0,0 @@ -package briefing.chatting.domain; - -import java.util.Arrays; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import briefing.exception.ErrorCode; -import briefing.exception.handler.ChattingException; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum MessageRole { - SYSTEM("system"), - ASSISTANT("assistant"), - USER("user"); - - @JsonValue private final String value; - - @JsonCreator - public static MessageRole from(final String role) { - return Arrays.stream(values()) - .filter(value -> value.getValue().equals(role)) - .findAny() - .orElseThrow(() -> new ChattingException(ErrorCode.NOT_FOUND_ROLE)); - } - - public boolean isNotUser() { - return !this.equals(USER); - } -} diff --git a/src/main/java/briefing/chatting/domain/repository/ChattingRepository.java b/src/main/java/briefing/chatting/domain/repository/ChattingRepository.java deleted file mode 100644 index cfa85d2..0000000 --- a/src/main/java/briefing/chatting/domain/repository/ChattingRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package briefing.chatting.domain.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import briefing.chatting.domain.Chatting; - -@Repository -public interface ChattingRepository extends JpaRepository {} diff --git a/src/main/java/briefing/chatting/domain/repository/MessageRepository.java b/src/main/java/briefing/chatting/domain/repository/MessageRepository.java deleted file mode 100644 index 6f82ee0..0000000 --- a/src/main/java/briefing/chatting/domain/repository/MessageRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package briefing.chatting.domain.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import briefing.chatting.domain.Message; - -@Repository -public interface MessageRepository extends JpaRepository {} diff --git a/src/main/java/briefing/chatting/domain/GptModel.java b/src/main/java/briefing/common/enums/GptModel.java similarity index 95% rename from src/main/java/briefing/chatting/domain/GptModel.java rename to src/main/java/briefing/common/enums/GptModel.java index 56c8e12..0c0624a 100644 --- a/src/main/java/briefing/chatting/domain/GptModel.java +++ b/src/main/java/briefing/common/enums/GptModel.java @@ -1,4 +1,4 @@ -package briefing.chatting.domain; +package briefing.common.enums; import java.util.Arrays; diff --git a/src/main/java/briefing/config/GlobalWebConfig.java b/src/main/java/briefing/config/GlobalWebConfig.java index 50466fe..fd5e808 100644 --- a/src/main/java/briefing/config/GlobalWebConfig.java +++ b/src/main/java/briefing/config/GlobalWebConfig.java @@ -27,7 +27,6 @@ public void addArgumentResolvers(List resolverLis public void addFormatters(final FormatterRegistry registry) { registry.addConverter(new BriefingTypeRequestConverter()); registry.addConverter(new GptModelRequestConverter()); - registry.addConverter(new MessageRoleRequestConverter()); registry.addConverter(new SocialTypeRequestConverter()); registry.addConverter(new TimeOfDayConverter()); registry.addConverter(new APIVersionRequestConverter()); diff --git a/src/main/java/briefing/converter/GptModelRequestConverter.java b/src/main/java/briefing/converter/GptModelRequestConverter.java index 32fd44b..1636b7a 100644 --- a/src/main/java/briefing/converter/GptModelRequestConverter.java +++ b/src/main/java/briefing/converter/GptModelRequestConverter.java @@ -2,7 +2,7 @@ import org.springframework.core.convert.converter.Converter; -import briefing.chatting.domain.GptModel; +import briefing.common.enums.GptModel; import lombok.NonNull; public class GptModelRequestConverter implements Converter { diff --git a/src/main/java/briefing/converter/MessageRoleRequestConverter.java b/src/main/java/briefing/converter/MessageRoleRequestConverter.java deleted file mode 100644 index 55482fc..0000000 --- a/src/main/java/briefing/converter/MessageRoleRequestConverter.java +++ /dev/null @@ -1,14 +0,0 @@ -package briefing.converter; - -import org.springframework.core.convert.converter.Converter; - -import briefing.chatting.domain.MessageRole; -import lombok.NonNull; - -public class MessageRoleRequestConverter implements Converter { - - @Override - public MessageRole convert(@NonNull final String role) { - return MessageRole.from(role); - } -} diff --git a/src/main/java/briefing/scrap/application/dto/ScrapResponse.java b/src/main/java/briefing/scrap/application/dto/ScrapResponse.java index 5875ee0..269aff7 100644 --- a/src/main/java/briefing/scrap/application/dto/ScrapResponse.java +++ b/src/main/java/briefing/scrap/application/dto/ScrapResponse.java @@ -4,7 +4,7 @@ import java.time.LocalDateTime; import briefing.briefing.domain.TimeOfDay; -import briefing.chatting.domain.GptModel; +import briefing.common.enums.GptModel; import lombok.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/test/java/briefing/chatting/application/ChattingCommandServiceTest.java b/src/test/java/briefing/chatting/application/ChattingCommandServiceTest.java index c757698..f2aca1c 100644 --- a/src/test/java/briefing/chatting/application/ChattingCommandServiceTest.java +++ b/src/test/java/briefing/chatting/application/ChattingCommandServiceTest.java @@ -1,9 +1,9 @@ package briefing.chatting.application; -import static briefing.chatting.domain.GptModel.GPT_3_5_TURBO; import static briefing.chatting.domain.MessageRole.ASSISTANT; import static briefing.chatting.domain.MessageRole.SYSTEM; import static briefing.chatting.domain.MessageRole.USER; +import static briefing.common.enums.GptModel.GPT_3_5_TURBO; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;