Skip to content

Commit

Permalink
refactor : GiftCouponMessageController 상수 값 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-spear committed May 23, 2024
1 parent 72cbbba commit c161b08
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.estdelivery.coupon.application.port.`in`.web

import com.example.estdelivery.coupon.application.port.`in`.EnrollCouponByMessageUseCase
import com.example.estdelivery.coupon.application.port.`in`.FindAvailableGiftCouponUseCase
import com.example.estdelivery.coupon.application.port.`in`.GiftCouponByMessageUseCase
import com.example.estdelivery.coupon.application.port.`in`.web.dto.GiftCouponResponse
import com.example.estdelivery.coupon.application.port.`in`.web.dto.GiftCouponResponses
import com.example.estdelivery.coupon.application.port.`in`.web.dto.GiftMessageResponse
import com.example.estdelivery.coupon.domain.coupon.Coupon.FixDiscountCoupon
import com.example.estdelivery.coupon.domain.coupon.Coupon.RateDiscountCoupon
import com.example.estdelivery.coupon.domain.coupon.GiftCouponCode
import java.net.URL
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
Expand All @@ -16,14 +18,17 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

private const val MEMBER_ID = "Member-ID"

@RestController
@RequestMapping("/gift-coupons")
class GiftCouponMessageController(
private val findAvailableGiftCouponUseCase: FindAvailableGiftCouponUseCase,
private val giftCouponByMessageUseCase: GiftCouponByMessageUseCase,
private val enrollCouponByMessageUseCase: EnrollCouponByMessageUseCase,
) {
@GetMapping
fun findAvailableGiftCoupons(@RequestHeader(value = "Member-ID") memberId: Long): GiftCouponResponses =
fun findAvailableGiftCoupons(@RequestHeader(value = MEMBER_ID) memberId: Long): GiftCouponResponses =
findAvailableGiftCouponUseCase.findAvailableGiftCoupon(memberId)
.map {
GiftCouponResponse(
Expand All @@ -39,7 +44,7 @@ class GiftCouponMessageController(

@PostMapping("/send/{couponId}")
fun sendGiftAvailableCoupon(
@RequestHeader(value = "Member-ID") memberId: Long,
@RequestHeader(value = MEMBER_ID) memberId: Long,
@RequestParam message: String,
@PathVariable couponId: Long,
): GiftMessageResponse =
Expand All @@ -54,4 +59,10 @@ class GiftCouponMessageController(
enrollHref = URL("http", "localhost", 8080, "/gift-coupons/enroll/${it.giftCouponCode.code}")
)
}

@GetMapping("/enroll/{code}")
fun enrollGiftCoupon(
@RequestHeader(value = MEMBER_ID) memberId: Long,
@PathVariable code: String
) = enrollCouponByMessageUseCase.enroll(memberId, GiftCouponCode(code))
}

0 comments on commit c161b08

Please sign in to comment.