diff --git a/cakk-admin/build.gradle.kts b/cakk-admin/build.gradle.kts index 6c431990..207c9889 100644 --- a/cakk-admin/build.gradle.kts +++ b/cakk-admin/build.gradle.kts @@ -15,6 +15,8 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-validation") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("org.springframework.boot:spring-boot-starter-oauth2-client") implementation("org.springframework:spring-tx") diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/AdminUser.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/AdminUser.kt new file mode 100644 index 00000000..75ad8606 --- /dev/null +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/AdminUser.kt @@ -0,0 +1,5 @@ +package com.cakk.admin.annotation + +@Target(AnnotationTarget.VALUE_PARAMETER) +@Retention(AnnotationRetention.RUNTIME) +annotation class AdminUser diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/OperationDay.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/OperationDay.kt index 25104f26..65d9052d 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/OperationDay.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/annotation/OperationDay.kt @@ -10,7 +10,7 @@ import kotlin.reflect.KClass @Constraint(validatedBy = [OperationValidator::class]) annotation class OperationDay( - val message: String = "영업 일자 형식이 잘못됐습니다.", - val groups: Array> = [], - val payload: Array> = [] + val message: String = "영업 일자 형식이 잘못됐습니다.", + val groups: Array> = [], + val payload: Array> = [] ) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/controller/BusinessInformationController.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/controller/BusinessInformationController.kt index a58ff10a..afe3b65e 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/controller/BusinessInformationController.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/controller/BusinessInformationController.kt @@ -1,38 +1,44 @@ package com.cakk.admin.controller -import com.cakk.admin.dto.request.PromotionRequest -import com.cakk.admin.dto.response.CakeShopOwnerCandidateResponse -import com.cakk.admin.dto.response.CakeShopOwnerCandidatesResponse -import com.cakk.admin.service.BusinessInformationService -import com.cakk.common.response.ApiResponse import jakarta.validation.Valid + import org.springframework.web.bind.annotation.* +import com.cakk.admin.dto.request.PromotionRequest +import com.cakk.admin.mapper.supplyPromotionParamBy +import com.cakk.common.response.ApiResponse +import com.cakk.core.dto.response.shop.CakeShopOwnerCandidateResponse +import com.cakk.core.dto.response.shop.CakeShopOwnerCandidatesResponse +import com.cakk.core.service.shop.ShopService + @RestController @RequestMapping("/business-information") class BusinessInformationController( - private val businessInformationService: BusinessInformationService + private val shopService: ShopService ) { - @GetMapping("/candidates") - fun getBusinessOwnerCandidates(): ApiResponse { - val response = businessInformationService.getBusinessOwnerCandidates() - return ApiResponse.success(response) - } - - @GetMapping("/candidates/{userId}") - fun getCandidateSpecificationInformation( - @PathVariable userId: Long - ): ApiResponse { - val response = businessInformationService.getCandidateInformation(userId) - return ApiResponse.success(response) - } - - @PutMapping("/promote") - fun promoteUser( - @RequestBody @Valid promotionRequest: PromotionRequest - ): ApiResponse { - businessInformationService.promoteUserToBusinessOwner(promotionRequest) - return ApiResponse.success() - } + @GetMapping("/candidates") + fun getBusinessOwnerCandidates(): ApiResponse { + val response = shopService.getBusinessOwnerCandidates() + return ApiResponse.success(response) + } + + @GetMapping("/candidates/{userId}") + fun getCandidateSpecificationInformation( + @PathVariable userId: Long + ): ApiResponse { + val response = shopService.getCandidateInformation(userId) + + return ApiResponse.success(response) + } + + @PutMapping("/promote") + fun promoteUser( + @RequestBody @Valid promotionRequest: PromotionRequest + ): ApiResponse { + val param = supplyPromotionParamBy(promotionRequest) + shopService.promoteUserToBusinessOwner(param) + + return ApiResponse.success() + } } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/controller/CakeController.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/controller/CakeController.kt index b7409c11..01aeaa43 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/controller/CakeController.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/controller/CakeController.kt @@ -1,44 +1,57 @@ package com.cakk.admin.controller +import jakarta.validation.Valid + +import org.springframework.web.bind.annotation.* + +import com.cakk.admin.annotation.AdminUser import com.cakk.admin.dto.request.CakeCreateByAdminRequest import com.cakk.admin.dto.request.CakeUpdateByAdminRequest -import com.cakk.admin.service.CakeService +import com.cakk.admin.mapper.supplyCakeCreateParamBy +import com.cakk.admin.mapper.supplyCakeUpdateParamBy import com.cakk.common.response.ApiResponse -import jakarta.validation.Valid -import org.springframework.web.bind.annotation.* +import com.cakk.core.service.cake.CakeService +import com.cakk.domain.mysql.entity.user.User @RestController @RequestMapping("/shops/{cakeShopId}/cakes") class CakeController( - private val cakeService: CakeService + private val cakeService: CakeService ) { - @PostMapping - fun create( - @PathVariable cakeShopId: Long, - @RequestBody @Valid dto: CakeCreateByAdminRequest - ): ApiResponse { - cakeService.createCake(dto.toParam(cakeShopId)) - return ApiResponse.success() - } - - @PutMapping("/{cakeId}") - fun update( - @PathVariable cakeShopId: Long, - @PathVariable cakeId: Long, - @RequestBody @Valid dto: CakeUpdateByAdminRequest - ): ApiResponse { - cakeService.updateCake(dto.toParam(cakeShopId)) - return ApiResponse.success() - } - - @DeleteMapping("/{cakeId}") - fun delete( - @PathVariable cakeShopId: Long, - @PathVariable cakeId: Long - ): ApiResponse { - cakeService.deleteCake(cakeId) - - return ApiResponse.success() - } + @PostMapping + fun create( + @PathVariable cakeShopId: Long, + @RequestBody @Valid dto: CakeCreateByAdminRequest, + @AdminUser admin: User + ): ApiResponse { + val param = supplyCakeCreateParamBy(dto, admin, cakeShopId) + cakeService.createCake(param) + + return ApiResponse.success() + } + + @PutMapping("/{cakeId}") + fun update( + @PathVariable cakeShopId: Long, + @PathVariable cakeId: Long, + @RequestBody @Valid dto: CakeUpdateByAdminRequest, + @AdminUser admin: User + ): ApiResponse { + val param = supplyCakeUpdateParamBy(dto, admin, cakeShopId) + cakeService.updateCake(param) + + return ApiResponse.success() + } + + @DeleteMapping("/{cakeId}") + fun delete( + @PathVariable cakeShopId: Long, + @PathVariable cakeId: Long, + @AdminUser admin: User + ): ApiResponse { + cakeService.deleteCake(admin, cakeId) + + return ApiResponse.success() + } } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/controller/ShopController.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/controller/ShopController.kt index e2641e47..3284199a 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/controller/ShopController.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/controller/ShopController.kt @@ -1,64 +1,78 @@ package com.cakk.admin.controller -import com.cakk.admin.dto.request.* -import com.cakk.admin.dto.response.CakeShopCreateResponse -import com.cakk.admin.service.ShopService -import com.cakk.common.response.ApiResponse import jakarta.validation.Valid + import org.springframework.web.bind.annotation.* +import com.cakk.admin.annotation.AdminUser +import com.cakk.admin.dto.request.* +import com.cakk.admin.mapper.* +import com.cakk.common.response.ApiResponse +import com.cakk.core.dto.response.shop.CakeShopCreateResponse +import com.cakk.core.service.shop.ShopService +import com.cakk.domain.mysql.entity.user.User + @RestController @RequestMapping("/shops") class ShopController( - private val shopService: ShopService + private val shopService: ShopService ) { - @PostMapping - fun createByAdmin( - @RequestBody @Valid request: CakeShopCreateByAdminRequest - ): ApiResponse { - val response = shopService.createCakeShopByCertification(request.toParam()) + @PostMapping + fun createByAdmin( + @RequestBody @Valid request: CakeShopCreateByAdminRequest + ): ApiResponse { + val param = supplyCreateShopParamBy(request) + val response = shopService.createCakeShopByCertification(param) - return ApiResponse.success(response) - } + return ApiResponse.success(response) + } - @PutMapping("/{cakeShopId}") - fun updateBasicInformation( - @PathVariable cakeShopId: Long, - @RequestBody @Valid request: CakeShopUpdateByAdminRequest - ): ApiResponse { - shopService.updateBasicInformation(request.toParam(cakeShopId)) + @PutMapping("/{cakeShopId}") + fun updateBasicInformation( + @PathVariable cakeShopId: Long, + @RequestBody @Valid request: CakeShopUpdateByAdminRequest, + @AdminUser admin: User + ): ApiResponse { + val param = supplyCakeShopUpdateParamBy(request, admin, cakeShopId) + shopService.updateBasicInformation(param) - return ApiResponse.success() - } + return ApiResponse.success() + } - @PutMapping("/{cakeShopId}/links") - fun updateLinks( - @PathVariable cakeShopId: Long, - @RequestBody request: @Valid LinkUpdateByAdminRequest - ): ApiResponse { - shopService.updateShopLinks(request.toParam(cakeShopId)) + @PutMapping("/{cakeShopId}/links") + fun updateLinks( + @PathVariable cakeShopId: Long, + @RequestBody @Valid request: LinkUpdateByAdminRequest, + @AdminUser admin: User + ): ApiResponse { + val param = supplyUpdateLinkParamBy(request, admin, cakeShopId) + shopService.updateShopLinks(param) - return ApiResponse.success() - } + return ApiResponse.success() + } - @PutMapping("/{cakeShopId}/operation-days") - fun updateOperationDays( - @PathVariable cakeShopId: Long, - @RequestBody @Valid request: ShopOperationUpdateByAdminRequest - ): ApiResponse { - shopService.updateShopOperationDays(request.toParam(cakeShopId)) + @PutMapping("/{cakeShopId}/operation-days") + fun updateOperationDays( + @PathVariable cakeShopId: Long, + @RequestBody @Valid request: ShopOperationUpdateByAdminRequest, + @AdminUser admin: User + ): ApiResponse { + val param = supplyUpdateShopOperationParamBy(request, admin, cakeShopId) + shopService.updateShopOperationDays(param) - return ApiResponse.success() - } + return ApiResponse.success() + } - @PutMapping("/{cakeShopId}/address") - fun updateAddress( - @PathVariable cakeShopId: Long, - @RequestBody @Valid request: AddressUpdateByAdminRequest - ): ApiResponse { - shopService.updateShopAddress(request.toParam(cakeShopId)) + @PutMapping("/{cakeShopId}/address") + fun updateAddress( + @PathVariable cakeShopId: Long, + @RequestBody @Valid request: AddressUpdateByAdminRequest, + @AdminUser admin: User + ): ApiResponse { + val param = supplyUpdateShopAddressParamBy(request, admin, cakeShopId) + shopService.updateShopAddress(param) - return ApiResponse.success() - } + return ApiResponse.success() + } } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeCreateByAdminParam.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeCreateByAdminParam.kt deleted file mode 100644 index 9278a135..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeCreateByAdminParam.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.cakk.admin.dto.param - -import com.cakk.domain.mysql.entity.cake.Cake -import com.cakk.domain.mysql.entity.cake.CakeCategory - -data class CakeCreateByAdminParam( - val cake: Cake, - val cakeCategories: List, - val tagNames: List, - val cakeShopId: Long -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeShopCreateByAdminParam.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeShopCreateByAdminParam.kt deleted file mode 100644 index 717c1dff..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeShopCreateByAdminParam.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.cakk.admin.dto.param - -import com.cakk.domain.mysql.entity.shop.CakeShop -import com.cakk.domain.mysql.entity.shop.CakeShopLink -import com.cakk.domain.mysql.entity.shop.CakeShopOperation -import com.cakk.domain.mysql.entity.user.BusinessInformation - -data class CakeShopCreateByAdminParam( - val cakeShop: CakeShop, - val businessInformation: BusinessInformation, - val cakeShopOperations: List, - val cakeShopLinks: List -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeUpdateByAdminParam.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeUpdateByAdminParam.kt deleted file mode 100644 index 88029662..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/CakeUpdateByAdminParam.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.cakk.admin.dto.param - -import com.cakk.domain.mysql.entity.cake.CakeCategory - -data class CakeUpdateByAdminParam( - val cakeId: Long, - val cakeImageUrl: String, - val cakeCategories: List, - val tagNames: List -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/OwnerCandidateParam.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/OwnerCandidateParam.kt deleted file mode 100644 index e6aef324..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/OwnerCandidateParam.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.cakk.admin.dto.param - -import java.time.LocalDateTime - -data class OwnerCandidateParam( - val userId: Long, - val nickname: String, - val profileImageUrl: String, - val email: String, - val timestamp: LocalDateTime -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/ShopLinkParam.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/ShopLinkParam.kt deleted file mode 100644 index 03951175..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/param/ShopLinkParam.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.cakk.admin.dto.param - -import com.cakk.common.enums.LinkKind -import jakarta.validation.constraints.NotBlank -import jakarta.validation.constraints.Size - -data class ShopLinkParam( - @field:NotBlank - val linkKind: LinkKind, - @field:NotBlank @field:Size(min = 1, max = 200) - val linkPath: String -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/AddressUpdateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/AddressUpdateByAdminRequest.kt index 01fdbede..eff22e6e 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/AddressUpdateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/AddressUpdateByAdminRequest.kt @@ -1,7 +1,5 @@ package com.cakk.admin.dto.request -import com.cakk.admin.mapper.supplyPointBy -import com.cakk.domain.mysql.dto.param.shop.UpdateShopAddressParam import jakarta.validation.constraints.Max import jakarta.validation.constraints.Min import jakarta.validation.constraints.NotBlank @@ -9,19 +7,10 @@ import jakarta.validation.constraints.NotNull import jakarta.validation.constraints.Size data class AddressUpdateByAdminRequest( - @field:NotBlank @field:Size(max = 50) - val shopAddress: String?, - @field:NotNull @field:Min(-90) @field:Max(90) - val latitude: Double?, - @field:NotNull @field:Min(-180) @field:Max(180) - val longitude: Double? -) { - - fun toParam(cakeShopId: Long): UpdateShopAddressParam { - return UpdateShopAddressParam.builder() - .cakeShopId(cakeShopId) - .shopAddress(shopAddress) - .location(supplyPointBy(latitude, longitude)) - .build() - } -} + @field:NotBlank @field:Size(max = 50) + val shopAddress: String?, + @field:NotNull @field:Min(-90) @field:Max(90) + val latitude: Double?, + @field:NotNull @field:Min(-180) @field:Max(180) + val longitude: Double? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeCreateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeCreateByAdminRequest.kt index 6c9fca87..09e2067f 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeCreateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeCreateByAdminRequest.kt @@ -1,28 +1,16 @@ package com.cakk.admin.dto.request -import com.cakk.admin.dto.param.CakeCreateByAdminParam -import com.cakk.admin.mapper.supplyCakeBy -import com.cakk.admin.mapper.supplyCakeCategoryListBy -import com.cakk.common.enums.CakeDesignCategory import jakarta.validation.constraints.NotBlank -import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.NotEmpty import jakarta.validation.constraints.Size -data class CakeCreateByAdminRequest( - @field:NotBlank @field:Size(max = 100) - val cakeImageUrl: String, - @field:NotNull - val cakeDesignCategories: List, - @field:NotNull - val tagNames: List -) { +import com.cakk.common.enums.CakeDesignCategory - fun toParam(cakeShopId: Long): CakeCreateByAdminParam { - return CakeCreateByAdminParam( - cake = supplyCakeBy(cakeImageUrl), - cakeCategories = supplyCakeCategoryListBy(cakeDesignCategories), - tagNames = tagNames, - cakeShopId = cakeShopId - ) - } -} +data class CakeCreateByAdminRequest( + @field:NotBlank @field:Size(max = 100) + val cakeImageUrl: String?, + @field:NotEmpty + val cakeDesignCategories: List?, + @field:NotEmpty + val tagNames: List? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopCreateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopCreateByAdminRequest.kt index 4b527014..546cae8e 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopCreateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopCreateByAdminRequest.kt @@ -1,49 +1,32 @@ package com.cakk.admin.dto.request -import com.cakk.admin.annotation.OperationDay -import com.cakk.admin.dto.param.CakeShopCreateByAdminParam -import com.cakk.admin.dto.param.ShopLinkParam -import com.cakk.admin.mapper.supplyBusinessInformationBy -import com.cakk.admin.mapper.supplyCakeShopBy -import com.cakk.admin.mapper.supplyCakeShopLinksBy -import com.cakk.admin.mapper.supplyCakeShopOperationsBy -import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam -import com.cakk.domain.mysql.entity.shop.CakeShop import jakarta.validation.constraints.Max import jakarta.validation.constraints.Min import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull import jakarta.validation.constraints.Size -data class CakeShopCreateByAdminRequest( - @field:Size(max = 20) - val businessNumber: String, - @field:OperationDay - val operationDays: List, - @field:NotBlank @field:Size(max = 30) - val shopName: String, - @field:Size(max = 40) - val shopBio: String, - @field:Size(max = 500) - val shopDescription: String, - @field:NotBlank @field:Size(max = 50) - val shopAddress: String, - @field:NotNull @field:Min(-90) @field:Max(90) - val latitude: Double, - @field:NotNull @field:Min(-180) @field:Max(180) - val longitude: Double, - @field:NotNull - val links: List -) { - - fun toParam(): CakeShopCreateByAdminParam { - val cakeShop: CakeShop = supplyCakeShopBy(this) +import com.cakk.admin.annotation.OperationDay +import com.cakk.core.dto.param.shop.ShopLinkParam +import com.cakk.core.dto.param.shop.ShopOperationParam - return CakeShopCreateByAdminParam( - cakeShop = cakeShop, - businessInformation = supplyBusinessInformationBy(businessNumber, cakeShop), - cakeShopOperations = supplyCakeShopOperationsBy(cakeShop, operationDays), - cakeShopLinks = supplyCakeShopLinksBy(cakeShop, links) - ) - } -} +data class CakeShopCreateByAdminRequest( + @field:Size(max = 20) + val businessNumber: String?, + @field:OperationDay + val operationDays: List?, + @field:NotBlank @field:Size(max = 30) + val shopName: String?, + @field:Size(max = 40) + val shopBio: String?, + @field:Size(max = 500) + val shopDescription: String?, + @field:NotBlank @field:Size(max = 50) + val shopAddress: String?, + @field:NotNull @field:Min(-90) @field:Max(90) + val latitude: Double?, + @field:NotNull @field:Min(-180) @field:Max(180) + val longitude: Double?, + @field:NotNull + val links: List? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopUpdateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopUpdateByAdminRequest.kt index 0c4ca55b..4290b6eb 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopUpdateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeShopUpdateByAdminRequest.kt @@ -1,27 +1,15 @@ package com.cakk.admin.dto.request -import com.cakk.domain.mysql.dto.param.shop.CakeShopUpdateParam import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.Size data class CakeShopUpdateByAdminRequest( - @field:Size(max = 200) - val thumbnailUrl: String?, - @field:NotBlank @Size(max = 30) - val shopName: String, - @field:Size(max = 40) - val shopBio: String?, - @field:Size(max = 500) - val shopDescription: String? -) { - - fun toParam(cakeShopId: Long): CakeShopUpdateParam { - return CakeShopUpdateParam.builder() - .cakeShopId(cakeShopId) - .thumbnailUrl(thumbnailUrl) - .shopName(shopName) - .shopBio(shopBio) - .shopDescription(shopDescription) - .build() - } -} + @field:Size(max = 200) + val thumbnailUrl: String?, + @field:NotBlank @Size(max = 30) + val shopName: String?, + @field:Size(max = 40) + val shopBio: String?, + @field:Size(max = 500) + val shopDescription: String? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeUpdateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeUpdateByAdminRequest.kt index cf96f9f4..84bf3dae 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeUpdateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/CakeUpdateByAdminRequest.kt @@ -1,27 +1,15 @@ package com.cakk.admin.dto.request -import com.cakk.admin.dto.param.CakeUpdateByAdminParam -import com.cakk.admin.mapper.supplyCakeCategoryListBy import com.cakk.common.enums.CakeDesignCategory import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull import jakarta.validation.constraints.Size data class CakeUpdateByAdminRequest( - @field:NotBlank @field:Size(max = 200) - val cakeImageUrl: String, - @field:NotNull - val cakeDesignCategories: List, - @field:NotNull - val tagNames: List -) { - - fun toParam(cakeId: Long): CakeUpdateByAdminParam { - return CakeUpdateByAdminParam( - cakeId = cakeId, - cakeImageUrl = cakeImageUrl, - cakeCategories = supplyCakeCategoryListBy(cakeDesignCategories), - tagNames = tagNames - ) - } -} + @field:NotBlank @field:Size(max = 200) + val cakeImageUrl: String?, + @field:NotNull + val cakeDesignCategories: List?, + @field:NotNull + val tagNames: List? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/LinkUpdateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/LinkUpdateByAdminRequest.kt index 39ed9c08..ff265c5f 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/LinkUpdateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/LinkUpdateByAdminRequest.kt @@ -1,31 +1,12 @@ package com.cakk.admin.dto.request -import com.cakk.admin.mapper.supplyCakeShopLinkByInstagram -import com.cakk.admin.mapper.supplyCakeShopLinkByKakao -import com.cakk.admin.mapper.supplyCakeShopLinkByWeb -import com.cakk.domain.mysql.dto.param.link.UpdateLinkParam -import com.cakk.domain.mysql.entity.shop.CakeShopLink import jakarta.validation.constraints.Size data class LinkUpdateByAdminRequest( - @field:Size(min = 1, max = 200) - val instagram: String?, - @field:Size(min = 1, max = 200) - val kakao: String?, - @field:Size(min = 1, max = 200) - val web: String? -) { - - fun toParam(cakeShopId: Long): UpdateLinkParam { - val cakeShopLinks = mutableListOf() - - instagram?.let { cakeShopLinks.add(supplyCakeShopLinkByInstagram(it)) } - kakao?.let { cakeShopLinks.add(supplyCakeShopLinkByKakao(it)) } - web?.let { cakeShopLinks.add(supplyCakeShopLinkByWeb(it)) } - - return UpdateLinkParam.builder() - .cakeShopId(cakeShopId) - .cakeShopLinks(cakeShopLinks) - .build() - } -} + @field:Size(min = 1, max = 200) + val instagram: String?, + @field:Size(min = 1, max = 200) + val kakao: String?, + @field:Size(min = 1, max = 200) + val web: String? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/PromotionRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/PromotionRequest.kt index 990d4aa8..fcfe2801 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/PromotionRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/PromotionRequest.kt @@ -3,8 +3,8 @@ package com.cakk.admin.dto.request import jakarta.validation.constraints.NotNull data class PromotionRequest( - @field:NotNull - val userId: Long, - @field:NotNull - val cakeShopId: Long + @field:NotNull + val userId: Long?, + @field:NotNull + val cakeShopId: Long? ) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/ShopOperationUpdateByAdminRequest.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/ShopOperationUpdateByAdminRequest.kt index d36c25bd..ed55d3ce 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/ShopOperationUpdateByAdminRequest.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/request/ShopOperationUpdateByAdminRequest.kt @@ -1,19 +1,10 @@ package com.cakk.admin.dto.request -import com.cakk.admin.mapper.supplyCakeShopOperationListBy -import com.cakk.domain.mysql.dto.param.operation.UpdateShopOperationParam -import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam import jakarta.validation.constraints.NotNull -data class ShopOperationUpdateByAdminRequest( - @field:NotNull - val operationDays: List -) { +import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam - fun toParam(cakeShopId: Long): UpdateShopOperationParam { - return UpdateShopOperationParam.builder() - .cakeShopId(cakeShopId) - .cakeShopOperations(supplyCakeShopOperationListBy(operationDays)) - .build() - } -} +data class ShopOperationUpdateByAdminRequest( + @field:NotNull + val operationDays: List? +) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopCreateResponse.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopCreateResponse.kt deleted file mode 100644 index 180cfcf4..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopCreateResponse.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.cakk.admin.dto.response - -data class CakeShopCreateResponse( - val cakeShopId: Long -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopOwnerCandidateResponse.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopOwnerCandidateResponse.kt deleted file mode 100644 index 94991674..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopOwnerCandidateResponse.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.cakk.admin.dto.response - -data class CakeShopOwnerCandidateResponse( - val userId: Long, - val cakeShopId: Long, - val email: String, - val businessRegistrationImageUrl: String, - val idCardImageUrl: String, - val emergencyContact: String -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopOwnerCandidatesResponse.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopOwnerCandidatesResponse.kt deleted file mode 100644 index ba9d0cd0..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/CakeShopOwnerCandidatesResponse.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.cakk.admin.dto.response - -import com.cakk.admin.dto.param.OwnerCandidateParam - -data class CakeShopOwnerCandidatesResponse( - val candidates: List -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/TagResponse.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/TagResponse.kt deleted file mode 100644 index 959f6328..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/dto/response/TagResponse.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.cakk.admin.dto.response - -data class TagResponse( - val tagId: Long, - val tagName: String -) diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/BusinessInformationMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/BusinessInformationMapper.kt deleted file mode 100644 index 0549ea5e..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/BusinessInformationMapper.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.cakk.admin.mapper - -import com.cakk.admin.dto.param.OwnerCandidateParam -import com.cakk.admin.dto.response.CakeShopOwnerCandidateResponse -import com.cakk.admin.dto.response.CakeShopOwnerCandidatesResponse -import com.cakk.domain.mysql.entity.shop.CakeShop -import com.cakk.domain.mysql.entity.user.BusinessInformation - -fun supplyCakeShopOwnerCandidatesResponseBy(businessInformationList: List): CakeShopOwnerCandidatesResponse { - val candidates: List = businessInformationList - .map { businessInformation: BusinessInformation -> - OwnerCandidateParam( - userId = businessInformation.user.id, - nickname = businessInformation.user.nickname, - profileImageUrl = businessInformation.user.profileImageUrl, - email = businessInformation.user.email, - timestamp = businessInformation.updatedAt - ) - }.toList() - - return CakeShopOwnerCandidatesResponse(candidates) -} - -fun supplyCakeShopOwnerCandidateResponseBy(businessInformation: BusinessInformation): CakeShopOwnerCandidateResponse { - return CakeShopOwnerCandidateResponse( - userId = businessInformation.user.id, - cakeShopId = businessInformation.cakeShop.id, - email = businessInformation.user.email, - businessRegistrationImageUrl = businessInformation.businessRegistrationImageUrl, - idCardImageUrl = businessInformation.idCardImageUrl, - emergencyContact = businessInformation.emergencyContact - ) -} - -fun supplyBusinessInformationBy(businessNumber: String, cakeShop: CakeShop): BusinessInformation { - return BusinessInformation.builder() - .businessNumber(businessNumber) - .cakeShop(cakeShop) - .build() -} diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeDesignCategoryMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeDesignCategoryMapper.kt index 330e9f2b..cbda8889 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeDesignCategoryMapper.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeDesignCategoryMapper.kt @@ -4,11 +4,11 @@ import com.cakk.common.enums.CakeDesignCategory import com.cakk.domain.mysql.entity.cake.CakeCategory fun supplyCakeCategoryListBy(cakeDesignCategories: List): List { - return cakeDesignCategories.map { supplyCakeCategoryBy(it) }.toList() + return cakeDesignCategories.map { supplyCakeCategoryBy(it) }.toList() } -fun supplyCakeCategoryBy(cakeDesignCategory: CakeDesignCategory?): CakeCategory { - return CakeCategory.builder() - .cakeDesignCategory(cakeDesignCategory) - .build() +private fun supplyCakeCategoryBy(cakeDesignCategory: CakeDesignCategory?): CakeCategory { + return CakeCategory.builder() + .cakeDesignCategory(cakeDesignCategory) + .build() } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeMapper.kt index d571979e..4f735a5a 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeMapper.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/CakeMapper.kt @@ -1,9 +1,28 @@ package com.cakk.admin.mapper -import com.cakk.domain.mysql.entity.cake.Cake +import com.cakk.admin.dto.request.CakeCreateByAdminRequest +import com.cakk.admin.dto.request.CakeUpdateByAdminRequest +import com.cakk.core.dto.param.cake.CakeCreateParam +import com.cakk.core.dto.param.cake.CakeUpdateParam +import com.cakk.core.mapper.supplyCakeBy +import com.cakk.domain.mysql.entity.user.User -fun supplyCakeBy(cakeImageUrl: String): Cake { - return Cake.builder() - .cakeImageUrl(cakeImageUrl) - .build() +fun supplyCakeCreateParamBy(dto: CakeCreateByAdminRequest, user: User, cakeShopId: Long): CakeCreateParam { + return CakeCreateParam( + cake = supplyCakeBy(dto.cakeImageUrl!!), + cakeCategories = supplyCakeCategoryListBy(dto.cakeDesignCategories!!), + tagNames = dto.tagNames!!, + owner = user, + cakeShopId = cakeShopId + ) +} + +fun supplyCakeUpdateParamBy(dto: CakeUpdateByAdminRequest, owner: User, cakeId: Long): CakeUpdateParam { + return CakeUpdateParam( + owner = owner, + cakeId = cakeId, + cakeImageUrl = dto.cakeImageUrl!!, + cakeCategories = supplyCakeCategoryListBy(dto.cakeDesignCategories!!), + tagNames = dto.tagNames!! + ) } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/LinkMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/LinkMapper.kt index 33238fba..42026cc8 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/LinkMapper.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/LinkMapper.kt @@ -1,40 +1,29 @@ package com.cakk.admin.mapper -import com.cakk.admin.dto.param.ShopLinkParam import com.cakk.common.enums.LinkKind import com.cakk.domain.mysql.entity.shop.CakeShop import com.cakk.domain.mysql.entity.shop.CakeShopLink -fun supplyCakeShopLinksBy(cakeShop: CakeShop, links: List): List { - return links.map { - when (it.linkKind) { - LinkKind.WEB -> supplyCakeShopLinkByWeb(it.linkPath, cakeShop) - LinkKind.INSTAGRAM -> supplyCakeShopLinkByInstagram(it.linkPath, cakeShop) - LinkKind.KAKAOTALK -> supplyCakeShopLinkByKakao(it.linkPath, cakeShop) - } - }.toList() -} - fun supplyCakeShopLinkByWeb(web: String, cakeShop: CakeShop? = null): CakeShopLink { - return CakeShopLink.builder() - .linkKind(LinkKind.WEB) - .linkPath(web) - .cakeShop(cakeShop) - .build() + return CakeShopLink.builder() + .linkKind(LinkKind.WEB) + .linkPath(web) + .cakeShop(cakeShop) + .build() } fun supplyCakeShopLinkByInstagram(instagram: String, cakeShop: CakeShop? = null): CakeShopLink { - return CakeShopLink.builder() - .linkKind(LinkKind.INSTAGRAM) - .linkPath(instagram) - .cakeShop(cakeShop) - .build() + return CakeShopLink.builder() + .linkKind(LinkKind.INSTAGRAM) + .linkPath(instagram) + .cakeShop(cakeShop) + .build() } fun supplyCakeShopLinkByKakao(kakao: String, cakeShop: CakeShop? = null): CakeShopLink { - return CakeShopLink.builder() - .linkKind(LinkKind.KAKAOTALK) - .linkPath(kakao) - .cakeShop(cakeShop) - .build() + return CakeShopLink.builder() + .linkKind(LinkKind.KAKAOTALK) + .linkPath(kakao) + .cakeShop(cakeShop) + .build() } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/PointMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/PointMapper.kt deleted file mode 100644 index 55043853..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/PointMapper.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.cakk.admin.mapper - -import com.cakk.common.enums.ReturnCode -import com.cakk.common.exception.CakkException -import org.locationtech.jts.geom.Coordinate -import org.locationtech.jts.geom.GeometryFactory -import org.locationtech.jts.geom.Point -import org.locationtech.jts.geom.PrecisionModel -import java.util.* - -private const val SPATIAL_REFERENCE_IDENTIFIER_NUMBER = 4326 - -private val geometryFactory = GeometryFactory(PrecisionModel(), SPATIAL_REFERENCE_IDENTIFIER_NUMBER) - -fun supplyPointBy(latitude: Double?, longitude: Double?): Point { - if (Objects.isNull(latitude) || Objects.isNull(longitude)) { - throw CakkException(ReturnCode.WRONG_PARAMETER) - } - return geometryFactory.createPoint(Coordinate(longitude!!, latitude!!)) -} diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopMapper.kt index 54f6112c..78706a0b 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopMapper.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopMapper.kt @@ -1,41 +1,87 @@ package com.cakk.admin.mapper -import com.cakk.admin.dto.request.CakeShopCreateByAdminRequest -import com.cakk.admin.dto.response.CakeShopCreateResponse -import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam -import com.cakk.domain.mysql.entity.shop.CakeShop -import com.cakk.domain.mysql.entity.shop.CakeShopOperation - -fun supplyCakeShopBy(dto: CakeShopCreateByAdminRequest): CakeShop { - return CakeShop.builder() - .shopName(dto.shopName) - .shopBio(dto.shopBio) - .shopDescription(dto.shopDescription) - .shopAddress(dto.shopAddress) - .location(supplyPointBy(dto.latitude, dto.longitude)) - .build() +import java.util.ArrayList + +import com.cakk.admin.dto.request.* +import com.cakk.core.dto.param.shop.CreateShopParam +import com.cakk.core.dto.param.shop.PromotionParam +import com.cakk.core.mapper.supplyPointBy +import com.cakk.domain.mysql.dto.param.link.UpdateLinkParam +import com.cakk.domain.mysql.dto.param.operation.UpdateShopOperationParam +import com.cakk.domain.mysql.dto.param.shop.CakeShopUpdateParam +import com.cakk.domain.mysql.dto.param.shop.UpdateShopAddressParam +import com.cakk.domain.mysql.entity.shop.CakeShopLink +import com.cakk.domain.mysql.entity.user.User + +fun supplyCreateShopParamBy(request: CakeShopCreateByAdminRequest): CreateShopParam { + return CreateShopParam( + businessNumber = request.businessNumber, + operationDays = request.operationDays!!, + shopName = request.shopName!!, + shopBio = request.shopBio, + shopDescription = request.shopDescription, + shopAddress = request.shopAddress!!, + latitude = request.latitude!!, + longitude = request.longitude!!, + links = request.links!! + ) +} + +fun supplyCakeShopUpdateParamBy( + request: CakeShopUpdateByAdminRequest, + user: User, + cakeShopId: Long +): CakeShopUpdateParam { + return CakeShopUpdateParam.builder() + .user(user) + .cakeShopId(cakeShopId) + .thumbnailUrl(request.thumbnailUrl) + .shopName(request.shopName) + .shopBio(request.shopBio) + .shopDescription(request.shopDescription) + .build() +} + +fun supplyUpdateLinkParamBy( + dto: LinkUpdateByAdminRequest, + user: User, + cakeShopId: Long +): UpdateLinkParam { + val cakeShopLinks: MutableList = ArrayList() + + dto.instagram?.let { cakeShopLinks.add(supplyCakeShopLinkByInstagram(dto.instagram)) } + dto.kakao?.let { cakeShopLinks.add(supplyCakeShopLinkByKakao(dto.kakao)) } + dto.web?.let { cakeShopLinks.add(supplyCakeShopLinkByWeb(dto.web)) } + + return UpdateLinkParam(user, cakeShopId, cakeShopLinks) +} + +fun supplyUpdateShopOperationParamBy( + request: ShopOperationUpdateByAdminRequest, + user: User, + cakeShopId: Long +): UpdateShopOperationParam { + val cakeShopOperations = supplyCakeShopOperationListBy(request.operationDays!!) + + return UpdateShopOperationParam(cakeShopOperations, user, cakeShopId) } -fun supplyCakeShopOperationsBy( - cakeShop: CakeShop?, - operationDays: List -): List { - val cakeShopOperations = mutableListOf() - - operationDays.forEach { - cakeShopOperations.add( - CakeShopOperation.builder() - .operationDay(it.operationDay) - .operationStartTime(it.operationStartTime) - .operationEndTime(it.operationEndTime) - .cakeShop(cakeShop) - .build() - ) - } - - return cakeShopOperations +fun supplyUpdateShopAddressParamBy( + dto: AddressUpdateByAdminRequest, + user: User, + cakeShopId: Long +): UpdateShopAddressParam { + return UpdateShopAddressParam( + dto.shopAddress!!, + supplyPointBy(dto.latitude!!, dto.longitude!!), + user, + cakeShopId + ) } -fun supplyCakeShopCreateResponseBy(cakeShop: CakeShop): CakeShopCreateResponse { - return CakeShopCreateResponse(cakeShop.id) +fun supplyPromotionParamBy(request: PromotionRequest): PromotionParam { + return PromotionParam( + userId = request.userId!!, + cakeShopId = request.cakeShopId!! + ) } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopOperationMapper.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopOperationMapper.kt index 089ef73f..0b88c1bb 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopOperationMapper.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/mapper/ShopOperationMapper.kt @@ -4,15 +4,15 @@ import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam import com.cakk.domain.mysql.entity.shop.CakeShopOperation fun supplyCakeShopOperationListBy(operationDays: List): List { - return operationDays - .map { supplyCakeShopOperationBy(it) } - .toList() + return operationDays + .map { supplyCakeShopOperationBy(it) } + .toList() } fun supplyCakeShopOperationBy(param: ShopOperationParam): CakeShopOperation { - return CakeShopOperation.builder() - .operationDay(param.operationDay) - .operationStartTime(param.operationStartTime) - .operationEndTime(param.operationEndTime) - .build() + return CakeShopOperation.builder() + .operationDay(param.operationDay) + .operationStartTime(param.operationStartTime) + .operationEndTime(param.operationEndTime) + .build() } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/resolver/AdminUserResolver.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/resolver/AdminUserResolver.kt new file mode 100644 index 00000000..24cfe7a0 --- /dev/null +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/resolver/AdminUserResolver.kt @@ -0,0 +1,31 @@ +package com.cakk.admin.resolver + +import org.springframework.core.MethodParameter +import org.springframework.security.core.context.SecurityContextHolder +import org.springframework.web.bind.support.WebDataBinderFactory +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.web.method.support.HandlerMethodArgumentResolver +import org.springframework.web.method.support.ModelAndViewContainer + +import com.cakk.admin.annotation.AdminUser +import com.cakk.admin.vo.OAuthUserDetails + +import com.cakk.domain.mysql.entity.user.User + +class AdminUserResolver : HandlerMethodArgumentResolver { + override fun supportsParameter(parameter: MethodParameter): Boolean { + return parameter.hasParameterAnnotation(AdminUser::class.java) + && User::class.java.isAssignableFrom(parameter.parameterType) + } + + override fun resolveArgument( + parameter: MethodParameter, + mavContainer: ModelAndViewContainer?, + webRequest: NativeWebRequest, + binderFactory: WebDataBinderFactory? + ): Any { + val userDetails = SecurityContextHolder.getContext().authentication.principal as OAuthUserDetails + + return userDetails.getUser() + } +} diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/service/BusinessInformationService.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/service/BusinessInformationService.kt deleted file mode 100644 index 4a5aa868..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/service/BusinessInformationService.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.cakk.admin.service - -import com.cakk.admin.dto.request.PromotionRequest -import com.cakk.admin.dto.response.CakeShopOwnerCandidateResponse -import com.cakk.admin.dto.response.CakeShopOwnerCandidatesResponse -import com.cakk.admin.mapper.* -import com.cakk.core.facade.cake.BusinessInformationReadFacade -import com.cakk.core.facade.cake.CakeShopReadFacade -import com.cakk.core.facade.user.UserReadFacade -import com.cakk.domain.mysql.bo.user.VerificationPolicy -import com.cakk.domain.mysql.entity.user.BusinessInformation -import com.cakk.domain.mysql.entity.user.User -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional - -@Service -class BusinessInformationService( - private val businessInformationReadFacade: BusinessInformationReadFacade, - private val userReadFacade: UserReadFacade, - private val cakeShopReadFacade: CakeShopReadFacade, - private val verificationPolicy: VerificationPolicy, -) { - - @Transactional - fun promoteUserToBusinessOwner(dto: PromotionRequest) { - val user: User = userReadFacade.findByUserId(dto.userId) - val businessInformation: BusinessInformation = cakeShopReadFacade.findBusinessInformationWithShop(dto.cakeShopId) - - businessInformation.updateBusinessOwner(verificationPolicy, user) - } - - @Transactional(readOnly = true) - fun getBusinessOwnerCandidates(): CakeShopOwnerCandidatesResponse { - var businessInformationList = businessInformationReadFacade.findAllCakeShopBusinessOwnerCandidates() - - businessInformationList = businessInformationList - .filter { it.isBusinessOwnerCandidate(verificationPolicy) } - .toList() - - return supplyCakeShopOwnerCandidatesResponseBy(businessInformationList) - } - - @Transactional(readOnly = true) - fun getCandidateInformation(userId: Long): CakeShopOwnerCandidateResponse { - val businessInformation = businessInformationReadFacade.findByUserId(userId) - - return supplyCakeShopOwnerCandidateResponseBy(businessInformation) - } -} diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/service/CakeService.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/service/CakeService.kt deleted file mode 100644 index e45fe772..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/service/CakeService.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.cakk.admin.service - -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional - -import com.cakk.admin.dto.param.CakeCreateByAdminParam -import com.cakk.admin.dto.param.CakeUpdateByAdminParam -import com.cakk.core.facade.cake.CakeManageFacade -import com.cakk.core.facade.cake.CakeReadFacade -import com.cakk.core.facade.cake.CakeShopReadFacade -import com.cakk.core.facade.tag.TagManageFacade - -@Service -class CakeService( - private val cakeReadFacade: CakeReadFacade, - private val cakeShopReadFacade: CakeShopReadFacade, - private val tagManageFacade: TagManageFacade, - private val cakeManageFacade: CakeManageFacade -) { - - @Transactional - fun createCake(dto: CakeCreateByAdminParam) { - val cakeShop = cakeShopReadFacade.findById(dto.cakeShopId) - val cake = dto.cake - val tags = dto.tagNames.map { tagManageFacade.create(it) }.toMutableList() - - cakeManageFacade.create(cakeShop, cake, tags, dto.cakeCategories) - } - - @Transactional - fun updateCake(dto: CakeUpdateByAdminParam) { - val cake = cakeReadFacade.findById(dto.cakeId) - val tags = dto.tagNames.map { tagManageFacade.create(it) }.toMutableList() - - cakeManageFacade.update(cake, dto.cakeImageUrl, tags, dto.cakeCategories) - } - - @Transactional - fun deleteCake(cakeId: Long) { - val cake = cakeReadFacade.findById(cakeId) - - cakeManageFacade.delete(cake) - } -} diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/service/ShopService.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/service/ShopService.kt deleted file mode 100644 index 9e12ec4d..00000000 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/service/ShopService.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.cakk.admin.service - -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional - -import com.cakk.admin.dto.param.CakeShopCreateByAdminParam -import com.cakk.admin.dto.response.CakeShopCreateResponse -import com.cakk.admin.mapper.supplyCakeShopCreateResponseBy -import com.cakk.core.facade.cake.CakeShopReadFacade -import com.cakk.core.facade.shop.CakeShopManageFacade -import com.cakk.domain.mysql.dto.param.link.UpdateLinkParam -import com.cakk.domain.mysql.dto.param.operation.UpdateShopOperationParam -import com.cakk.domain.mysql.dto.param.shop.CakeShopUpdateParam -import com.cakk.domain.mysql.dto.param.shop.UpdateShopAddressParam -import com.cakk.domain.mysql.entity.shop.CakeShop - -@Service -class ShopService( - private val cakeShopReadFacade: CakeShopReadFacade, - private val cakeShopManageFacade: CakeShopManageFacade -) { - - @Transactional - fun createCakeShopByCertification(dto: CakeShopCreateByAdminParam): CakeShopCreateResponse { - val result: CakeShop = cakeShopManageFacade.create( - dto.cakeShop, - dto.cakeShopOperations, - dto.businessInformation, - dto.cakeShopLinks - ) - - return supplyCakeShopCreateResponseBy(result) - } - - @Transactional - fun updateBasicInformation(dto: CakeShopUpdateParam) { - val cakeShop = cakeShopReadFacade.findById(dto.cakeShopId) - cakeShop.updateBasicInformation(dto) - } - - @Transactional - fun updateShopLinks(param: UpdateLinkParam) { - val cakeShop = cakeShopReadFacade.findById(param.cakeShopId) - cakeShop.updateShopLinks(param.cakeShopLinks) - } - - @Transactional - fun updateShopOperationDays(param: UpdateShopOperationParam) { - val cakeShop = cakeShopReadFacade.findById(param.cakeShopId) - cakeShop.updateShopOperationDays(param.cakeShopOperations) - } - - @Transactional - fun updateShopAddress(param: UpdateShopAddressParam) { - val cakeShop = cakeShopReadFacade.findById(param.cakeShopId) - cakeShop.updateShopAddress(param) - } -} diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/validator/OperationValidator.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/validator/OperationValidator.kt index 18f43e44..a7f5c452 100644 --- a/cakk-admin/src/main/kotlin/com/cakk/admin/validator/OperationValidator.kt +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/validator/OperationValidator.kt @@ -1,25 +1,27 @@ package com.cakk.admin.validator +import java.util.* + +import jakarta.validation.ConstraintValidator +import jakarta.validation.ConstraintValidatorContext + import com.cakk.admin.annotation.OperationDay import com.cakk.common.enums.Days import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam -import jakarta.validation.ConstraintValidator -import jakarta.validation.ConstraintValidatorContext -import java.util.* class OperationValidator : ConstraintValidator> { - override fun isValid(operationParams: List?, context: ConstraintValidatorContext): Boolean { - operationParams ?: return false + override fun isValid(operationParams: List?, context: ConstraintValidatorContext): Boolean { + operationParams ?: return false - val days: MutableMap = EnumMap(Days::class.java) - for (operationParam in operationParams) { - if (days.containsKey(operationParam.operationDay)) { - return false - } else { - days[operationParam.operationDay] = true - } - } - return true - } + val days: MutableMap = EnumMap(Days::class.java) + for (operationParam in operationParams) { + if (days.containsKey(operationParam.operationDay)) { + return false + } else { + days[operationParam.operationDay] = true + } + } + return true + } } diff --git a/cakk-admin/src/main/kotlin/com/cakk/admin/vo/OAuthUserDetails.kt b/cakk-admin/src/main/kotlin/com/cakk/admin/vo/OAuthUserDetails.kt new file mode 100644 index 00000000..dacb5dc3 --- /dev/null +++ b/cakk-admin/src/main/kotlin/com/cakk/admin/vo/OAuthUserDetails.kt @@ -0,0 +1,69 @@ +package com.cakk.admin.vo + +import org.springframework.security.core.GrantedAuthority +import org.springframework.security.core.authority.SimpleGrantedAuthority +import org.springframework.security.core.userdetails.UserDetails +import org.springframework.security.oauth2.core.oidc.OidcIdToken +import org.springframework.security.oauth2.core.oidc.OidcUserInfo +import org.springframework.security.oauth2.core.oidc.user.OidcUser +import org.springframework.security.oauth2.core.user.OAuth2User + +import com.cakk.domain.mysql.entity.user.User + +class OAuthUserDetails( + private val user: User, + private val attribute: Map +) : UserDetails, OidcUser, OAuth2User { + + constructor(user: User) : this(user, mapOf("id" to user.id)) + + fun getUser(): User = user + + override fun getName(): String { + return user.id.toString() + } + + override fun getAttributes(): Map { + return attribute + } + + override fun getAuthorities(): Collection { + return listOf(SimpleGrantedAuthority(user.role.securityRole)) + } + + override fun getPassword(): String { + return "password" + } + + override fun getUsername(): String { + return user.id.toString() + } + + override fun isAccountNonExpired(): Boolean { + return true + } + + override fun isAccountNonLocked(): Boolean { + return true + } + + override fun isCredentialsNonExpired(): Boolean { + return true + } + + override fun isEnabled(): Boolean { + return true + } + + override fun getClaims(): Map? { + return null + } + + override fun getUserInfo(): OidcUserInfo? { + return null + } + + override fun getIdToken(): OidcIdToken? { + return null + } +} diff --git a/cakk-api/src/main/kotlin/com/cakk/api/mapper/ShopMapper.kt b/cakk-api/src/main/kotlin/com/cakk/api/mapper/ShopMapper.kt index 74d8423d..947d1d29 100644 --- a/cakk-api/src/main/kotlin/com/cakk/api/mapper/ShopMapper.kt +++ b/cakk-api/src/main/kotlin/com/cakk/api/mapper/ShopMapper.kt @@ -11,9 +11,7 @@ import com.cakk.api.dto.request.shop.UpdateShopRequest import com.cakk.api.dto.request.user.CertificationRequest import com.cakk.core.dto.param.shop.CreateShopParam import com.cakk.core.dto.param.shop.PromotionParam -import com.cakk.core.mapper.supplyCakeShopLinkByInstagram -import com.cakk.core.mapper.supplyCakeShopOperationListBy -import com.cakk.core.mapper.supplyPointBy +import com.cakk.core.mapper.* import com.cakk.domain.mysql.dto.param.link.UpdateLinkParam import com.cakk.domain.mysql.dto.param.operation.UpdateShopOperationParam import com.cakk.domain.mysql.dto.param.shop.CakeShopUpdateParam @@ -77,8 +75,8 @@ fun supplyUpdateLinkParamBy( val cakeShopLinks: MutableList = ArrayList() dto.instagram?.let { cakeShopLinks.add(supplyCakeShopLinkByInstagram(dto.instagram)) } - dto.kakao?.let { cakeShopLinks.add(supplyCakeShopLinkByInstagram(dto.kakao)) } - dto.web?.let { cakeShopLinks.add(supplyCakeShopLinkByInstagram(dto.web)) } + dto.kakao?.let { cakeShopLinks.add(supplyCakeShopLinkByKakao(dto.kakao)) } + dto.web?.let { cakeShopLinks.add(supplyCakeShopLinkByWeb(dto.web)) } return UpdateLinkParam(user, cakeShopId, cakeShopLinks) } diff --git a/cakk-domain/mysql/src/test/java/com/cakk/domain/entity/user/BusinessInformationTest.kt b/cakk-domain/mysql/src/test/java/com/cakk/domain/entity/user/BusinessInformationTest.kt index c74cf428..d3a47e12 100644 --- a/cakk-domain/mysql/src/test/java/com/cakk/domain/entity/user/BusinessInformationTest.kt +++ b/cakk-domain/mysql/src/test/java/com/cakk/domain/entity/user/BusinessInformationTest.kt @@ -48,7 +48,7 @@ internal class BusinessInformationTest : DomainTest() { //given val businessInformation = getBusinessInformationFixtureWithCakeShop(VerificationStatus.PENDING) val verificationPolicy = verificationPolicy - val user = getUserFixture(Role.USER) + val user = getUserFixture() //when businessInformation.updateBusinessOwner(verificationPolicy, user)