💻Development
-
[SpringBatch] 적용 예시, 구성 방안 간단 정리Back-end/TIL 2022. 4. 26. 09:31
스타트업 백엔드 인턴 업무 중 필요했던 스프링 배치에 대해 알게된 내용을 정리하는 글 입니다. 📌 배치 작업 적용 예시 예시1) 회원 탈퇴 상황 - 회원 탈퇴를 클릭했는데, 해당 회원과 관련된 데이터를 모두 삭제하려면 시간이 오래 걸리고, 삭제하면 안되는 데이터가 존재할 수 있기 때문에 회원 탈퇴 요청을 했을 때 주로 flag로 처리만 해두고 실제 데이터를 삭제하지는 않는다. 처리 - 정해진 날짜 이후에 배치로 자동 삭제되도록 한다. 예시2) 회원가입용 주민등록증 사본, 사업자등록증 사본 삭제 상황 - 회원가입 시 사용자가 등록한 위의 2가지 사진은 승인 후 바로 삭제하지 않고(사용자가 데이터 변경 요청을 할 수 있으니까) AWS S3에 저장해둔다. 처리 - 정해진 날짜 이후에 배치로 자동 삭제되도록 한..
-
Spring 개방 폐쇄의 원칙을 반영한 코드 리팩토링Back-end/TIL 2022. 4. 25. 09:26
📌 상황 팀장님께서 리팩토링한 코드를 보고 인터페이스 구현체를 명시해주는 것에 대해 고민하며 ‘Spring의 개방 폐쇄 원칙’ 개념에 대해 직접적인 이해를 하게 되었다. 현재 회사 코드는 위와 같은 구조를 가지고 있고, 지금은 SmsExternalService 인터페이스의 구현체가 SmsNaverService 뿐이지만, 만약 다른 구현체가 생긴다면, SpringBoot가 어떤 구현체를 사용해야할 지 몰라 에러가 발생할 것이다. 따라서 이러한 부분에 대한 리팩토링이 추가로 필요하다고 생각했다. 📌 개선 @RestController public class UserV2Controller { private SmsExternalService smsExternalService; @PostMapping(..) pub..
-
JPA의 Cross Join 개선하기Back-end/TIL 2022. 4. 20. 09:29
📌 상황 아래 예시 코드에서 PharmacyEmployee 엔티티는 Pharamcy, PharmacyEmpUser 엔티티와 각각 N:1 관계이다. 아래와 같이 JPQL 작성시 Join을 명시하지 않았다. public interface PharmacyEmployeeRepository extends JpaRepository { @Query("select pe.id as id, " + "pe.pharmacy.pharmacyName as pharmacyName, " + "pe.pharmacyEmpUser.email as email, " + "pe.pharmacyEmpUser.name as name " + "from PharmacyEmployee pe " + "where pe.pharmacy.id = :pharm..
-
[JPA] 연관관계 매핑Back-end/JPA 2022. 4. 14. 09:59
# 연관관계가 필요한 이유 객체를 테이블에 맞춰 데이터 중심으로 모델링하면, 협력 관계를 만들 수 없다. - 테이블은 외래 키(FK)로 조인을 사용해 연관된 테이블을 찾는다. - 객체는 참조를 사용해 연관된 객체를 찾는다. # 연관관계 매핑시 고려사항 3가지 단방향 vs. 양방향 양방향 관계일 때의 연관관계의 주인 다중성 @ManyToOne, @OneToMany, @OneToOne, @ManyToMany 1. 단방향 vs. 양방향 테이블 외래 키 하나로 양쪽 조인 가능 사실 방향이라는 개념이 없음 객체 참조용 필드가 있는 쪽으로만 참조 가능 한쪽만 참조하면 단방향 양쪽이 서로 참조하면 양방향 # 단방향 연관관계 객체 지향 모델링 - ORM 매핑 객체 지향 모델링 - 객체의 참조와 테이블의 외래 키를 매핑..