From d571d56250796c38795c2984d644b38909a270c8 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Sat, 18 Jun 2022 00:38:40 +0900 Subject: [PATCH 01/17] =?UTF-8?q?refactor:=20component=20->=20repository?= =?UTF-8?q?=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../performance/adapter/persistence/PerformanceAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java index 155d759..f499ce4 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java @@ -5,13 +5,13 @@ import com.jummi.ticket.performance.domain.Performance; import com.jummi.ticket.performance.domain.Series; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; -@Component +@Repository @RequiredArgsConstructor @Transactional(readOnly = true) class PerformanceAdapter implements SavePerformancePort { From 4d928c5a8e1b2dcf147cbb22414ca0e7d40463fd Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Sat, 18 Jun 2022 00:40:35 +0900 Subject: [PATCH 02/17] =?UTF-8?q?chore:=20RequestDto=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20application=20->=20web=20adapter=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/web/RegisterPerformanceController.java | 1 - .../port/in => adapter/web}/RegisterPerformanceRequest.java | 2 +- .../{application/port/in => adapter/web}/SeriesRequest.java | 2 +- .../application/port/in/RegisterPerformanceCommand.java | 1 + .../application/service/RegisterPerformanceService.java | 2 +- .../jummi/ticket/performance/converter/PerformanceMapper.java | 4 ++-- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/com/jummi/ticket/performance/{application/port/in => adapter/web}/RegisterPerformanceRequest.java (94%) rename src/main/java/com/jummi/ticket/performance/{application/port/in => adapter/web}/SeriesRequest.java (88%) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java index 9167286..b1e787d 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java @@ -1,7 +1,6 @@ package com.jummi.ticket.performance.adapter.web; import com.jummi.ticket.performance.application.port.in.RegisterPerformanceCommand; -import com.jummi.ticket.performance.application.port.in.RegisterPerformanceRequest; import com.jummi.ticket.performance.domain.PerformanceId; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceRequest.java b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java similarity index 94% rename from src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceRequest.java rename to src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java index afdf1c7..dd46777 100644 --- a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceRequest.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java @@ -1,4 +1,4 @@ -package com.jummi.ticket.performance.application.port.in; +package com.jummi.ticket.performance.adapter.web; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/jummi/ticket/performance/application/port/in/SeriesRequest.java b/src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java similarity index 88% rename from src/main/java/com/jummi/ticket/performance/application/port/in/SeriesRequest.java rename to src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java index 64baebb..5ac2eef 100644 --- a/src/main/java/com/jummi/ticket/performance/application/port/in/SeriesRequest.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java @@ -1,4 +1,4 @@ -package com.jummi.ticket.performance.application.port.in; +package com.jummi.ticket.performance.adapter.web; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java b/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java index 5f58c2c..ef31d21 100644 --- a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java +++ b/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java @@ -1,5 +1,6 @@ package com.jummi.ticket.performance.application.port.in; +import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; import com.jummi.ticket.performance.domain.PerformanceId; public interface RegisterPerformanceCommand { diff --git a/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java b/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java index 157d864..343eff8 100644 --- a/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java +++ b/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java @@ -1,7 +1,7 @@ package com.jummi.ticket.performance.application.service; +import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; import com.jummi.ticket.performance.application.port.in.RegisterPerformanceCommand; -import com.jummi.ticket.performance.application.port.in.RegisterPerformanceRequest; import com.jummi.ticket.performance.application.port.out.SavePerformancePort; import com.jummi.ticket.performance.converter.PerformanceMapper; import com.jummi.ticket.performance.domain.Performance; diff --git a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java index f631096..8b05b2b 100644 --- a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java +++ b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java @@ -2,8 +2,8 @@ import com.jummi.ticket.performance.adapter.persistence.PerformanceEntity; import com.jummi.ticket.performance.adapter.persistence.SeriesEntity; -import com.jummi.ticket.performance.application.port.in.RegisterPerformanceRequest; -import com.jummi.ticket.performance.application.port.in.SeriesRequest; +import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; +import com.jummi.ticket.performance.adapter.web.SeriesRequest; import com.jummi.ticket.performance.domain.*; import org.mapstruct.Mapper; import org.springframework.stereotype.Component; From b25320f7631bf51114cb4021737d3ff21d24368f Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Sat, 18 Jun 2022 01:05:54 +0900 Subject: [PATCH 03/17] =?UTF-8?q?chore:=20incoming,=20outgoing=20port=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/persistence/PerformanceAdapter.java | 4 ++-- .../adapter/persistence/SeriesRepository.java | 2 +- .../adapter/web/RegisterPerformanceController.java | 6 +++--- ...nceCommand.java => RegisterPerformanceUseCase.java} | 2 +- ...erformancePort.java => SavePerformanceCommand.java} | 2 +- .../service/RegisterPerformanceService.java | 10 +++++----- 6 files changed, 13 insertions(+), 13 deletions(-) rename src/main/java/com/jummi/ticket/performance/application/port/in/{RegisterPerformanceCommand.java => RegisterPerformanceUseCase.java} (85%) rename src/main/java/com/jummi/ticket/performance/application/port/out/{SavePerformancePort.java => SavePerformanceCommand.java} (86%) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java index f499ce4..5b8d8f7 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java @@ -1,6 +1,6 @@ package com.jummi.ticket.performance.adapter.persistence; -import com.jummi.ticket.performance.application.port.out.SavePerformancePort; +import com.jummi.ticket.performance.application.port.out.SavePerformanceCommand; import com.jummi.ticket.performance.converter.PerformanceMapper; import com.jummi.ticket.performance.domain.Performance; import com.jummi.ticket.performance.domain.Series; @@ -14,7 +14,7 @@ @Repository @RequiredArgsConstructor @Transactional(readOnly = true) -class PerformanceAdapter implements SavePerformancePort { +class PerformanceAdapter implements SavePerformanceCommand { private final PerformanceMapper mapper; private final PerformanceRepository performanceRepository; private final SeriesRepository seriesRepository; diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesRepository.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesRepository.java index be0c3aa..160353d 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesRepository.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesRepository.java @@ -2,5 +2,5 @@ import org.springframework.data.jpa.repository.JpaRepository; -public interface SeriesRepository extends JpaRepository { +interface SeriesRepository extends JpaRepository { } diff --git a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java index b1e787d..bca62d1 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java @@ -1,6 +1,6 @@ package com.jummi.ticket.performance.adapter.web; -import com.jummi.ticket.performance.application.port.in.RegisterPerformanceCommand; +import com.jummi.ticket.performance.application.port.in.RegisterPerformanceUseCase; import com.jummi.ticket.performance.domain.PerformanceId; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -16,11 +16,11 @@ @RequestMapping("/api/performances") @RestController class RegisterPerformanceController { - private final RegisterPerformanceCommand registerPerformanceCommand; + private final RegisterPerformanceUseCase registerPerformanceUseCase; @PostMapping ResponseEntity registerPerformance(@RequestBody @Valid RegisterPerformanceRequest request) { - PerformanceId performanceId = registerPerformanceCommand.registerPerformance(request); + PerformanceId performanceId = registerPerformanceUseCase.registerPerformance(request); return ResponseEntity.created( URI.create("/api/performances/" + performanceId.id())) diff --git a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java b/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java similarity index 85% rename from src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java rename to src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java index ef31d21..5e1a733 100644 --- a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceCommand.java +++ b/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java @@ -3,6 +3,6 @@ import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; import com.jummi.ticket.performance.domain.PerformanceId; -public interface RegisterPerformanceCommand { +public interface RegisterPerformanceUseCase { PerformanceId registerPerformance(RegisterPerformanceRequest request); } diff --git a/src/main/java/com/jummi/ticket/performance/application/port/out/SavePerformancePort.java b/src/main/java/com/jummi/ticket/performance/application/port/out/SavePerformanceCommand.java similarity index 86% rename from src/main/java/com/jummi/ticket/performance/application/port/out/SavePerformancePort.java rename to src/main/java/com/jummi/ticket/performance/application/port/out/SavePerformanceCommand.java index 19a10ac..bdbb921 100644 --- a/src/main/java/com/jummi/ticket/performance/application/port/out/SavePerformancePort.java +++ b/src/main/java/com/jummi/ticket/performance/application/port/out/SavePerformanceCommand.java @@ -5,6 +5,6 @@ import java.util.List; -public interface SavePerformancePort { +public interface SavePerformanceCommand { Long savePerformance(Performance performance, List series); } diff --git a/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java b/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java index 343eff8..58ed0cf 100644 --- a/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java +++ b/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java @@ -1,8 +1,8 @@ package com.jummi.ticket.performance.application.service; import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; -import com.jummi.ticket.performance.application.port.in.RegisterPerformanceCommand; -import com.jummi.ticket.performance.application.port.out.SavePerformancePort; +import com.jummi.ticket.performance.application.port.in.RegisterPerformanceUseCase; +import com.jummi.ticket.performance.application.port.out.SavePerformanceCommand; import com.jummi.ticket.performance.converter.PerformanceMapper; import com.jummi.ticket.performance.domain.Performance; import com.jummi.ticket.performance.domain.PerformanceId; @@ -14,15 +14,15 @@ @RequiredArgsConstructor @Service -public class RegisterPerformanceService implements RegisterPerformanceCommand { +public class RegisterPerformanceService implements RegisterPerformanceUseCase { private final PerformanceMapper mapper; - private final SavePerformancePort savePerformancePort; + private final SavePerformanceCommand savePerformanceCommand; @Override public PerformanceId registerPerformance(RegisterPerformanceRequest request) { Performance performance = mapper.convertRequestToDomainEntity(request); List series = mapper.extractSeriesDomainEntity(request); - Long performanceId = savePerformancePort.savePerformance(performance, series); + Long performanceId = savePerformanceCommand.savePerformance(performance, series); return new PerformanceId(performanceId); } From 14d3c1b34f2eba587f6b11571a52c933f35acd2b Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Sat, 18 Jun 2022 01:41:25 +0900 Subject: [PATCH 04/17] =?UTF-8?q?refactor:=20mapping=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/PerformanceAdapter.java | 5 +---- .../converter/PerformanceMapper.java | 18 ++++++------------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java index 5b8d8f7..6ce56dd 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java @@ -9,7 +9,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.stream.Collectors; @Repository @RequiredArgsConstructor @@ -26,9 +25,7 @@ public Long savePerformance(Performance performance, List series) { PerformanceEntity saved = performanceRepository.save(performanceEntity); Long performanceId = saved.getPerformanceId(); - List seriesEntities = series.stream() - .map(mapper::convertDomainEntityToJpaEntity) - .collect(Collectors.toList()); + List seriesEntities = mapper.convertDomainEntityToJpaEntity(series); seriesEntities.forEach(seriesEntity -> seriesEntity.setPerformanceId(performanceId)); seriesRepository.saveAll(seriesEntities); diff --git a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java index 8b05b2b..c830df9 100644 --- a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java +++ b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java @@ -6,10 +6,9 @@ import com.jummi.ticket.performance.adapter.web.SeriesRequest; import com.jummi.ticket.performance.domain.*; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.springframework.stereotype.Component; -import java.time.LocalDate; -import java.time.LocalTime; import java.util.List; import java.util.stream.Collectors; @@ -37,7 +36,7 @@ default List convertStringToEnum(List reservationSites) .collect(Collectors.toList()); } - SeriesEntity convertDomainEntityToJpaEntity(Series series); + List convertDomainEntityToJpaEntity(List series); default List extractSeriesDomainEntity(RegisterPerformanceRequest request) { return request.getSeries() @@ -46,13 +45,8 @@ default List extractSeriesDomainEntity(RegisterPerformanceRequest reques .collect(Collectors.toList()); } - default Series convertRequestToDomainEntity(SeriesRequest seriesRequest) { - LocalDate date = seriesRequest.getDateTime().toLocalDate(); - LocalTime time = seriesRequest.getDateTime().toLocalTime(); - return Series.builder() - .playDate(date) - .playTime(time) - .isPerformed(seriesRequest.isPerformed()) - .build(); - } + @Mapping(expression = "java(seriesRequest.getDateTime().toLocalDate())", target = "playDate") + @Mapping(expression = "java(seriesRequest.getDateTime().toLocalTime())", target = "playTime") + @Mapping(expression = "java(seriesRequest.isPerformed())", target = "isPerformed") + Series convertRequestToDomainEntity(SeriesRequest seriesRequest); } From ccdd4513810e715521aa0d24f061f416d5488198 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Wed, 22 Jun 2022 15:21:51 +0900 Subject: [PATCH 05/17] =?UTF-8?q?refactor:=20=EC=98=88=EB=A7=A4=EC=B2=98?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/persistence/ReservationSiteEntity.java | 8 -------- .../ticket/performance/domain/ReservationSite.java | 13 ++++++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) delete mode 100644 src/main/java/com/jummi/ticket/performance/adapter/persistence/ReservationSiteEntity.java diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/ReservationSiteEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/ReservationSiteEntity.java deleted file mode 100644 index 92f3851..0000000 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/ReservationSiteEntity.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.jummi.ticket.performance.adapter.persistence; - -import javax.persistence.Embeddable; - -@Embeddable -public enum ReservationSiteEntity { - INTERPARK, YES24, MELON -} diff --git a/src/main/java/com/jummi/ticket/performance/domain/ReservationSite.java b/src/main/java/com/jummi/ticket/performance/domain/ReservationSite.java index f840e2f..ca82f19 100644 --- a/src/main/java/com/jummi/ticket/performance/domain/ReservationSite.java +++ b/src/main/java/com/jummi/ticket/performance/domain/ReservationSite.java @@ -1,5 +1,16 @@ package com.jummi.ticket.performance.domain; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor public enum ReservationSite { - INTERPARK, YES24, MELON + INTERPARK("INTERPARK", "인터파크"), + YES24("YES24", "예스24"), + MELON("MELON TICKET", "멜론티켓"), + ; + + private final String globalName; + private final String koreanName; } From 94f3e30cbf5db880c537ab533d3dc19e3dadd9d7 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Wed, 22 Jun 2022 15:22:22 +0900 Subject: [PATCH 06/17] =?UTF-8?q?feat:=20BaseEntity=20=EB=B6=84=EB=A6=AC,?= =?UTF-8?q?=20jpa=20config=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/persistence/BaseEntity.java | 29 ++++++++++++++++++ .../ticket/config/jpa/JpaConfiguration.java | 9 ++++++ .../persistence/PerformanceEntity.java | 30 +++++++++---------- .../adapter/persistence/SeriesEntity.java | 24 +++++++++++---- 4 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/jummi/ticket/common/adapter/persistence/BaseEntity.java create mode 100644 src/main/java/com/jummi/ticket/config/jpa/JpaConfiguration.java diff --git a/src/main/java/com/jummi/ticket/common/adapter/persistence/BaseEntity.java b/src/main/java/com/jummi/ticket/common/adapter/persistence/BaseEntity.java new file mode 100644 index 0000000..f07bfab --- /dev/null +++ b/src/main/java/com/jummi/ticket/common/adapter/persistence/BaseEntity.java @@ -0,0 +1,29 @@ +package com.jummi.ticket.common.adapter.persistence; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@EntityListeners(AuditingEntityListener.class) +@MappedSuperclass +public abstract class BaseEntity { + @CreatedDate + @Column(updatable = false) + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; + + @Column(columnDefinition = "boolean default false") + private boolean isDeleted; +} diff --git a/src/main/java/com/jummi/ticket/config/jpa/JpaConfiguration.java b/src/main/java/com/jummi/ticket/config/jpa/JpaConfiguration.java new file mode 100644 index 0000000..40a7af6 --- /dev/null +++ b/src/main/java/com/jummi/ticket/config/jpa/JpaConfiguration.java @@ -0,0 +1,9 @@ +package com.jummi.ticket.config.jpa; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@EnableJpaAuditing +@Configuration +public class JpaConfiguration { +} diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java index 72ea889..94d2d07 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java @@ -1,22 +1,29 @@ package com.jummi.ticket.performance.adapter.persistence; +import com.jummi.ticket.common.adapter.persistence.BaseEntity; import com.jummi.ticket.performance.domain.Genre; -import lombok.*; +import com.jummi.ticket.performance.domain.ReservationSite; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.time.LocalDate; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; @Getter @Builder -@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "performance") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "UPDATE performance SET is_deleted = true WHERE performance_id = ?") @Entity -public class PerformanceEntity { +public class PerformanceEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long performanceId; @@ -32,11 +39,7 @@ public class PerformanceEntity { private String venue; - @ElementCollection - @CollectionTable( - name = "series", - joinColumns = @JoinColumn(name = "performance_id") - ) + @OneToMany(mappedBy = "performance", cascade = CascadeType.REMOVE) private List series = new ArrayList<>(); @ElementCollection @@ -48,10 +51,7 @@ public class PerformanceEntity { private int minAvailableAge; @Enumerated(EnumType.STRING) - @ElementCollection - @CollectionTable( - name = "reservation_sites", - joinColumns = @JoinColumn(name = "performance_id") - ) - private Set reservationSites = new HashSet<>(); + @ElementCollection(targetClass = ReservationSite.class) + @CollectionTable + private Set reservationSites; } diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java index 0ff8118..ad585e5 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java @@ -1,20 +1,32 @@ package com.jummi.ticket.performance.adapter.persistence; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.Setter; +import com.jummi.ticket.common.adapter.persistence.BaseEntity; +import lombok.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; -import javax.persistence.Embeddable; +import javax.persistence.*; import java.time.LocalDate; import java.time.LocalTime; -@Embeddable +@Getter +@Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class SeriesEntity { +@Table(name = "series") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "UPDATE series SET is_deleted = true WHERE series_id = ?") +@Entity +public class SeriesEntity extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long seriesId; + @Setter private Long performanceId; + private LocalDate playDate; + private LocalTime playTime; + private boolean isPerformed; } From e8c68514e09d3a4842b304e915e080b53c286689 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 02:23:09 +0900 Subject: [PATCH 07/17] =?UTF-8?q?refactor:=20casts=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20performance=EC=97=90=EC=84=9C=20series=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../performance/adapter/persistence/PerformanceEntity.java | 4 ---- .../performance/adapter/persistence/SeriesEntity.java | 6 ++++++ .../performance/adapter/web/RegisterPerformanceRequest.java | 3 --- .../jummi/ticket/performance/adapter/web/SeriesRequest.java | 5 +++++ .../com/jummi/ticket/performance/domain/Performance.java | 3 ++- .../java/com/jummi/ticket/performance/domain/Series.java | 4 +++- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java index 94d2d07..fbaa31c 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java @@ -42,10 +42,6 @@ public class PerformanceEntity extends BaseEntity { @OneToMany(mappedBy = "performance", cascade = CascadeType.REMOVE) private List series = new ArrayList<>(); - @ElementCollection - @Column(name = "casts") - private List casts = new ArrayList<>(); - private int runTime; private int minAvailableAge; diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java index ad585e5..0c34d14 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java @@ -8,6 +8,8 @@ import javax.persistence.*; import java.time.LocalDate; import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; @Getter @Builder @@ -28,5 +30,9 @@ public class SeriesEntity extends BaseEntity { private LocalTime playTime; + @ElementCollection + @Column(name = "casts") + private List casts = new ArrayList<>(); + private boolean isPerformed; } diff --git a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java index dd46777..f3f6536 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceRequest.java @@ -35,9 +35,6 @@ public class RegisterPerformanceRequest { @NotNull private final List series; - @NotBlank - private final List casts; - @Positive private final int runTime; diff --git a/src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java b/src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java index 5ac2eef..07e3b86 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/SeriesRequest.java @@ -5,8 +5,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.List; @Builder @RequiredArgsConstructor @@ -16,5 +18,8 @@ public class SeriesRequest { @DateTimeFormat(pattern = "yyyyMMddHHmm") private final LocalDateTime dateTime; + @NotBlank + private final List casts; + private final boolean isPerformed; } diff --git a/src/main/java/com/jummi/ticket/performance/domain/Performance.java b/src/main/java/com/jummi/ticket/performance/domain/Performance.java index 0d6733c..28e703e 100644 --- a/src/main/java/com/jummi/ticket/performance/domain/Performance.java +++ b/src/main/java/com/jummi/ticket/performance/domain/Performance.java @@ -3,9 +3,11 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Getter; import java.util.List; +@Getter @Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) public class Performance { @@ -15,7 +17,6 @@ public class Performance { private Period period; private String venue; private List series; - private List casts; private int runTime; private int minAvailableAge; private List reservationSites; diff --git a/src/main/java/com/jummi/ticket/performance/domain/Series.java b/src/main/java/com/jummi/ticket/performance/domain/Series.java index 3967e30..6d327a1 100644 --- a/src/main/java/com/jummi/ticket/performance/domain/Series.java +++ b/src/main/java/com/jummi/ticket/performance/domain/Series.java @@ -4,8 +4,10 @@ import java.time.LocalDate; import java.time.LocalTime; +import java.util.List; -public record Series(Long seriesId, Long performanceId, LocalDate playDate, LocalTime playTime, boolean isPerformed) { +public record Series(Long seriesId, Long performanceId, LocalDate playDate, LocalTime playTime, List casts, + boolean isPerformed) { @Builder public Series { } From 605708286c7129c3592b22e65192cb2075af6292 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 02:33:36 +0900 Subject: [PATCH 08/17] =?UTF-8?q?fix:=20=ED=95=84=EB=93=9C=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EC=A0=9C=EA=B1=B0,=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/persistence/PerformanceEntity.java | 9 +++------ .../performance/adapter/persistence/SeriesEntity.java | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java index fbaa31c..b1edd46 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java @@ -3,21 +3,18 @@ import com.jummi.ticket.common.adapter.persistence.BaseEntity; import com.jummi.ticket.performance.domain.Genre; import com.jummi.ticket.performance.domain.ReservationSite; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; import javax.persistence.*; import java.time.LocalDate; -import java.util.ArrayList; import java.util.List; import java.util.Set; @Getter @Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "performance") @Where(clause = "is_deleted = false") @@ -40,7 +37,7 @@ public class PerformanceEntity extends BaseEntity { private String venue; @OneToMany(mappedBy = "performance", cascade = CascadeType.REMOVE) - private List series = new ArrayList<>(); + private List series; private int runTime; diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java index 0c34d14..51d1fcb 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java @@ -8,11 +8,11 @@ import javax.persistence.*; import java.time.LocalDate; import java.time.LocalTime; -import java.util.ArrayList; import java.util.List; @Getter @Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "series") @Where(clause = "is_deleted = false") @@ -32,7 +32,7 @@ public class SeriesEntity extends BaseEntity { @ElementCollection @Column(name = "casts") - private List casts = new ArrayList<>(); + private List casts; private boolean isPerformed; } From b8d513217bd5dffcd318dde0a07a8a95ffd21d0c Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 03:45:04 +0900 Subject: [PATCH 09/17] =?UTF-8?q?fix:=20mapper=EA=B0=80=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=EB=A7=A4=ED=95=91=20=EB=AA=BB=ED=95=B4=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=20=ED=95=84=EB=93=9C=20=EC=A7=81=EC=A0=91=20=EB=A7=A4?= =?UTF-8?q?=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/PerformanceMapper.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java index c830df9..32b5c20 100644 --- a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java +++ b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java @@ -15,6 +15,10 @@ @Component @Mapper public interface PerformanceMapper { + + @Mapping(expression = "java(performance.getPerformanceId().id())", target = "performanceId") + @Mapping(expression = "java(performance.getPeriod().startDate())", target = "startDate") + @Mapping(expression = "java(performance.getPeriod().endDate())", target = "endDate") PerformanceEntity convertDomainEntityToJpaEntity(Performance performance); default Performance convertRequestToDomainEntity(RegisterPerformanceRequest request) { @@ -23,21 +27,18 @@ default Performance convertRequestToDomainEntity(RegisterPerformanceRequest requ .genre(Genre.valueOf(request.getGenre())) .period(new Period(request.getStartDate(), request.getEndDate())) .venue(request.getVenue()) - .casts(request.getCasts()) .runTime(request.getRunTime()) .minAvailableAge(request.getMinAvailableAge()) .reservationSites(convertStringToEnum(request.getReservationSites())) .build(); } - default List convertStringToEnum(List reservationSites) { + private List convertStringToEnum(List reservationSites) { return reservationSites.stream() .map(ReservationSite::valueOf) .collect(Collectors.toList()); } - List convertDomainEntityToJpaEntity(List series); - default List extractSeriesDomainEntity(RegisterPerformanceRequest request) { return request.getSeries() .stream() @@ -45,8 +46,14 @@ default List extractSeriesDomainEntity(RegisterPerformanceRequest reques .collect(Collectors.toList()); } - @Mapping(expression = "java(seriesRequest.getDateTime().toLocalDate())", target = "playDate") - @Mapping(expression = "java(seriesRequest.getDateTime().toLocalTime())", target = "playTime") - @Mapping(expression = "java(seriesRequest.isPerformed())", target = "isPerformed") - Series convertRequestToDomainEntity(SeriesRequest seriesRequest); + private Series convertRequestToDomainEntity(SeriesRequest seriesRequest) { + return Series.builder() + .playDate(seriesRequest.getDateTime().toLocalDate()) + .playTime(seriesRequest.getDateTime().toLocalTime()) + .casts(seriesRequest.getCasts()) + .isPerformed(seriesRequest.isPerformed()) + .build(); + } + + List convertDomainEntityToJpaEntity(List series); } From 14a1355da0e2e0b0facc402778632b6de4eff994 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 03:48:08 +0900 Subject: [PATCH 10/17] =?UTF-8?q?feat:=20mapper=20=EB=AA=A8=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jummi/ticket/common/converter/Converters.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/jummi/ticket/common/converter/Converters.java diff --git a/src/main/java/com/jummi/ticket/common/converter/Converters.java b/src/main/java/com/jummi/ticket/common/converter/Converters.java new file mode 100644 index 0000000..6dfb577 --- /dev/null +++ b/src/main/java/com/jummi/ticket/common/converter/Converters.java @@ -0,0 +1,8 @@ +package com.jummi.ticket.common.converter; + +import com.jummi.ticket.performance.converter.PerformanceMapper; +import org.mapstruct.factory.Mappers; + +public class Converters { + public static final PerformanceMapper PERFORMANCE_MAPPER = Mappers.getMapper(PerformanceMapper.class); +} From 92e82446ee4ca6b61c7aa2e5a5a8fe7bc45b4751 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 03:48:35 +0900 Subject: [PATCH 11/17] test: test performance mapper --- .../converter/PerformanceMapperTest.java | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java diff --git a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java new file mode 100644 index 0000000..8986916 --- /dev/null +++ b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java @@ -0,0 +1,185 @@ +package com.jummi.ticket.performance.converter; + +import com.jummi.ticket.common.converter.Converters; +import com.jummi.ticket.performance.adapter.persistence.PerformanceEntity; +import com.jummi.ticket.performance.adapter.persistence.SeriesEntity; +import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; +import com.jummi.ticket.performance.adapter.web.SeriesRequest; +import com.jummi.ticket.performance.domain.*; +import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +class PerformanceMapperTest { + + private final PerformanceMapper mapper = Converters.PERFORMANCE_MAPPER; + + private List playDates; + private List playTimes; + private List> casts; + + @BeforeEach + void setUp() { + playDates = List.of( + LocalDate.of(2022, 5, 13), + LocalDate.of(2022, 5, 14), + LocalDate.of(2022, 5, 15) + ); + playTimes = List.of(LocalTime.of(15, 0), LocalTime.of(12, 0)); + casts = List.of(List.of("잔나비", "솔루션스"), List.of("LUCY", "daybreak", "폴킴"), List.of("소란", "멜로망스", "N.Flying")); + } + + @Test + @DisplayName("convert performance domain entity to performance jpa entity") + void convertPerformanceDomainEntityToJpaEntity() { + Long performanceId = 1L; + Performance performance = createPerformance(performanceId); + PerformanceEntity performanceEntity = mapper.convertDomainEntityToJpaEntity(performance); + + assertAll( + () -> assertThat(performanceEntity.getPerformanceId().longValue()).isEqualTo(performanceId), + () -> assertThat(performanceEntity.getTitle()).isEqualTo("BML"), + () -> assertThat(performanceEntity.getGenre()).isEqualTo(Genre.CONCERT), + () -> assertThat(performanceEntity.getStartDate()).isEqualTo("2022-05-13"), + () -> assertThat(performanceEntity.getEndDate()).isEqualTo("2022-05-15"), + () -> assertThat(performanceEntity.getRunTime()).isEqualTo(540), + () -> assertThat(performanceEntity.getReservationSites()).hasSize(2) + ); + } + + @Test + @DisplayName("convert performance request to performance domain entity") + void convertPerformanceRequestToDomainEntity() { + RegisterPerformanceRequest request = createRegisterPerformanceRequest(); + Performance performance = mapper.convertRequestToDomainEntity(request); + + assertAll( + () -> assertThat(performance.getPerformanceId()).isNull(), + () -> assertThat(performance.getTitle()).isEqualTo("BML"), + () -> assertThat(performance.getGenre()).isEqualTo(Genre.CONCERT), + () -> assertThat(performance.getPeriod().startDate()).isEqualTo("2022-05-13"), + () -> assertThat(performance.getPeriod().endDate()).isEqualTo("2022-05-15"), + () -> assertThat(performance.getSeries()).isNull(), + () -> assertThat(performance.getMinAvailableAge()).isEqualTo(10), + () -> assertThat(performance.getReservationSites()).hasSize(2), + () -> assertThat(performance.getReservationSites()).containsExactlyInAnyOrder(ReservationSite.YES24, ReservationSite.INTERPARK) + ); + } + + @Test + @DisplayName("extract series domain entity from performance request") + void extractSeriesDomainEntity() { + RegisterPerformanceRequest request = createRegisterPerformanceRequest(); + List series = mapper.extractSeriesDomainEntity(request); + + assertAll( + () -> assertThat(series).hasSize(3), + () -> assertThat(series).extracting("playDate", "playTime", "casts", "isPerformed") + .containsExactlyInAnyOrder( + Tuple.tuple(playDates.get(1), playTimes.get(1), casts.get(1), true), + Tuple.tuple(playDates.get(2), playTimes.get(1), casts.get(2), false), + Tuple.tuple(playDates.get(0), playTimes.get(0), casts.get(0), true) + ), + () -> assertThat(series).extracting("seriesId", "performanceId") + .contains(Tuple.tuple(null, null)) + ); + } + + @Test + @DisplayName("convert series domain entity to series jpa entity") + void convertSeriesDomainEntityToJpaEntity() { + List series = createSeries(); + List seriesEntities = mapper.convertDomainEntityToJpaEntity(series); + + assertAll( + () -> assertThat(seriesEntities).hasSize(3), + () -> assertThat(seriesEntities).extracting("playDate", "playTime", "casts", "isPerformed") + .containsExactlyInAnyOrder( + Tuple.tuple(playDates.get(1), playTimes.get(1), casts.get(1), true), + Tuple.tuple(playDates.get(2), playTimes.get(1), casts.get(2), false), + Tuple.tuple(playDates.get(0), playTimes.get(0), casts.get(0), true) + ), + () -> assertThat(seriesEntities).extracting("seriesId", "performanceId") + .contains(Tuple.tuple(null, null)) + ); + } + + private Performance createPerformance(Long performanceId) { + return Performance.builder() + .performanceId(new PerformanceId(performanceId)) + .title("BML") + .genre(Genre.CONCERT) + .period(new Period(LocalDate.of(2022, 5, 13), LocalDate.of(2022, 5, 15))) + .venue("올림픽 공원") + .runTime(540) + .minAvailableAge(10) + .reservationSites(List.of(ReservationSite.INTERPARK, ReservationSite.YES24)) + .build(); + } + + private RegisterPerformanceRequest createRegisterPerformanceRequest() { + return RegisterPerformanceRequest.builder() + .title("BML") + .genre("CONCERT") + .startDate(LocalDate.of(2022, 5, 13)) + .endDate(LocalDate.of(2022, 5, 15)) + .venue("올림픽 공원") + .series(createSeriesRequests()) + .runTime(540) + .minAvailableAge(10) + .reservationSites(List.of("INTERPARK", "YES24")) + .build(); + } + + private List createSeriesRequests() { + return List.of( + SeriesRequest.builder() + .dateTime(LocalDateTime.of(2022, 5, 13, 15, 0)) + .casts(casts.get(0)) + .isPerformed(true) + .build(), + SeriesRequest.builder() + .dateTime(LocalDateTime.of(2022, 5, 14, 12, 0)) + .casts(casts.get(1)) + .isPerformed(true) + .build(), + SeriesRequest.builder() + .dateTime(LocalDateTime.of(2022, 5, 15, 12, 0)) + .casts(casts.get(2)) + .isPerformed(false) + .build() + ); + } + + private List createSeries() { + return List.of( + Series.builder() + .playDate(playDates.get(0)) + .playTime(playTimes.get(0)) + .casts(casts.get(0)) + .isPerformed(true) + .build(), + Series.builder() + .playDate(playDates.get(1)) + .playTime(playTimes.get(1)) + .casts(casts.get(1)) + .isPerformed(true) + .build(), + Series.builder() + .playDate(playDates.get(2)) + .playTime(playTimes.get(1)) + .casts(casts.get(2)) + .isPerformed(false) + .build() + ); + } +} From 8f96a9b8ebe6c429bc0fee61d4cd90c21bb7c3ca Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 11:45:42 +0900 Subject: [PATCH 12/17] =?UTF-8?q?refactor:=20=EB=A7=A4=ED=8D=BC=20?= =?UTF-8?q?=EC=BB=AC=EB=A0=89=EC=85=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jummi/ticket/common/converter/Converters.java | 8 -------- .../performance/converter/PerformanceMapperTest.java | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/com/jummi/ticket/common/converter/Converters.java diff --git a/src/main/java/com/jummi/ticket/common/converter/Converters.java b/src/main/java/com/jummi/ticket/common/converter/Converters.java deleted file mode 100644 index 6dfb577..0000000 --- a/src/main/java/com/jummi/ticket/common/converter/Converters.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.jummi.ticket.common.converter; - -import com.jummi.ticket.performance.converter.PerformanceMapper; -import org.mapstruct.factory.Mappers; - -public class Converters { - public static final PerformanceMapper PERFORMANCE_MAPPER = Mappers.getMapper(PerformanceMapper.class); -} diff --git a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java index 8986916..c00be55 100644 --- a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java +++ b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java @@ -1,6 +1,5 @@ package com.jummi.ticket.performance.converter; -import com.jummi.ticket.common.converter.Converters; import com.jummi.ticket.performance.adapter.persistence.PerformanceEntity; import com.jummi.ticket.performance.adapter.persistence.SeriesEntity; import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; @@ -10,6 +9,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; import java.time.LocalDate; import java.time.LocalDateTime; @@ -21,7 +21,7 @@ class PerformanceMapperTest { - private final PerformanceMapper mapper = Converters.PERFORMANCE_MAPPER; + private final PerformanceMapper mapper = Mappers.getMapper(PerformanceMapper.class); private List playDates; private List playTimes; From facba05f24d0eb04fc36f8c007cefc7c49cf6a54 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 11:46:02 +0900 Subject: [PATCH 13/17] =?UTF-8?q?test:=20=EA=B3=B5=EC=97=B0=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RegisterPerformanceServiceTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java diff --git a/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java b/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java new file mode 100644 index 0000000..d92802b --- /dev/null +++ b/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java @@ -0,0 +1,60 @@ +package com.jummi.ticket.performance.application.service; + +import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; +import com.jummi.ticket.performance.application.port.out.SavePerformanceCommand; +import com.jummi.ticket.performance.converter.PerformanceMapper; +import com.jummi.ticket.performance.domain.Performance; +import com.jummi.ticket.performance.domain.PerformanceId; +import com.jummi.ticket.performance.domain.Series; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class RegisterPerformanceServiceTest { + + @Mock + private PerformanceMapper performanceMapper; + + @Mock + private SavePerformanceCommand savePerformanceCommand; + + @InjectMocks + private RegisterPerformanceService registerPerformanceService; + + @Test + @DisplayName("register performance use case") + void registerPerformance() { + RegisterPerformanceRequest request = mock(RegisterPerformanceRequest.class); + Performance performance = mock(Performance.class); + List series = mock(ArrayList.class); + + given(performanceMapper.convertRequestToDomainEntity(request)) + .willReturn(performance); + given(performanceMapper.extractSeriesDomainEntity(request)) + .willReturn(series); + given(savePerformanceCommand.savePerformance(performance, series)) + .willReturn(anyLong()); + + PerformanceId performanceId = registerPerformanceService.registerPerformance(request); + + assertThat(performanceId.id()).isNotNull(); + verify(performanceMapper, times(1)) + .convertRequestToDomainEntity(request); + verify(performanceMapper, times(1)) + .extractSeriesDomainEntity(request); + verify(savePerformanceCommand, times(1)) + .savePerformance(performance, series); + } +} From abf46e558ef49c336d0ed03c85f1eeb2caf88b98 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 17:51:41 +0900 Subject: [PATCH 14/17] =?UTF-8?q?feat:=20performance=EC=99=80=20series=20?= =?UTF-8?q?=EB=8B=A8=EB=B0=A9=ED=96=A5=20=EB=A7=A4=ED=95=91=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/persistence/PerformanceAdapter.java | 6 ++---- .../adapter/persistence/PerformanceEntity.java | 4 ---- .../adapter/persistence/SeriesEntity.java | 4 +++- .../performance/converter/PerformanceMapper.java | 10 +++++++++- .../converter/PerformanceMapperTest.java | 16 ++++++++++------ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java index 6ce56dd..08c3a92 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapter.java @@ -23,12 +23,10 @@ class PerformanceAdapter implements SavePerformanceCommand { public Long savePerformance(Performance performance, List series) { PerformanceEntity performanceEntity = mapper.convertDomainEntityToJpaEntity(performance); PerformanceEntity saved = performanceRepository.save(performanceEntity); - Long performanceId = saved.getPerformanceId(); - List seriesEntities = mapper.convertDomainEntityToJpaEntity(series); - seriesEntities.forEach(seriesEntity -> seriesEntity.setPerformanceId(performanceId)); + List seriesEntities = mapper.convertDomainEntitiesToJpaEntities(series, saved); seriesRepository.saveAll(seriesEntities); - return performanceId; + return saved.getPerformanceId(); } } diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java index b1edd46..304107f 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/PerformanceEntity.java @@ -9,7 +9,6 @@ import javax.persistence.*; import java.time.LocalDate; -import java.util.List; import java.util.Set; @Getter @@ -36,9 +35,6 @@ public class PerformanceEntity extends BaseEntity { private String venue; - @OneToMany(mappedBy = "performance", cascade = CascadeType.REMOVE) - private List series; - private int runTime; private int minAvailableAge; diff --git a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java index 51d1fcb..622240e 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/persistence/SeriesEntity.java @@ -24,7 +24,9 @@ public class SeriesEntity extends BaseEntity { private Long seriesId; @Setter - private Long performanceId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "performance_id") + private PerformanceEntity performance; private LocalDate playDate; diff --git a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java index 32b5c20..2115abe 100644 --- a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java +++ b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java @@ -55,5 +55,13 @@ private Series convertRequestToDomainEntity(SeriesRequest seriesRequest) { .build(); } - List convertDomainEntityToJpaEntity(List series); + @Mapping(source = "performanceEntity", target = "performance") + default List convertDomainEntitiesToJpaEntities(List series, PerformanceEntity performanceEntity) { + return series.stream() + .map(s -> convertDomainEntityToJpaEntity(s, performanceEntity)) + .collect(Collectors.toList()); + } + + @Mapping(source = "performanceEntity", target = "performance") + SeriesEntity convertDomainEntityToJpaEntity(Series series, PerformanceEntity performanceEntity); } diff --git a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java index c00be55..8b51fa6 100644 --- a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java +++ b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java @@ -21,7 +21,7 @@ class PerformanceMapperTest { - private final PerformanceMapper mapper = Mappers.getMapper(PerformanceMapper.class); + private PerformanceMapper mapper = Mappers.getMapper(PerformanceMapper.class); private List playDates; private List playTimes; @@ -95,10 +95,12 @@ void extractSeriesDomainEntity() { } @Test - @DisplayName("convert series domain entity to series jpa entity") - void convertSeriesDomainEntityToJpaEntity() { + @DisplayName("convert series domain entities to series jpa entities") + void convertSeriesDomainEntitiesToJpaEntities() { List series = createSeries(); - List seriesEntities = mapper.convertDomainEntityToJpaEntity(series); + Performance performance = createPerformance(1L); + PerformanceEntity performanceEntity = mapper.convertDomainEntityToJpaEntity(performance); + List seriesEntities = mapper.convertDomainEntitiesToJpaEntities(series, performanceEntity); assertAll( () -> assertThat(seriesEntities).hasSize(3), @@ -108,8 +110,10 @@ void convertSeriesDomainEntityToJpaEntity() { Tuple.tuple(playDates.get(2), playTimes.get(1), casts.get(2), false), Tuple.tuple(playDates.get(0), playTimes.get(0), casts.get(0), true) ), - () -> assertThat(seriesEntities).extracting("seriesId", "performanceId") - .contains(Tuple.tuple(null, null)) + () -> assertThat(seriesEntities).extracting("seriesId") + .containsNull(), + () -> assertThat(seriesEntities).extracting("performance") + .contains(performanceEntity) ); } From 0581693fd765cb7f7830041b9f24c9d8659eb454 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 17:58:56 +0900 Subject: [PATCH 15/17] =?UTF-8?q?refactor:=20=EA=B3=B5=EC=97=B0=EC=9D=98?= =?UTF-8?q?=20id=EB=A5=BC=20PerformanceId=20->=20Long=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/web/RegisterPerformanceController.java | 5 ++--- .../application/port/in/RegisterPerformanceUseCase.java | 3 +-- .../application/service/RegisterPerformanceService.java | 6 ++---- .../ticket/performance/converter/PerformanceMapper.java | 2 +- .../com/jummi/ticket/performance/domain/Performance.java | 2 +- .../jummi/ticket/performance/domain/PerformanceId.java | 4 ---- .../service/RegisterPerformanceServiceTest.java | 5 ++--- .../performance/converter/PerformanceMapperTest.java | 9 +++------ 8 files changed, 12 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/com/jummi/ticket/performance/domain/PerformanceId.java diff --git a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java index bca62d1..63a153f 100644 --- a/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java +++ b/src/main/java/com/jummi/ticket/performance/adapter/web/RegisterPerformanceController.java @@ -1,7 +1,6 @@ package com.jummi.ticket.performance.adapter.web; import com.jummi.ticket.performance.application.port.in.RegisterPerformanceUseCase; -import com.jummi.ticket.performance.domain.PerformanceId; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -20,10 +19,10 @@ class RegisterPerformanceController { @PostMapping ResponseEntity registerPerformance(@RequestBody @Valid RegisterPerformanceRequest request) { - PerformanceId performanceId = registerPerformanceUseCase.registerPerformance(request); + Long performanceId = registerPerformanceUseCase.registerPerformance(request); return ResponseEntity.created( - URI.create("/api/performances/" + performanceId.id())) + URI.create("/api/performances/" + performanceId)) .build(); } } diff --git a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java b/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java index 5e1a733..78e38c8 100644 --- a/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java +++ b/src/main/java/com/jummi/ticket/performance/application/port/in/RegisterPerformanceUseCase.java @@ -1,8 +1,7 @@ package com.jummi.ticket.performance.application.port.in; import com.jummi.ticket.performance.adapter.web.RegisterPerformanceRequest; -import com.jummi.ticket.performance.domain.PerformanceId; public interface RegisterPerformanceUseCase { - PerformanceId registerPerformance(RegisterPerformanceRequest request); + Long registerPerformance(RegisterPerformanceRequest request); } diff --git a/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java b/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java index 58ed0cf..9164b54 100644 --- a/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java +++ b/src/main/java/com/jummi/ticket/performance/application/service/RegisterPerformanceService.java @@ -5,7 +5,6 @@ import com.jummi.ticket.performance.application.port.out.SavePerformanceCommand; import com.jummi.ticket.performance.converter.PerformanceMapper; import com.jummi.ticket.performance.domain.Performance; -import com.jummi.ticket.performance.domain.PerformanceId; import com.jummi.ticket.performance.domain.Series; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,11 +18,10 @@ public class RegisterPerformanceService implements RegisterPerformanceUseCase { private final SavePerformanceCommand savePerformanceCommand; @Override - public PerformanceId registerPerformance(RegisterPerformanceRequest request) { + public Long registerPerformance(RegisterPerformanceRequest request) { Performance performance = mapper.convertRequestToDomainEntity(request); List series = mapper.extractSeriesDomainEntity(request); - Long performanceId = savePerformanceCommand.savePerformance(performance, series); - return new PerformanceId(performanceId); + return savePerformanceCommand.savePerformance(performance, series); } } diff --git a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java index 2115abe..0a8ccb6 100644 --- a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java +++ b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java @@ -16,7 +16,7 @@ @Mapper public interface PerformanceMapper { - @Mapping(expression = "java(performance.getPerformanceId().id())", target = "performanceId") + @Mapping(expression = "java(performance.getPerformanceId())", target = "performanceId") @Mapping(expression = "java(performance.getPeriod().startDate())", target = "startDate") @Mapping(expression = "java(performance.getPeriod().endDate())", target = "endDate") PerformanceEntity convertDomainEntityToJpaEntity(Performance performance); diff --git a/src/main/java/com/jummi/ticket/performance/domain/Performance.java b/src/main/java/com/jummi/ticket/performance/domain/Performance.java index 28e703e..3d5e913 100644 --- a/src/main/java/com/jummi/ticket/performance/domain/Performance.java +++ b/src/main/java/com/jummi/ticket/performance/domain/Performance.java @@ -11,7 +11,7 @@ @Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) public class Performance { - private PerformanceId performanceId; + private Long performanceId; private String title; private Genre genre; private Period period; diff --git a/src/main/java/com/jummi/ticket/performance/domain/PerformanceId.java b/src/main/java/com/jummi/ticket/performance/domain/PerformanceId.java deleted file mode 100644 index 829fcda..0000000 --- a/src/main/java/com/jummi/ticket/performance/domain/PerformanceId.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.jummi.ticket.performance.domain; - -public record PerformanceId(Long id) { -} diff --git a/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java b/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java index d92802b..9de4e96 100644 --- a/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java +++ b/src/test/java/com/jummi/ticket/performance/application/service/RegisterPerformanceServiceTest.java @@ -4,7 +4,6 @@ import com.jummi.ticket.performance.application.port.out.SavePerformanceCommand; import com.jummi.ticket.performance.converter.PerformanceMapper; import com.jummi.ticket.performance.domain.Performance; -import com.jummi.ticket.performance.domain.PerformanceId; import com.jummi.ticket.performance.domain.Series; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -47,9 +46,9 @@ void registerPerformance() { given(savePerformanceCommand.savePerformance(performance, series)) .willReturn(anyLong()); - PerformanceId performanceId = registerPerformanceService.registerPerformance(request); + Long performanceId = registerPerformanceService.registerPerformance(request); - assertThat(performanceId.id()).isNotNull(); + assertThat(performanceId).isNotNull(); verify(performanceMapper, times(1)) .convertRequestToDomainEntity(request); verify(performanceMapper, times(1)) diff --git a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java index 8b51fa6..d51fdf2 100644 --- a/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java +++ b/src/test/java/com/jummi/ticket/performance/converter/PerformanceMapperTest.java @@ -41,12 +41,10 @@ void setUp() { @Test @DisplayName("convert performance domain entity to performance jpa entity") void convertPerformanceDomainEntityToJpaEntity() { - Long performanceId = 1L; - Performance performance = createPerformance(performanceId); + Performance performance = createPerformance(); PerformanceEntity performanceEntity = mapper.convertDomainEntityToJpaEntity(performance); assertAll( - () -> assertThat(performanceEntity.getPerformanceId().longValue()).isEqualTo(performanceId), () -> assertThat(performanceEntity.getTitle()).isEqualTo("BML"), () -> assertThat(performanceEntity.getGenre()).isEqualTo(Genre.CONCERT), () -> assertThat(performanceEntity.getStartDate()).isEqualTo("2022-05-13"), @@ -98,7 +96,7 @@ void extractSeriesDomainEntity() { @DisplayName("convert series domain entities to series jpa entities") void convertSeriesDomainEntitiesToJpaEntities() { List series = createSeries(); - Performance performance = createPerformance(1L); + Performance performance = createPerformance(); PerformanceEntity performanceEntity = mapper.convertDomainEntityToJpaEntity(performance); List seriesEntities = mapper.convertDomainEntitiesToJpaEntities(series, performanceEntity); @@ -117,9 +115,8 @@ void convertSeriesDomainEntitiesToJpaEntities() { ); } - private Performance createPerformance(Long performanceId) { + private Performance createPerformance() { return Performance.builder() - .performanceId(new PerformanceId(performanceId)) .title("BML") .genre(Genre.CONCERT) .period(new Period(LocalDate.of(2022, 5, 13), LocalDate.of(2022, 5, 15))) From c6b7343021f0db99f3a3e5ce37a977d22caf6b53 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 18:00:33 +0900 Subject: [PATCH 16/17] =?UTF-8?q?chore:=20mapper=20bean=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EB=B0=A9=EB=B2=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit component scan -> mapstruct library --- .../jummi/ticket/performance/converter/PerformanceMapper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java index 0a8ccb6..2b74c26 100644 --- a/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java +++ b/src/main/java/com/jummi/ticket/performance/converter/PerformanceMapper.java @@ -7,13 +7,11 @@ import com.jummi.ticket.performance.domain.*; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors; -@Component -@Mapper +@Mapper(componentModel = "spring") public interface PerformanceMapper { @Mapping(expression = "java(performance.getPerformanceId())", target = "performanceId") From 652867645135e5ec2dbecc2b1d2a9c01e1dee8d8 Mon Sep 17 00:00:00 2001 From: jummi <98qkrwjdal@naver.com> Date: Thu, 23 Jun 2022 18:01:04 +0900 Subject: [PATCH 17/17] =?UTF-8?q?test:=20performance=20=EC=98=81=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=96=B4=EB=8C=91=ED=84=B0=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/PerformanceAdapterTest.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/test/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapterTest.java diff --git a/src/test/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapterTest.java b/src/test/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapterTest.java new file mode 100644 index 0000000..dab7f05 --- /dev/null +++ b/src/test/java/com/jummi/ticket/performance/adapter/persistence/PerformanceAdapterTest.java @@ -0,0 +1,84 @@ +package com.jummi.ticket.performance.adapter.persistence; + +import com.jummi.ticket.performance.converter.PerformanceMapperImpl; +import com.jummi.ticket.performance.domain.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +@DataJpaTest +@Import({PerformanceMapperImpl.class, PerformanceAdapter.class}) +class PerformanceAdapterTest { + + @Autowired + private PerformanceAdapter performanceAdapter; + + private List playDates; + private List playTimes; + private List> casts; + + @BeforeEach + void setUp() { + playDates = List.of( + LocalDate.of(2022, 5, 13), + LocalDate.of(2022, 5, 14), + LocalDate.of(2022, 5, 15) + ); + playTimes = List.of(LocalTime.of(15, 0), LocalTime.of(12, 0)); + casts = List.of(List.of("잔나비", "솔루션스"), List.of("LUCY", "daybreak", "폴킴"), List.of("소란", "멜로망스", "N.Flying")); + } + + @Test + @DisplayName("save performance") + void savePerformance() { + Performance performance = createPerformance(); + List series = createSeries(); + Long performanceId = performanceAdapter.savePerformance(performance, series); + + assertThat(performanceId).isInstanceOf(Long.class); + } + + private Performance createPerformance() { + return Performance.builder() + .title("BML") + .genre(Genre.CONCERT) + .period(new Period(LocalDate.of(2022, 5, 13), LocalDate.of(2022, 5, 15))) + .venue("올림픽 공원") + .runTime(540) + .minAvailableAge(10) + .reservationSites(List.of(ReservationSite.INTERPARK, ReservationSite.YES24)) + .build(); + } + + private List createSeries() { + return List.of( + Series.builder() + .playDate(playDates.get(0)) + .playTime(playTimes.get(0)) + .casts(casts.get(0)) + .isPerformed(true) + .build(), + Series.builder() + .playDate(playDates.get(1)) + .playTime(playTimes.get(1)) + .casts(casts.get(1)) + .isPerformed(true) + .build(), + Series.builder() + .playDate(playDates.get(2)) + .playTime(playTimes.get(1)) + .casts(casts.get(2)) + .isPerformed(false) + .build() + ); + } +}