From 40d034d474c243a1895e81381cc85532aca543ec Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 5 Mar 2024 15:38:16 +0900 Subject: [PATCH 01/23] =?UTF-8?q?feat:=20=EC=8A=A4=EC=BC=80=EC=A5=B4?= =?UTF-8?q?=EB=9F=AC=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/config/SchedulerConfig.java | 10 ++++++++++ .../scheduler/application/SchedulerService.java | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 backend/src/main/java/com/festago/config/SchedulerConfig.java create mode 100644 backend/src/main/java/com/festago/scheduler/application/SchedulerService.java diff --git a/backend/src/main/java/com/festago/config/SchedulerConfig.java b/backend/src/main/java/com/festago/config/SchedulerConfig.java new file mode 100644 index 000000000..3a496b0d8 --- /dev/null +++ b/backend/src/main/java/com/festago/config/SchedulerConfig.java @@ -0,0 +1,10 @@ +package com.festago.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; + +@EnableScheduling +@Configuration +public class SchedulerConfig { + +} diff --git a/backend/src/main/java/com/festago/scheduler/application/SchedulerService.java b/backend/src/main/java/com/festago/scheduler/application/SchedulerService.java new file mode 100644 index 000000000..e0720712f --- /dev/null +++ b/backend/src/main/java/com/festago/scheduler/application/SchedulerService.java @@ -0,0 +1,13 @@ +package com.festago.scheduler.application; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class SchedulerService { + + @Scheduled(fixedDelay = 1000) + public void run() { + System.out.println("called"); + } +} From 95c8bf64083a1bdab60bc4107b985e61f8952af0 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 5 Mar 2024 16:13:26 +0900 Subject: [PATCH 02/23] =?UTF-8?q?feat:=20=EC=95=B1=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EC=8B=9C=20=ED=95=99=EA=B5=90=EC=99=80=20=EC=B6=95=EC=A0=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/mock/MockArtist.java | 40 ++++++++++++++++ .../CommandLineAppStartupRunner.java | 17 +++++++ .../mock/application/MockDataInitializer.java | 48 +++++++++++++++++++ .../application/SchedulerService.java | 2 +- 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/com/festago/mock/MockArtist.java create mode 100644 backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java create mode 100644 backend/src/main/java/com/festago/mock/application/MockDataInitializer.java rename backend/src/main/java/com/festago/{scheduler => mock}/application/SchedulerService.java (85%) diff --git a/backend/src/main/java/com/festago/mock/MockArtist.java b/backend/src/main/java/com/festago/mock/MockArtist.java new file mode 100644 index 000000000..ede1c5f65 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/MockArtist.java @@ -0,0 +1,40 @@ +package com.festago.mock; + +public enum MockArtist { + 윤하("https://i.namu.wiki/i/GXgnzRzEe4tq0YmevyZdmLNTPmVK2fzRyZtiCMA-0QSO8vbau9tah4rgP3qNokmT33-El0fx2PauysBruWpTk8B6MLu73gDgVnC3tvFeBnm3Lwo9oRreHM6slID3ilDTyFjpV2eKMO80Jf5u5E920g.webp", + "https://i.namu.wiki/i/IBHythQ09eithIwC-Ix3hr0Sh-AohBVBavl0u-2WW28L6f16JM8F8Klm-0A6gDacgy4t7ATbto7wBc9xt5gwsj0IVG1y9EphSkJun-op4O9OGwvOvX8ES8aTUejOsKPFX5Iat_ubwgGWAYudo5q-Yw.webp"), + 뉴진스("https://i.namu.wiki/i/l1co7IV1KFVJ9HBgzxCXkMbgMfuZp_MJhjhqgB7e76DLuokabw6CNlltqr7HGzAMFqt42JfXF94Cflw5XdDuXTS2QkvomS7WYpiiJbuAn5MAjBxOA_zT93dsgyLO-gJXtV0JN-jEQ4tQ-MWtqbHJyA.webp", + "https://i.namu.wiki/i/j5Fs-OjRcQsjfrrFFUVumAWauv-47tj5WPrfyIcCMuBrV5UeStJwaFK17HKcaKxvME2NVpo5PuxVgRpED1huULNxCYBydqsOs-HCLRD-kMztnZdaMJJvi1VefVB1RN0MnwMdxS7xKzxJa11qem0LMg.svg"), + 아이유("https://i.namu.wiki/i/k-to3_lfqjjcdnXtWMu3aLtZAArBM1nDpDP6cCWz5iJYm3HjJZ3b7i2H-4-KFSkQ6HOeftXIilMOQXvkdp83hu1FdBv5GE_PyYuacNUSygQ2cnT8vfNHqQVUReYdEYY3ob1BWoyGBE6BQRaHmnGPLw.webp", + "https://i.namu.wiki/i/bJDL9DWmKsrHvvMcLOSKMlVv_E62CX6brjhiddhFuLrGPVYN6-bYcJxUHnE_KP04Ok-8PqezYob8OCepRWFBw6CTDE5Jvde2iJOZEqGgYVt6Gdbub0s9pBIOqzI1DQYZvJbAezbh-8xns_ZugPW68g.webp"), + 방탄소년단( + "https://i.namu.wiki/i/EvnNG2DchyHHYmFtyWWzVHhPKkURdc6kdoiRVYisSKHE6BDE8itzfhfYvIMdoX0-6wvum0UgELIowRGR6cuwfNsR1OHrLamq-Rpg0F4XzFMSJHJ_xchPwFBBurNR45kOUYk2ueOKasd-xZ0g9Z14dg.webp", + "https://i.namu.wiki/i/PmFR4AjifhcmdLRXQUPPce9Z7BXVWc6mVX4N22fPUKOzK5ZfjNTfo9e1M7HPa2jiEmG_tuhm43aJMGWLylyQqw.svg"), + 푸우("https://i.namu.wiki/i/aj4JXZR4P-ZiY6Gf0EsoPMK3XFHHsSmx0b8ysKnUDpEd0ET1BVQHZIEAGvZGHCNJrn7Nkz7N5zeYzKh3WPSTGdCdOPpj1LnlAceeLWTmMSsiXvl2fyGaEZfRjm7i6DiBTW6_7pDqIRCWfYRQFKUsdg.webp", + "https://i.namu.wiki/i/_EIBF52MTqZAj5wtmY86jsU4fs7aYsdns4guDgLKYWQGoauVdCyZZiFcxc5qI92HxTUiWRRRrK0qk4Ot0qCRGpIc1GUTjUaYz1Y20IKkDuIo9472InXbpNMxcsE8PmP-taYj-7-Ql3_P557yYOk3EA.webp"), + 장범준("https://i.namu.wiki/i/6VAPyai_C0lBvsGytiMDu3moDOzS9UH9TDHqxzkjPWFymhQV-vcyH4q884nf1KKH2lVzLqMndBnCOTlUh4ZJE6QeB1oUQEH23d_FwMa3CFsyj8mkn3nG2DQMmJ31TN0cvCrxk6II8-IWq6C-d883zA.webp", + "https://i.namu.wiki/i/WPzIZvkNW_-q9UZmEHLKMtrvAQ2g2Oo7MwbrbzWnWEkRYYAdc2cyougS-n8-BwWsLuo3knt9aaHYEGiyhd7jtg.webp"), + 세븐틴("https://i.namu.wiki/i/55JrvWZKaTo_Vik4Wim6-PfXiEmWqwYnAwL5_KmNg9FWiM31U5VV-lmMl76TgtON5hpGP9dIEBhub70rAQvbvOVWt7dQ6GLqvrnpbQSV3Vr1vEKRXjk_RSqCpz5a_7nupUqhB8sBJExEDHf7WGKQDw.webp", + "https://i.namu.wiki/i/l4c_545au41xOK_9XRJyDh1PoNU1k9v-T5NF1UhLHxgCBQJzahV-ra8kP87FLmVFhey_OaWJcrBDJs0RmqbBB3lziiAgbM9lkDUAkENQBv4GweS2MSglXGGno9XQfnzisf5e-Z7185_U4jTqIqTiQA.svg"), + 아이들("https://i.namu.wiki/i/LTu_7r5vrTyZgjGb0pV79BoSI_CZr3hwLMnj2s1-ShPb-A07Nc0Gh_rGn8dic1_JwcJlB-pnSunyqmmIP-UhKRw33PlPO5GECFE2u4I5EtKIXN3c5u8_Wln6U22-Ofyjf90PxLLG1BLQziOoQ0d-pg.webp", + "https://i.namu.wiki/i/KwThwv_MdMM3O7mCr-WyXHXCZhfwKtLgAof5i-wIkkgp10izoSGyTKwCgMgBcoAaIP7VocBS-D36nHI6pkiPy3E8ncWJqsqrghC8bwoaM5dOEs32E9QSxk12CZUKCzGg9AM1bJivIuBBzFBpuc5JBg.webp"), + 에스파("https://i.namu.wiki/i/KJ5Gpz42djU6ZUsFKnkAnpMS1zRFxUOuqzt9plzbjV_mkFlruZcDULsfEjpVw-2vxjsSKbcGflPlOThHE1DgzST-hnm9jmxPqdPMExPkqH_71ZMF6jhQVfQX6QuNZw3Bz0EZ4C1sO5vpZ-OJNfvTyg.webp", + "https://i.namu.wiki/i/yAfAHme6H-HfWWQCvNAje-KInl_XM-xzRHOUmUxvRxh-HLbzk8KbG6zmD9qQXfUAeCenhHM5whZJ2nhQk0lanzT1LVja3BEQCVk1yPWABxy4NygdaLGyNpiRZTwVFkhD_PnCcESdUQ7-oEtK0YptsQ.webp"), + ; + + private final String profileImage; + private final String backgroundImageUrl; + + MockArtist(String profileImage, String backgroundImageUrl) { + this.profileImage = profileImage; + this.backgroundImageUrl = backgroundImageUrl; + } + + public String getProfileImage() { + return profileImage; + } + + public String getBackgroundImageUrl() { + return backgroundImageUrl; + } +} diff --git a/backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java b/backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java new file mode 100644 index 000000000..c473a14b4 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java @@ -0,0 +1,17 @@ +package com.festago.mock.application; + +import lombok.RequiredArgsConstructor; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class CommandLineAppStartupRunner implements CommandLineRunner { + + private final MockDataInitializer mockDataInitializer; + + @Override + public void run(String... args) { + mockDataInitializer.initialize(); + } +} diff --git a/backend/src/main/java/com/festago/mock/application/MockDataInitializer.java b/backend/src/main/java/com/festago/mock/application/MockDataInitializer.java new file mode 100644 index 000000000..b8b8b5e78 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/application/MockDataInitializer.java @@ -0,0 +1,48 @@ +package com.festago.mock.application; + +import com.festago.artist.domain.Artist; +import com.festago.artist.repository.ArtistRepository; +import com.festago.mock.MockArtist; +import com.festago.school.domain.School; +import com.festago.school.domain.SchoolRegion; +import com.festago.school.repository.SchoolRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class MockDataInitializer { + + private final SchoolRepository schoolRepository; + private final ArtistRepository artistRepository; + + public void initialize() { + if (alreadyInitialized()) { + return; + } + initializeData(); + } + + private boolean alreadyInitialized() { + return !schoolRepository.findAll().isEmpty(); + } + + private void initializeData() { + initializeSchool(); + initializeArtist(); + } + + private void initializeSchool() { + for (SchoolRegion schoolRegion : SchoolRegion.values()) { + schoolRepository.save(new School("domain", schoolRegion.name() + "대 축제", schoolRegion)); + } + } + + private void initializeArtist() { + for (MockArtist artist : MockArtist.values()) { + artistRepository.save(new Artist(artist.name(), artist.getProfileImage(), artist.getBackgroundImageUrl())); + } + } +} diff --git a/backend/src/main/java/com/festago/scheduler/application/SchedulerService.java b/backend/src/main/java/com/festago/mock/application/SchedulerService.java similarity index 85% rename from backend/src/main/java/com/festago/scheduler/application/SchedulerService.java rename to backend/src/main/java/com/festago/mock/application/SchedulerService.java index e0720712f..24a9797e4 100644 --- a/backend/src/main/java/com/festago/scheduler/application/SchedulerService.java +++ b/backend/src/main/java/com/festago/mock/application/SchedulerService.java @@ -1,4 +1,4 @@ -package com.festago.scheduler.application; +package com.festago.mock.application; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; From b577046c13c303523e320dca9e810781e9075fc0 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 5 Mar 2024 17:15:36 +0900 Subject: [PATCH 03/23] =?UTF-8?q?chore:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{application => }/CommandLineAppStartupRunner.java | 7 ++++--- .../SchedulerService.java => MockScheduler.java} | 8 ++++---- .../{MockDataInitializer.java => MockDataService.java} | 6 +++++- 3 files changed, 13 insertions(+), 8 deletions(-) rename backend/src/main/java/com/festago/mock/{application => }/CommandLineAppStartupRunner.java (64%) rename backend/src/main/java/com/festago/mock/{application/SchedulerService.java => MockScheduler.java} (56%) rename backend/src/main/java/com/festago/mock/application/{MockDataInitializer.java => MockDataService.java} (94%) diff --git a/backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java similarity index 64% rename from backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java rename to backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java index c473a14b4..f17882ac0 100644 --- a/backend/src/main/java/com/festago/mock/application/CommandLineAppStartupRunner.java +++ b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java @@ -1,5 +1,6 @@ -package com.festago.mock.application; +package com.festago.mock; +import com.festago.mock.application.MockDataService; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -8,10 +9,10 @@ @RequiredArgsConstructor public class CommandLineAppStartupRunner implements CommandLineRunner { - private final MockDataInitializer mockDataInitializer; + private final MockDataService mockDataService; @Override public void run(String... args) { - mockDataInitializer.initialize(); + mockDataService.initialize(); } } diff --git a/backend/src/main/java/com/festago/mock/application/SchedulerService.java b/backend/src/main/java/com/festago/mock/MockScheduler.java similarity index 56% rename from backend/src/main/java/com/festago/mock/application/SchedulerService.java rename to backend/src/main/java/com/festago/mock/MockScheduler.java index 24a9797e4..346736207 100644 --- a/backend/src/main/java/com/festago/mock/application/SchedulerService.java +++ b/backend/src/main/java/com/festago/mock/MockScheduler.java @@ -1,10 +1,10 @@ -package com.festago.mock.application; +package com.festago.mock; import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; -@Service -public class SchedulerService { +@Component +public class MockScheduler { @Scheduled(fixedDelay = 1000) public void run() { diff --git a/backend/src/main/java/com/festago/mock/application/MockDataInitializer.java b/backend/src/main/java/com/festago/mock/application/MockDataService.java similarity index 94% rename from backend/src/main/java/com/festago/mock/application/MockDataInitializer.java rename to backend/src/main/java/com/festago/mock/application/MockDataService.java index b8b8b5e78..4aedbf2c5 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataInitializer.java +++ b/backend/src/main/java/com/festago/mock/application/MockDataService.java @@ -13,7 +13,7 @@ @Service @Transactional @RequiredArgsConstructor -public class MockDataInitializer { +public class MockDataService { private final SchoolRepository schoolRepository; private final ArtistRepository artistRepository; @@ -45,4 +45,8 @@ private void initializeArtist() { artistRepository.save(new Artist(artist.name(), artist.getProfileImage(), artist.getBackgroundImageUrl())); } } + + public void makeMockFestivals() { + + } } From 6a0beff65a13a88bffebd5dabe48854740370309 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 05:58:24 +0900 Subject: [PATCH 04/23] =?UTF-8?q?feat:=20MockService=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/FestivalRepository.java | 5 +- .../mock/CommandLineAppStartupRunner.java | 2 + .../java/com/festago/mock/MockScheduler.java | 13 +- .../application/FestivalDateGenerator.java | 10 + .../mock/application/MockDataService.java | 119 ++++++++++- .../RandomFestivalDateGenerator.java | 30 +++ .../repository/StageArtistRepository.java | 2 + .../stage/repository/StageRepository.java | 2 + .../repository/MemoryFestivalRepository.java | 7 + .../mock/application/MockDataServiceTest.java | 197 ++++++++++++++++++ .../festago/mock/config/MockDataConfig.java | 63 ++++++ .../MemoryStageArtistRepository.java | 6 + .../repository/MemoryStageRepository.java | 6 + 13 files changed, 457 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java create mode 100644 backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java create mode 100644 backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java create mode 100644 backend/src/test/java/com/festago/mock/config/MockDataConfig.java diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java index e807237b6..785668ca6 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java @@ -3,6 +3,7 @@ import com.festago.common.exception.ErrorCode; import com.festago.common.exception.NotFoundException; import com.festago.festival.domain.Festival; +import java.util.List; import java.util.Optional; import org.springframework.data.repository.Repository; @@ -16,8 +17,10 @@ default Festival getOrThrow(Long festivalId) { boolean existsBySchoolId(Long schoolId); Festival save(Festival festival); - + Optional findById(Long festivalId); void deleteById(Long festivalId); + + List findAll(); } diff --git a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java index f17882ac0..bcf1561e4 100644 --- a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java +++ b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java @@ -3,8 +3,10 @@ import com.festago.mock.application.MockDataService; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; +import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; +@Profile({"dev"}) @Component @RequiredArgsConstructor public class CommandLineAppStartupRunner implements CommandLineRunner { diff --git a/backend/src/main/java/com/festago/mock/MockScheduler.java b/backend/src/main/java/com/festago/mock/MockScheduler.java index 346736207..bb07bb652 100644 --- a/backend/src/main/java/com/festago/mock/MockScheduler.java +++ b/backend/src/main/java/com/festago/mock/MockScheduler.java @@ -1,13 +1,22 @@ package com.festago.mock; +import com.festago.mock.application.MockDataService; +import java.util.concurrent.TimeUnit; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +@Profile("dev") @Component +@RequiredArgsConstructor public class MockScheduler { - @Scheduled(fixedDelay = 1000) + private static final long SCHEDULER_CYCLE = 7; + private final MockDataService mockDataService; + + @Scheduled(fixedDelay = SCHEDULER_CYCLE, timeUnit = TimeUnit.DAYS) public void run() { - System.out.println("called"); + mockDataService.makeMockFestivals((int) SCHEDULER_CYCLE); } } diff --git a/backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java new file mode 100644 index 000000000..8a4008ec9 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java @@ -0,0 +1,10 @@ +package com.festago.mock.application; + +import java.time.LocalDate; + +public interface FestivalDateGenerator { + + LocalDate makeRandomStartDate(int festivalDuration, LocalDate now); + + LocalDate makeRandomEndDate(int festivalDuration, LocalDate now, LocalDate startDate); +} diff --git a/backend/src/main/java/com/festago/mock/application/MockDataService.java b/backend/src/main/java/com/festago/mock/application/MockDataService.java index 4aedbf2c5..b7e0daad3 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/application/MockDataService.java @@ -1,22 +1,54 @@ package com.festago.mock.application; import com.festago.artist.domain.Artist; +import com.festago.artist.domain.ArtistsSerializer; import com.festago.artist.repository.ArtistRepository; +import com.festago.festival.domain.Festival; +import com.festago.festival.domain.FestivalQueryInfo; +import com.festago.festival.repository.FestivalInfoRepository; +import com.festago.festival.repository.FestivalRepository; import com.festago.mock.MockArtist; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; import com.festago.school.repository.SchoolRepository; +import com.festago.stage.domain.Stage; +import com.festago.stage.domain.StageArtist; +import com.festago.stage.domain.StageQueryInfo; +import com.festago.stage.repository.StageArtistRepository; +import com.festago.stage.repository.StageQueryInfoRepository; +import com.festago.stage.repository.StageRepository; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.atomic.AtomicLong; import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +@Profile({"dev"}) @Service @Transactional @RequiredArgsConstructor public class MockDataService { + private static final AtomicLong FESTIVAL_SEQUENCE = new AtomicLong(); + private static final long STAGE_START_HOUR = 19L; + private static final int STAGE_ARTIST_COUNT = 3; + + private final FestivalDateGenerator festivalDateGenerator; private final SchoolRepository schoolRepository; private final ArtistRepository artistRepository; + private final FestivalRepository festivalRepository; + private final StageRepository stageRepository; + private final StageArtistRepository stageArtistRepository; + private final FestivalInfoRepository festivalInfoRepository; + private final StageQueryInfoRepository stageQueryInfoRepository; + private final ArtistsSerializer artistsSerializer; public void initialize() { if (alreadyInitialized()) { @@ -36,8 +68,25 @@ private void initializeData() { private void initializeSchool() { for (SchoolRegion schoolRegion : SchoolRegion.values()) { - schoolRepository.save(new School("domain", schoolRegion.name() + "대 축제", schoolRegion)); + if (SchoolRegion.ANY.equals(schoolRegion)) { + continue; + } + schoolRepository.saveAll(makeRegionSchools(schoolRegion)); + } + } + + private List makeRegionSchools(SchoolRegion schoolRegion) { + List result = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + int schoolNumber = i + 1; + String schoolName = schoolRegion.name() + schoolNumber; + result.add(new School( + schoolName + ".com", + schoolName, + schoolRegion + )); } + return result; } private void initializeArtist() { @@ -46,7 +95,73 @@ private void initializeArtist() { } } - public void makeMockFestivals() { + public void makeMockFestivals(int availableFestivalDuration) { + List allSchool = schoolRepository.findAll(); + List allArtist = artistRepository.findAll(); + for (School school : allSchool) { + makeFestival(availableFestivalDuration, school, allArtist); + } + } + + private void makeFestival(int availableFestivalDuration, School school, List artists) { + LocalDate now = LocalDate.now(); + LocalDate startDate = festivalDateGenerator.makeRandomStartDate(availableFestivalDuration, now); + LocalDate endDate = festivalDateGenerator.makeRandomEndDate(availableFestivalDuration, now, startDate); + + Festival newFestival = festivalRepository.save( + new Festival("Festival" + FESTIVAL_SEQUENCE.incrementAndGet(), startDate, endDate, school)); + List participatedArtists = makeStages(newFestival, makeRandomArtists(artists)); + + makeFestivalQueryInfo(newFestival, participatedArtists); + } + + private Queue makeRandomArtists(List artists) { + List randomArtists = new ArrayList<>(artists); + Collections.shuffle(randomArtists); + return new ArrayDeque<>(randomArtists); + } + + private List makeStages(Festival festival, Queue artists) { + LocalDate endDate = festival.getEndDate(); + LocalDate dateCursor = festival.getStartDate(); + List participatedArtists = new ArrayList<>(); + while (dateCursor.isAfter(endDate)) { + participatedArtists.addAll(makeStage(festival, artists, dateCursor)); + dateCursor = dateCursor.plusDays(1); + } + return participatedArtists; + } + + private List makeStage(Festival festival, Queue artists, LocalDate localDate) { + LocalDateTime startTime = localDate.atStartOfDay().plusHours(STAGE_START_HOUR); + Stage stage = stageRepository.save(new Stage(startTime, startTime.minusDays(1L), festival)); + List stageArtists = selectArtists(artists, STAGE_ARTIST_COUNT); + makeStageArtists(stageArtists, stage); + return stageArtists; + } + + private List selectArtists(Queue artists, int count) { + List result = new ArrayList<>(); + for (int i = 0; i < count; i++) { + Artist artist = artists.poll(); + if (artist == null) { + throw new IllegalArgumentException("축제를 만들기 위한 Artist 가 부족합니다"); + } + result.add(artist); + } + return result; + } + + private void makeStageArtists(List artists, Stage stage) { + for (Artist artist : artists) { + stageArtistRepository.save(new StageArtist(stage.getId(), artist.getId())); + } + stageQueryInfoRepository.save(StageQueryInfo.of(stage.getId(), artists, artistsSerializer)); + } + private void makeFestivalQueryInfo(Festival newFestival, List participatedArtists) { + FestivalQueryInfo festivalQueryInfo = FestivalQueryInfo.create(newFestival.getId()); + festivalQueryInfo.updateArtistInfo(participatedArtists, artistsSerializer); + festivalInfoRepository.save(festivalQueryInfo); } } diff --git a/backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java new file mode 100644 index 000000000..ec8aa21fd --- /dev/null +++ b/backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java @@ -0,0 +1,30 @@ +package com.festago.mock.application; + +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.Random; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Profile("dev") +@Component +public class RandomFestivalDateGenerator implements FestivalDateGenerator{ + + private static final int COUNT_FIRST_DAY_AS_DURATION_ONE = 1; + private static final int RANDOM_OFFSET = 1; + private static final int MAX_END_DATE_FROM_START_DATE = 2; + private final Random random = new Random(); + + @Override + public LocalDate makeRandomStartDate(int festivalDuration, LocalDate now) { + return now.plusDays(random.nextInt(festivalDuration)); + } + + @Override + public LocalDate makeRandomEndDate(int festivalDuration, LocalDate now, LocalDate startDate) { + long timeUntilFestivalStart = startDate.until(now, ChronoUnit.DAYS); + long maxAvailableEndDateFromStartDate = festivalDuration - (timeUntilFestivalStart + COUNT_FIRST_DAY_AS_DURATION_ONE); + int randomEndDate = random.nextInt((int) (maxAvailableEndDateFromStartDate + RANDOM_OFFSET)); + return startDate.plusDays(Math.min(randomEndDate, MAX_END_DATE_FROM_START_DATE)); + } +} diff --git a/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java b/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java index 0c239b68a..9c22e7df9 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java @@ -18,4 +18,6 @@ public interface StageArtistRepository extends Repository { Set findAllArtistIdByStageIdIn(@Param("stageIds") List stageIds); void deleteByStageId(Long stageId); + + List findAll(); } diff --git a/backend/src/main/java/com/festago/stage/repository/StageRepository.java b/backend/src/main/java/com/festago/stage/repository/StageRepository.java index 584107e74..916075077 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageRepository.java @@ -19,4 +19,6 @@ public interface StageRepository extends Repository, StageRepositor List findAllByFestivalId(Long festivalId); + List findAll(); + } diff --git a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java index f8257c591..2e327b968 100644 --- a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java +++ b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java @@ -2,6 +2,8 @@ import com.festago.festival.domain.Festival; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -43,4 +45,9 @@ public Optional findById(Long festivalId) { public void deleteById(Long festivalId) { memory.remove(festivalId); } + + @Override + public List findAll() { + return new ArrayList<>(memory.values()); + } } diff --git a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java new file mode 100644 index 000000000..87e30e381 --- /dev/null +++ b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java @@ -0,0 +1,197 @@ +package com.festago.mock.application; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; + +import com.festago.artist.domain.Artist; +import com.festago.artist.repository.ArtistRepository; +import com.festago.festival.domain.Festival; +import com.festago.festival.repository.FestivalRepository; +import com.festago.mock.MockArtist; +import com.festago.school.domain.School; +import com.festago.school.domain.SchoolRegion; +import com.festago.school.repository.SchoolRepository; +import com.festago.stage.domain.Stage; +import com.festago.stage.domain.StageArtist; +import com.festago.stage.repository.StageArtistRepository; +import com.festago.stage.repository.StageRepository; +import com.festago.support.ApplicationIntegrationTest; +import com.festago.mock.config.MockDataConfig; +import com.festago.support.fixture.SchoolFixture; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.context.annotation.Import; +import org.springframework.transaction.annotation.Transactional; + +@DisplayNameGeneration(ReplaceUnderscores.class) +@SuppressWarnings("NonAsciiCharacters") +@Import(MockDataConfig.class) +class MockDataServiceTest extends ApplicationIntegrationTest { + + @Autowired + ArtistRepository artistRepository; + + @Autowired + SchoolRepository schoolRepository; + + @Autowired + FestivalRepository festivalRepository; + + @Autowired + StageRepository stageRepository; + + @Autowired + StageArtistRepository stageArtistRepository; + + @SpyBean + FestivalDateGenerator festivalDateGenerator; + + @Autowired + MockDataService mockDataService; + + @Nested + class 목_데이터_초기화는 { + + @Test + void 만약_하나의_학교라도_존재하면_초기화_된_상태로_판단한다() { + // given + schoolRepository.save(SchoolFixture.builder().build()); + + // when + mockDataService.initialize(); + List allSchool = schoolRepository.findAll(); + + // then + assertThat(allSchool).hasSize(1); + } + + @Test + void 학교가_없다면_ANY_를_제외한_지역_곱하기_3개만큼의_학교와_MOCK_ARTIST_만큼의_아티스트를_생성한다() { + // given + mockDataService.initialize(); + int expectGeneratedSchoolSize = (SchoolRegion.values().length - 1) * 3; + int expectArtistSize = MockArtist.values().length; + + // when + List allSchool = schoolRepository.findAll(); + List allArtist = artistRepository.findAll(); + + // then + assertSoftly(softly -> { + softly.assertThat(allSchool).hasSize(expectGeneratedSchoolSize); + softly.assertThat(allArtist).hasSize(expectArtistSize); + }); + } + } + + @Nested + class 목_축제_생성_요청은 { + + @Test + @Transactional + void 존재하는_학교수_만큼의_축제를_만들어_낸다() { + // given + mockDataService.initialize(); + List allSchool = schoolRepository.findAll(); + List beforeFestivals = festivalRepository.findAll(); + + // when + mockDataService.makeMockFestivals(7); + List afterFestivals = festivalRepository.findAll(); + List festivalSchools = afterFestivals.stream() + .map(festival -> festival.getSchool()) + .toList(); + + // then + assertSoftly(softly -> { + softly.assertThat(beforeFestivals).hasSize(0); + softly.assertThat(afterFestivals).hasSize(allSchool.size()); + softly.assertThat(festivalSchools).containsAll(allSchool); + }); + } + + @Test + void 생성된_모든_축제는_기간은_전달_받은_기간_이내_이다() { + // given + mockDataService.initialize(); + mockDataService.makeMockFestivals(1); + + // when + List allFestival = festivalRepository.findAll(); + + // then + assertThat(allFestival).allMatch( + festival -> festival.getEndDate().until(festival.getStartDate(), ChronoUnit.DAYS) == 0); + } + + @Test + @Transactional + void 무대는_생성된_축제_기간동안_전부_존재한다() { + // given + LocalDate now = LocalDate.now(); + doReturn(now).when(festivalDateGenerator) + .makeRandomStartDate(anyInt(), any(LocalDate.class)); + doReturn(now.plusDays(2)).when(festivalDateGenerator) + .makeRandomEndDate(anyInt(), any(LocalDate.class), any(LocalDate.class)); + + mockDataService.initialize(); + mockDataService.makeMockFestivals(7); + List allFestival = festivalRepository.findAll(); + + // when + List allStage = stageRepository.findAll(); + Map> stageByFestival = allStage.stream() + .collect(Collectors.groupingBy(Stage::getFestival)); + + // then + assertThat(stageByFestival.values()).allMatch(stages -> stages.size() == 3); + } + + @Test + void 같은_축제_속_무대_아티스트_들은_겹치지_않는다() { + // given + mockDataService.initialize(); + mockDataService.makeMockFestivals(7); + + List stageArtists = stageArtistRepository.findAll(); + List allStage = stageRepository.findAll(); + + Map> stageArtistByStageId = stageArtists.stream() + .collect(Collectors.groupingBy(StageArtist::getStageId)); + Map> stageByFestival = allStage.stream() + .collect(Collectors.groupingBy(Stage::getFestival)); + + // when + Map> stageArtistsByFestival = new HashMap<>(); + + stageByFestival.forEach((festival, stages) -> { + List artistsForFestival = stages.stream() + .map(stage -> stageArtistByStageId.getOrDefault(stage.getId(), Collections.emptyList())) + .flatMap(List::stream) + .collect(Collectors.toList()); + + stageArtistsByFestival.put(festival, artistsForFestival); + }); + + + // then + assertThat(stageArtistsByFestival.values()) + .allMatch(target -> target.size() != target.stream() + .map(stageArtist -> stageArtist.getArtistId()).distinct().count()); + } + } +} diff --git a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java new file mode 100644 index 000000000..bee95b8b3 --- /dev/null +++ b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java @@ -0,0 +1,63 @@ +package com.festago.mock.config; + +import com.festago.artist.domain.ArtistsSerializer; +import com.festago.artist.repository.ArtistRepository; +import com.festago.festival.repository.FestivalInfoRepository; +import com.festago.festival.repository.FestivalRepository; +import com.festago.mock.CommandLineAppStartupRunner; +import com.festago.mock.application.FestivalDateGenerator; +import com.festago.mock.application.MockDataService; +import com.festago.mock.application.RandomFestivalDateGenerator; +import com.festago.school.repository.SchoolRepository; +import com.festago.stage.repository.StageArtistRepository; +import com.festago.stage.repository.StageQueryInfoRepository; +import com.festago.stage.repository.StageRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +@TestConfiguration +public class MockDataConfig { + + @Autowired + private SchoolRepository schoolRepository; + + @Autowired + private ArtistRepository artistRepository; + + @Autowired + private FestivalRepository festivalRepository; + + @Autowired + private StageRepository stageRepository; + + @Autowired + private StageArtistRepository stageArtistRepository; + + @Autowired + private FestivalInfoRepository festivalInfoRepository; + + @Autowired + private StageQueryInfoRepository stageQueryInfoRepository; + + @Autowired + private ArtistsSerializer artistsSerializer; + + + @Bean + public FestivalDateGenerator festivalDateGenerator() { + return new RandomFestivalDateGenerator(); + } + + @Bean + public MockDataService mockDataService() { + return new MockDataService(festivalDateGenerator(), schoolRepository, artistRepository, festivalRepository, + stageRepository, stageArtistRepository, festivalInfoRepository, stageQueryInfoRepository, + artistsSerializer); + } + + @Bean + public CommandLineAppStartupRunner commandLineAppStartupRunner(){ + return new CommandLineAppStartupRunner(mockDataService()); + } +} diff --git a/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java b/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java index 419e886da..5809c7e40 100644 --- a/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java +++ b/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java @@ -4,6 +4,7 @@ import com.festago.stage.domain.StageArtist; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -51,4 +52,9 @@ public Set findAllArtistIdByStageIdIn(List stageIds) { public void deleteByStageId(Long stageId) { memory.entrySet().removeIf(entry -> Objects.equals(entry.getValue().getStageId(), stageId)); } + + @Override + public List findAll() { + return new ArrayList<>(memory.values()); + } } diff --git a/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java b/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java index 0724e300a..588cdd599 100644 --- a/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java +++ b/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java @@ -2,6 +2,7 @@ import com.festago.stage.domain.Stage; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -57,6 +58,11 @@ public List findAllByFestivalId(Long festivalId) { .toList(); } + @Override + public List findAll() { + return new ArrayList<>(memory.values()); + } + @Override public List findAllDetailByFestivalId(Long festivalId) { return findAllByFestivalId(festivalId); From a8f348ed8b2400fd37d6cbc6137939f88673511e Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 07:10:22 +0900 Subject: [PATCH 05/23] =?UTF-8?q?feat:=20=EC=95=B1=20=EC=8B=9C=EC=9E=91?= =?UTF-8?q?=EC=8B=9C=20=EC=8A=A4=EC=BC=80=EC=A5=B4=EB=9F=AC=201=ED=9A=8C?= =?UTF-8?q?=20=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/festago/mock/CommandLineAppStartupRunner.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java index bcf1561e4..ab192444c 100644 --- a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java +++ b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java @@ -12,9 +12,11 @@ public class CommandLineAppStartupRunner implements CommandLineRunner { private final MockDataService mockDataService; + private final MockScheduler mockScheduler; @Override public void run(String... args) { mockDataService.initialize(); + mockScheduler.run(); } } From 2a1f3a7e1410042816cdc2d6bf2205e4dd81d46b Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 09:43:57 +0900 Subject: [PATCH 06/23] =?UTF-8?q?feat:=20=EB=8C=80=ED=95=99=20=EC=B6=95?= =?UTF-8?q?=EC=A0=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/mock/application/MockDataService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/festago/mock/application/MockDataService.java b/backend/src/main/java/com/festago/mock/application/MockDataService.java index b7e0daad3..dcfcb1e6d 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/application/MockDataService.java @@ -109,7 +109,10 @@ private void makeFestival(int availableFestivalDuration, School school, List participatedArtists = makeStages(newFestival, makeRandomArtists(artists)); makeFestivalQueryInfo(newFestival, participatedArtists); From cf65c16759206518bcf661095325810a1523c29b Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 11:48:00 +0900 Subject: [PATCH 07/23] =?UTF-8?q?test:=20=EC=B6=95=EC=A0=9C=20=EB=AC=B4?= =?UTF-8?q?=EB=8C=80=20=EA=B2=80=EC=A6=9D=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F?= =?UTF-8?q?=20=EC=8A=A4=EC=BC=80=EC=A5=B4=EB=9F=AC=20=EB=B9=88=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mock/application/MockDataServiceTest.java | 16 +++++++--------- .../com/festago/mock/config/MockDataConfig.java | 8 +++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java index 87e30e381..7cb963c5c 100644 --- a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java +++ b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java @@ -42,6 +42,7 @@ @Import(MockDataConfig.class) class MockDataServiceTest extends ApplicationIntegrationTest { + private static final int INCLUDE_FIRST_DATE = 1; @Autowired ArtistRepository artistRepository; @@ -57,9 +58,6 @@ class MockDataServiceTest extends ApplicationIntegrationTest { @Autowired StageArtistRepository stageArtistRepository; - @SpyBean - FestivalDateGenerator festivalDateGenerator; - @Autowired MockDataService mockDataService; @@ -135,7 +133,7 @@ class 목_축제_생성_요청은 { // then assertThat(allFestival).allMatch( - festival -> festival.getEndDate().until(festival.getStartDate(), ChronoUnit.DAYS) == 0); + festival -> festival.getStartDate().until(festival.getStartDate(), ChronoUnit.DAYS) == 0); } @Test @@ -143,10 +141,6 @@ class 목_축제_생성_요청은 { void 무대는_생성된_축제_기간동안_전부_존재한다() { // given LocalDate now = LocalDate.now(); - doReturn(now).when(festivalDateGenerator) - .makeRandomStartDate(anyInt(), any(LocalDate.class)); - doReturn(now.plusDays(2)).when(festivalDateGenerator) - .makeRandomEndDate(anyInt(), any(LocalDate.class), any(LocalDate.class)); mockDataService.initialize(); mockDataService.makeMockFestivals(7); @@ -158,7 +152,11 @@ class 목_축제_생성_요청은 { .collect(Collectors.groupingBy(Stage::getFestival)); // then - assertThat(stageByFestival.values()).allMatch(stages -> stages.size() == 3); + assertThat(stageByFestival.entrySet()).allMatch(festivalListEntry -> { + Festival festival = festivalListEntry.getKey(); + long festivalDuration = festival.getEndDate().until(festival.getStartDate(), ChronoUnit.DAYS) + INCLUDE_FIRST_DATE; + return festivalListEntry.getValue().size() == festivalDuration; + }); } @Test diff --git a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java index bee95b8b3..e10fb3310 100644 --- a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java +++ b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java @@ -5,6 +5,7 @@ import com.festago.festival.repository.FestivalInfoRepository; import com.festago.festival.repository.FestivalRepository; import com.festago.mock.CommandLineAppStartupRunner; +import com.festago.mock.MockScheduler; import com.festago.mock.application.FestivalDateGenerator; import com.festago.mock.application.MockDataService; import com.festago.mock.application.RandomFestivalDateGenerator; @@ -56,8 +57,13 @@ public MockDataService mockDataService() { artistsSerializer); } + @Bean + public MockScheduler mockScheduler(){ + return new MockScheduler(mockDataService()); + + } @Bean public CommandLineAppStartupRunner commandLineAppStartupRunner(){ - return new CommandLineAppStartupRunner(mockDataService()); + return new CommandLineAppStartupRunner(mockDataService(), mockScheduler()); } } From 9c9703052d08846c06e732101fd67baa5e873c13 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 11:52:31 +0900 Subject: [PATCH 08/23] =?UTF-8?q?chore:=20=EC=B6=95=EC=A0=9C=20=EC=9D=B4?= =?UTF-8?q?=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 --- .../java/com/festago/mock/application/MockDataService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/application/MockDataService.java b/backend/src/main/java/com/festago/mock/application/MockDataService.java index dcfcb1e6d..76a11debc 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/application/MockDataService.java @@ -30,7 +30,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Profile({"dev"}) +@Profile({"local"}) @Service @Transactional @RequiredArgsConstructor @@ -109,7 +109,7 @@ private void makeFestival(int availableFestivalDuration, School school, List Date: Fri, 29 Mar 2024 12:38:26 +0900 Subject: [PATCH 09/23] =?UTF-8?q?refactor:=20Service=20=EA=B8=B0=EB=B0=98?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20mock=20=EC=9D=84=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mock/application/MockDataService.java | 113 +++++++++--------- .../festago/mock/config/MockDataConfig.java | 34 ++---- 2 files changed, 68 insertions(+), 79 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/application/MockDataService.java b/backend/src/main/java/com/festago/mock/application/MockDataService.java index 76a11debc..9aa5aeb66 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/application/MockDataService.java @@ -1,22 +1,23 @@ package com.festago.mock.application; +import com.festago.artist.application.ArtistCommandService; import com.festago.artist.domain.Artist; -import com.festago.artist.domain.ArtistsSerializer; +import com.festago.artist.dto.command.ArtistCreateCommand; import com.festago.artist.repository.ArtistRepository; +import com.festago.common.exception.ErrorCode; +import com.festago.common.exception.NotFoundException; +import com.festago.festival.application.command.FestivalCommandFacadeService; import com.festago.festival.domain.Festival; -import com.festago.festival.domain.FestivalQueryInfo; -import com.festago.festival.repository.FestivalInfoRepository; +import com.festago.festival.dto.command.FestivalCreateCommand; import com.festago.festival.repository.FestivalRepository; import com.festago.mock.MockArtist; +import com.festago.school.application.SchoolCommandService; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; +import com.festago.school.dto.SchoolCreateCommand; import com.festago.school.repository.SchoolRepository; -import com.festago.stage.domain.Stage; -import com.festago.stage.domain.StageArtist; -import com.festago.stage.domain.StageQueryInfo; -import com.festago.stage.repository.StageArtistRepository; -import com.festago.stage.repository.StageQueryInfoRepository; -import com.festago.stage.repository.StageRepository; +import com.festago.stage.application.command.StageCommandFacadeService; +import com.festago.stage.dto.command.StageCreateCommand; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayDeque; @@ -44,11 +45,11 @@ public class MockDataService { private final SchoolRepository schoolRepository; private final ArtistRepository artistRepository; private final FestivalRepository festivalRepository; - private final StageRepository stageRepository; - private final StageArtistRepository stageArtistRepository; - private final FestivalInfoRepository festivalInfoRepository; - private final StageQueryInfoRepository stageQueryInfoRepository; - private final ArtistsSerializer artistsSerializer; + private final FestivalCommandFacadeService festivalCommandFacadeService; + private final StageCommandFacadeService stageCommandFacadeService; + private final ArtistCommandService artistCommandService; + private final SchoolCommandService schoolCommandService; + public void initialize() { if (alreadyInitialized()) { @@ -71,27 +72,33 @@ private void initializeSchool() { if (SchoolRegion.ANY.equals(schoolRegion)) { continue; } - schoolRepository.saveAll(makeRegionSchools(schoolRegion)); + makeRegionSchools(schoolRegion); } } - private List makeRegionSchools(SchoolRegion schoolRegion) { - List result = new ArrayList<>(); + private void makeRegionSchools(SchoolRegion schoolRegion) { for (int i = 0; i < 3; i++) { int schoolNumber = i + 1; String schoolName = schoolRegion.name() + schoolNumber; - result.add(new School( - schoolName + ".com", - schoolName, - schoolRegion - )); + schoolCommandService.createSchool(new SchoolCreateCommand( + schoolName, + schoolName + ".com", + schoolRegion, + null, + null + ) + ); } - return result; } private void initializeArtist() { for (MockArtist artist : MockArtist.values()) { - artistRepository.save(new Artist(artist.name(), artist.getProfileImage(), artist.getBackgroundImageUrl())); + artistCommandService.save(new ArtistCreateCommand( + artist.name(), + artist.getProfileImage(), + artist.getBackgroundImageUrl() + ) + ); } } @@ -108,14 +115,15 @@ private void makeFestival(int availableFestivalDuration, School school, List participatedArtists = makeStages(newFestival, makeRandomArtists(artists)); + Long newFestivalId = festivalCommandFacadeService.createFestival(new FestivalCreateCommand( + school.getName() + "대 축제" + FESTIVAL_SEQUENCE.incrementAndGet(), + startDate, + endDate, + "https://picsum.photos/536/354", + school.getId() + )); - makeFestivalQueryInfo(newFestival, participatedArtists); + makeStages(newFestivalId, makeRandomArtists(artists)); } private Queue makeRandomArtists(List artists) { @@ -124,47 +132,38 @@ private Queue makeRandomArtists(List artists) { return new ArrayDeque<>(randomArtists); } - private List makeStages(Festival festival, Queue artists) { + private void makeStages(Long festivalId, Queue artists) { + Festival festival = festivalRepository.findById(festivalId) + .orElseThrow(() -> new NotFoundException(ErrorCode.FESTIVAL_NOT_FOUND)); LocalDate endDate = festival.getEndDate(); LocalDate dateCursor = festival.getStartDate(); - List participatedArtists = new ArrayList<>(); while (dateCursor.isAfter(endDate)) { - participatedArtists.addAll(makeStage(festival, artists, dateCursor)); + makeStage(festival, artists, dateCursor); dateCursor = dateCursor.plusDays(1); } - return participatedArtists; } - private List makeStage(Festival festival, Queue artists, LocalDate localDate) { + private void makeStage(Festival festival, Queue artists, LocalDate localDate) { LocalDateTime startTime = localDate.atStartOfDay().plusHours(STAGE_START_HOUR); - Stage stage = stageRepository.save(new Stage(startTime, startTime.minusDays(1L), festival)); - List stageArtists = selectArtists(artists, STAGE_ARTIST_COUNT); - makeStageArtists(stageArtists, stage); - return stageArtists; + stageCommandFacadeService.createStage(new StageCreateCommand( + festival.getId(), + startTime, + startTime.minusDays(1L), + makeStageArtists(artists) + )); } - private List selectArtists(Queue artists, int count) { + private List makeStageArtists(Queue artists) { List result = new ArrayList<>(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < STAGE_ARTIST_COUNT; i++) { Artist artist = artists.poll(); if (artist == null) { - throw new IllegalArgumentException("축제를 만들기 위한 Artist 가 부족합니다"); + throw new IllegalArgumentException("축제를 구성하기 위한 아티스트가 부족합니다"); } result.add(artist); } - return result; - } - - private void makeStageArtists(List artists, Stage stage) { - for (Artist artist : artists) { - stageArtistRepository.save(new StageArtist(stage.getId(), artist.getId())); - } - stageQueryInfoRepository.save(StageQueryInfo.of(stage.getId(), artists, artistsSerializer)); - } - - private void makeFestivalQueryInfo(Festival newFestival, List participatedArtists) { - FestivalQueryInfo festivalQueryInfo = FestivalQueryInfo.create(newFestival.getId()); - festivalQueryInfo.updateArtistInfo(participatedArtists, artistsSerializer); - festivalInfoRepository.save(festivalQueryInfo); + return result.stream() + .map(Artist::getId) + .toList(); } } diff --git a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java index e10fb3310..e3258b14b 100644 --- a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java +++ b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java @@ -1,18 +1,17 @@ package com.festago.mock.config; -import com.festago.artist.domain.ArtistsSerializer; +import com.festago.artist.application.ArtistCommandService; import com.festago.artist.repository.ArtistRepository; -import com.festago.festival.repository.FestivalInfoRepository; +import com.festago.festival.application.command.FestivalCommandFacadeService; import com.festago.festival.repository.FestivalRepository; import com.festago.mock.CommandLineAppStartupRunner; import com.festago.mock.MockScheduler; import com.festago.mock.application.FestivalDateGenerator; import com.festago.mock.application.MockDataService; import com.festago.mock.application.RandomFestivalDateGenerator; +import com.festago.school.application.SchoolCommandService; import com.festago.school.repository.SchoolRepository; -import com.festago.stage.repository.StageArtistRepository; -import com.festago.stage.repository.StageQueryInfoRepository; -import com.festago.stage.repository.StageRepository; +import com.festago.stage.application.command.StageCommandFacadeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; @@ -22,27 +21,18 @@ public class MockDataConfig { @Autowired private SchoolRepository schoolRepository; - @Autowired private ArtistRepository artistRepository; - @Autowired private FestivalRepository festivalRepository; - @Autowired - private StageRepository stageRepository; - + private FestivalCommandFacadeService festivalCommandFacadeService; @Autowired - private StageArtistRepository stageArtistRepository; - + private StageCommandFacadeService stageCommandFacadeService; @Autowired - private FestivalInfoRepository festivalInfoRepository; - - @Autowired - private StageQueryInfoRepository stageQueryInfoRepository; - + private ArtistCommandService artistCommandService; @Autowired - private ArtistsSerializer artistsSerializer; + private SchoolCommandService schoolCommandService; @Bean @@ -53,17 +43,17 @@ public FestivalDateGenerator festivalDateGenerator() { @Bean public MockDataService mockDataService() { return new MockDataService(festivalDateGenerator(), schoolRepository, artistRepository, festivalRepository, - stageRepository, stageArtistRepository, festivalInfoRepository, stageQueryInfoRepository, - artistsSerializer); + festivalCommandFacadeService, stageCommandFacadeService, artistCommandService, schoolCommandService); } @Bean - public MockScheduler mockScheduler(){ + public MockScheduler mockScheduler() { return new MockScheduler(mockDataService()); } + @Bean - public CommandLineAppStartupRunner commandLineAppStartupRunner(){ + public CommandLineAppStartupRunner commandLineAppStartupRunner() { return new CommandLineAppStartupRunner(mockDataService(), mockScheduler()); } } From fd0d2bcf32fb457a8e00325d353f3f5aae9195f1 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 13:01:28 +0900 Subject: [PATCH 10/23] =?UTF-8?q?feat:=20MockDataService=20cursor=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20queryInfo?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EA=B2=80=EC=A6=9D=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 --- .../repository/FestivalInfoRepository.java | 3 ++ .../mock/application/MockDataService.java | 2 +- .../repository/StageQueryInfoRepository.java | 3 ++ .../MemoryFestivalQueryInfoRepository.java | 7 +++ .../mock/application/MockDataServiceTest.java | 49 +++++++++++++++---- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java b/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java index 56c44fd56..3dce9a9b4 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java @@ -1,6 +1,7 @@ package com.festago.festival.repository; import com.festago.festival.domain.FestivalQueryInfo; +import java.util.List; import java.util.Optional; import org.springframework.data.repository.Repository; @@ -11,5 +12,7 @@ public interface FestivalInfoRepository extends Repository findByFestivalId(Long festivalId); void deleteByFestivalId(Long festivalId); + + List findAll(); } diff --git a/backend/src/main/java/com/festago/mock/application/MockDataService.java b/backend/src/main/java/com/festago/mock/application/MockDataService.java index 9aa5aeb66..71df1f95b 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/application/MockDataService.java @@ -137,7 +137,7 @@ private void makeStages(Long festivalId, Queue artists) { .orElseThrow(() -> new NotFoundException(ErrorCode.FESTIVAL_NOT_FOUND)); LocalDate endDate = festival.getEndDate(); LocalDate dateCursor = festival.getStartDate(); - while (dateCursor.isAfter(endDate)) { + while (dateCursor.isBefore(endDate) || dateCursor.equals(endDate)) { makeStage(festival, artists, dateCursor); dateCursor = dateCursor.plusDays(1); } diff --git a/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java b/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java index 60e21bcc8..0daea7408 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java @@ -1,6 +1,7 @@ package com.festago.stage.repository; import com.festago.stage.domain.StageQueryInfo; +import java.util.List; import java.util.Optional; import org.springframework.data.repository.Repository; @@ -11,4 +12,6 @@ public interface StageQueryInfoRepository extends Repository findByStageId(Long stageId); void deleteByStageId(Long stageId); + + List findAll(); } diff --git a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java index b2c96cd96..894e3155f 100644 --- a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java +++ b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java @@ -2,6 +2,8 @@ import com.festago.festival.domain.FestivalQueryInfo; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -39,4 +41,9 @@ public Optional findByFestivalId(Long festivalId) { public void deleteByFestivalId(Long festivalId) { memory.entrySet().removeIf(it -> Objects.equals(it.getValue().getFestivalId(), festivalId)); } + + @Override + public List findAll() { + return new ArrayList<>(memory.values()); + } } diff --git a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java index 7cb963c5c..b2e81da31 100644 --- a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java +++ b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java @@ -2,24 +2,25 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.doReturn; import com.festago.artist.domain.Artist; import com.festago.artist.repository.ArtistRepository; import com.festago.festival.domain.Festival; +import com.festago.festival.domain.FestivalQueryInfo; +import com.festago.festival.repository.FestivalInfoRepository; import com.festago.festival.repository.FestivalRepository; import com.festago.mock.MockArtist; +import com.festago.mock.config.MockDataConfig; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; import com.festago.school.repository.SchoolRepository; import com.festago.stage.domain.Stage; import com.festago.stage.domain.StageArtist; +import com.festago.stage.domain.StageQueryInfo; import com.festago.stage.repository.StageArtistRepository; +import com.festago.stage.repository.StageQueryInfoRepository; import com.festago.stage.repository.StageRepository; import com.festago.support.ApplicationIntegrationTest; -import com.festago.mock.config.MockDataConfig; import com.festago.support.fixture.SchoolFixture; import java.time.LocalDate; import java.time.temporal.ChronoUnit; @@ -33,7 +34,6 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.context.annotation.Import; import org.springframework.transaction.annotation.Transactional; @@ -58,6 +58,12 @@ class MockDataServiceTest extends ApplicationIntegrationTest { @Autowired StageArtistRepository stageArtistRepository; + @Autowired + StageQueryInfoRepository stageQueryInfoRepository; + + @Autowired + FestivalInfoRepository festivalInfoRepository; + @Autowired MockDataService mockDataService; @@ -122,6 +128,23 @@ class 목_축제_생성_요청은 { }); } + @Test + void 쿼리_최적화_정보들을_생성한다() { + // given + mockDataService.initialize(); + mockDataService.makeMockFestivals(7); + + // when + List stageQueryInfos = stageQueryInfoRepository.findAll(); + List festivalQueryInfos = festivalInfoRepository.findAll(); + + // then + assertSoftly(softly -> { + assertThat(stageQueryInfos).isNotEmpty(); + assertThat(festivalQueryInfos).isNotEmpty(); + }); + } + @Test void 생성된_모든_축제는_기간은_전달_받은_기간_이내_이다() { // given @@ -154,7 +177,8 @@ class 목_축제_생성_요청은 { // then assertThat(stageByFestival.entrySet()).allMatch(festivalListEntry -> { Festival festival = festivalListEntry.getKey(); - long festivalDuration = festival.getEndDate().until(festival.getStartDate(), ChronoUnit.DAYS) + INCLUDE_FIRST_DATE; + long festivalDuration = + festival.getStartDate().until(festival.getEndDate(), ChronoUnit.DAYS) + INCLUDE_FIRST_DATE; return festivalListEntry.getValue().size() == festivalDuration; }); } @@ -185,11 +209,16 @@ class 목_축제_생성_요청은 { stageArtistsByFestival.put(festival, artistsForFestival); }); - // then - assertThat(stageArtistsByFestival.values()) - .allMatch(target -> target.size() != target.stream() - .map(stageArtist -> stageArtist.getArtistId()).distinct().count()); + assertThat(stageArtistsByFestival.keySet()) + .allMatch(festival -> { + List stageArtistsValue = stageArtistsByFestival.get(festival); + long uniqueStageArtists = stageArtistsValue.stream() + .map(stageArtist -> stageArtist.getArtistId()) + .distinct() + .count(); + return stageArtistsValue.size() == uniqueStageArtists; + }); } } } From 2b5b88acdefed799606e638f236d34a01df50b7e Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 13:06:51 +0900 Subject: [PATCH 11/23] =?UTF-8?q?chore:=20=EA=B0=9C=ED=96=89=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 --- .../test/java/com/festago/mock/config/MockDataConfig.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java index e3258b14b..889a6fd68 100644 --- a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java +++ b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java @@ -21,16 +21,22 @@ public class MockDataConfig { @Autowired private SchoolRepository schoolRepository; + @Autowired private ArtistRepository artistRepository; + @Autowired private FestivalRepository festivalRepository; + @Autowired private FestivalCommandFacadeService festivalCommandFacadeService; + @Autowired private StageCommandFacadeService stageCommandFacadeService; + @Autowired private ArtistCommandService artistCommandService; + @Autowired private SchoolCommandService schoolCommandService; From fc36678cada5df003978fd57ae1591bd77244756 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 13:08:30 +0900 Subject: [PATCH 12/23] =?UTF-8?q?chore:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/mock/CommandLineAppStartupRunner.java | 1 - .../mock/{application => }/FestivalDateGenerator.java | 2 +- .../com/festago/mock/{application => }/MockDataService.java | 3 +-- backend/src/main/java/com/festago/mock/MockScheduler.java | 1 - .../mock/{application => }/RandomFestivalDateGenerator.java | 4 ++-- .../com/festago/mock/application/MockDataServiceTest.java | 1 + .../test/java/com/festago/mock/config/MockDataConfig.java | 6 +++--- 7 files changed, 8 insertions(+), 10 deletions(-) rename backend/src/main/java/com/festago/mock/{application => }/FestivalDateGenerator.java (86%) rename backend/src/main/java/com/festago/mock/{application => }/MockDataService.java (98%) rename backend/src/main/java/com/festago/mock/{application => }/RandomFestivalDateGenerator.java (96%) diff --git a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java index ab192444c..353848c93 100644 --- a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java +++ b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java @@ -1,6 +1,5 @@ package com.festago.mock; -import com.festago.mock.application.MockDataService; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; import org.springframework.context.annotation.Profile; diff --git a/backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/FestivalDateGenerator.java similarity index 86% rename from backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java rename to backend/src/main/java/com/festago/mock/FestivalDateGenerator.java index 8a4008ec9..15bcdb76a 100644 --- a/backend/src/main/java/com/festago/mock/application/FestivalDateGenerator.java +++ b/backend/src/main/java/com/festago/mock/FestivalDateGenerator.java @@ -1,4 +1,4 @@ -package com.festago.mock.application; +package com.festago.mock; import java.time.LocalDate; diff --git a/backend/src/main/java/com/festago/mock/application/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java similarity index 98% rename from backend/src/main/java/com/festago/mock/application/MockDataService.java rename to backend/src/main/java/com/festago/mock/MockDataService.java index 71df1f95b..24b55aa8d 100644 --- a/backend/src/main/java/com/festago/mock/application/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -1,4 +1,4 @@ -package com.festago.mock.application; +package com.festago.mock; import com.festago.artist.application.ArtistCommandService; import com.festago.artist.domain.Artist; @@ -10,7 +10,6 @@ import com.festago.festival.domain.Festival; import com.festago.festival.dto.command.FestivalCreateCommand; import com.festago.festival.repository.FestivalRepository; -import com.festago.mock.MockArtist; import com.festago.school.application.SchoolCommandService; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; diff --git a/backend/src/main/java/com/festago/mock/MockScheduler.java b/backend/src/main/java/com/festago/mock/MockScheduler.java index bb07bb652..98d171068 100644 --- a/backend/src/main/java/com/festago/mock/MockScheduler.java +++ b/backend/src/main/java/com/festago/mock/MockScheduler.java @@ -1,6 +1,5 @@ package com.festago.mock; -import com.festago.mock.application.MockDataService; import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Profile; diff --git a/backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/RandomFestivalDateGenerator.java similarity index 96% rename from backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java rename to backend/src/main/java/com/festago/mock/RandomFestivalDateGenerator.java index ec8aa21fd..9f45b9808 100644 --- a/backend/src/main/java/com/festago/mock/application/RandomFestivalDateGenerator.java +++ b/backend/src/main/java/com/festago/mock/RandomFestivalDateGenerator.java @@ -1,4 +1,4 @@ -package com.festago.mock.application; +package com.festago.mock; import java.time.LocalDate; import java.time.temporal.ChronoUnit; @@ -8,7 +8,7 @@ @Profile("dev") @Component -public class RandomFestivalDateGenerator implements FestivalDateGenerator{ +public class RandomFestivalDateGenerator implements FestivalDateGenerator { private static final int COUNT_FIRST_DAY_AS_DURATION_ONE = 1; private static final int RANDOM_OFFSET = 1; diff --git a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java index b2e81da31..bf9b71c5a 100644 --- a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java +++ b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java @@ -10,6 +10,7 @@ import com.festago.festival.repository.FestivalInfoRepository; import com.festago.festival.repository.FestivalRepository; import com.festago.mock.MockArtist; +import com.festago.mock.MockDataService; import com.festago.mock.config.MockDataConfig; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; diff --git a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java index 889a6fd68..6c7588bad 100644 --- a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java +++ b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java @@ -6,9 +6,9 @@ import com.festago.festival.repository.FestivalRepository; import com.festago.mock.CommandLineAppStartupRunner; import com.festago.mock.MockScheduler; -import com.festago.mock.application.FestivalDateGenerator; -import com.festago.mock.application.MockDataService; -import com.festago.mock.application.RandomFestivalDateGenerator; +import com.festago.mock.FestivalDateGenerator; +import com.festago.mock.MockDataService; +import com.festago.mock.RandomFestivalDateGenerator; import com.festago.school.application.SchoolCommandService; import com.festago.school.repository.SchoolRepository; import com.festago.stage.application.command.StageCommandFacadeService; From 5a78aca135176ab453e549af26d0f54801e568a0 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 18:57:17 +0900 Subject: [PATCH 13/23] =?UTF-8?q?chore:=20MockDataService=20profile=20dev?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/com/festago/mock/MockDataService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index 24b55aa8d..cb7967ae0 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -30,7 +30,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Profile({"local"}) +@Profile({"dev"}) @Service @Transactional @RequiredArgsConstructor From 9e0e7e6604e6ca15fce744afaf0c9cb2487cc9b7 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 18:58:38 +0900 Subject: [PATCH 14/23] =?UTF-8?q?refactor:=20=EB=A7=8C=EC=95=BD=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=20DB=EB=A5=BC=20=EC=B4=88=EA=B8=B0=ED=99=94?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EC=95=98=EB=8B=A4=EB=A9=B4=20?= =?UTF-8?q?=EC=B6=95=EC=A0=9C=20=EC=83=9D=EC=84=B1=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=80=20=EC=83=9D=EB=9E=B5=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/mock/CommandLineAppStartupRunner.java | 5 +++-- backend/src/main/java/com/festago/mock/MockDataService.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java index 353848c93..cde40d7a4 100644 --- a/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java +++ b/backend/src/main/java/com/festago/mock/CommandLineAppStartupRunner.java @@ -15,7 +15,8 @@ public class CommandLineAppStartupRunner implements CommandLineRunner { @Override public void run(String... args) { - mockDataService.initialize(); - mockScheduler.run(); + if (mockDataService.initialize()) { + mockScheduler.run(); + } } } diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index cb7967ae0..0ed0570f5 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -50,11 +50,12 @@ public class MockDataService { private final SchoolCommandService schoolCommandService; - public void initialize() { + public boolean initialize() { if (alreadyInitialized()) { - return; + return false; } initializeData(); + return true; } private boolean alreadyInitialized() { From ce7423465c1cf5612b891f979deb2691aa516d25 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 19:09:20 +0900 Subject: [PATCH 15/23] =?UTF-8?q?refactor:=20mock=20=EC=A0=84=EC=9A=A9=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4,=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/festago/mock/MockDataService.java | 22 ++++++++++--------- ...or.java => MockFestivalDateGenerator.java} | 2 +- ...a => RandomMockFestivalDateGenerator.java} | 2 +- .../repository/ForMockArtistRepository.java | 8 +++++++ .../ForMockFestivalInfoRepository.java | 8 +++++++ .../repository/ForMockFestivalRepository.java | 8 +++++++ .../repository/ForMockSchoolRepository.java | 8 +++++++ .../ForMockStageArtistRepository.java | 8 +++++++ .../ForMockStageQueryInfoRepository.java | 8 +++++++ .../repository/ForMockStageRepository.java | 8 +++++++ .../mock/application/MockDataServiceTest.java | 21 ++++++++++++------ .../festago/mock/config/MockDataConfig.java | 17 ++++++++------ 12 files changed, 94 insertions(+), 26 deletions(-) rename backend/src/main/java/com/festago/mock/{FestivalDateGenerator.java => MockFestivalDateGenerator.java} (83%) rename backend/src/main/java/com/festago/mock/{RandomFestivalDateGenerator.java => RandomMockFestivalDateGenerator.java} (93%) create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockArtistRepository.java create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockFestivalInfoRepository.java create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockFestivalRepository.java create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockSchoolRepository.java create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockStageArtistRepository.java create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockStageQueryInfoRepository.java create mode 100644 backend/src/main/java/com/festago/mock/repository/ForMockStageRepository.java diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index 0ed0570f5..d9a9702da 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -3,18 +3,19 @@ import com.festago.artist.application.ArtistCommandService; import com.festago.artist.domain.Artist; import com.festago.artist.dto.command.ArtistCreateCommand; -import com.festago.artist.repository.ArtistRepository; import com.festago.common.exception.ErrorCode; import com.festago.common.exception.NotFoundException; import com.festago.festival.application.command.FestivalCommandFacadeService; import com.festago.festival.domain.Festival; import com.festago.festival.dto.command.FestivalCreateCommand; -import com.festago.festival.repository.FestivalRepository; +; +import com.festago.mock.repository.ForMockArtistRepository; +import com.festago.mock.repository.ForMockFestivalRepository; +import com.festago.mock.repository.ForMockSchoolRepository; import com.festago.school.application.SchoolCommandService; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; import com.festago.school.dto.SchoolCreateCommand; -import com.festago.school.repository.SchoolRepository; import com.festago.stage.application.command.StageCommandFacadeService; import com.festago.stage.dto.command.StageCreateCommand; import java.time.LocalDate; @@ -39,11 +40,12 @@ public class MockDataService { private static final AtomicLong FESTIVAL_SEQUENCE = new AtomicLong(); private static final long STAGE_START_HOUR = 19L; private static final int STAGE_ARTIST_COUNT = 3; + private static final int SCHOOL_PER_REGION = 3; - private final FestivalDateGenerator festivalDateGenerator; - private final SchoolRepository schoolRepository; - private final ArtistRepository artistRepository; - private final FestivalRepository festivalRepository; + private final MockFestivalDateGenerator mockFestivalDateGenerator; + private final ForMockSchoolRepository schoolRepository; + private final ForMockArtistRepository artistRepository; + private final ForMockFestivalRepository festivalRepository; private final FestivalCommandFacadeService festivalCommandFacadeService; private final StageCommandFacadeService stageCommandFacadeService; private final ArtistCommandService artistCommandService; @@ -77,7 +79,7 @@ private void initializeSchool() { } private void makeRegionSchools(SchoolRegion schoolRegion) { - for (int i = 0; i < 3; i++) { + for (int i = 0; i < SCHOOL_PER_REGION; i++) { int schoolNumber = i + 1; String schoolName = schoolRegion.name() + schoolNumber; schoolCommandService.createSchool(new SchoolCreateCommand( @@ -112,8 +114,8 @@ public void makeMockFestivals(int availableFestivalDuration) { private void makeFestival(int availableFestivalDuration, School school, List artists) { LocalDate now = LocalDate.now(); - LocalDate startDate = festivalDateGenerator.makeRandomStartDate(availableFestivalDuration, now); - LocalDate endDate = festivalDateGenerator.makeRandomEndDate(availableFestivalDuration, now, startDate); + LocalDate startDate = mockFestivalDateGenerator.makeRandomStartDate(availableFestivalDuration, now); + LocalDate endDate = mockFestivalDateGenerator.makeRandomEndDate(availableFestivalDuration, now, startDate); Long newFestivalId = festivalCommandFacadeService.createFestival(new FestivalCreateCommand( school.getName() + "대 축제" + FESTIVAL_SEQUENCE.incrementAndGet(), diff --git a/backend/src/main/java/com/festago/mock/FestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/MockFestivalDateGenerator.java similarity index 83% rename from backend/src/main/java/com/festago/mock/FestivalDateGenerator.java rename to backend/src/main/java/com/festago/mock/MockFestivalDateGenerator.java index 15bcdb76a..51b72e243 100644 --- a/backend/src/main/java/com/festago/mock/FestivalDateGenerator.java +++ b/backend/src/main/java/com/festago/mock/MockFestivalDateGenerator.java @@ -2,7 +2,7 @@ import java.time.LocalDate; -public interface FestivalDateGenerator { +public interface MockFestivalDateGenerator { LocalDate makeRandomStartDate(int festivalDuration, LocalDate now); diff --git a/backend/src/main/java/com/festago/mock/RandomFestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java similarity index 93% rename from backend/src/main/java/com/festago/mock/RandomFestivalDateGenerator.java rename to backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java index 9f45b9808..7fcb9453d 100644 --- a/backend/src/main/java/com/festago/mock/RandomFestivalDateGenerator.java +++ b/backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java @@ -8,7 +8,7 @@ @Profile("dev") @Component -public class RandomFestivalDateGenerator implements FestivalDateGenerator { +public class RandomMockFestivalDateGenerator implements MockFestivalDateGenerator { private static final int COUNT_FIRST_DAY_AS_DURATION_ONE = 1; private static final int RANDOM_OFFSET = 1; diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockArtistRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockArtistRepository.java new file mode 100644 index 000000000..15970e2c6 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockArtistRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.artist.domain.Artist; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockArtistRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockFestivalInfoRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockFestivalInfoRepository.java new file mode 100644 index 000000000..37f78f296 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockFestivalInfoRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.festival.domain.FestivalQueryInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockFestivalInfoRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockFestivalRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockFestivalRepository.java new file mode 100644 index 000000000..a18224397 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockFestivalRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.festival.domain.Festival; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockFestivalRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockSchoolRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockSchoolRepository.java new file mode 100644 index 000000000..312f55dbc --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockSchoolRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.school.domain.School; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockSchoolRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockStageArtistRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockStageArtistRepository.java new file mode 100644 index 000000000..cc666e420 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockStageArtistRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.stage.domain.StageArtist; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockStageArtistRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockStageQueryInfoRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockStageQueryInfoRepository.java new file mode 100644 index 000000000..6a6480c63 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockStageQueryInfoRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.stage.domain.StageQueryInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockStageQueryInfoRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/festago/mock/repository/ForMockStageRepository.java b/backend/src/main/java/com/festago/mock/repository/ForMockStageRepository.java new file mode 100644 index 000000000..e606c76d5 --- /dev/null +++ b/backend/src/main/java/com/festago/mock/repository/ForMockStageRepository.java @@ -0,0 +1,8 @@ +package com.festago.mock.repository; + +import com.festago.stage.domain.Stage; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ForMockStageRepository extends JpaRepository { + +} diff --git a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java index bf9b71c5a..67ff9ba12 100644 --- a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java +++ b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java @@ -12,6 +12,13 @@ import com.festago.mock.MockArtist; import com.festago.mock.MockDataService; import com.festago.mock.config.MockDataConfig; +import com.festago.mock.repository.ForMockArtistRepository; +import com.festago.mock.repository.ForMockFestivalInfoRepository; +import com.festago.mock.repository.ForMockFestivalRepository; +import com.festago.mock.repository.ForMockSchoolRepository; +import com.festago.mock.repository.ForMockStageArtistRepository; +import com.festago.mock.repository.ForMockStageQueryInfoRepository; +import com.festago.mock.repository.ForMockStageRepository; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; import com.festago.school.repository.SchoolRepository; @@ -45,25 +52,25 @@ class MockDataServiceTest extends ApplicationIntegrationTest { private static final int INCLUDE_FIRST_DATE = 1; @Autowired - ArtistRepository artistRepository; + ForMockArtistRepository artistRepository; @Autowired - SchoolRepository schoolRepository; + ForMockSchoolRepository schoolRepository; @Autowired - FestivalRepository festivalRepository; + ForMockFestivalRepository festivalRepository; @Autowired - StageRepository stageRepository; + ForMockStageRepository stageRepository; @Autowired - StageArtistRepository stageArtistRepository; + ForMockStageArtistRepository stageArtistRepository; @Autowired - StageQueryInfoRepository stageQueryInfoRepository; + ForMockStageQueryInfoRepository stageQueryInfoRepository; @Autowired - FestivalInfoRepository festivalInfoRepository; + ForMockFestivalInfoRepository festivalInfoRepository; @Autowired MockDataService mockDataService; diff --git a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java index 6c7588bad..ba4632540 100644 --- a/backend/src/test/java/com/festago/mock/config/MockDataConfig.java +++ b/backend/src/test/java/com/festago/mock/config/MockDataConfig.java @@ -6,9 +6,12 @@ import com.festago.festival.repository.FestivalRepository; import com.festago.mock.CommandLineAppStartupRunner; import com.festago.mock.MockScheduler; -import com.festago.mock.FestivalDateGenerator; +import com.festago.mock.MockFestivalDateGenerator; import com.festago.mock.MockDataService; -import com.festago.mock.RandomFestivalDateGenerator; +import com.festago.mock.RandomMockFestivalDateGenerator; +import com.festago.mock.repository.ForMockArtistRepository; +import com.festago.mock.repository.ForMockFestivalRepository; +import com.festago.mock.repository.ForMockSchoolRepository; import com.festago.school.application.SchoolCommandService; import com.festago.school.repository.SchoolRepository; import com.festago.stage.application.command.StageCommandFacadeService; @@ -20,13 +23,13 @@ public class MockDataConfig { @Autowired - private SchoolRepository schoolRepository; + private ForMockSchoolRepository schoolRepository; @Autowired - private ArtistRepository artistRepository; + private ForMockArtistRepository artistRepository; @Autowired - private FestivalRepository festivalRepository; + private ForMockFestivalRepository festivalRepository; @Autowired private FestivalCommandFacadeService festivalCommandFacadeService; @@ -42,8 +45,8 @@ public class MockDataConfig { @Bean - public FestivalDateGenerator festivalDateGenerator() { - return new RandomFestivalDateGenerator(); + public MockFestivalDateGenerator festivalDateGenerator() { + return new RandomMockFestivalDateGenerator(); } @Bean From 78b13c100f728b35b4e8c12c363a0c9b8bd0a039 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 19:14:58 +0900 Subject: [PATCH 16/23] =?UTF-8?q?chore:=20=EB=B9=84=20=EC=83=81=EC=88=98?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/com/festago/mock/MockDataService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index d9a9702da..8c75bf127 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -37,7 +37,7 @@ @RequiredArgsConstructor public class MockDataService { - private static final AtomicLong FESTIVAL_SEQUENCE = new AtomicLong(); + private static final AtomicLong festivalSequence = new AtomicLong(); private static final long STAGE_START_HOUR = 19L; private static final int STAGE_ARTIST_COUNT = 3; private static final int SCHOOL_PER_REGION = 3; @@ -118,7 +118,7 @@ private void makeFestival(int availableFestivalDuration, School school, List Date: Fri, 29 Mar 2024 19:16:36 +0900 Subject: [PATCH 17/23] =?UTF-8?q?refactor:=20=EB=A9=80=ED=8B=B0=20?= =?UTF-8?q?=EC=93=B0=EB=A0=88=EB=93=9C=EC=97=90=20=EC=95=88=EC=A0=84?= =?UTF-8?q?=ED=95=9C=20random=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/mock/RandomMockFestivalDateGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java b/backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java index 7fcb9453d..7ec66a5b5 100644 --- a/backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java +++ b/backend/src/main/java/com/festago/mock/RandomMockFestivalDateGenerator.java @@ -3,6 +3,7 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -13,7 +14,7 @@ public class RandomMockFestivalDateGenerator implements MockFestivalDateGenerato private static final int COUNT_FIRST_DAY_AS_DURATION_ONE = 1; private static final int RANDOM_OFFSET = 1; private static final int MAX_END_DATE_FROM_START_DATE = 2; - private final Random random = new Random(); + private final Random random = ThreadLocalRandom.current(); @Override public LocalDate makeRandomStartDate(int festivalDuration, LocalDate now) { From 851300672ae1dcae74380b345461a89c0edda79e Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 19:40:21 +0900 Subject: [PATCH 18/23] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EA=B0=80=EB=8F=85=EC=84=B1=20=EA=B0=9C=EC=84=A0=20=EB=B0=8F?= =?UTF-8?q?=20=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/festago/mock/MockDataService.java | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index 8c75bf127..729dbe9d3 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -8,7 +8,6 @@ import com.festago.festival.application.command.FestivalCommandFacadeService; import com.festago.festival.domain.Festival; import com.festago.festival.dto.command.FestivalCreateCommand; -; import com.festago.mock.repository.ForMockArtistRepository; import com.festago.mock.repository.ForMockFestivalRepository; import com.festago.mock.repository.ForMockSchoolRepository; @@ -38,9 +37,10 @@ public class MockDataService { private static final AtomicLong festivalSequence = new AtomicLong(); - private static final long STAGE_START_HOUR = 19L; + private static final int STAGE_START_HOUR = 19; private static final int STAGE_ARTIST_COUNT = 3; private static final int SCHOOL_PER_REGION = 3; + private static final int DATE_OFFSET = 1; private final MockFestivalDateGenerator mockFestivalDateGenerator; private final ForMockSchoolRepository schoolRepository; @@ -78,21 +78,28 @@ private void initializeSchool() { } } + /** + * 각 지역 별로 3개의 학교를 만듭니다. ex) 서울1대학교 서울2대학교 서울3대학교 + */ private void makeRegionSchools(SchoolRegion schoolRegion) { for (int i = 0; i < SCHOOL_PER_REGION; i++) { - int schoolNumber = i + 1; - String schoolName = schoolRegion.name() + schoolNumber; - schoolCommandService.createSchool(new SchoolCreateCommand( - schoolName, - schoolName + ".com", - schoolRegion, - null, - null - ) - ); + String schoolName = String.format("%s%d대학교", schoolRegion.name(), i + 1); + String schoolEmail = String.format("%s%d.com", schoolRegion.name(), i + 1); + crateSchool(schoolRegion, schoolName, schoolEmail); } } + private void crateSchool(SchoolRegion schoolRegion, String schoolName, String schoolEmail) { + schoolCommandService.createSchool(new SchoolCreateCommand( + schoolName, + schoolEmail, + schoolRegion, + null, + null + ) + ); + } + private void initializeArtist() { for (MockArtist artist : MockArtist.values()) { artistCommandService.save(new ArtistCreateCommand( @@ -112,13 +119,17 @@ public void makeMockFestivals(int availableFestivalDuration) { } } + /** + * 현재 날짜 + 입력받은 축제 기간 안의 기간을 갖는 축제를 생성합니다. 이때 하나의 축제에 중복된 아티스트가 포함되지 않기 위해서 makeRandomArtists 라는 메서드를 통해 섞인 Artist + * 들의 큐가 생성됩니다. + */ private void makeFestival(int availableFestivalDuration, School school, List artists) { LocalDate now = LocalDate.now(); LocalDate startDate = mockFestivalDateGenerator.makeRandomStartDate(availableFestivalDuration, now); LocalDate endDate = mockFestivalDateGenerator.makeRandomEndDate(availableFestivalDuration, now, startDate); Long newFestivalId = festivalCommandFacadeService.createFestival(new FestivalCreateCommand( - school.getName() + "대 축제" + festivalSequence.incrementAndGet(), + school.getName() + "축제" + festivalSequence.incrementAndGet(), startDate, endDate, "https://picsum.photos/536/354", @@ -134,19 +145,24 @@ private Queue makeRandomArtists(List artists) { return new ArrayDeque<>(randomArtists); } + /** + * 축제 기간 동안 축제를 채웁니다. 에를 들어 Festival 이 23~25일 이라면 23, 24, 25 날짜의 stage 를 생성합니다. + */ private void makeStages(Long festivalId, Queue artists) { Festival festival = festivalRepository.findById(festivalId) .orElseThrow(() -> new NotFoundException(ErrorCode.FESTIVAL_NOT_FOUND)); LocalDate endDate = festival.getEndDate(); - LocalDate dateCursor = festival.getStartDate(); - while (dateCursor.isBefore(endDate) || dateCursor.equals(endDate)) { - makeStage(festival, artists, dateCursor); - dateCursor = dateCursor.plusDays(1); - } + LocalDate startDate = festival.getStartDate(); + startDate.datesUntil(endDate.plusDays(DATE_OFFSET)) + .forEach(localDate -> makeStage(festival, artists, localDate)); } + /** + * 실질적으로 무대를 만드는 부분으로 이때 하나의 stage 는 랜덤한 아티스트 3명을 갖도록 만듭니다. 축제 별로 생성되는 queue 에서 poll 을 통해 stageArtist 를 결정하기 때문에 같은 + * 축제에서 아티스트는 중복되지 않습니다. + */ private void makeStage(Festival festival, Queue artists, LocalDate localDate) { - LocalDateTime startTime = localDate.atStartOfDay().plusHours(STAGE_START_HOUR); + LocalDateTime startTime = localDate.atTime(STAGE_START_HOUR, 0); stageCommandFacadeService.createStage(new StageCreateCommand( festival.getId(), startTime, @@ -155,6 +171,9 @@ private void makeStage(Festival festival, Queue artists, LocalDate local )); } + /** + * 아티스트는 무대별로 3명 배치하였고 이는 임의로 설정된 값입니다. + */ private List makeStageArtists(Queue artists) { List result = new ArrayList<>(); for (int i = 0; i < STAGE_ARTIST_COUNT; i++) { From db8721dd5f6ad6ce872d5db1777c06e13ddae4ac Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 19:41:02 +0900 Subject: [PATCH 19/23] =?UTF-8?q?chore:=20=EA=B0=9C=ED=96=89=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/com/festago/mock/MockDataService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index 729dbe9d3..8da1a3f5b 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -51,7 +51,6 @@ public class MockDataService { private final ArtistCommandService artistCommandService; private final SchoolCommandService schoolCommandService; - public boolean initialize() { if (alreadyInitialized()) { return false; From 92cae38c0ca5754b1eea6c65c95bd195611ba495 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 22:57:15 +0900 Subject: [PATCH 20/23] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20Repository=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/repository/FestivalInfoRepository.java | 3 --- .../festago/festival/repository/FestivalRepository.java | 5 +---- .../festago/stage/repository/StageArtistRepository.java | 2 -- .../festago/stage/repository/StageQueryInfoRepository.java | 3 --- .../java/com/festago/stage/repository/StageRepository.java | 3 --- .../repository/MemoryFestivalQueryInfoRepository.java | 7 ------- .../festival/repository/MemoryFestivalRepository.java | 7 ------- .../stage/repository/MemoryStageArtistRepository.java | 6 ------ .../festago/stage/repository/MemoryStageRepository.java | 6 ------ 9 files changed, 1 insertion(+), 41 deletions(-) diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java b/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java index 3dce9a9b4..56c44fd56 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalInfoRepository.java @@ -1,7 +1,6 @@ package com.festago.festival.repository; import com.festago.festival.domain.FestivalQueryInfo; -import java.util.List; import java.util.Optional; import org.springframework.data.repository.Repository; @@ -12,7 +11,5 @@ public interface FestivalInfoRepository extends Repository findByFestivalId(Long festivalId); void deleteByFestivalId(Long festivalId); - - List findAll(); } diff --git a/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java b/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java index 785668ca6..e807237b6 100644 --- a/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java +++ b/backend/src/main/java/com/festago/festival/repository/FestivalRepository.java @@ -3,7 +3,6 @@ import com.festago.common.exception.ErrorCode; import com.festago.common.exception.NotFoundException; import com.festago.festival.domain.Festival; -import java.util.List; import java.util.Optional; import org.springframework.data.repository.Repository; @@ -17,10 +16,8 @@ default Festival getOrThrow(Long festivalId) { boolean existsBySchoolId(Long schoolId); Festival save(Festival festival); - + Optional findById(Long festivalId); void deleteById(Long festivalId); - - List findAll(); } diff --git a/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java b/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java index 9c22e7df9..0c239b68a 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageArtistRepository.java @@ -18,6 +18,4 @@ public interface StageArtistRepository extends Repository { Set findAllArtistIdByStageIdIn(@Param("stageIds") List stageIds); void deleteByStageId(Long stageId); - - List findAll(); } diff --git a/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java b/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java index 0daea7408..60e21bcc8 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageQueryInfoRepository.java @@ -1,7 +1,6 @@ package com.festago.stage.repository; import com.festago.stage.domain.StageQueryInfo; -import java.util.List; import java.util.Optional; import org.springframework.data.repository.Repository; @@ -12,6 +11,4 @@ public interface StageQueryInfoRepository extends Repository findByStageId(Long stageId); void deleteByStageId(Long stageId); - - List findAll(); } diff --git a/backend/src/main/java/com/festago/stage/repository/StageRepository.java b/backend/src/main/java/com/festago/stage/repository/StageRepository.java index 916075077..27335cf93 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageRepository.java @@ -18,7 +18,4 @@ public interface StageRepository extends Repository, StageRepositor boolean existsByFestivalId(Long festivalId); List findAllByFestivalId(Long festivalId); - - List findAll(); - } diff --git a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java index 894e3155f..b2c96cd96 100644 --- a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java +++ b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalQueryInfoRepository.java @@ -2,8 +2,6 @@ import com.festago.festival.domain.FestivalQueryInfo; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -41,9 +39,4 @@ public Optional findByFestivalId(Long festivalId) { public void deleteByFestivalId(Long festivalId) { memory.entrySet().removeIf(it -> Objects.equals(it.getValue().getFestivalId(), festivalId)); } - - @Override - public List findAll() { - return new ArrayList<>(memory.values()); - } } diff --git a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java index 2e327b968..f8257c591 100644 --- a/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java +++ b/backend/src/test/java/com/festago/festival/repository/MemoryFestivalRepository.java @@ -2,8 +2,6 @@ import com.festago.festival.domain.Festival; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -45,9 +43,4 @@ public Optional findById(Long festivalId) { public void deleteById(Long festivalId) { memory.remove(festivalId); } - - @Override - public List findAll() { - return new ArrayList<>(memory.values()); - } } diff --git a/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java b/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java index 5809c7e40..419e886da 100644 --- a/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java +++ b/backend/src/test/java/com/festago/stage/repository/MemoryStageArtistRepository.java @@ -4,7 +4,6 @@ import com.festago.stage.domain.StageArtist; import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -52,9 +51,4 @@ public Set findAllArtistIdByStageIdIn(List stageIds) { public void deleteByStageId(Long stageId) { memory.entrySet().removeIf(entry -> Objects.equals(entry.getValue().getStageId(), stageId)); } - - @Override - public List findAll() { - return new ArrayList<>(memory.values()); - } } diff --git a/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java b/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java index 588cdd599..0724e300a 100644 --- a/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java +++ b/backend/src/test/java/com/festago/stage/repository/MemoryStageRepository.java @@ -2,7 +2,6 @@ import com.festago.stage.domain.Stage; import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -58,11 +57,6 @@ public List findAllByFestivalId(Long festivalId) { .toList(); } - @Override - public List findAll() { - return new ArrayList<>(memory.values()); - } - @Override public List findAllDetailByFestivalId(Long festivalId) { return findAllByFestivalId(festivalId); From 91fbafce4a2779f6e442ffca1ed2becd15b0c262 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 23:49:17 +0900 Subject: [PATCH 21/23] =?UTF-8?q?feat:=20=EB=A7=8C=EC=95=BD=20artist=20?= =?UTF-8?q?=EA=B0=80=20=EB=B6=80=EC=A1=B1=ED=95=A0=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EB=A5=BC=20=EB=B0=9C=EC=83=9D=EC=8B=9C?= =?UTF-8?q?=ED=82=A4=EA=B1=B0=EB=82=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/festago/mock/MockDataService.java | 45 +++++++++++--- .../mock/application/MockDataServiceTest.java | 62 ++++++++++++++++--- 2 files changed, 92 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index 8da1a3f5b..5f11a212d 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -36,9 +36,9 @@ @RequiredArgsConstructor public class MockDataService { + public static final int STAGE_ARTIST_COUNT = 3; private static final AtomicLong festivalSequence = new AtomicLong(); private static final int STAGE_START_HOUR = 19; - private static final int STAGE_ARTIST_COUNT = 3; private static final int SCHOOL_PER_REGION = 3; private static final int DATE_OFFSET = 1; @@ -113,6 +113,11 @@ private void initializeArtist() { public void makeMockFestivals(int availableFestivalDuration) { List allSchool = schoolRepository.findAll(); List allArtist = artistRepository.findAll(); + int artistSize = allArtist.size(); + if (STAGE_ARTIST_COUNT > artistSize) { + throw new IllegalArgumentException( + String.format("공연을 구성하기 위한 아티스트의 최소 수를 만족하지 못합니다 최소 수 : %d 현재 수 : %d", STAGE_ARTIST_COUNT, artistSize)); + } for (School school : allSchool) { makeFestival(availableFestivalDuration, school, allArtist); } @@ -171,19 +176,43 @@ private void makeStage(Festival festival, Queue artists, LocalDate local } /** - * 아티스트는 무대별로 3명 배치하였고 이는 임의로 설정된 값입니다. + * 아티스트는 무대별로 3명 배치하였고 이는 임의로 설정된 값입니다. 만약 아티스트가 무대별 인원 + 1 보다 작다면 peek 를 통한 연산 결과는 빈 아티스트 큐이기 때문에 poll 을 통해 동작합니다 */ private List makeStageArtists(Queue artists) { + return makeStageArtistsByArtistCount(artists).stream() + .map(Artist::getId) + .toList(); + } + + /** + * Stage 는 생성 제약 조건에 의해서 무조건 다른 아티스트로 구성해야합니다. 만약 STAGE_ARTIST_COUNT * 2 값보다 큐에 artist 가 작게 들어있으면 peek 연산 이후 artist + * 는 STAGE_ARTIST_COUNT 보다 적게 들어있습니다. 예를 들어 STAGE_ARTIST_COUNT = 3 일떄 6개의 아티스트에 대해서 peek 를 한다면 3개가 남아 나머지 3개로 중복 없는 + * Stage 를 구성할 수 있지만 5개의 아티스트에 대해서 peek 한 후에 2개의 artist 로는 Stage 에 중복이 생길 수 밖에 없습니다. 따라서 STAGE_ARTIST_COUNT * 2 + * artists 가 크다면 peek, 아닐 경우 peek 이후 다시 insert 해주는 로직을 진행합니다. + */ + private List makeStageArtistsByArtistCount(Queue artists) { + if (artists.size() < STAGE_ARTIST_COUNT * 2) { + return makeDuplicateStageArtists(artists); + } + return makeUniqueStageArtists(artists); + } + + private List makeDuplicateStageArtists(Queue artists) { List result = new ArrayList<>(); for (int i = 0; i < STAGE_ARTIST_COUNT; i++) { Artist artist = artists.poll(); - if (artist == null) { - throw new IllegalArgumentException("축제를 구성하기 위한 아티스트가 부족합니다"); - } result.add(artist); + artists.add(artist); } - return result.stream() - .map(Artist::getId) - .toList(); + return result; + } + + private List makeUniqueStageArtists(Queue artists) { + List result = new ArrayList<>(); + for (int i = 0; i < STAGE_ARTIST_COUNT; i++) { + Artist artist = artists.poll(); + result.add(artist); + } + return result; } } diff --git a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java index 67ff9ba12..7acf0249c 100644 --- a/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java +++ b/backend/src/test/java/com/festago/mock/application/MockDataServiceTest.java @@ -2,15 +2,16 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; import com.festago.artist.domain.Artist; -import com.festago.artist.repository.ArtistRepository; import com.festago.festival.domain.Festival; import com.festago.festival.domain.FestivalQueryInfo; -import com.festago.festival.repository.FestivalInfoRepository; -import com.festago.festival.repository.FestivalRepository; import com.festago.mock.MockArtist; import com.festago.mock.MockDataService; +import com.festago.mock.MockFestivalDateGenerator; import com.festago.mock.config.MockDataConfig; import com.festago.mock.repository.ForMockArtistRepository; import com.festago.mock.repository.ForMockFestivalInfoRepository; @@ -21,27 +22,26 @@ import com.festago.mock.repository.ForMockStageRepository; import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; -import com.festago.school.repository.SchoolRepository; import com.festago.stage.domain.Stage; import com.festago.stage.domain.StageArtist; import com.festago.stage.domain.StageQueryInfo; -import com.festago.stage.repository.StageArtistRepository; -import com.festago.stage.repository.StageQueryInfoRepository; -import com.festago.stage.repository.StageRepository; import com.festago.support.ApplicationIntegrationTest; import com.festago.support.fixture.SchoolFixture; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Queue; import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.context.annotation.Import; import org.springframework.transaction.annotation.Transactional; @@ -72,6 +72,9 @@ class MockDataServiceTest extends ApplicationIntegrationTest { @Autowired ForMockFestivalInfoRepository festivalInfoRepository; + @SpyBean + MockFestivalDateGenerator mockFestivalDateGenerator; + @Autowired MockDataService mockDataService; @@ -228,5 +231,50 @@ class 목_축제_생성_요청은 { return stageArtistsValue.size() == uniqueStageArtists; }); } + + @Test + void 만약_아티스트가_중복없이_무대를_구성하기_부족하다면_중복을_허용한다() { + + // given + LocalDate now = LocalDate.now(); + int availableUniqueStageCount = MockArtist.values().length / MockDataService.STAGE_ARTIST_COUNT; + doReturn(now) + .when(mockFestivalDateGenerator) + .makeRandomStartDate(anyInt(), any(LocalDate.class)); + doReturn(now.plusDays(availableUniqueStageCount + 1)) + .when(mockFestivalDateGenerator) + .makeRandomEndDate(anyInt(), any(LocalDate.class), any(LocalDate.class)); + + mockDataService.initialize(); + mockDataService.makeMockFestivals(10); + + List stageArtists = stageArtistRepository.findAll(); + List allStage = stageRepository.findAll(); + + Map> stageArtistByStageId = stageArtists.stream() + .collect(Collectors.groupingBy(StageArtist::getStageId)); + Map> stageByFestival = allStage.stream() + .collect(Collectors.groupingBy(Stage::getFestival)); + + // when + Map> stageArtistsByFestival = new HashMap<>(); + + stageByFestival.forEach((festival, stages) -> { + List artistsForFestival = stages.stream() + .map(stage -> stageArtistByStageId.getOrDefault(stage.getId(), Collections.emptyList())) + .flatMap(List::stream) + .collect(Collectors.toList()); + + stageArtistsByFestival.put(festival, artistsForFestival); + }); + + List artistIds = stageArtistsByFestival.values().stream() + .flatMap(List::stream) + .map(stageArtist -> stageArtist.getArtistId()) + .toList(); + + // then + assertThat(artistIds.size()).isNotEqualTo(new HashSet<>(artistIds).size()); + } } } From 8a89543b2117a56f5c8aa1472a74085a1a03c547 Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 23:52:11 +0900 Subject: [PATCH 22/23] =?UTF-8?q?chore:=20=EA=B0=9C=ED=96=89=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 --- .../main/java/com/festago/stage/repository/StageRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/com/festago/stage/repository/StageRepository.java b/backend/src/main/java/com/festago/stage/repository/StageRepository.java index 27335cf93..584107e74 100644 --- a/backend/src/main/java/com/festago/stage/repository/StageRepository.java +++ b/backend/src/main/java/com/festago/stage/repository/StageRepository.java @@ -18,4 +18,5 @@ public interface StageRepository extends Repository, StageRepositor boolean existsByFestivalId(Long festivalId); List findAllByFestivalId(Long festivalId); + } From be08c63d19bda1ac4c2627c14d001cb6ff14986e Mon Sep 17 00:00:00 2001 From: BGuga Date: Fri, 29 Mar 2024 23:55:17 +0900 Subject: [PATCH 23/23] =?UTF-8?q?chore:=20=EC=A3=BC=EC=84=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/festago/mock/MockDataService.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/com/festago/mock/MockDataService.java b/backend/src/main/java/com/festago/mock/MockDataService.java index 5f11a212d..81081a7cc 100644 --- a/backend/src/main/java/com/festago/mock/MockDataService.java +++ b/backend/src/main/java/com/festago/mock/MockDataService.java @@ -162,8 +162,8 @@ private void makeStages(Long festivalId, Queue artists) { } /** - * 실질적으로 무대를 만드는 부분으로 이때 하나의 stage 는 랜덤한 아티스트 3명을 갖도록 만듭니다. 축제 별로 생성되는 queue 에서 poll 을 통해 stageArtist 를 결정하기 때문에 같은 - * 축제에서 아티스트는 중복되지 않습니다. + * 실질적으로 무대를 만드는 부분으로 이때 하나의 stage 는 랜덤한 아티스트 3명을 갖도록 만듭니다. + * 축제 별로 생성되는 queue 에서 poll 을 통해 stageArtist 를 결정하기 때문에 같은 축제에서 아티스트는 중복되지 않습니다. */ private void makeStage(Festival festival, Queue artists, LocalDate localDate) { LocalDateTime startTime = localDate.atTime(STAGE_START_HOUR, 0); @@ -175,9 +175,6 @@ private void makeStage(Festival festival, Queue artists, LocalDate local )); } - /** - * 아티스트는 무대별로 3명 배치하였고 이는 임의로 설정된 값입니다. 만약 아티스트가 무대별 인원 + 1 보다 작다면 peek 를 통한 연산 결과는 빈 아티스트 큐이기 때문에 poll 을 통해 동작합니다 - */ private List makeStageArtists(Queue artists) { return makeStageArtistsByArtistCount(artists).stream() .map(Artist::getId) @@ -185,10 +182,11 @@ private List makeStageArtists(Queue artists) { } /** - * Stage 는 생성 제약 조건에 의해서 무조건 다른 아티스트로 구성해야합니다. 만약 STAGE_ARTIST_COUNT * 2 값보다 큐에 artist 가 작게 들어있으면 peek 연산 이후 artist - * 는 STAGE_ARTIST_COUNT 보다 적게 들어있습니다. 예를 들어 STAGE_ARTIST_COUNT = 3 일떄 6개의 아티스트에 대해서 peek 를 한다면 3개가 남아 나머지 3개로 중복 없는 - * Stage 를 구성할 수 있지만 5개의 아티스트에 대해서 peek 한 후에 2개의 artist 로는 Stage 에 중복이 생길 수 밖에 없습니다. 따라서 STAGE_ARTIST_COUNT * 2 - * artists 가 크다면 peek, 아닐 경우 peek 이후 다시 insert 해주는 로직을 진행합니다. + * Stage 는 생성 제약 조건에 의해서 무조건 다른 아티스트로 구성해야합니다. + * 만약 STAGE_ARTIST_COUNT * 2 값보다 큐에 artist 가 작게 들어있으면 poll 연산 이후 artist 는 STAGE_ARTIST_COUNT 보다 적게 들어있습니다. + * 예를 들어 STAGE_ARTIST_COUNT = 3 일떄 6개의 아티스트에 대해서 poll 를 한다면 3개가 남아 나머지 3개로 중복 없는Stage 를 구성할 수 있지만 + * 5개의 아티스트에 대해서 poll 한 후에 2개의 artist 로는 Stage 에 중복이 생길 수 밖에 없습니다. + * 따라서 STAGE_ARTIST_COUNT * 2 artists 가 크다면 poll, 아닐 경우 poll 이후 다시 insert 해주는 로직을 진행합니다. */ private List makeStageArtistsByArtistCount(Queue artists) { if (artists.size() < STAGE_ARTIST_COUNT * 2) {