-
Notifications
You must be signed in to change notification settings - Fork 0
#164 서비스 약관 동의 API 구현 #165
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
Changes from all commits
44043b6
b3c9ebe
17c385b
61193f4
87a43e2
52c858e
658f79a
57e90b6
f67542c
e01bca5
9e84704
7ed4f36
afc7169
1c1ad1f
538bb45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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 { | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| termRepo.saveAll(termList) | ||
| } | ||
|
|
||
| return saved | ||
| } | ||
|
|
||
| @Transactional | ||
|
|
||
| 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) | ||
| } | ||
| } |
| 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( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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, | ||
|
|
@@ -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) }, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class name에 약관(term)이라는 내용이 들어가면 어떨까 싶은데, 어떤가요? |
||
| } | ||
| 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( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 class는 삭제해주세요. |
||
| @Schema(description = "약관 항목", example = "SERVICE_TERMS") | ||
| val type: TermType, | ||
|
|
||
| @Schema(description = "사용자의 동의 여부") | ||
| val agreed: Boolean, | ||
| ) | ||
| 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) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.