[신지연] Sprint7#223
Open
Nooroong wants to merge 38 commits into
Open
Conversation
- 스프린트 미션#4에서 구현한 API를 RESTful API로 다시 설계 - 공통 성공 응답모델(SuccessResponse)을 컨트롤러에 적용하기 - Service 레벨에서 예외처리 하는 부분에 BusinessLogicException 적용하기 - GlobalHandlerException 작성 - springdoc-openapi를 활용하여 Swagger 기반의 API 문서를 생성
- 프론트에서 이 형태를 받지 않으므로 제거했습니다.
- 이전 미션에 남겨주신 내용에 따라 파일 확장자를 스펙에 맞게 변경
- 공통사항 - 파일 이름 앞에 랜덤한 UUID를 붙여 파일 이름이 중복되지 않도록 하였습니다. - 첨부파일이 존재하는지를 service에서 확인하도록 했습니다. - BasicMessageService - 여러 첨부파일을 저장할 수 있도록 기존의 코드를 활용하여 작성했습니다.
- Swagger에서 multipart/form-data로 request를 날릴 때 Octet-Stream 문제가 발생함 - 이를 해겷하기 위해 Octet-Stream을 처리하는 코드를 작성
- 참가자 검증은 private channel에서만 하도록 함 - readStatus 생성을 서버가 아닌 프론트에게 맡김
- 엔티티 리턴에서 DTO 리턴으로 변경
- mapper를 통해 코드를 분리
- 회원가입, 회원정보 수정, 메시지 전송에서 첨부파일을 저장하는 코드가 중복됨 - 이를 AttachmentUtil 클래스를 통해 분리함 - 또한 첨부파일 저장 경로를 application.yml에 분리함
- PATCH /api/users/{userId}의 응답 형태 수정
- ChannelPatchDto(ChannelUpdateRequest) 필드 수정
- Bean Validation을 이용하여 요청과 관련된 DTO의 필드에 대해 유효성 검사를 하도록 수정
- application.yml에 데이터베이스, JPA와 관련된 설정을 추가 - ERD를 참고하여 DDL을 작성(schema.sql)
- 클래스 다이어그램을 참고해 JPA 어노테이션을 활용하여 엔티티를 정의 - JpaAuditing 적용
- 클래스 다이어그램을 참고하여 DTO를 정의 - MapStruct를 적용하여 mapper 작성
- DTO와 Entity 간의 필드가 일치하지 않는 경우 @mapping 어노테이션으로 따로 처리함
- 클래스 다이어그램과 불일치한 부분, 추가적인 요구사항에 맞춰 수정
- 변경된 DTO와 Mapper에 맞춰 코드를 수정
- Message 엔티티를 messages 테이블에 매핑 - BusinessLogicException전용 핸들러 생성 - 사용자 삭제 시 메시지가 참조하는 사용자가 set null이 되도록 수정 - UserStatusDto 필드명을 API 스펙과 동일하게 수정 - 채널 삭제 로직 조건 수정 - 채널 조회에서 N+1 문제 해결 - 유저 정보 중복 검사 방식을 JPA 쿼리 메소드로 변경
- application-dev.yaml, application-prod.yaml을 생성하여 개발, 운영 환경에 대한 프로파일을 구성
- 환경에 따른 로깅 레벨을 설정 - logback-spring.xml을 통해 로깅 패턴과 출력 방식을 커스텀 - 일자별 롤링 설정
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
기본 요구사항
프로파일 기반 설정 관리
application-dev.yaml,application-prod.yaml파일을 생성하세요.로그 관리
@Slf4j어노테이션을 활용해 로깅을 쉽게 추가할 수 있도록 구성하세요.application.yaml에 기본 로깅 레벨을 설정하세요.info레벨로 설정합니다.debug, 운영 환경에서는info레벨로 설정합니다.logback-spring.xml파일을 생성하세요.다음 예시와 같은 로그 메시지를 출력하기 위한 로깅 패턴과 출력 방식을 커스터마이징하세요.
콘솔과 파일에 동시에 로그를 기록하도록 설정하세요.
{프로젝트 루트}/.logs경로에 저장되도록 설정하세요.로그 파일은 일자별로 롤링되도록 구성하세요.
로그 파일은 30일간 보관하도록 구성하세요.
예외 처리 고도화
com.sprint.mission.discodeit.exception[.{도메인}]ErrorCodeEnum 클래스를 통해 예외 코드명과 메시지를 정의하세요.6ag3lzl9i-image.png
DiscodeitException클래스를 정의하세요.j5vtp941a-image.png
details는 예외 발생 상황에 대한 추가정보를 저장하기 위한 속성입니다.DiscodeitException을 상속하는 주요 도메인 별 메인 예외 클래스를 정의하세요.UserException,ChannelException등UserNotFoundException,UserAlreadyExistException등 필요한 예외를 정의하세요.a6f585icy-image.png
NoSuchElementExceptionIllegalArgumentExceptionErrorResponse를 통해 일관된 예외 응답을 정의하세요.3gqeampkw-image.png
int status: HTTP 상태코드String exceptionType: 발생한 예외의 클래스 이름ErrorResponse와@RestControllerAdvice를 활용해 예외를 처리하는 예외 핸들러를 구현하세요.ErrorResponse)을 가져야 합니다.유효성 검사
@NotNull,@NotBlank,@Size,@Email등@Valid를 사용해 요청 데이터를 검증하세요.MethodArgumentNotValidException을 전역 예외 핸들러에서 처리하세요.Actuator
Discodeit1.7.0173.4.0/actuator/info/actuator/metrics/actuator/health/actuator/loggers단위 테스트
Mockito를 활용해 Repository 의존성을 모의(mock)하세요.BDDMockito를 활용해 테스트 가독성을 높이세요.슬라이스 테스트
@DataJpaTest를 활용해 테스트를 구현하세요.application-test.yaml을 생성하세요.test프로파일을 활성화 하세요.@EnableJpaAuditing을 추가하세요.@WebMvcTest를 활용해 테스트를 구현하세요.WebMvcTest에서 자동으로 등록되지 않는 유형의 Bean이 필요하다면@Import를 활용해 추가하세요.통합 테스트
@SpringBootTest를 활용해 Spring 애플리케이션 컨텍스트를 로드하세요.@Transactional을 활용해 독립적으로 실행하세요.심화 요구 사항
MDC를 활용한 로깅 고도화
Spring Boot Admin을 활용한 메트릭 가시화
dependencies { ... implementation 'de.codecentric:spring-boot-admin-starter-client:3.4.5 }테스트 커버리지 관리
plugins { id 'jacoco' } test { finalizedBy jacocoTestReport } jacocoTestReport { dependsOn test reports { xml.required = true html.required = true } }주요 변경사항
스크린샷
멘토에게