Entity
setter 사용 금지메서드명은 기능을 명시적으로 정하기컬럼으로 래퍼 클래스 통일Usertb_ 접두사 붙이기Optional 사용
생성자
@Bbuilder 패턴 사용@JsonIgnoreProperties 이용레포지토리
객체간 변환 작업
org.mapstruct.Mapper 사용
@Mapper
public interface CommentServiceMapper {
CommentServiceMapper INSTANCE = Mappers.getMapper(CommentServiceMapper.class);
CommentSaveRes toCommentSaveRes(Comment comment);
}
@Override
@Transactional
public CommentSaveRes saveComment(CommentSaveReq req) {
Card card = findCard(req.getCardId());
TeamRole teamRole = findTeamRole(req.getUsername(), card.getCategory().getTeam().getTeamId());
return CommentServiceMapper.INSTANCE.toCommentSaveRes(
commentRepository.save(
Comment.builder().content(req.getContent()).card(card).teamRole(teamRole).build()));
}
code, message 사용.천 단위로 다르게 예외코드 작성CustomException을 만들어서 ResultCode만 넣어서 throw 하기Custom ResponseEntity 사용
테스트는 단위 테스트만, 성공케이스만 작성
API 1개당 요청, 응답 DTO 1개씩 만들기.
Request, Response 모두 Java 8 record 사용하기
Request, Response 모두 필드가 있다면 클래스 레벨 @Builder적용하기
필드 없을 시 만들 예시
@JsonIgnoreProperties
public class UserUpdateProfileRes {}
DTO
도메인 + 기능 + 요청/응답 Dto기능 작명을 할 때는 가능한 HTTP Method 명으로 하기.UserLoginRequestDtoRecord 사용패키지 구조
domain, global, infra 로 대분류 하여 구분Repository
아래 구조로 통일한다 (작성자 @임지훈)
public interface PostsRepository extends JpaRepository<Posts, Long> {
}