Skip to content
Closed
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 gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.damaba.damaba.application.photographer

import com.damaba.damaba.application.term.TermItem
import com.damaba.damaba.domain.common.Address
import com.damaba.damaba.domain.common.constant.PhotographyType
import com.damaba.damaba.domain.file.Image
import com.damaba.damaba.domain.photographer.PhotographerValidator
import com.damaba.damaba.domain.region.Region
import com.damaba.damaba.domain.term.TermValidator
import com.damaba.damaba.domain.user.UserValidator
import com.damaba.damaba.domain.user.constant.Gender

Expand All @@ -16,12 +18,14 @@ data class RegisterPhotographerCommand(
val profileImage: Image,
val mainPhotographyTypes: Set<PhotographyType>,
val activeRegions: Set<Region>,
val terms: List<TermItem>,
) {
init {
PhotographerValidator.validateNickname(nickname)
if (instagramId != null) UserValidator.validateInstagramId(instagramId)
PhotographerValidator.validateMainPhotographyTypes(mainPhotographyTypes)
PhotographerValidator.validateActiveRegions(activeRegions)
TermValidator.validatePhotographerRequired(terms)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.damaba.damaba.application.photographer

import com.damaba.damaba.application.term.TermItem
import com.damaba.damaba.domain.common.Pagination
import com.damaba.damaba.domain.photographer.Photographer
import com.damaba.damaba.domain.photographer.PhotographerListItem
import com.damaba.damaba.domain.photographer.PhotographerSave
import com.damaba.damaba.domain.photographer.exception.AlreadyPhotographerSaveException
import com.damaba.damaba.domain.photographer.exception.PhotographerSaveNotFoundException
import com.damaba.damaba.domain.term.Term
import com.damaba.damaba.domain.user.User
import com.damaba.damaba.domain.user.exception.NicknameAlreadyExistsException
import com.damaba.damaba.domain.user.exception.UserAlreadyRegisteredException
import com.damaba.damaba.infrastructure.photographer.PhotographerRepository
import com.damaba.damaba.infrastructure.photographer.PhotographerSaveRepository
import com.damaba.damaba.infrastructure.promotion.PromotionRepository
import com.damaba.damaba.infrastructure.promotion.PromotionSaveRepository
import com.damaba.damaba.infrastructure.term.TermRepository
import com.damaba.damaba.infrastructure.user.UserRepository
import com.damaba.damaba.mapper.PhotographerMapper
import org.springframework.stereotype.Service
Expand All @@ -25,6 +28,7 @@ class PhotographerService(
private val photographerSaveRepo: PhotographerSaveRepository,
private val promotionRepo: PromotionRepository,
private val promotionSaveRepo: PromotionSaveRepository,
private val termRepo: TermRepository,
) {
@Transactional
fun register(command: RegisterPhotographerCommand): Photographer {
Expand All @@ -46,7 +50,21 @@ class PhotographerService(
mainPhotographyTypes = command.mainPhotographyTypes,
activeRegions = command.activeRegions,
)
return photographerRepo.createIfUserExists(photographer)
val saved = photographerRepo.createIfUserExists(photographer)

if (command.terms.isNotEmpty()) {
val termList: List<Term> = command.terms.map { item: TermItem ->
Term(
id = null,
userId = saved.id,
type = item.type,
agreed = item.agreed,
)
}
Comment on lines +56 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TermItemTerm으로 변환하는 건 TermMapper를 만들어서 MapStruct를 사용해보면 어떨까요?

termRepo.saveAll(termList)
}

return saved
}

@Transactional
Expand Down
29 changes: 29 additions & 0 deletions src/main/kotlin/com/damaba/damaba/application/term/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.damaba.damaba.application.term

import com.damaba.damaba.domain.term.TermType
import com.damaba.damaba.domain.term.TermValidator

data class TermItem(
val type: TermType,
val agreed: Boolean,
)

data class AcceptUserTermsCommand(
val userId: Long,
val terms: List<TermItem>,
) {
init {
// TermValidator 에서 필수 약관 체크
TermValidator.validateUserRequired(terms)
}
}

data class AcceptPhotographerTermsCommand(
val userId: Long,
val terms: List<TermItem>,
) {
init {
// TermValidator 에서 유저+작가 필수 약관 체크
TermValidator.validatePhotographerRequired(terms)
}
}
39 changes: 39 additions & 0 deletions src/main/kotlin/com/damaba/damaba/application/term/TermService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.damaba.damaba.application.term

import com.damaba.damaba.domain.term.Term
import com.damaba.damaba.infrastructure.term.TermRepository
import jakarta.transaction.Transactional
import org.springframework.stereotype.Service

@Service
class TermService(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 혹시 사용하는 class인가요?
아니라면, 삭제해주세요

private val termRepo: TermRepository,
) {
// 일반 유저용 약관 동의 내역 저장
@Transactional
fun acceptUserTerms(command: AcceptUserTermsCommand) {
val userTerms = command.terms.map { item ->
Term(
id = 0L,
userId = command.userId,
type = item.type,
agreed = item.agreed,
)
}
termRepo.saveAll(userTerms)
}

// 사진 작가용 약관 동의 내역 저장
@Transactional
fun acceptPhotographerTerms(command: AcceptPhotographerTermsCommand) {
val photoTerm = command.terms.map { item ->
Term(
id = 0L,
userId = command.userId,
type = item.type,
agreed = item.agreed,
)
}
termRepo.saveAll(photoTerm)
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/damaba/damaba/application/user/Command.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.damaba.damaba.application.user

import com.damaba.damaba.application.term.TermItem
import com.damaba.damaba.domain.file.Image
import com.damaba.damaba.domain.term.TermValidator
import com.damaba.damaba.domain.user.UserValidator
import com.damaba.damaba.domain.user.constant.Gender

Expand All @@ -9,10 +11,12 @@ data class RegisterUserCommand(
val nickname: String,
val gender: Gender,
val instagramId: String?,
val terms: List<TermItem>,
) {
init {
UserValidator.validateNickname(nickname)
if (instagramId != null) UserValidator.validateInstagramId(instagramId)
TermValidator.validateUserRequired(terms)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.damaba.damaba.application.user

import com.damaba.damaba.application.term.TermItem
import com.damaba.damaba.domain.term.Term
import com.damaba.damaba.domain.user.User
import com.damaba.damaba.domain.user.exception.NicknameAlreadyExistsException
import com.damaba.damaba.domain.user.exception.UserAlreadyRegisteredException
import com.damaba.damaba.domain.user.exception.UserNotFoundException
import com.damaba.damaba.infrastructure.photographer.PhotographerSaveRepository
import com.damaba.damaba.infrastructure.promotion.PromotionSaveRepository
import com.damaba.damaba.infrastructure.term.TermRepository
import com.damaba.damaba.infrastructure.user.UserRepository
import com.damaba.damaba.mapper.UserMapper
import org.springframework.stereotype.Service
Expand All @@ -16,6 +19,7 @@ class UserService(
private val userRepo: UserRepository,
private val photographerSaveRepo: PhotographerSaveRepository,
private val promotionSaveRepo: PromotionSaveRepository,
private val termRepo: TermRepository,
) {
@Transactional(readOnly = true)
fun getUser(userId: Long): User = userRepo.getById(userId)
Expand Down Expand Up @@ -49,7 +53,20 @@ class UserService(
gender = command.gender,
instagramId = command.instagramId,
)
return userRepo.update(user)
val saved = userRepo.update(user)

if (command.terms.isNotEmpty()) {
val termList: List<Term> = command.terms.map { item: TermItem ->
Term(
id = 0L,
userId = saved.id,
type = item.type,
agreed = item.agreed,
)
}
termRepo.saveAll(termList)
}
return saved
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.damaba.damaba.controller.photographer
import com.damaba.damaba.application.photographer.RegisterPhotographerCommand
import com.damaba.damaba.application.photographer.UpdatePhotographerPageCommand
import com.damaba.damaba.application.photographer.UpdatePhotographerProfileCommand
import com.damaba.damaba.application.term.TermItem
import com.damaba.damaba.controller.common.AddressRequest
import com.damaba.damaba.controller.common.ImageRequest
import com.damaba.damaba.controller.region.RegionRequest
import com.damaba.damaba.controller.term.AgreementRequestItem
import com.damaba.damaba.domain.common.constant.PhotographyType
import com.damaba.damaba.domain.term.TermType
import com.damaba.damaba.domain.user.constant.Gender
import com.damaba.damaba.mapper.AddressMapper
import com.damaba.damaba.mapper.ImageMapper
Expand All @@ -20,6 +23,7 @@ data class RegisterPhotographerRequest(
val profileImage: ImageRequest,
val mainPhotographyTypes: Set<PhotographyType>,
val activeRegions: Set<RegionRequest>,
val agreements: List<AgreementRequestItem>,
) {
fun toCommand(requesterId: Long) = RegisterPhotographerCommand(
userId = requesterId,
Expand All @@ -29,6 +33,7 @@ data class RegisterPhotographerRequest(
profileImage = ImageMapper.INSTANCE.toImage(profileImage),
mainPhotographyTypes = mainPhotographyTypes,
activeRegions = activeRegions.map { regionRequest -> RegionMapper.INSTANCE.toRegion(regionRequest) }.toSet(),
terms = agreements.map { TermItem(it.type, it.agreed) },
)
}

Expand Down Expand Up @@ -69,4 +74,12 @@ data class UpdateMyPhotographerProfileRequest(
mainPhotographyTypes = this.mainPhotographyTypes,
activeRegions = this.activeRegions.map { RegionMapper.INSTANCE.toRegion(it) }.toSet(),
)

data class AgreementRequestItem(
@Schema(description = "약관 종류", example = "SERVICE_TERMS")
val type: TermType,

@Schema(description = "사용자 동의 여부", example = "ture")
val agreed: Boolean,
)
Comment on lines +78 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class name에 약관(term)이라는 내용이 들어가면 어떨까 싶은데, 어떤가요?

}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/damaba/damaba/controller/term/Request.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@file:Suppress("ktlint:standard:filename")

package com.damaba.damaba.controller.term

import com.damaba.damaba.domain.term.TermType
import io.swagger.v3.oas.annotations.media.Schema

data class AgreementRequestItem(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 class는 삭제해주세요. photographer.Request, user.Request에 있는 AgreementRequestItem와 겹치는 거 같아요.
정작 해당 file에서는 추가 구현한 class를 안쓰고 term.Request를 참조하고 있네요.

@Schema(description = "약관 항목", example = "SERVICE_TERMS")
val type: TermType,

@Schema(description = "사용자의 동의 여부")
val agreed: Boolean,
)
14 changes: 14 additions & 0 deletions src/main/kotlin/com/damaba/damaba/controller/term/Response.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@file:Suppress("ktlint:standard:filename")

package com.damaba.damaba.controller.term

import com.damaba.damaba.domain.term.TermType
import io.swagger.v3.oas.annotations.media.Schema

data class TermMetadataResponse(
@Schema(description = "약관 항목", example = "SERVICE_TERMS")
val type: TermType,

@Schema(description = "필수 약관 여부", example = "true")
val required: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.damaba.damaba.controller.term

import com.damaba.damaba.application.term.TermService
import com.damaba.damaba.domain.term.TermType
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Tag(name = "서비스 약관 동의 관련 API")
@RestController
@RequestMapping("/api/v1/terms")
class TermController(
private val termService: TermService,
) {
/**
* 일반 유저의 서비스 약관 동의 목록 조회 (type, required)
*/
@Operation(
summary = "회원용 약관 목록 조회",
description = "가입 시 일반 유저가 동의해야 하는 약관 동의 목록 조회",
)
@ApiResponses(
ApiResponse(responseCode = "200"),
)
@GetMapping("/user")
fun getUserTerms(): ResponseEntity<List<TermMetadataResponse>> {
val userTerms = TermType.values()
.filter { it != TermType.PHOTOGRAPHER_TERMS }
.map { TermMetadataResponse(type = it, required = it.required) }
return ResponseEntity.ok(userTerms)
}

/**
* 사진 작가의 서비스 약관 동의 목록 조회 (type, required)
*/
@Operation(
summary = "작가용 약관 목록 조회",
description = "가입 시 작가가 동의해야 하는 약관 동의 목록 조회",
)
@ApiResponses(
ApiResponse(responseCode = "200"),
)
@GetMapping("/photographer")
fun getPhotographerTerms(): ResponseEntity<List<TermMetadataResponse>> {
val photographerTerms = TermType.values()
.map { TermMetadataResponse(type = it, required = it.required) }
return ResponseEntity.ok(photographerTerms)
}
}
Loading
Loading