-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCouponController.java
More file actions
40 lines (33 loc) · 1.47 KB
/
CouponController.java
File metadata and controls
40 lines (33 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package NextLevel.demo.funding.controller;
import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.funding.dto.request.RequestAddCouponDto;
import NextLevel.demo.funding.dto.response.ResponseCouponDto;
import NextLevel.demo.funding.service.CouponService;
import NextLevel.demo.util.jwt.JWTUtil;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
@Controller
@RequiredArgsConstructor
public class CouponController {
private final CouponService couponService;
@PostMapping("/admin/coupon/add")
public ResponseEntity addCoupon(@RequestBody @Valid RequestAddCouponDto dto) {
if(dto.getUserId()==null)
dto.setUserId(JWTUtil.getUserIdFromSecurityContext());
couponService.addCoupon(dto);
return ResponseEntity.ok().body(new SuccessResponse("success", null));
}
@GetMapping("/social/coupon")
public ResponseEntity getCoupon() {
List<ResponseCouponDto> coupons =
couponService.couponList(JWTUtil.getUserIdFromSecurityContext())
.stream().map(ResponseCouponDto::of).toList();
return ResponseEntity.ok().body(new SuccessResponse("success", coupons));
}
}