Skip to content

Commit

Permalink
feat: Innoculation 포함 회원가입 API
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Mar 20, 2024
1 parent 785ae5a commit 938394c
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.vacgom.backend.application.auth

import com.vacgom.backend.application.auth.dto.AuthResponse
import com.vacgom.backend.application.auth.dto.MemberResponse
import com.vacgom.backend.application.auth.dto.TokenResponse
import com.vacgom.backend.application.auth.dto.response.AuthResponse
import com.vacgom.backend.application.auth.dto.response.MemberResponse
import com.vacgom.backend.application.auth.dto.response.TokenResponse
import com.vacgom.backend.domain.auth.constants.Role.ROLE_TEMP_USER
import com.vacgom.backend.domain.auth.oauth.constants.ProviderType
import com.vacgom.backend.domain.member.Member
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package com.vacgom.backend.application.member
package com.vacgom.backend.application.auth

import com.vacgom.backend.application.auth.dto.AuthResponse
import com.vacgom.backend.application.auth.dto.MemberResponse
import com.vacgom.backend.application.auth.dto.TokenResponse
import com.vacgom.backend.application.member.dto.request.SignUpRequest
import com.vacgom.backend.application.auth.dto.request.SignUpRequest
import com.vacgom.backend.application.auth.dto.response.AuthResponse
import com.vacgom.backend.application.auth.dto.response.MemberResponse
import com.vacgom.backend.application.auth.dto.response.TokenResponse
import com.vacgom.backend.domain.auth.constants.Role
import com.vacgom.backend.domain.member.HealthProfile
import com.vacgom.backend.domain.member.MemberDetails
import com.vacgom.backend.domain.member.Nickname
import com.vacgom.backend.domain.vaccine.Inoculation
import com.vacgom.backend.domain.vaccine.constants.Vaccination
import com.vacgom.backend.exception.member.MemberError
import com.vacgom.backend.exception.member.NicknameError
import com.vacgom.backend.global.exception.error.BusinessException
import com.vacgom.backend.global.security.jwt.JwtFactory
import com.vacgom.backend.infrastructure.member.persistence.HealthProfileRepository
import com.vacgom.backend.infrastructure.member.persistence.MemberRepository
import com.vacgom.backend.infrastructure.vaccine.persistence.InoculationRepository
import jakarta.transaction.Transactional
import org.springframework.stereotype.Service
import java.util.*

