Skip to content

Commit

Permalink
feature/QFEED-50-Daily-Question (#7)
Browse files Browse the repository at this point in the history
* [QFEED-50] Feat: Question 엔티티 클래스 추가

* [QFEED-50] Chore: Spring Open AI 의존성 추가

* [QFEED-50] Chore: openai 설정정보 추가

* [QFEED-50] Rename: Question 엔티티 디렉토리 이동

* [QFEED-50] Feat: OpenAI 연동 및 질문 생성 기능 구현

- AIQuestionResponse 형식으로 각 카테고리의 질문을 받아옴
- Json 형식으로 질문을 받아오도록 설정함
- 추후 LLM 모델 변경시 유지보수의 용이성을 위해 질문 생성 책임을 가지는 클래스에는 특정 LLM 모델 관련 클래스 의존하지 않도록 설계
- temperature를 1.2로 높혀 질문이 다양하게 출력되게 끔 하였음.

* [QFEED-50] Chore: 질문 생성 모델 temperature 0.9로 변경

- 질문에 이상한 텍스트가 포함되는 현상 해결

* [QFEED-50] Feat: Category 엔티티 추가

* [QFEED-50] Feat: Question에 Category 연관관계 추가

* [QFEED-50] Refactor: Question 엔티티 수정

- 키 생성 전략 추가
- id 컬럼명 지정

* [QFEED-50] Rename: 오타 수정

* [QFEED-50] Rename: common 모듈 패키지명 오타 수정

* [QFEED-50] Rename: api 모듈 패키지명 오타 수정

* [QFEED-50] Rename: Category 엔티티 디렉토리 이동

* [QFEED-50] Refactor: Question 엔티티에 isToday -> QuestionStatus로 수정 및 질문활성화 비즈니스 로직 추가

* [QFEED-50] Refactor: QuestionRepository 추가

- Domain 계층에 인터페이스 추가
- Infra 계층에 Jpa에 의존하는 인터페이스 추가

* [QFEED-50] Rename: external-api 계층 yml 파일명 application-external-api.yml로 변경

* [QFEED-50] Rename: QuestionJpaRepository 디렉토리 구조 변경

* [QFEED-50] Chore: Test를 위한 설정 추가

* [QFEED-50] Feat: Question 엔티티 정적 팩토리 메서드 추가

* [QFEED-50] Feat: 질문 상태 업데이트 스케줄링 로직 추가

* [QFEED-50] Refactor: cron 시간 주기 설정 변경

* [QFEED-50] Fix: Exception 디렉토리 문제 해결

* [QFEED-50] Rename: SchedulingConfig Common 모듈로 이동

* [QFEED-50] Refactor: Category 별도의 에그리거트로 분리 및 Question <-> Category 연관관계 해제

- Category는 User에서도 의존하는 엔티티라 분리하는게 좋다고 판단
- 다른 에그리거트와의 연관관계는 기본키로만 연관
  • Loading branch information
jhk01007 authored Nov 29, 2024
1 parent da329fb commit 3105850
Show file tree
Hide file tree
Showing 58 changed files with 351 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ replay_pid*
# JIRA plugin
atlassian-ide-plugin.xml

build-test.gradle
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ sonar {
allprojects {
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.wsws.moduleapi.exception.ErrorInfo;
import com.wsws.moduleapi.exception.GlobalErrorCode;
import com.wsws.modulecommon.exception.ErrorInfo;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wsws.moduleapi.global.exception;

import com.wsws.moduleapi.exception.CustomException;
import com.wsws.moduleapi.exception.ErrorInfo;
import com.wsws.moduleapi.exception.GlobalErrorCode;
import com.wsws.modulecommon.exception.CustomException;
import com.wsws.modulecommon.exception.ErrorInfo;
import com.wsws.modulecommon.exception.GlobalErrorCode;
import com.wsws.moduleapi.global.dto.ErrorResponse;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
Expand Down
6 changes: 6 additions & 0 deletions module-application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
}

test {
if (file('build-test.gradle').exists()) {
apply from: 'build-test.gradle'
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.wsws.moduleapplication.auth.exception;


import com.wsws.moduleapi.exception.BaseErrorCode;
import com.wsws.moduleapi.exception.ErrorInfo;
import com.wsws.modulecommon.exception.BaseErrorCode;
import com.wsws.modulecommon.exception.ErrorInfo;
import lombok.RequiredArgsConstructor;

import static com.wsws.moduleapi.constants.ErrorCodeConstants.UNAUTHORIZED;
import static com.wsws.modulecommon.constants.ErrorCodeConstants.UNAUTHORIZED;

@RequiredArgsConstructor
public enum AuthServiceErrorCode implements BaseErrorCode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wsws.moduleapplication.auth.exception;

import com.wsws.moduleapi.exception.ApplicationException;

import com.wsws.modulecommon.exception.ApplicationException;

public class EmailNotFoundException extends ApplicationException {
public static final EmailNotFoundException EXCEPTION = new EmailNotFoundException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wsws.moduleapplication.auth.exception;

import com.wsws.moduleapi.exception.ApplicationException;

import com.wsws.modulecommon.exception.ApplicationException;

public class InvalidRefreshTokenException extends ApplicationException {
public static final InvalidRefreshTokenException EXCEPTION = new InvalidRefreshTokenException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wsws.moduleapplication.auth.exception;

import com.wsws.moduleapi.exception.ApplicationException;

import com.wsws.modulecommon.exception.ApplicationException;

public class PasswordMismatchException extends ApplicationException {
public static final PasswordMismatchException EXCEPTION = new PasswordMismatchException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wsws.moduleapplication.auth.exception;


import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.modulecommon.exception.ApplicationException;

public class RefreshTokenExpiredException extends ApplicationException {
public static final RefreshTokenExpiredException EXCEPTION = new RefreshTokenExpiredException();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.wsws.moduleapplication.feed.service.scheduler;

import com.wsws.moduledomain.feed.question.Question;
import com.wsws.moduledomain.feed.question.repo.QuestionRepository;
import com.wsws.moduledomain.feed.question.vo.QuestionStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
@Slf4j
public class ScheduledQuestionUpdateService {
private final QuestionRepository questionRepository;

/**
* 매일 자정에 Question 테이블의 Question Status 컬럼 변경
* 어제 질문들은 isToday: ACTIVATED -> INACTICATED
* 오늘 질문들은 isToday: CREATED -> ACTIVATED
*/
@Scheduled(cron = "0 0 0 * * ?") // 매일 00시 00분에 실행되도록 설정
public void updateQuestions() {
// 어제 질문들 비활성화
questionRepository.findByQuestionStatus(QuestionStatus.ACTIVATED)
.forEach(Question::inactivateQuestion);

// 오늘 질문들 활성화
questionRepository.findByQuestionStatus(QuestionStatus.CREATED)
.forEach(Question::activateQuestion);

log.info("스케줄링 작업 완료");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wsws.moduleapplication.follow.exception;


import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.modulecommon.exception.ApplicationException;

public class AlreadyFollowedException extends ApplicationException {
public static final AlreadyFollowedException EXCEPTION = new AlreadyFollowedException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wsws.moduleapplication.follow.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.modulecommon.exception.ApplicationException;

public class FollowNotFoundException extends ApplicationException {
public static final FollowNotFoundException EXCEPTION = new FollowNotFoundException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.wsws.moduleapplication.follow.exception;

import com.wsws.moduleapi.exception.BaseErrorCode;
import com.wsws.moduleapi.exception.ErrorInfo;
import com.wsws.modulecommon.exception.BaseErrorCode;
import com.wsws.modulecommon.exception.ErrorInfo;
import lombok.RequiredArgsConstructor;

import static com.wsws.moduleapi.constants.ErrorCodeConstants.BAD_REQUEST;
import static com.wsws.modulecommon.constants.ErrorCodeConstants.BAD_REQUEST;

@RequiredArgsConstructor
public enum FollowServiceErrorCode implements BaseErrorCode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;

import com.wsws.modulecommon.exception.ApplicationException;

public class DuplicateEmailException extends ApplicationException {
public static final DuplicateEmailException EXCEPTION = new DuplicateEmailException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;
import com.wsws.modulecommon.exception.ApplicationException;

public class DuplicateNicknameException extends ApplicationException {
public static final DuplicateNicknameException EXCEPTION = new DuplicateNicknameException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;

import com.wsws.modulecommon.exception.ApplicationException;

public class ProfileImageProcessingException extends ApplicationException {
public static final ProfileImageProcessingException EXCEPTION = new ProfileImageProcessingException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;

import com.wsws.modulecommon.exception.ApplicationException;

public class ProfileImageRequiredException extends ApplicationException {
public static final ProfileImageRequiredException EXCEPTION = new ProfileImageRequiredException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;

import com.wsws.modulecommon.exception.ApplicationException;

public class ProfileImageTooLargeException extends ApplicationException {
public static final ProfileImageTooLargeException EXCEPTION = new ProfileImageTooLargeException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;
import com.wsws.modulecommon.exception.ApplicationException;

public class UnsupportedImageFormatException extends ApplicationException {
public static final UnsupportedImageFormatException EXCEPTION = new UnsupportedImageFormatException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;

import com.wsws.modulecommon.exception.ApplicationException;

public class UserNotFoundException extends ApplicationException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.wsws.moduleapplication.user.exception;

import com.wsws.moduleapi.exception.BaseErrorCode;
import com.wsws.moduleapi.exception.ErrorInfo;
import com.wsws.modulecommon.exception.BaseErrorCode;
import com.wsws.modulecommon.exception.ErrorInfo;
import lombok.RequiredArgsConstructor;

import static com.wsws.moduleapi.constants.ErrorCodeConstants.*;
import static com.wsws.modulecommon.constants.ErrorCodeConstants.*;


@RequiredArgsConstructor
public enum UserServiceErrorCode implements BaseErrorCode {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wsws.modulecommon.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
public class SchedulingConfig {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.constants;
package com.wsws.modulecommon.constants;

public class ErrorCodeConstants {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public class ApiException extends CustomException{
public ApiException(BaseErrorCode errorCode, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public class ApplicationException extends CustomException{
public ApplicationException(BaseErrorCode errorCode, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public interface BaseErrorCode {
ErrorInfo getErrorInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public class DomainException extends CustomException {
public DomainException(BaseErrorCode errorCode, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public record ErrorInfo(Integer status, String errorCode, String message) {
public static ErrorInfo of(Integer status, String errorCode, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public class ExternalApiException extends CustomException{
public ExternalApiException(BaseErrorCode errorCode, String sourceLayer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

import lombok.RequiredArgsConstructor;

import static com.wsws.moduleapi.constants.ErrorCodeConstants.*;
import static com.wsws.modulecommon.constants.ErrorCodeConstants.*;

@RequiredArgsConstructor
public enum GlobalErrorCode implements BaseErrorCode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

public class InfraException extends CustomException{
public InfraException(BaseErrorCode errorCode, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.wsws.moduleapi.exception;
package com.wsws.modulecommon.exception;

import com.wsws.modulecommon.exception.BaseErrorCode;
import com.wsws.modulecommon.exception.CustomException;

public class SecurityException extends CustomException {
public SecurityException(BaseErrorCode errorCode, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.wsws.moduledomain.auth.exception;

import com.wsws.moduleapi.exception.BaseErrorCode;
import com.wsws.moduleapi.exception.ErrorInfo;
import com.wsws.modulecommon.exception.BaseErrorCode;
import com.wsws.modulecommon.exception.ErrorInfo;
import lombok.RequiredArgsConstructor;

import static com.wsws.moduleapi.constants.ErrorCodeConstants.UNAUTHORIZED;
import static com.wsws.modulecommon.constants.ErrorCodeConstants.UNAUTHORIZED;


@RequiredArgsConstructor
public enum AuthErrorCode implements BaseErrorCode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wsws.moduledomain.auth.exception;

import com.wsws.moduleapi.exception.BaseErrorCode;
import com.wsws.moduleapi.exception.DomainException;

import com.wsws.modulecommon.exception.DomainException;

public class ExpiredRefreshTokenException extends DomainException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wsws.moduledomain.auth.exception;

import com.wsws.moduleapi.exception.DomainException;

import com.wsws.modulecommon.exception.DomainException;

public class InvalidRefreshTokenException extends DomainException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.wsws.moduledomain.auth.exception;

import com.wsws.moduleapi.exception.ApplicationException;
import com.wsws.moduleapi.exception.DomainException;
import com.wsws.moduledomain.user.exception.UserErrorCode;

import com.wsws.modulecommon.exception.DomainException;

public class PasswordMismatchException extends DomainException {
public static final PasswordMismatchException EXCEPTION = new PasswordMismatchException();
Expand Down
Loading

0 comments on commit 3105850

Please sign in to comment.