Skip to content

Commit

Permalink
✨feature : 요청,응답 객체 json포맷 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkYunHo committed Aug 27, 2023
1 parent bf307f2 commit d2b5e4a
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.john.lotto.member.adapter.`in`.web

import com.john.lotto.member.adapter.`in`.web.dto.MemberInput
import com.john.lotto.member.adapter.`in`.web.dto.MemberResult
import com.john.lotto.member.dto.MemberDto
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.Content
Expand Down Expand Up @@ -118,7 +119,7 @@ class MemberRouter(
ApiResponse(
description = "삭제된 회원ID",
responseCode = "200",
content = [Content(schema = Schema(implementation = String::class))]
content = [Content(schema = Schema(implementation = MemberResult::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ data class MemberInput(
@Schema(description = "email", example = "lotto@email.com")
val email: String? = "",
@Schema(description = "닉네임", example = "admin1")
val nickName: String? = ""
val nickname: String? = ""
): Serializable {

fun validate(): MemberInput {
if(this.email.isNullOrEmpty()) {
throw BadRequestException("이메일 정보가 누락되었습니다.")
}

if(this.nickName.isNullOrEmpty()) {
if(this.nickname.isNullOrEmpty()) {
throw BadRequestException("닉네임 정보가 누락되었습니다")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.john.lotto.member.adapter.`in`.web.dto

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

/**
* @author yoonho
* @since 2023.08.27
*/
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class MemberResult(
val userId: String? = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.john.lotto.common.exception.BadRequestException
import com.john.lotto.common.exception.InternalServerException
import com.john.lotto.member.MemberRepository
import com.john.lotto.member.adapter.`in`.web.dto.MemberInput
import com.john.lotto.member.adapter.`in`.web.dto.MemberResult
import com.john.lotto.member.application.port.`in`.DeleteMemberUseCase
import com.john.lotto.member.application.port.`in`.FindMemberUseCase
import com.john.lotto.member.application.port.`in`.RegisterUseCase
Expand Down Expand Up @@ -43,7 +44,7 @@ class MemberService(
val param = MemberDto(
userId = userId,
email = input.email!!,
nickname = input.nickName!!,
nickname = input.nickname!!,
updatedAt = null,
createdAt = LocalDateTime.now()
)
Expand Down Expand Up @@ -73,8 +74,8 @@ class MemberService(
}

// 닉네임 업데이트
if(input.nickName.isNullOrEmpty()) {
userInfo.nickname = input.nickName!!
if(input.nickname.isNullOrEmpty()) {
userInfo.nickname = input.nickname!!
}

val result = memberRepository.updateMember(userInfo)
Expand Down Expand Up @@ -103,16 +104,16 @@ class MemberService(
* 사용자 탈퇴
*
* @param userId [String]
* @return [Mono]<[String]>
* @return [Mono]<[MemberResult]>
* @author yoonho
* @since 2023.07.19
* @since 2023.08.27
*/
override fun delete(userId: String): Mono<String> {
override fun delete(userId: String): Mono<MemberResult> {
val result = memberRepository.deleteMember(userId = userId)
if(result <= 0) {
throw BadRequestException("미등록된 회원입니다 - userId: $userId")
}

return Mono.just(userId)
return Mono.just(MemberResult(userId = userId))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.john.lotto.member.application.port.`in`

import com.john.lotto.member.adapter.`in`.web.dto.MemberResult
import reactor.core.publisher.Mono

/**
Expand All @@ -12,9 +13,9 @@ interface DeleteMemberUseCase {
* 사용자 탈퇴
*
* @param userId [String]
* @return [Mono]<[String]>
* @return [Mono]<[MemberResult]>
* @author yoonho
* @since 2023.07.19
*/
fun delete(userId: String): Mono<String>
fun delete(userId: String): Mono<MemberResult>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.john.lotto.common.exception.InternalServerException
import com.john.lotto.number.NumberRepository
import com.john.lotto.number.application.dto.LottoTotalInfo
import com.john.lotto.number.application.port.`in`.FindLottoNumberUseCase
import com.john.lotto.number.dto.LottoNumberDto
import org.slf4j.LoggerFactory
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -47,10 +46,10 @@ class NumberService(
drwtNo6 = lottoNumber.drwtNo6,
bnusNo = lottoNumber.bnusNo,

totSellamnt = lottoWinAmount.totSellamnt,
firstWinamnt = lottoWinAmount.firstWinamnt,
firstPrzwnerCo = lottoWinAmount.firstPrzwnerCo,
firstAccumamnt = lottoWinAmount.firstAccumamnt,
totSellAmount = lottoWinAmount.totSellamnt,
firstWinAmount = lottoWinAmount.firstWinamnt,
firstWinCount = lottoWinAmount.firstPrzwnerCo,
firstTotAmount = lottoWinAmount.firstAccumamnt,
)
log.info(" >>> [findLottoNumber] drwtNo: $drwtNo, result: $result")
return Mono.just(result)
Expand Down Expand Up @@ -80,10 +79,10 @@ class NumberService(
drwtNo6 = lottoNumber.drwtNo6,
bnusNo = lottoNumber.bnusNo,

totSellamnt = lottoWinAmount.totSellamnt,
firstWinamnt = lottoWinAmount.firstWinamnt,
firstPrzwnerCo = lottoWinAmount.firstPrzwnerCo,
firstAccumamnt = lottoWinAmount.firstAccumamnt,
totSellAmount = lottoWinAmount.totSellamnt,
firstWinAmount = lottoWinAmount.firstWinamnt,
firstWinCount = lottoWinAmount.firstPrzwnerCo,
firstTotAmount = lottoWinAmount.firstAccumamnt,
)
log.info(" >>> [findLottoNumberLatest] result: $result")
return Mono.just(result)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
package com.john.lotto.number.application.dto

import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDate

/**
* @author yoonho
* @since 2023.07.119
*/
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class LottoTotalInfo(
@Schema(description = "당첨회차", example = "0")
val drwtNo: Long? = -1L,

@Schema(description = "추첨일자", example = "yyyy-MM-dd")
@field:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
val drwtDate: LocalDate? = null,
@Schema(description = "당첨번호1", example = "0")
val drwtNo1: Long? = -1L,
@Schema(description = "당첨번호2", example = "0")
val drwtNo2: Long? = -1L,
@Schema(description = "당첨번호3", example = "0")
val drwtNo3: Long? = -1L,
@Schema(description = "당첨번호4", example = "0")
val drwtNo4: Long? = -1L,
@Schema(description = "당첨번호5", example = "0")
val drwtNo5: Long? = -1L,
@Schema(description = "당첨번호6", example = "0")
val drwtNo6: Long? = -1L,
@Schema(description = "보너스번호", example = "0")
val bnusNo: Long? = -1L,

val totSellamnt: Long? = -1L, // 총 판매금액
val firstWinamnt: Long? = -1L, // 1등 1게임당 당첨금액
val firstPrzwnerCo: Long? = -1L, // 1등 당첨게임수
val firstAccumamnt: Long? = -1L, // 1등 전체 당첨금액
@Schema(description = "총 판매금액", example = "0")
val totSellAmount: Long? = -1L, // 총 판매금액
@Schema(description = "1등 1게임당 당첨금액", example = "0")
val firstWinAmount: Long? = -1L, // 1등 1게임당 당첨금액
@Schema(description = "1등 당첨게임수", example = "0")
val firstWinCount: Long? = -1L, // 1등 당첨게임수
@Schema(description = "1등 전체 당첨금액", example = "0")
val firstTotAmount: Long? = -1L, // 1등 전체 당첨금액
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ScrapHandler(
fun register(request: ServerRequest): Mono<ServerResponse> =
request.bodyToMono(ScrapInput::class.java)
.flatMap { return@flatMap Mono.just(it.validate()) }
.flatMap { registerScrapUseCase.register(userId = request.userId(), rtlrid = it.rtlrid!!) }
.flatMap { registerScrapUseCase.register(userId = request.userId(), rtlrid = it.storeId!!) }
.flatMap { BaseResponse().success(it) }

/**
Expand All @@ -61,7 +61,7 @@ class ScrapHandler(
fun delete(request: ServerRequest): Mono<ServerResponse> =
deleteStoreScrapUseCase.delete(
userId = request.userId(),
rtlrid = request.queryParam("rtlrid").orElseThrow { BadRequestException("필수 입력값 누락") }.toString()
storeId = request.queryParam("storeId").orElseThrow { BadRequestException("필수 입력값 누락") }.toString()
)
.flatMap { BaseResponse().success(it) }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.john.lotto.scrap.adatper.`in`.web

import com.john.lotto.scrap.adatper.`in`.web.dto.ScrapInput
import com.john.lotto.scrap.adatper.`in`.web.dto.ScrapResult
import com.john.lotto.scrap.dto.StoreScrapDto
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.ExampleObject
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
Expand Down Expand Up @@ -86,11 +89,18 @@ class ScrapRouter(
tags = ["판매점스크랩"],
summary = "판매점스크랩 삭제",
operationId = "delete",
parameters = [
Parameter(
name = "storeId",
description = "판매점 고유ID",
example = "0"
)
],
responses = [
ApiResponse(
description = "삭제된 회원ID",
description = "삭제된 판매점스크랩 정보",
responseCode = "200",
content = [Content(schema = Schema(implementation = String::class))]
content = [Content(schema = Schema(implementation = ScrapResult::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.john.lotto.scrap.adatper.`in`.web.dto

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import com.john.lotto.common.exception.BadRequestException
import io.swagger.v3.oas.annotations.media.Schema
import java.io.Serializable
Expand All @@ -9,13 +11,14 @@ import java.io.Serializable
* @author yoonho
* @since 2023.07.23
*/
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class ScrapInput(
@Schema(description = "rtlrid", example = "1111")
val rtlrid: String? = ""
@Schema(description = "판매점 고유ID", example = "1111")
val storeId: String? = ""
): Serializable {

fun validate(): ScrapInput {
if(this.rtlrid.isNullOrEmpty()) {
if(this.storeId.isNullOrEmpty()) {
throw BadRequestException("판매점정보가 정보가 누락되었습니다.")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.john.lotto.scrap.adatper.`in`.web.dto

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

/**
* @author yoonho
* @since 2023.08.27
*/
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class ScrapResult(
val userId: String? = "",
val storeId: String? = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.john.lotto.scrap.application

import com.john.lotto.common.exception.BadRequestException
import com.john.lotto.scrap.StoreScrapRepository
import com.john.lotto.scrap.adatper.`in`.web.dto.ScrapResult
import com.john.lotto.scrap.application.port.`in`.DeleteStoreScrapUseCase
import com.john.lotto.scrap.application.port.`in`.FindStoreScrapUseCase
import com.john.lotto.scrap.application.port.`in`.RegisterScrapUseCase
Expand Down Expand Up @@ -37,7 +38,7 @@ class ScrapService(

val param = StoreScrapDto(
userId = userId,
rtlrid = rtlrid,
storeId = rtlrid,
updatedAt = null,
createdAt = LocalDateTime.now()
)
Expand All @@ -63,17 +64,17 @@ class ScrapService(
* 판매점스크랩 탈퇴
*
* @param userId [String]
* @param rtlrid [String]
* @return [Mono]<[String]>
* @param storeId [String]
* @return [Mono]<[ScrapResult]>
* @author yoonho
* @since 2023.07.23
*/
override fun delete(userId: String, rtlrid: String): Mono<String> {
val result = storeScrapRepository.deleteStoreScrap(userId = userId, rtlrid = rtlrid)
override fun delete(userId: String, storeId: String): Mono<ScrapResult> {
val result = storeScrapRepository.deleteStoreScrap(userId = userId, rtlrid = storeId)
if(result <= 0) {
throw BadRequestException("미등록된 판매점스크랩입니다 - userId: $userId, rtlrid: $rtlrid")
throw BadRequestException("미등록된 판매점스크랩입니다 - userId: $userId, rtlrid: $storeId")
}

return Mono.just(userId)
return Mono.just(ScrapResult(userId = userId, storeId = storeId))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.john.lotto.scrap.application.port.`in`

import com.john.lotto.scrap.adatper.`in`.web.dto.ScrapResult
import reactor.core.publisher.Mono

/**
Expand All @@ -12,10 +13,10 @@ interface DeleteStoreScrapUseCase {
* 판매점스크랩 탈퇴
*
* @param userId [String]
* @param rtlrid [String]
* @return [Mono]<[String]>
* @param storeId [String]
* @return [Mono]<[ScrapResult]>
* @author yoonho
* @since 2023.07.23
*/
fun delete(userId: String, rtlrid: String): Mono<String>
fun delete(userId: String, storeId: String): Mono<ScrapResult>
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StoreRouter(
operationId = "findLocation",
responses = [
ApiResponse(
description = "위치정",
description = "위치정보",
responseCode = "200",
content = [Content(schema = Schema(implementation = LocationDto::class))]
)
Expand Down
Loading

0 comments on commit d2b5e4a

Please sign in to comment.