Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor | CAKK-41 | 케이크 샵 관련 기능 이관 #191

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
root = true

[{*.java,*.gradle}]
[{*.java,*.gradle,*.kt,*.kts}]
charset = utf-8
end_of_line = lf
indent_style = tab
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.cakk.admin.controller

import com.cakk.admin.dto.request.CakeShopCreateByAdminRequest
import com.cakk.admin.dto.request.PromotionRequest
import com.cakk.admin.dto.response.CakeShopCreateResponse
import com.cakk.admin.dto.response.CakeShopOwnerCandidateResponse
import com.cakk.admin.dto.response.CakeShopOwnerCandidatesResponse
import com.cakk.admin.service.BusinessInformationService
Expand All @@ -11,7 +9,7 @@ import jakarta.validation.Valid
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/shops")
@RequestMapping("/business-information")
class BusinessInformationController(
private val businessInformationService: BusinessInformationService
) {
Expand All @@ -30,15 +28,7 @@ class BusinessInformationController(
return ApiResponse.success(response)
}

@PostMapping("/create")
fun createByAdmin(
@RequestBody @Valid request: CakeShopCreateByAdminRequest
): ApiResponse<CakeShopCreateResponse> {
val response = businessInformationService.createCakeShopByCertification(request.toParam())
return ApiResponse.success(response)
}

@PutMapping("/shops/promote")
@PutMapping("/promote")
fun promoteUser(
@RequestBody @Valid promotionRequest: PromotionRequest
): ApiResponse<Unit> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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.*

@RestController
@RequestMapping("/shops")
class ShopController(
private val shopService: ShopService
) {

@PostMapping
fun createByAdmin(
@RequestBody @Valid request: CakeShopCreateByAdminRequest
): ApiResponse<CakeShopCreateResponse> {
val response = shopService.createCakeShopByCertification(request.toParam())

return ApiResponse.success(response)
}

@PutMapping("/{cakeShopId}")
fun updateBasicInformation(
@PathVariable cakeShopId: Long,
@RequestBody @Valid request: CakeShopUpdateByAdminRequest
): ApiResponse<Unit> {
shopService.updateBasicInformation(request.toParam(cakeShopId))

return ApiResponse.success()
}

@PutMapping("/{cakeShopId}/links")
fun updateLinks(
@PathVariable cakeShopId: Long,
@RequestBody request: @Valid LinkUpdateByAdminRequest
): ApiResponse<Unit> {
shopService.updateShopLinks(request.toParam(cakeShopId))

return ApiResponse.success()
}

@PutMapping("/{cakeShopId}/operation-days")
fun updateOperationDays(
@PathVariable cakeShopId: Long,
@RequestBody @Valid request: ShopOperationUpdateByAdminRequest
): ApiResponse<Unit> {
shopService.updateShopOperationDays(request.toParam(cakeShopId))

return ApiResponse.success()
}

@PutMapping("/{cakeShopId}/address")
fun updateAddress(
@PathVariable cakeShopId: Long,
@RequestBody @Valid request: AddressUpdateByAdminRequest
): ApiResponse<Unit> {
shopService.updateShopAddress(request.toParam(cakeShopId))

return ApiResponse.success()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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<CakeShopLink>()

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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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<ShopOperationParam>
) {

fun toParam(cakeShopId: Long): UpdateShopOperationParam {
return UpdateShopOperationParam.builder()
.cakeShopId(cakeShopId)
.cakeShopOperations(supplyCakeShopOperationListBy(operationDays))
.build()
}
}
12 changes: 6 additions & 6 deletions cakk-admin/src/main/kotlin/com/cakk/admin/mapper/LinkMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ import com.cakk.domain.mysql.entity.shop.CakeShopLink
fun supplyCakeShopLinksBy(cakeShop: CakeShop, links: List<ShopLinkParam>): List<CakeShopLink> {
return links.map {
when (it.linkKind) {
LinkKind.WEB -> supplyCakeShopLinkByWeb(cakeShop, it.linkPath)
LinkKind.INSTAGRAM -> supplyCakeShopLinkByInstagram(cakeShop, it.linkPath)
LinkKind.KAKAOTALK -> supplyCakeShopLinkByKakao(cakeShop, it.linkPath)
LinkKind.WEB -> supplyCakeShopLinkByWeb(it.linkPath, cakeShop)
LinkKind.INSTAGRAM -> supplyCakeShopLinkByInstagram(it.linkPath, cakeShop)
LinkKind.KAKAOTALK -> supplyCakeShopLinkByKakao(it.linkPath, cakeShop)
}
}.toList()
}

private fun supplyCakeShopLinkByWeb(cakeShop: CakeShop, web: String): CakeShopLink {
fun supplyCakeShopLinkByWeb(web: String, cakeShop: CakeShop? = null): CakeShopLink {
return CakeShopLink.builder()
.linkKind(LinkKind.WEB)
.linkPath(web)
.cakeShop(cakeShop)
.build()
}

private fun supplyCakeShopLinkByInstagram(cakeShop: CakeShop, instagram: String): CakeShopLink {
fun supplyCakeShopLinkByInstagram(instagram: String, cakeShop: CakeShop? = null): CakeShopLink {
return CakeShopLink.builder()
.linkKind(LinkKind.INSTAGRAM)
.linkPath(instagram)
.cakeShop(cakeShop)
.build()
}

private fun supplyCakeShopLinkByKakao(cakeShop: CakeShop, kakao: String): CakeShopLink {
fun supplyCakeShopLinkByKakao(kakao: String, cakeShop: CakeShop? = null): CakeShopLink {
return CakeShopLink.builder()
.linkKind(LinkKind.KAKAOTALK)
.linkPath(kakao)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.cakk.admin.mapper

import com.cakk.domain.mysql.dto.param.shop.ShopOperationParam
import com.cakk.domain.mysql.entity.shop.CakeShopOperation

fun supplyCakeShopOperationListBy(operationDays: List<ShopOperationParam>): List<CakeShopOperation> {
return operationDays
.map { supplyCakeShopOperationBy(it) }
.toList()
}

fun supplyCakeShopOperationBy(param: ShopOperationParam): CakeShopOperation {
return CakeShopOperation.builder()
.operationDay(param.operationDay)
.operationStartTime(param.operationStartTime)
.operationEndTime(param.operationEndTime)
.build()
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
package com.cakk.admin.service

import com.cakk.admin.dto.param.CakeShopCreateByAdminParam
import com.cakk.admin.dto.request.PromotionRequest
import com.cakk.admin.dto.response.CakeShopCreateResponse
import com.cakk.admin.dto.response.CakeShopOwnerCandidateResponse
import com.cakk.admin.dto.response.CakeShopOwnerCandidatesResponse
import com.cakk.admin.mapper.*
import com.cakk.domain.mysql.bo.user.VerificationPolicy
import com.cakk.domain.mysql.entity.shop.CakeShop
import com.cakk.domain.mysql.entity.user.BusinessInformation
import com.cakk.domain.mysql.entity.user.User
import com.cakk.domain.mysql.repository.reader.BusinessInformationReader
import com.cakk.domain.mysql.repository.reader.CakeShopReader
import com.cakk.domain.mysql.repository.reader.UserReader
import com.cakk.domain.mysql.repository.writer.CakeShopWriter
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class BusinessInformationService(
private val businessInformationReader: BusinessInformationReader,
private val userReader: UserReader,
private val cakeShopWriter: CakeShopWriter,
private val cakeShopReader: CakeShopReader,
private val verificationPolicy: VerificationPolicy,
) {

@Transactional
fun createCakeShopByCertification(dto: CakeShopCreateByAdminParam): CakeShopCreateResponse {
val result: CakeShop = cakeShopWriter.createCakeShop(
dto.cakeShop,
dto.cakeShopOperations,
dto.businessInformation,
dto.cakeShopLinks
)

return supplyCakeShopCreateResponseBy(result)
}

@Transactional
fun promoteUserToBusinessOwner(dto: PromotionRequest) {
val user: User = userReader.findByUserId(dto.userId)
Expand Down
57 changes: 57 additions & 0 deletions cakk-admin/src/main/kotlin/com/cakk/admin/service/ShopService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.cakk.admin.service

import com.cakk.admin.dto.param.CakeShopCreateByAdminParam
import com.cakk.admin.dto.response.CakeShopCreateResponse
import com.cakk.admin.mapper.supplyCakeShopCreateResponseBy
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
import com.cakk.domain.mysql.repository.reader.CakeShopReader
import com.cakk.domain.mysql.repository.writer.CakeShopWriter
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class ShopService(
private val cakeShopReader: CakeShopReader,
private val cakeShopWriter: CakeShopWriter
) {

@Transactional
fun createCakeShopByCertification(dto: CakeShopCreateByAdminParam): CakeShopCreateResponse {
val result: CakeShop = cakeShopWriter.createCakeShop(
dto.cakeShop,
dto.cakeShopOperations,
dto.businessInformation,
dto.cakeShopLinks
)

return supplyCakeShopCreateResponseBy(result)
}

@Transactional
fun updateBasicInformation(dto: CakeShopUpdateParam) {
val cakeShop = cakeShopReader.findById(dto.cakeShopId)
cakeShop.updateBasicInformation(dto)
}

@Transactional
fun updateShopLinks(param: UpdateLinkParam) {
val cakeShop = cakeShopReader.findById(param.cakeShopId)
cakeShop.updateShopLinks(param.cakeShopLinks)
}

@Transactional
fun updateShopOperationDays(param: UpdateShopOperationParam) {
val cakeShop = cakeShopReader.findById(param.cakeShopId)
cakeShop.updateShopOperationDays(param.cakeShopOperations)
}

@Transactional
fun updateShopAddress(param: UpdateShopAddressParam) {
val cakeShop = cakeShopReader.findById(param.cakeShopId)
cakeShop.updateShopAddress(param)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public record UpdateShopRequest(
) {

public CakeShopUpdateParam toParam(User user, Long cakeShopId) {
return new CakeShopUpdateParam(
thumbnailUrl,
shopName,
shopBio,
shopDescription,
user,
cakeShopId
);
return CakeShopUpdateParam.builder()
.user(user)
.cakeShopId(cakeShopId)
.thumbnailUrl(thumbnailUrl())
.shopName(shopName())
.shopBio(shopBio())
.shopDescription(shopDescription())
.build();
}
}
Loading
Loading