Skip to content

Commit

Permalink
✨feature : 판매점 스크랩 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkYunHo committed Jul 23, 2023
1 parent 08ec6c2 commit 37bc9b8
Show file tree
Hide file tree
Showing 13 changed files with 534 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.john.lotto.common.exception.UnAuthorizedException
import com.john.lotto.common.utils.CipherUtils
import com.john.lotto.common.utils.EnvironmentUtils
import com.john.lotto.common.utils.ObjectMapperUtils
import com.john.lotto.member.MemberRepository
import io.jsonwebtoken.ExpiredJwtException
import io.jsonwebtoken.Jwts
import org.slf4j.LoggerFactory
Expand All @@ -36,7 +37,7 @@ import java.util.*
@Component
class KakaoAuthAdapter(
private val defaultWebClient: WebClient,
private val objectMapper: ObjectMapper
private val memberRepository: MemberRepository
): AuthPort {
private val log = LoggerFactory.getLogger(this::class.java)

Expand Down Expand Up @@ -199,6 +200,13 @@ class KakaoAuthAdapter(
}

val userId = CipherUtils.encode(str = "${CommCode.Social.KAKAO.code}:${claims.subject}")

// 회원정보 등록여부 체크
val existsMember = memberRepository.findMember(userId = userId)
if(existsMember == null) {
return Mono.error(UnAuthorizedException("등록된 회원이 아닙니다 - userId: $userId"))
}

return Mono.just(userId)
} catch (uae: UnAuthorizedException) {
return Mono.error(uae)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.john.lotto.member.adapter.`in`.web

import com.john.lotto.member.adapter.`in`.web.dto.MemberInput
import com.john.lotto.member.dto.MemberDto
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import org.springdoc.core.annotations.RouterOperation
import org.springdoc.core.annotations.RouterOperations
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.reactive.function.server.RouterFunction
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.reactive.function.server.router
Expand All @@ -17,6 +28,76 @@ class MemberRouter(
) {

@Bean
@RouterOperations(
value = [
RouterOperation(
path = "/api/member",
method = [RequestMethod.POST],
beanClass = MemberHandler::class,
beanMethod = "register",
operation = Operation(
tags = ["회원정보"],
summary = "회원정보 등록",
operationId = "register",
requestBody = RequestBody(
required = true,
description = "회원 등록정보",
content = [
Content(
schema = Schema(implementation = MemberInput::class)
)
]
),
responses = [
ApiResponse(
description = "등록된 회원정보",
responseCode = "200",
content = [Content(schema = Schema(implementation = MemberDto::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
)
),
RouterOperation(
path = "/api/member",
method = [RequestMethod.GET],
beanClass = MemberHandler::class,
beanMethod = "search",
operation = Operation(
tags = ["회원정보"],
summary = "회원정보 조회",
operationId = "search",
responses = [
ApiResponse(
description = "회원정보",
responseCode = "200",
content = [Content(schema = Schema(implementation = MemberDto::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
)
),
RouterOperation(
path = "/api/member",
method = [RequestMethod.DELETE],
beanClass = MemberHandler::class,
beanMethod = "delete",
operation = Operation(
tags = ["회원정보"],
summary = "회원정보 삭제",
operationId = "delete",
responses = [
ApiResponse(
description = "삭제된 회원ID",
responseCode = "200",
content = [Content(schema = Schema(implementation = String::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
)
),
]
)
fun memberRouterFunction(): RouterFunction<ServerResponse> = router {
accept(MediaType.APPLICATION_JSON).nest {
POST("/api/member", memberHandler::register)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NumberRouter(
beanClass = NumberHandler::class,
beanMethod = "findLottoNumber",
operation = Operation(
tags = ["당첨번호 조회"],
tags = ["당첨번호"],
summary = "특정 당첨번호 조회",
operationId = "findLottoNumber",
parameters = [
Expand Down Expand Up @@ -67,7 +67,7 @@ class NumberRouter(
beanClass = NumberHandler::class,
beanMethod = "findLottoNumberLatest",
operation = Operation(
tags = ["당첨번호 조회"],
tags = ["당첨번호"],
summary = "최신 당첨번호 조회",
operationId = "findLottoNumberLatest",
responses = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
package com.john.lotto.scrap.adatper.`in`.web

import com.john.lotto.common.dto.BaseResponse
import com.john.lotto.common.exception.BadRequestException
import com.john.lotto.common.filter.userId
import com.john.lotto.scrap.adatper.`in`.web.dto.ScrapInput
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
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
import reactor.core.publisher.Mono

/**
* @author yoonho
* @since 2023.07.19
*/
@Component
class ScrapHandler(

private val registerScrapUseCase: RegisterScrapUseCase,
private val findStoreScrapUseCase: FindStoreScrapUseCase,
private val deleteStoreScrapUseCase: DeleteStoreScrapUseCase
) {

// TODO:
// - 스크랩 조회
// - 스크랩 등록
// - 스크랩 삭제
/**
* 판매점스크랩 등록
*
* @param request [ServerRequest]
* @return [Mono]<[ServerResponse]>
* @author yoonho
* @since 2023.07.23
*/
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 { BaseResponse().success(it) }

/**
* 판매점스크랩 조회
*
* @param request [ServerRequest]
* @return [Mono]<[ServerResponse]>
* @author yoonho
* @since 2023.07.23
*/
fun search(request: ServerRequest): Mono<ServerResponse> =
findStoreScrapUseCase.search(userId = request.userId())
.collectList()
.flatMap { BaseResponse().success(it) }

/**
* 판매점스크랩 탈퇴
*
* @param request [ServerRequest]
* @return [Mono]<[ServerResponse]>
* @author yoonho
* @since 2023.07.23
*/
fun delete(request: ServerRequest): Mono<ServerResponse> =
deleteStoreScrapUseCase.delete(
userId = request.userId(),
rtlrid = request.queryParam("rtlrid").orElseThrow { BadRequestException("필수 입력값 누락") }.toString()
)
.flatMap { BaseResponse().success(it) }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.john.lotto.scrap.adatper.`in`.web

import com.john.lotto.scrap.adatper.`in`.web.dto.ScrapInput
import com.john.lotto.scrap.dto.StoreScrapDto
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import org.springdoc.core.annotations.RouterOperation
import org.springdoc.core.annotations.RouterOperations
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.reactive.function.server.RouterFunction
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.reactive.function.server.router
Expand All @@ -16,10 +27,82 @@ class ScrapRouter(
private val scrapHandler: ScrapHandler
) {

// @Bean
// fun scrapRouterFunction(): RouterFunction<ServerResponse> = router {
// accept(MediaType.APPLICATION_JSON).nest {
//// POST("/api/member", memberHandler::register)
// }
// }
@Bean
@RouterOperations(
value = [
RouterOperation(
path = "/api/scrap/store",
method = [RequestMethod.POST],
beanClass = ScrapHandler::class,
beanMethod = "register",
operation = Operation(
tags = ["판매점스크랩"],
summary = "판매점스크랩 등록",
operationId = "register",
requestBody = RequestBody(
required = true,
description = "판매점스크랩 등록정보",
content = [
Content(
schema = Schema(implementation = ScrapInput::class)
)
]
),
responses = [
ApiResponse(
description = "등록된 판매점스크랩정보",
responseCode = "200",
content = [Content(schema = Schema(implementation = StoreScrapDto::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
)
),
RouterOperation(
path = "/api/scrap/store",
method = [RequestMethod.GET],
beanClass = ScrapHandler::class,
beanMethod = "search",
operation = Operation(
tags = ["판매점스크랩"],
summary = "판매점스크랩 조회",
operationId = "search",
responses = [
ApiResponse(
description = "판매점스크랩 정보",
responseCode = "200",
content = [Content(schema = Schema(implementation = StoreScrapDto::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
)
),
RouterOperation(
path = "/api/scrap/store",
method = [RequestMethod.DELETE],
beanClass = ScrapHandler::class,
beanMethod = "delete",
operation = Operation(
tags = ["판매점스크랩"],
summary = "판매점스크랩 삭제",
operationId = "delete",
responses = [
ApiResponse(
description = "삭제된 회원ID",
responseCode = "200",
content = [Content(schema = Schema(implementation = String::class))]
)
],
security = [SecurityRequirement(name = "OpenID Connection Authentication")]
)
),
]
)
fun scrapRouterFunction(): RouterFunction<ServerResponse> = router {
accept(MediaType.APPLICATION_JSON).nest {
POST("/api/scrap/store", scrapHandler::register)
GET("/api/scrap/store", scrapHandler::search)
DELETE("/api/scrap/store", scrapHandler::delete)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.john.lotto.scrap.adatper.`in`.web.dto

import com.john.lotto.common.exception.BadRequestException
import io.swagger.v3.oas.annotations.media.Schema
import java.io.Serializable


/**
* @author yoonho
* @since 2023.07.23
*/
data class ScrapInput(
@Schema(description = "rtlrid", example = "1111")
val rtlrid: String? = ""
): Serializable {

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

return this
}
}
Loading

0 comments on commit 37bc9b8

Please sign in to comment.