-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implements participant signup - 참여자 회원가입 API 구현 - 구글 OAuth 에외처리 로직 일부 수정 * test: add test codes for SignupMapper and ParticipantSignupUseCase - 테스트 커버리지 충족을 위해 테스트 코드 추가 - `SignupMapperTest` 코드 추가 - `ParticipantSignupUseCase` 코드 추가 * fix: resolve duplicate requested authentication - 실험자 회원가입 시, Authentication 중복 생성 코드 제거 * refact: move DB Transaction to seperate responsibility to satisfy clean architecture principal - DB 트랜잭션 책임 관련: UseCase → Service 계층으로 위임 * refact: Applay automatic Component Scan for UseCase classes - UseCase 클래스가 비즈니스 로직의 핵심 계층: 자동으로 컴포넌트 스캔 대상에 포함되도록 어노테이션 제거 - 관리와 확장성을 고려하여 클린 아키텍처를 적용한 구현 방식 * style: rename API endpoint signup to meet the convention rule - 회원가입 API endpoint 관련하여 기존 `/join` → `/signup` 으로 개선 - 코드 컨벤션을 위한 API endpoint 개선 * refact: update annotations to validate DateTime Format - 생년월일 데이터 포맷 관련: 기존: `@NotBlank` → `@NotNull` `@Past` `@DateTimeFormat` * refact: rename mapper function to match its usecase - dto → entity 변환하는 용례에 따라, 기존: `toAddressInfoDto` → `toAddressInfo` 로 리네이밍 * fix: reflect updated codes to test code - dto 함수 리네이밍 반영한 `SingupMapperTest` 버그 해결
- Loading branch information
Showing
24 changed files
with
388 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/dobby/backend/application/mapper/SignupMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.dobby.backend.application.mapper | ||
|
||
import com.dobby.backend.infrastructure.database.entity.MemberEntity | ||
import com.dobby.backend.infrastructure.database.entity.ParticipantEntity | ||
import com.dobby.backend.infrastructure.database.entity.enum.MemberStatus | ||
import com.dobby.backend.infrastructure.database.entity.enum.RoleType | ||
import com.dobby.backend.presentation.api.dto.request.ParticipantSignupRequest | ||
import com.dobby.backend.presentation.api.dto.response.MemberResponse | ||
import com.dobby.backend.infrastructure.database.entity.AddressInfo as AddressInfo | ||
import com.dobby.backend.presentation.api.dto.request.AddressInfo as DtoAddressInfo | ||
|
||
object SignupMapper { | ||
fun toAddressInfo(dto: DtoAddressInfo): AddressInfo { | ||
return AddressInfo( | ||
dto.region, | ||
dto.area | ||
) | ||
} | ||
fun toMember(req: ParticipantSignupRequest): MemberEntity { | ||
return MemberEntity( | ||
id = 0, // Auto-generated | ||
oauthEmail = req.oauthEmail, | ||
provider = req.provider, | ||
status = MemberStatus.ACTIVE, | ||
role = RoleType.PARTICIPANT, | ||
contactEmail = req.contactEmail, | ||
name = req.name, | ||
birthDate = req.birthDate | ||
) | ||
} | ||
fun toParticipant( | ||
member: MemberEntity, | ||
req: ParticipantSignupRequest | ||
): ParticipantEntity { | ||
return ParticipantEntity( | ||
member = member, | ||
basicAddressInfo = toAddressInfo(req.basicAddressInfo), | ||
additionalAddressInfo = req.additionalAddressInfo?.let { toAddressInfo(it) }, | ||
preferType = req.preferType, | ||
gender = req.gender | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/dobby/backend/application/service/SignupService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.dobby.backend.application.service | ||
|
||
import com.dobby.backend.application.usecase.ParticipantSignupUseCase | ||
import com.dobby.backend.presentation.api.dto.request.ParticipantSignupRequest | ||
import com.dobby.backend.presentation.api.dto.response.signup.SignupResponse | ||
import jakarta.transaction.Transactional | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SignupService( | ||
private val participantSignupUseCase: ParticipantSignupUseCase | ||
) { | ||
@Transactional | ||
fun participantSignup(input: ParticipantSignupRequest): SignupResponse { | ||
return participantSignupUseCase.execute(input) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/dobby/backend/application/usecase/ParticipantSignupUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.dobby.backend.application.usecase | ||
|
||
import com.dobby.backend.application.mapper.SignupMapper | ||
import com.dobby.backend.infrastructure.database.repository.ParticipantRepository | ||
import com.dobby.backend.infrastructure.token.JwtTokenProvider | ||
import com.dobby.backend.presentation.api.dto.request.ParticipantSignupRequest | ||
import com.dobby.backend.presentation.api.dto.response.MemberResponse | ||
import com.dobby.backend.presentation.api.dto.response.signup.SignupResponse | ||
import com.dobby.backend.util.AuthenticationUtils | ||
|
||
class ParticipantSignupUseCase ( | ||
private val participantRepository: ParticipantRepository, | ||
private val jwtTokenProvider: JwtTokenProvider | ||
):UseCase<ParticipantSignupRequest, SignupResponse> | ||
{ | ||
override fun execute(input: ParticipantSignupRequest): SignupResponse { | ||
val memberEntity = SignupMapper.toMember(input) | ||
val participantEntity = SignupMapper.toParticipant(memberEntity, input) | ||
|
||
val newParticipant = participantRepository.save(participantEntity) | ||
val authentication = AuthenticationUtils.createAuthentication(memberEntity) | ||
val accessToken = jwtTokenProvider.generateAccessToken(authentication) | ||
val refreshToken = jwtTokenProvider.generateRefreshToken(authentication) | ||
|
||
return SignupResponse( | ||
memberInfo = MemberResponse.fromDomain(newParticipant.member.toDomain()), | ||
accessToken = accessToken, | ||
refreshToken = refreshToken | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...dobby/backend/presentation/api/controller/SignupController/ParticipantSignupController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.dobby.backend.presentation.api.controller.SignupController | ||
|
||
import com.dobby.backend.application.service.SignupService | ||
import com.dobby.backend.infrastructure.database.entity.enum.RoleType | ||
import com.dobby.backend.infrastructure.database.entity.enum.RoleType.* | ||
import com.dobby.backend.presentation.api.dto.request.ParticipantSignupRequest | ||
import com.dobby.backend.presentation.api.dto.response.signup.SignupResponse | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import jakarta.validation.Valid | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@Tag(name = "회원가입 API") | ||
@RestController | ||
@RequestMapping("/v1/participants") | ||
class ParticipantSignupController( | ||
private val signupService: SignupService | ||
) { | ||
@PostMapping("/signup") | ||
@Operation( | ||
summary = "참여자 회원가입 API- OAuth 로그인 필수", | ||
description = "참여자 OAuth 로그인 실패 시, 리다이렉팅하여 참여자 회원가입하는 API입니다." | ||
) | ||
fun signup( | ||
@RequestBody @Valid req: ParticipantSignupRequest | ||
): SignupResponse { | ||
return signupService.participantSignup(req) | ||
} | ||
} |
Oops, something went wrong.