@Service
@Transactional
class MemberService(
class VacgomSignupService(
private val memberRepository: MemberRepository,
private val healthProfileRepository: HealthProfileRepository,
private val inoculationRepository: InoculationRepository,
private val jwtFactory: JwtFactory
) {
fun validateNickname(id: String) {
Expand All @@ -35,23 +39,37 @@ class MemberService(
memberId: UUID,
request: SignUpRequest
): AuthResponse {
val (nickname, healthConditions) = request.memberInfo
val (name, birthday, sex, vaccines) = request.vaccinationInfo

val member = memberRepository.findById(memberId).orElseThrow { BusinessException(MemberError.NOT_FOUND) }
val nickname = Nickname(request.nickname)
val memberDetails = MemberDetails(request.name, request.birthday, request.sex)
val validatedNickname = Nickname(nickname)
val memberDetails = MemberDetails(name, birthday, sex)

member.updateNickname(nickname)
member.updateNickname(validatedNickname)
member.updateMemberDetails(memberDetails)
member.updateRole(Role.ROLE_USER)

val healthConditions = request.healthConditions.stream()
val healthProfiles = healthConditions.stream()
.map { condition ->
HealthProfile(member, condition)
}.toList()
healthProfileRepository.saveAll(healthConditions)
healthProfileRepository.saveAll(healthProfiles)

val memberResponse = MemberResponse(member.id!!, member.role)
val tokenResponse = TokenResponse(jwtFactory.createAccessToken(member))

val inoculations = vaccines.stream()
.map { vaccine ->
val (vaccineType, inoculationOrder, inoculationOrderString, date, agency, vaccineName, vaccineBrandName, lotNumber)
= vaccine
val vaccination = Vaccination.getVaccinationByName(vaccineType)
Inoculation(vaccination, inoculationOrder, inoculationOrderString, date, agency, vaccineName, vaccineBrandName, lotNumber, member)
}.toList()

inoculationRepository.saveAll(inoculations)
member.addInoculations(inoculations)

return AuthResponse(memberResponse, tokenResponse)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.vacgom.backend.application.auth.dto.request

import com.vacgom.backend.domain.member.constants.HealthCondition

data class MemberInfoRequest(
val nickname: String,
val healthConditions: MutableList<HealthCondition>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.vacgom.backend.application.auth.dto.request

data class SignUpRequest(
val memberInfo: MemberInfoRequest,
val vaccinationInfo: VaccinationInfoRequest
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.vacgom.backend.application.auth.dto.request

data class VaccinationInfoRequest(
val name: String,
val birth: String,
val sex: String,
val vaccineList: MutableList<Vaccines>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.vacgom.backend.application.auth.dto.request

import java.time.LocalDate

data class Vaccines(
val vaccineType: String, //DTap
val inoculationOrder: Long, // 4
val inoculationOrderString: String, // 4차(추가)
val date: LocalDate, // 2024-03-21
val agency: String, // 광명시보건소
val vaccineName: String?, // 보령정제피디티백신
val vaccineBrandName: String?, // (주)보령바이오파마
val lotNumber: String?, //AC14B097BB
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.application.auth.dto
package com.vacgom.backend.application.auth.dto.response

data class AuthResponse(
val member: MemberResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.application.auth.dto
package com.vacgom.backend.application.auth.dto.response

import com.vacgom.backend.domain.auth.constants.Role
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.application.auth.dto
package com.vacgom.backend.application.auth.dto.response

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.vacgom.backend.application.auth.dto.response

data class ResourceIdResponse(
val id: Long
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.application.auth.dto
package com.vacgom.backend.application.auth.dto.response


data class TokenResponse(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vacgom.backend.domain.auth.oauth

import com.vacgom.backend.application.auth.dto.OauthTokenResponse
import com.vacgom.backend.application.auth.dto.ResourceIdResponse
import com.vacgom.backend.application.auth.dto.response.OauthTokenResponse
import com.vacgom.backend.application.auth.dto.response.ResourceIdResponse
import com.vacgom.backend.domain.auth.oauth.constants.ProviderType

interface OauthConnector {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/vacgom/backend/domain/member/Member.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Member(
@OneToMany(mappedBy = "member")
val inoculations: MutableList<Inoculation> = mutableListOf()

fun addInoculation(inoculation: Inoculation) {
inoculations.add(inoculation)
fun addInoculations(inoculations: List<Inoculation>) {
this.inoculations.addAll(inoculations)
}

fun updateMemberDetails(memberDetails: MemberDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class MemberDetails(
constructor(name: String, birthday: String, sex: String) : this(
name,
LocalDate.parse(birthday, DateTimeFormatter.ofPattern("yyyy-MM-dd")),
Sex.valueOf(sex)
Sex.getSexByValue(sex)
)
}
18 changes: 15 additions & 3 deletions src/main/kotlin/com/vacgom/backend/domain/member/constants/Sex.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package com.vacgom.backend.domain.member.constants

enum class Sex {
MALE,
FEMALE
import com.vacgom.backend.exception.member.MemberError
import com.vacgom.backend.global.exception.error.BusinessException

enum class Sex(
val value: String
) {
MALE("M"),
FEMALE("F");

companion object {
fun getSexByValue(value: String): Sex {
return entries.find { it.value == value }
?: throw BusinessException(MemberError.INVALID_SEX_REQUESTED)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class Inoculation(
)
val date: LocalDate,
val agency: String,
val vaccineName: String,
val vaccineBrandName: String,
val lotNumber: String,
val vaccineName: String?,
val vaccineBrandName: String?,
val lotNumber: String?,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand All @@ -34,5 +34,5 @@ class Inoculation(
@Id
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)", name = "vaccine_id")
val id: UUID? = null
val id: UUID = UUID.randomUUID()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.vacgom.backend.domain.vaccine.constants

import com.vacgom.backend.exception.vaccine.VaccineError
import com.vacgom.backend.global.exception.error.BusinessException

enum class Vaccination(
val diseaseName: String,
val vaccineName: String,
Expand All @@ -9,7 +12,7 @@ enum class Vaccination(
BCG("결핵", "BCG(피내용)", 1, 1),
HEPB("B형간염", "HepB", 1, 3),
DTAP("디프테리아·파상풍·백일해", "DTaP", 1, 5),
TDAP("디프테리아·파상풍·백일해", "DTaP", 6, 6),
TDAP("디프테리아·파상풍·백일해", "Tdap", 6, 6),
IPV("폴리오", "IPV", 1, 4),
HIB("b형헤모필루스인플루엔자", "Hib", 1, 4),
PCV("폐렴구균", "PCV", 1, 4),
Expand All @@ -22,5 +25,14 @@ enum class Vaccination(
HPV("사람유두종바이러스감염증", "HPV", 1, 3),
IIV("인플루엔자", "IIV", 1, Long.MAX_VALUE),
HPV9("사람유두종바이러스감염증", "HPV9(가다실9)", 1, 3),
COVID19("코로나19", "COVID19", 1, 3)
COVID19("코로나19", "COVID19", 1, 3);

companion object {
fun getVaccinationByName(vaccineName: String): Vaccination {
return entries.find { it.vaccineName == vaccineName }
?: throw BusinessException(VaccineError.UNKNOWN_VACCINE_REQUESTED).also {
println("Requested vaccine with name '$vaccineName' is unknown.")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ enum class MemberError(
override val status: HttpStatus,
override val code: String
) : ErrorCode {
NOT_FOUND("사용자를 찾을 수 없습니다.", HttpStatus.NOT_FOUND, "M_001")
NOT_FOUND("사용자를 찾을 수 없습니다.", HttpStatus.NOT_FOUND, "M_001"),
INVALID_SEX_REQUESTED("사용자를 찾을 수 없습니다.", HttpStatus.NOT_FOUND, "M_002")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.vacgom.backend.exception.vaccine

import com.vacgom.backend.global.exception.error.ErrorCode
import org.springframework.http.HttpStatus

enum class VaccineError(
override val message: String,
override val status: HttpStatus,
override val code: String
) : ErrorCode {
UNKNOWN_VACCINE_REQUESTED("확인되지 않은 백신이 요청되었습니다.", HttpStatus.BAD_REQUEST, "VI_001"),
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CustomRequestMatcher {
return OrRequestMatcher(
AntPathRequestMatcher("/"), // Actuator Health Checker
AntPathRequestMatcher("/api/v1/oauth/**"), // Oauth Login
AntPathRequestMatcher("/api/v1/member/validation") // VacgomId Validation Checker
AntPathRequestMatcher("/api/v1/member/validation"), // VacgomId Validation Checker
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vacgom.backend.infrastructure.auth.oauth.kakao

import com.vacgom.backend.application.auth.dto.OauthTokenResponse
import com.vacgom.backend.application.auth.dto.ResourceIdResponse
import com.vacgom.backend.application.auth.dto.response.OauthTokenResponse
import com.vacgom.backend.application.auth.dto.response.ResourceIdResponse
import com.vacgom.backend.domain.auth.oauth.OauthConnector
import com.vacgom.backend.domain.auth.oauth.constants.ProviderType
import com.vacgom.backend.global.exception.error.BusinessException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.vacgom.backend.infrastructure.vaccine.persistence

import com.vacgom.backend.domain.vaccine.Inoculation
import org.springframework.data.jpa.repository.JpaRepository
import java.util.*

interface InoculationRepository : JpaRepository<Inoculation, UUID>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vacgom.backend.presentation.auth

import com.vacgom.backend.application.auth.AuthService
import com.vacgom.backend.application.auth.dto.AuthResponse
import com.vacgom.backend.application.auth.dto.response.AuthResponse
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.vacgom.backend.presentation.member
package com.vacgom.backend.presentation.auth

import com.vacgom.backend.application.auth.dto.AuthResponse
import com.vacgom.backend.application.member.MemberService
import com.vacgom.backend.application.member.dto.request.SignUpRequest
import com.vacgom.backend.application.auth.VacgomSignupService
import com.vacgom.backend.application.auth.dto.request.SignUpRequest
import com.vacgom.backend.application.auth.dto.response.AuthResponse
import com.vacgom.backend.global.security.annotation.AuthId
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
Expand All @@ -11,12 +11,12 @@ import java.util.*

@RestController
@RequestMapping("/api/v1/member")
class MemberController(
private val memberService: MemberService
class SignUpController(
private val vacgomSignupService: VacgomSignupService
) {
@PostMapping("/validation")
fun validateNickname(@RequestParam nickname: String): ResponseEntity<Unit> {
memberService.validateNickname(nickname)
vacgomSignupService.validateNickname(nickname)
return ResponseEntity.ok().build()
}

Expand All @@ -25,7 +25,7 @@ class MemberController(
@AuthId memberId: UUID,
@RequestBody request: SignUpRequest
): ResponseEntity<AuthResponse> {
val authResponse = memberService.signUpVacgom(memberId, request)
val authResponse = vacgomSignupService.signUpVacgom(memberId, request)
return ResponseEntity.ok(authResponse)
}
}

0 comments on commit 938394c

Please sign in to comment.