From faf7bbc0d36c91581a0020245baefb1911aea5cb Mon Sep 17 00:00:00 2001 From: rlaisqls Date: Wed, 10 May 2023 07:14:22 +0900 Subject: [PATCH] chore: (#490) createSchool api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 테스트용 api. url 권한은 설정하지 않았습니다. ㅇ . --- .../domain/school/dto/CreateSchoolRequest.kt | 37 +++++++++++++++++++ .../aliens/dms/domain/school/model/School.kt | 2 +- .../school/service/CommandSchoolService.kt | 3 ++ .../service/CommandSchoolServiceImpl.kt | 4 ++ .../domain/school/spi/CommandSchoolPort.kt | 3 ++ .../school/usecase/CreateSchoolUseCase.kt | 21 +++++++++++ .../dms/domain/school/SchoolWebAdapter.kt | 35 +++++++++++++++--- .../dto/request/CreateSchoolWebRequest.kt | 11 ++++++ 8 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/school/dto/CreateSchoolRequest.kt create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/school/usecase/CreateSchoolUseCase.kt create mode 100644 dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/dto/request/CreateSchoolWebRequest.kt diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/dto/CreateSchoolRequest.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/dto/CreateSchoolRequest.kt new file mode 100644 index 000000000..98149ed16 --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/dto/CreateSchoolRequest.kt @@ -0,0 +1,37 @@ +package team.aliens.dms.domain.school.dto + +import java.time.LocalDate +import java.util.UUID +import team.aliens.dms.common.util.StringUtil +import team.aliens.dms.domain.school.model.AvailableFeature +import team.aliens.dms.domain.school.model.School + +class CreateSchoolRequest( + val schoolName: String, + val schoolAddress: String, + val mealService: Boolean, + val noticeService: Boolean, + val pointService: Boolean, + val studyRoomService: Boolean, + val remainService: Boolean +) { + fun toSchool() = + School( + name = schoolName, + code = StringUtil.randomNumber(School.SCHOOL_CODE_SIZE), + question = "우리 학교 이름은?", + answer = schoolName, + address = schoolAddress, + contractStartedAt = LocalDate.now() + ) + + fun toAvailableFeature(schoolId: UUID) = + AvailableFeature( + schoolId = schoolId, + mealService = mealService, + noticeService = noticeService, + pointService = pointService, + studyRoomService = studyRoomService, + remainService = remainService + ) +} diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/model/School.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/model/School.kt index 377eba22a..18767eb00 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/model/School.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/model/School.kt @@ -22,7 +22,7 @@ data class School( val contractStartedAt: LocalDate, - val contractEndedAt: LocalDate? + val contractEndedAt: LocalDate? = null ) { companion object { diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolService.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolService.kt index 80d3435f7..1c6a2d9a6 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolService.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolService.kt @@ -1,8 +1,11 @@ package team.aliens.dms.domain.school.service +import team.aliens.dms.domain.school.model.AvailableFeature import team.aliens.dms.domain.school.model.School interface CommandSchoolService { fun saveSchool(school: School): School + + fun saveAvailableFeature(availableFeature: AvailableFeature): AvailableFeature } diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolServiceImpl.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolServiceImpl.kt index cdc6e7007..47ac40050 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolServiceImpl.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/service/CommandSchoolServiceImpl.kt @@ -1,6 +1,7 @@ package team.aliens.dms.domain.school.service import team.aliens.dms.common.annotation.Service +import team.aliens.dms.domain.school.model.AvailableFeature import team.aliens.dms.domain.school.model.School import team.aliens.dms.domain.school.spi.CommandSchoolPort @@ -11,4 +12,7 @@ class CommandSchoolServiceImpl( override fun saveSchool(school: School) = commandSchoolPort.saveSchool(school) + + override fun saveAvailableFeature(availableFeature: AvailableFeature) = + commandSchoolPort.saveAvailableFeature(availableFeature) } diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/spi/CommandSchoolPort.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/spi/CommandSchoolPort.kt index 919ae2510..6eb1aa2d6 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/spi/CommandSchoolPort.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/spi/CommandSchoolPort.kt @@ -1,8 +1,11 @@ package team.aliens.dms.domain.school.spi +import team.aliens.dms.domain.school.model.AvailableFeature import team.aliens.dms.domain.school.model.School interface CommandSchoolPort { fun saveSchool(school: School): School + + fun saveAvailableFeature(availableFeature: AvailableFeature): AvailableFeature } diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/school/usecase/CreateSchoolUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/usecase/CreateSchoolUseCase.kt new file mode 100644 index 000000000..0c5f5811e --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/school/usecase/CreateSchoolUseCase.kt @@ -0,0 +1,21 @@ +package team.aliens.dms.domain.school.usecase + +import team.aliens.dms.common.annotation.UseCase +import team.aliens.dms.common.service.security.SecurityService +import team.aliens.dms.domain.school.dto.CreateSchoolRequest +import team.aliens.dms.domain.school.service.SchoolService + +@UseCase +class CreateSchoolUseCase( + private val schoolService: SchoolService, + private val securityService: SecurityService +) { + + fun execute(request: CreateSchoolRequest) { + val school = schoolService.saveSchool( + request.toSchool() + ) + schoolService.saveAvailableFeature(request.toAvailableFeature(school.id)) + securityService.createSchoolSecretBySchoolId(school.id) + } +} \ No newline at end of file diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/SchoolWebAdapter.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/SchoolWebAdapter.kt index 8c37edfe3..4f25b7df2 100644 --- a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/SchoolWebAdapter.kt +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/SchoolWebAdapter.kt @@ -1,34 +1,38 @@ package team.aliens.dms.domain.school +import java.util.UUID +import javax.validation.Valid +import javax.validation.constraints.NotBlank +import javax.validation.constraints.NotNull +import javax.validation.constraints.Size import org.springframework.http.HttpStatus import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController +import team.aliens.dms.domain.school.dto.CreateSchoolRequest import team.aliens.dms.domain.school.dto.QueryAvailableFeaturesResponse import team.aliens.dms.domain.school.dto.SchoolsResponse import team.aliens.dms.domain.school.dto.UpdateQuestionRequest +import team.aliens.dms.domain.school.dto.request.CreateSchoolWebRequest import team.aliens.dms.domain.school.dto.request.UpdateQuestionWebRequest import team.aliens.dms.domain.school.dto.response.ReissueSchoolCodeResponse import team.aliens.dms.domain.school.dto.response.SchoolIdResponse import team.aliens.dms.domain.school.dto.response.SchoolQuestionResponse import team.aliens.dms.domain.school.usecase.CheckSchoolAnswerUseCase import team.aliens.dms.domain.school.usecase.CheckSchoolCodeUseCase +import team.aliens.dms.domain.school.usecase.CreateSchoolUseCase import team.aliens.dms.domain.school.usecase.QueryAvailableFeaturesUseCase import team.aliens.dms.domain.school.usecase.QuerySchoolQuestionUseCase import team.aliens.dms.domain.school.usecase.QuerySchoolsUseCase import team.aliens.dms.domain.school.usecase.ReissueSchoolCodeUseCase import team.aliens.dms.domain.school.usecase.UpdateQuestionUseCase -import java.util.UUID -import javax.validation.Valid -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull -import javax.validation.constraints.Size @Validated @RequestMapping("/schools") @@ -40,7 +44,8 @@ class SchoolWebAdapter( private val checkSchoolCodeUseCase: CheckSchoolCodeUseCase, private val updateQuestionUseCase: UpdateQuestionUseCase, private val reissueSchoolCodeUseCase: ReissueSchoolCodeUseCase, - private val queryAvailableFeaturesUseCase: QueryAvailableFeaturesUseCase + private val queryAvailableFeaturesUseCase: QueryAvailableFeaturesUseCase, + private val createSchoolUseCase: CreateSchoolUseCase ) { @GetMapping @@ -97,4 +102,22 @@ class SchoolWebAdapter( updateQuestionUseCase.execute(request) } + + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping + fun createSchool(@RequestBody @Valid request: CreateSchoolWebRequest) { + createSchoolUseCase.execute( + request.run { + CreateSchoolRequest( + schoolName = schoolName, + schoolAddress = schoolAddress, + mealService = mealService, + noticeService = noticeService, + pointService = pointService, + studyRoomService = studyRoomService, + remainService = remainService + ) + } + ) + } } diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/dto/request/CreateSchoolWebRequest.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/dto/request/CreateSchoolWebRequest.kt new file mode 100644 index 000000000..40cc1ca48 --- /dev/null +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/school/dto/request/CreateSchoolWebRequest.kt @@ -0,0 +1,11 @@ +package team.aliens.dms.domain.school.dto.request + +class CreateSchoolWebRequest( + val schoolName: String, + val schoolAddress: String, + val mealService: Boolean, + val noticeService: Boolean, + val pointService: Boolean, + val studyRoomService: Boolean, + val remainService: Boolean +) \ No newline at end of file