From 1c59894beafe61f4646c1ea47cc4c032dc90818c Mon Sep 17 00:00:00 2001 From: huuuunee Date: Fri, 18 Aug 2023 09:37:33 +0900 Subject: [PATCH 1/6] =?UTF-8?q?:recycle:=20=EB=93=A4=EC=97=AC=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=9D=B4=EC=83=81=ED=95=9C=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/team/msg/sms/domain/prize/service/PrizeService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/prize/service/PrizeService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/prize/service/PrizeService.kt index 9fbc2463..2e392e3d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/prize/service/PrizeService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/prize/service/PrizeService.kt @@ -5,6 +5,6 @@ import team.msg.sms.common.annotation.Service @Service class PrizeService( commandPrizeService: CommandPrizeService, - getPrizeService: GetPrizeService + getPrizeService: GetPrizeService ) : CommandPrizeService by commandPrizeService, GetPrizeService by getPrizeService \ No newline at end of file From 1cbd70d8ed4a6d2b3123b8e6ed87825f9b0adf7e Mon Sep 17 00:00:00 2001 From: huuuunee Date: Fri, 18 Aug 2023 09:38:29 +0900 Subject: [PATCH 2/6] =?UTF-8?q?:recycle:=20[Certificate]=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=ED=95=99=EC=83=9D=EA=B3=BC=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B0=9B=EC=95=84=EC=84=9C=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=AA=A8=EB=8D=B8=EC=9D=98=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A1=9C=EB=A7=8C=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../certificate/service/CommandCertificateService.kt | 3 +-- .../service/impl/CommandCertificateServiceImpl.kt | 5 ++--- .../domain/certificate/spi/CommandCertificatePort.kt | 3 +-- .../certificate/CertificatePersistenceAdapter.kt | 11 ++++++----- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/CommandCertificateService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/CommandCertificateService.kt index 87989568..8a4902a2 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/CommandCertificateService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/CommandCertificateService.kt @@ -2,9 +2,8 @@ package team.msg.sms.domain.certificate.service import team.msg.sms.domain.certificate.model.Certificate import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User interface CommandCertificateService { - fun saveAll(certificate: List, student: Student, user: User): List + fun saveAll(certificate: List): List fun deleteAllByStudent(student: Student) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/impl/CommandCertificateServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/impl/CommandCertificateServiceImpl.kt index c1d0359b..9e8248d4 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/impl/CommandCertificateServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/service/impl/CommandCertificateServiceImpl.kt @@ -5,14 +5,13 @@ import team.msg.sms.domain.certificate.model.Certificate import team.msg.sms.domain.certificate.service.CommandCertificateService import team.msg.sms.domain.certificate.spi.CertificatePort import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User @Service class CommandCertificateServiceImpl( private val certificatePort: CertificatePort ) : CommandCertificateService { - override fun saveAll(certificate: List, student: Student, user: User): List = - certificatePort.saveAll(certificate, student, user) + override fun saveAll(certificate: List): List = + certificatePort.saveAll(certificate) override fun deleteAllByStudent(student: Student) = certificatePort.deleteAllByStudent(student) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/spi/CommandCertificatePort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/spi/CommandCertificatePort.kt index d2d5b736..a64cda0d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/spi/CommandCertificatePort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/certificate/spi/CommandCertificatePort.kt @@ -2,9 +2,8 @@ package team.msg.sms.domain.certificate.spi import team.msg.sms.domain.certificate.model.Certificate import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User interface CommandCertificatePort { - fun saveAll(certificate: List, student: Student, user: User): List + fun saveAll(certificate: List): List fun deleteAllByStudent(student: Student) } \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt index 4f964145..4dbfa2b5 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt @@ -6,13 +6,10 @@ import team.msg.sms.domain.certificate.model.Certificate import team.msg.sms.domain.certificate.spi.CertificatePort import team.msg.sms.domain.student.exception.StudentNotFoundException import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User import team.msg.sms.persistence.certificate.mapper.toDomain import team.msg.sms.persistence.certificate.mapper.toEntity import team.msg.sms.persistence.certificate.repository.CertificateJpaRepository -import team.msg.sms.persistence.student.mapper.toEntity import team.msg.sms.persistence.student.repository.StudentJpaRepository -import team.msg.sms.persistence.user.mapper.toEntity import java.util.* @Component @@ -20,9 +17,13 @@ class CertificatePersistenceAdapter( private val certificateJpaRepository: CertificateJpaRepository, private val studentJpaRepository: StudentJpaRepository ) : CertificatePort { - override fun saveAll(certificate: List, student: Student, user: User): List = - certificateJpaRepository.saveAll(certificate.map { it.toEntity(student.toEntity(user.toEntity())) }) + override fun saveAll(certificate: List): List { + val student = studentJpaRepository.findByIdOrNull(certificate[0].studentId) + ?: throw StudentNotFoundException + return certificateJpaRepository.saveAll(certificate + .map { it.toEntity(student = student) }) .map { it.toDomain() } + } override fun deleteAllByStudent(student: Student) { val student = studentJpaRepository.findByIdOrNull(student.id) From 70b49c1c8b0967c0144b3eab9253b0401646ad53 Mon Sep 17 00:00:00 2001 From: huuuunee Date: Fri, 18 Aug 2023 09:38:42 +0900 Subject: [PATCH 3/6] =?UTF-8?q?:recycle:=20[LanguageCertificate]=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=ED=95=99=EC=83=9D=EA=B3=BC=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=84=9C=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=97=90=EC=84=9C=20=EB=AA=A8=EB=8D=B8=EC=9D=98=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A1=9C=EB=A7=8C=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CommandLanguageCertificateService.kt | 2 +- .../impl/CommandLanguageCertificateServiceImpl.kt | 5 +---- .../spi/CommandLanguageCertificatePort.kt | 3 +-- .../LanguageCertificatePersistenceAdapter.kt | 11 ++++++----- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/CommandLanguageCertificateService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/CommandLanguageCertificateService.kt index f1ce039f..0b558ffd 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/CommandLanguageCertificateService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/CommandLanguageCertificateService.kt @@ -5,6 +5,6 @@ import team.msg.sms.domain.student.model.Student import team.msg.sms.domain.user.model.User interface CommandLanguageCertificateService { - fun saveAll(languageCertificate: List, student: Student, user: User): List + fun saveAll(languageCertificate: List): List fun deleteAllByStudent(student: Student) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/impl/CommandLanguageCertificateServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/impl/CommandLanguageCertificateServiceImpl.kt index 56dc4cda..3797d758 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/impl/CommandLanguageCertificateServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/service/impl/CommandLanguageCertificateServiceImpl.kt @@ -5,7 +5,6 @@ import team.msg.sms.domain.languagecertificate.model.LanguageCertificate import team.msg.sms.domain.languagecertificate.service.CommandLanguageCertificateService import team.msg.sms.domain.languagecertificate.spi.LanguageCertificatePort import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User @Service class CommandLanguageCertificateServiceImpl( @@ -13,10 +12,8 @@ class CommandLanguageCertificateServiceImpl( ) : CommandLanguageCertificateService { override fun saveAll( languageCertificate: List, - student: Student, - user: User ): List = - languageCertificatePort.saveAll(languageCertificate, student, user) + languageCertificatePort.saveAll(languageCertificate) override fun deleteAllByStudent(student: Student) = languageCertificatePort.deleteAllByStudent(student) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/spi/CommandLanguageCertificatePort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/spi/CommandLanguageCertificatePort.kt index 969518f4..b20573ed 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/spi/CommandLanguageCertificatePort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/languagecertificate/spi/CommandLanguageCertificatePort.kt @@ -2,9 +2,8 @@ package team.msg.sms.domain.languagecertificate.spi import team.msg.sms.domain.languagecertificate.model.LanguageCertificate import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User interface CommandLanguageCertificatePort { - fun saveAll(region: List, student: Student, user: User): List + fun saveAll(languageCertificates: List): List fun deleteAllByStudent(student: Student) } \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt index 9cdbd2e5..e170b4ca 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt @@ -6,13 +6,10 @@ import team.msg.sms.domain.languagecertificate.model.LanguageCertificate import team.msg.sms.domain.languagecertificate.spi.LanguageCertificatePort import team.msg.sms.domain.student.exception.StudentNotFoundException import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User import team.msg.sms.persistence.languagecertificate.mapper.toDomain import team.msg.sms.persistence.languagecertificate.mapper.toEntity import team.msg.sms.persistence.languagecertificate.repository.LanguageCertificateJpaRepository -import team.msg.sms.persistence.student.mapper.toEntity import team.msg.sms.persistence.student.repository.StudentJpaRepository -import team.msg.sms.persistence.user.mapper.toEntity import java.util.* @Component @@ -20,9 +17,13 @@ class LanguageCertificatePersistenceAdapter( private val languageCertificateJpaRepository: LanguageCertificateJpaRepository, private val studentJpaRepository: StudentJpaRepository ) : LanguageCertificatePort { - override fun saveAll(region: List, student: Student, user: User): List = - languageCertificateJpaRepository.saveAll(region.map { it.toEntity(student.toEntity(user.toEntity())) }) + override fun saveAll(languageCertificates: List): List { + val student = studentJpaRepository.findByIdOrNull(languageCertificates[0].studentId) + ?: throw StudentNotFoundException + return languageCertificateJpaRepository.saveAll(languageCertificates + .map { it.toEntity(student) }) .map { it.toDomain() } + } override fun deleteAllByStudent(student: Student) { val student = studentJpaRepository.findByIdOrNull(student.id) From 86abff9181c462b95bc5e4b7a16496a69eb10013 Mon Sep 17 00:00:00 2001 From: huuuunee Date: Fri, 18 Aug 2023 09:38:50 +0900 Subject: [PATCH 4/6] =?UTF-8?q?:recycle:=20[Region]=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=ED=95=99=EC=83=9D=EA=B3=BC=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AA=A8=EB=8D=B8=EC=9D=98=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A1=9C=EB=A7=8C=20=EC=A0=80=EC=9E=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/region/service/CommandRegionService.kt | 3 +-- .../region/service/impl/CommandRegionServiceImpl.kt | 5 ++--- .../msg/sms/domain/region/spi/CommandRegionPort.kt | 2 +- .../persistence/region/RegionPersistenceAdapter.kt | 12 +++++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/CommandRegionService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/CommandRegionService.kt index 0d00677c..db2ecf0d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/CommandRegionService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/CommandRegionService.kt @@ -2,9 +2,8 @@ package team.msg.sms.domain.region.service import team.msg.sms.domain.region.model.Region import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User interface CommandRegionService { - fun saveAll(region: List, student: Student, user: User): List + fun saveAll(region: List): List fun deleteAllByStudent(student: Student) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/impl/CommandRegionServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/impl/CommandRegionServiceImpl.kt index 71d63f14..605dff9c 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/impl/CommandRegionServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/region/service/impl/CommandRegionServiceImpl.kt @@ -5,14 +5,13 @@ import team.msg.sms.domain.region.model.Region import team.msg.sms.domain.region.service.CommandRegionService import team.msg.sms.domain.region.spi.RegionPort import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User @Service class CommandRegionServiceImpl( private val regionPort: RegionPort ) : CommandRegionService { - override fun saveAll(region: List, student: Student, user: User): List = - regionPort.saveAll(region, student, user) + override fun saveAll(region: List): List = + regionPort.saveAll(region) override fun deleteAllByStudent(student: Student) = regionPort.deleteAllByStudent(student) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/region/spi/CommandRegionPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/region/spi/CommandRegionPort.kt index e47f0a6e..a2f697a6 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/region/spi/CommandRegionPort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/region/spi/CommandRegionPort.kt @@ -5,6 +5,6 @@ import team.msg.sms.domain.student.model.Student import team.msg.sms.domain.user.model.User interface CommandRegionPort { - fun saveAll(region: List, student: Student, user: User): List + fun saveAll(region: List): List fun deleteAllByStudent(student: Student) } \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt index fbd3d826..3b24bcf5 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt @@ -6,13 +6,10 @@ import team.msg.sms.domain.region.model.Region import team.msg.sms.domain.region.spi.RegionPort import team.msg.sms.domain.student.exception.StudentNotFoundException import team.msg.sms.domain.student.model.Student -import team.msg.sms.domain.user.model.User import team.msg.sms.persistence.region.mapper.toDomain import team.msg.sms.persistence.region.mapper.toEntity import team.msg.sms.persistence.region.repository.RegionJpaRepository -import team.msg.sms.persistence.student.mapper.toEntity import team.msg.sms.persistence.student.repository.StudentJpaRepository -import team.msg.sms.persistence.user.mapper.toEntity import java.util.* @Component @@ -20,8 +17,13 @@ class RegionPersistenceAdapter( private val regionJpaRepository: RegionJpaRepository, private val studentJpaRepository: StudentJpaRepository ) : RegionPort { - override fun saveAll(region: List, student: Student, user: User): List = - regionJpaRepository.saveAll(region.map { it.toEntity(student.toEntity(user.toEntity())) }).map { it.toDomain() } + override fun saveAll(regions: List): List { + val student = studentJpaRepository.findByIdOrNull(regions[0].studentId) + ?: throw StudentNotFoundException + return regionJpaRepository.saveAll(regions + .map { it.toEntity(student) }) + .map { it.toDomain() } + } override fun deleteAllByStudent(student: Student) { val student = studentJpaRepository.findByIdOrNull(student.id) From 1a94387a01a13834049fc561a000d173563dcb6b Mon Sep 17 00:00:00 2001 From: huuuunee Date: Fri, 18 Aug 2023 09:39:08 +0900 Subject: [PATCH 5/6] =?UTF-8?q?:recycle:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=EA=B0=80=20=EB=B9=88=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=9D=BC=EB=95=8C=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/student/usecase/SignUpUseCase.kt | 72 ++++++++++++------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/student/usecase/SignUpUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/student/usecase/SignUpUseCase.kt index 46a63721..67dd6028 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/student/usecase/SignUpUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/student/usecase/SignUpUseCase.kt @@ -72,37 +72,50 @@ class SignUpUseCase( signUpData.projects.forEach { val project = projectService.save(project = toProjectModel(it, studentId = student.id)) projectTechStackValid(techStacks, it.techStacks, project.id) - projectLinkService.saveAll(it.links.map { linkRequestData -> - toProjectLinkModel(projectLink = linkRequestData, projectId = project.id) - }) - imageService.saveAll(it.previewImages.map { url -> - toImageModel(url = url, projectId = project.id) - }) + saveAllIfNotEmpty( + it.links, + { projectLink -> toProjectLinkModel(projectLink = projectLink, projectId = project.id) }, + projectLinkService::saveAll + ) + saveAllIfNotEmpty( + it.previewImages, + { previewImage -> toImageModel(url = previewImage, projectId = project.id) }, + imageService::saveAll + ) } - regionService.saveAll(signUpData.region.map { toRegionModel(it, studentId = student.id) }, student, user) + saveAllIfNotEmpty( + signUpData.region, + { toRegionModel(region = it, studentId = student.id) }, + regionService::saveAll + ) - languageCertificateService.saveAll(signUpData.languageCertificate.map { - toLanguageCertificate( - languageCertificate = it, - studentId = student.id - ) - }, student, user) + saveAllIfNotEmpty( + signUpData.languageCertificate, + { toLanguageCertificate(languageCertificate = it, studentId = student.id) }, + languageCertificateService::saveAll + ) - certificateService.saveAll( - signUpData.certificate.map { toCertificate(certificate = it, studentId = student.id) }, - student, - user + saveAllIfNotEmpty( + signUpData.certificate, + { toCertificate(certificate = it, studentId = student.id) }, + certificateService::saveAll ) - prizeService.saveAll( - signUpData.prizes - .map { - toPrizeModel(prize = it, studentId = student.id) - } + saveAllIfNotEmpty( + signUpData.prizes, + { toPrizeModel(prize = it, studentId = student.id) }, + prizeService::saveAll ) } + private fun saveAllIfNotEmpty(dataList: List, transform: (T) -> R, saveFunction: (List) -> Unit) { + dataList + .takeIf { it.isNotEmpty() } + ?.map { transform(it) } + ?.let { saveFunction(it) } + } + private fun toImageModel(url: String, projectId: Long): Image = Image( id = 0, @@ -202,7 +215,11 @@ class SignUpUseCase( studentId = studentId ) - private fun projectTechStackValid(stack: MutableList, projectTechStacks: List, projectId: Long) { + private fun projectTechStackValid( + stack: MutableList, + projectTechStacks: List, + projectId: Long + ) { for (stackItem in projectTechStacks) { val techStackData = stack.find { it.stack == stackItem } if (techStackData == null) { @@ -218,7 +235,11 @@ class SignUpUseCase( } } - private fun studentTechStackValid(stack: MutableList, studentTechStacks: List, studentId: UUID) { + private fun studentTechStackValid( + stack: MutableList, + studentTechStacks: List, + studentId: UUID + ) { for (stackItem in studentTechStacks) { val techStackData = stack.find { it.stack == stackItem } if (techStackData == null) { @@ -226,7 +247,8 @@ class SignUpUseCase( stack.add(0, techStack) studentTechStackService.save(toStudentTechStackModel(studentId, techStack.id)) } else { - val techStack = techStackService.save(techStack = techStackData.copy(count = techStackData.count + 1)) + val techStack = + techStackService.save(techStack = techStackData.copy(count = techStackData.count + 1)) stack.add(0, techStack) studentTechStackService.save(toStudentTechStackModel(studentId, techStack.id)) } From 6824f1d526e09530e9f04f9a8737f931fe00b879 Mon Sep 17 00:00:00 2001 From: huuuunee Date: Fri, 18 Aug 2023 10:35:29 +0900 Subject: [PATCH 6/6] =?UTF-8?q?:recycle:=20[0]=20=EC=9D=B8=EB=8D=B1?= =?UTF-8?q?=EC=8A=A4=EC=97=90=EC=84=9C=20.first()=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EC=B0=BE=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/certificate/CertificatePersistenceAdapter.kt | 2 +- .../team/msg/sms/persistence/image/ImagePersistenceAdapter.kt | 2 +- .../LanguageCertificatePersistenceAdapter.kt | 2 +- .../team/msg/sms/persistence/prize/PrizePersistenceAdapter.kt | 2 +- .../sms/persistence/project/ProjectLinkPersistenceAdapter.kt | 2 +- .../team/msg/sms/persistence/region/RegionPersistenceAdapter.kt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt index 4dbfa2b5..75941093 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/certificate/CertificatePersistenceAdapter.kt @@ -18,7 +18,7 @@ class CertificatePersistenceAdapter( private val studentJpaRepository: StudentJpaRepository ) : CertificatePort { override fun saveAll(certificate: List): List { - val student = studentJpaRepository.findByIdOrNull(certificate[0].studentId) + val student = studentJpaRepository.findByIdOrNull(certificate.first().studentId) ?: throw StudentNotFoundException return certificateJpaRepository.saveAll(certificate .map { it.toEntity(student = student) }) diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/image/ImagePersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/image/ImagePersistenceAdapter.kt index f6fe52bc..7010ebb2 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/image/ImagePersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/image/ImagePersistenceAdapter.kt @@ -17,7 +17,7 @@ class ImagePersistenceAdapter( private val projectJpaRepository: ProjectJpaRepository ) : ImagePort { override fun saveAll(images: List) { - val project = projectJpaRepository.findByIdOrNull(images[0].projectId) + val project = projectJpaRepository.findByIdOrNull(images.first().projectId) ?: throw ProjectNotFoundException imageJpaRepository.saveAll(images .map { diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt index e170b4ca..b7eaead9 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/languagecertificate/LanguageCertificatePersistenceAdapter.kt @@ -18,7 +18,7 @@ class LanguageCertificatePersistenceAdapter( private val studentJpaRepository: StudentJpaRepository ) : LanguageCertificatePort { override fun saveAll(languageCertificates: List): List { - val student = studentJpaRepository.findByIdOrNull(languageCertificates[0].studentId) + val student = studentJpaRepository.findByIdOrNull(languageCertificates.first().studentId) ?: throw StudentNotFoundException return languageCertificateJpaRepository.saveAll(languageCertificates .map { it.toEntity(student) }) diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/prize/PrizePersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/prize/PrizePersistenceAdapter.kt index dbe0303f..cdf9a0c4 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/prize/PrizePersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/prize/PrizePersistenceAdapter.kt @@ -18,7 +18,7 @@ class PrizePersistenceAdapter( private val studentJpaRepository: StudentJpaRepository ) : PrizePort { override fun saveAll(prizes: List) { - val student = studentJpaRepository.findByIdOrNull(prizes[0].studentId) + val student = studentJpaRepository.findByIdOrNull(prizes.first().studentId) ?: throw StudentNotFoundException prizeJpaRepository.saveAll( prizes diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/project/ProjectLinkPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/project/ProjectLinkPersistenceAdapter.kt index e7f8f799..4fe0efb3 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/project/ProjectLinkPersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/project/ProjectLinkPersistenceAdapter.kt @@ -17,7 +17,7 @@ class ProjectLinkPersistenceAdapter( val projectJpaRepository: ProjectJpaRepository ) : ProjectLinkPort { override fun saveAll(projectLinks: List) { - val project = projectJpaRepository.findByIdOrNull(projectLinks[0].projectId) + val project = projectJpaRepository.findByIdOrNull(projectLinks.first().projectId) ?: throw ProjectNotFoundException projectLinkJpaRepository.saveAll( projectLinks diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt index 3b24bcf5..7d70c355 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/region/RegionPersistenceAdapter.kt @@ -18,7 +18,7 @@ class RegionPersistenceAdapter( private val studentJpaRepository: StudentJpaRepository ) : RegionPort { override fun saveAll(regions: List): List { - val student = studentJpaRepository.findByIdOrNull(regions[0].studentId) + val student = studentJpaRepository.findByIdOrNull(regions.first().studentId) ?: throw StudentNotFoundException return regionJpaRepository.saveAll(regions .map { it.toEntity(student) })