2021-10-26-TIL

TODO

  • 아침에 등산 가볍게 하고오기
  • 카페에 가서 일기쓰고 계획 정리하기
  • 취업 일정 정리하기
  • 우테코 지원서 제출
  • TIL 템플릿 만들기

Today I Learned

Greenion Project

Greenion 프로젝트를 본격적으로 시작하였다. 우선은 페어프로그래밍으로 시작하였는데, 페어분께서는 어떻게 생각하실지는 모르겠지만… 나는 상대적으로 배우는게 많았다. 그리고 페어프로그래밍을 진행하면서 대화를 하는 도중에 생각할거리가 무궁무진하게 나온다는 장점이 있었다. 다만 Code With Me를 30분 마다 재접속 해야한다던가, 잘 접속이 되지 않는다는 문제는 좀 아쉬웠다.

우리가 맡은 부분은 피드 도메인인데, 인스타그램에서 태그는 어떻게 구현이 되는지 생각해보게 되었다. 단순히 리스트 형태로 담는다던가, Tag테이블이 있을 것 같지는 않고, NoSQL로 빠른 검색이 가능하도록 하는 방법을 사용할 것 같다는 예상이 되었다. 이 이야기를 하면서 설계에 관한 좋은 책을 추천받았다.

  • http://www.yes24.com/Product/Goods/102819435
  • http://www.yes24.com/Product/Goods/56972293?OzSrank=1

Google Guava

  • https://recordsoflife.tistory.com/646

Gradle 의존 설정 : implementation vs compileOnly

  • https://deque.tistory.com/137
  • https://discuss.gradle.org/t/is-it-recommended-to-use-compileonly-over-implementation-if-another-module-use-implementation-already/26699

Lombok을 테스트 환경에서 사용하기

그냥 의존 설정을 할 때 testCompileOnly, testImplementation과 같이 별도로 설정을 해주어야한다.

  • https://jundragon.tistory.com/9

DTO의 객체변환은 어느 계층에서 하는것이 적절한가?

하나의 도메인 클래스를 만들고 거기에 내부클래스로 묶어주는 방식을 사용하는 사람도 있다. 우리는 그냥 도메인 패키지 내부에 바로 request와 response 패키지를 만들고, 그 안에 dto를 작성하였다.

  • https://anaog.tistory.com/7
  • https://velog.io/@p4rksh/Spring-Boot%EC%97%90%EC%84%9C-%EA%B9%94%EB%81%94%ED%95%98%EA%B2%8C-DTO-%EA%B4%80%EB%A6%AC%ED%95%98%EA%B8%B0

필수값을 검증하기 위한 빌더

@Builder
public User(Name name, Email email, String password) {
  this(name, email, password, null);
}

@Builder
public User(Name name, Email email, String password, String profileImageUrl) {
  this(null, name, email, password, profileImageUrl, 0, null, null);
}

@Builder
public User(Long id, Name name, Email email, String password, String profileImageUrl, int loginCount, LocalDateTime lastLoginAt, LocalDateTime createAt) {
  // TODO: validation code
  this.id = id;
  this.name = name;
  this.email = email;
  this.password = password;
  this.profileImageUrl = profileImageUrl;
  this.loginCount = loginCount;
  this.lastLoginAt = lastLoginAt;
  this.createAt = defaultIfNull(createAt, now());
}

위와 같이 코드를 작성하면 name, email, password라는 필수값은 무조건 포함하면서 빌더를 사용할 수 있도록해서 검증하는 코드를 최종적으로 실행될 생성자(All Arguments Constructor)에 작성할 수 있다.

물론 필드가 매우 많은 경우, 3개의 필드만 필수값이라고 한다면 일일이 빌더를 모든 경우에 대해 만들어주어야하는가에 대한 의문은 아직 든다. 하지만 그렇게 극단적인 경우가 아직 생길것 같진않다.

@Builder 애노테이션을 클래스가 아니라 생성자에 붙이는 방법

클래스에 붙이면 모든 필드에 대해서 빌더가 만들어진다. 하지만 원하지 않는 필드를 제외하고 싶을 수도 있다. 그런 경우에 @JsonIgnore같은 애노테이션이 별도로 존재할까?

  • https://stackoverflow.com/questions/30717640/how-to-exclude-property-from-lombok-builder

위 글에 따르면 생각보다 애노테이션을 통한 방법이 있지는 않은 것 같다.

@Builder
public class MyClass {
   private String myField;

   private final String excludeThisField = "bar";
}

이렇게 final이나 static으로 선언해버리면 롬복의 @Builder 애노테이션이 해당 필드를 무시하는 것은 당연한 것 같아보인다.

XYZClientWrapper{
    String name;
    String domain;
    XYZClient client;
    
    @Builder
    public XYZClientWrapper(String name, String domain) {
        this.name = name;
        this.domain = domain;
        this.client = calculateClient();
    }
}

가장 설득력있는 방법이 현성님이 알려준 방법과 동일하게 생성자에 @Builder를 붙여서 해당 생성자를 기반으로 빌더를 사용하는 것이다.

Tomorrow I'll Learn

  • 스프링 핵심원리 강의 다 듣기
  • 프로그래머스 3문제 풀기 및 풀이작성