| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 88ff213 commit 2592dc1
15 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ public Page<CategoryResponse> getPageOfCategory( | |||
| 22 | 22 | @RequestParam(name = "pageNumber" , defaultValue = "0") int pageNumber , | |
| 23 | 23 | @RequestParam(name = "pageSize" , defaultValue = "0") int pageSize | |
| 24 | 24 | ){ | |
| 25 | - return categoryService.pageOfData(pageNumber, pageSize); | ||
| 25 | + return categoryService.getAllAsPage(pageNumber, pageSize); | ||
| 26 | 26 | ||
| 27 | 27 | } | |
| 28 | 28 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,69 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.controller; | ||
| 2 | + | ||
| 3 | + import com.hamzabekkaoui.ecommerceapplication.dto.request.CouponRequest; | ||
| 4 | + import com.hamzabekkaoui.ecommerceapplication.dto.response.CouponResponse; | ||
| 5 | + import com.hamzabekkaoui.ecommerceapplication.service.CouponService; | ||
| 6 | + import org.springframework.data.domain.Page; | ||
| 7 | + import org.springframework.security.access.prepost.PreAuthorize; | ||
| 8 | + import org.springframework.web.bind.annotation.*; | ||
| 9 | + | ||
| 10 | + import java.util.List; | ||
| 11 | + | ||
| 12 | + @RestController | ||
| 13 | + @RequestMapping("api/v1/coupons") | ||
| 14 | + public class CouponController { | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + private final CouponService couponService; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + public CouponController(CouponService couponService) { | ||
| 21 | + this.couponService = couponService; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @PostMapping | ||
| 25 | + @PreAuthorize("hasAuthority('ADMIN')") | ||
| 26 | + public CouponResponse createCoupon(@RequestBody CouponRequest couponRequest){ | ||
| 27 | + return this.couponService.create(couponRequest); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @PutMapping("/{couponId}") | ||
| 31 | + @PreAuthorize("hasAuthority('ADMIN')") | ||
| 32 | + public CouponResponse updateCoupon(@RequestBody CouponRequest couponRequest, @PathVariable Integer couponId){ | ||
| 33 | + return this.couponService.update(couponRequest , couponId); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + @DeleteMapping("/{couponId}") | ||
| 38 | + @PreAuthorize("hasAuthority('ADMIN')") | ||
| 39 | + public boolean deleteCoupon(@PathVariable Integer couponId){ | ||
| 40 | + return this.couponService.delete(couponId); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + @GetMapping("/list") | ||
| 45 | + @PreAuthorize("hasAuthority('ADMIN')") | ||
| 46 | + public List<CouponResponse> getAllCouponsAsList(){ | ||
| 47 | + return this.couponService.getAllAsList(); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + @GetMapping("/page") | ||
| 52 | + @PreAuthorize("hasAuthority('ADMIN')") | ||
| 53 | + public Page<CouponResponse> getAllCouponsAsPage( | ||
| 54 | + @RequestParam(name = "pageNumber", defaultValue = "0") int pageNumber, | ||
| 55 | + @RequestParam(name = "pageSize", defaultValue = "9") int pageSize | ||
| 56 | + ){ | ||
| 57 | + return this.couponService.getAllAsPage(pageNumber, pageSize); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @GetMapping("/code") | ||
| 61 | + @PreAuthorize("hasAuthority('ADMIN')") | ||
| 62 | + public CouponResponse getAllCouponsAsPage( | ||
| 63 | + @RequestParam(name = "couponCode") String couponCode | ||
| 64 | + ){ | ||
| 65 | + return this.couponService.getCouponByCode(couponCode); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ public Page<OrderResponse> getAllOrders( | |||
| 30 | 30 | @RequestParam(name = "pageNumber" , defaultValue = "0") int pageNumber , | |
| 31 | 31 | @RequestParam(name = "pageSize" , defaultValue = "0") int pageSize | |
| 32 | 32 | ){ | |
| 33 | - return orderService.pageOfData(pageNumber, pageSize); | ||
| 33 | + return orderService.getAllAsPage(pageNumber, pageSize); | ||
| 34 | 34 | ||
| 35 | 35 | } | |
| 36 | 36 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ public Page<ProductResponse> getAllProducts( | |||
| 25 | 25 | @RequestParam(name = "pageNumber" , defaultValue = "0") int pageNumber , | |
| 26 | 26 | @RequestParam(name = "pageSize" , defaultValue = "0") int pageSize | |
| 27 | 27 | ){ | |
| 28 | - return productService.pageOfData(pageNumber, pageSize); | ||
| 28 | + return productService.getAllAsPage(pageNumber, pageSize); | ||
| 29 | 29 | ||
| 30 | 30 | } | |
| 31 | 31 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.dto.request; | ||
| 2 | + | ||
| 3 | + import lombok.Builder; | ||
| 4 | + | ||
| 5 | + import java.time.LocalDateTime; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + @Builder | ||
| 9 | + public record CouponRequest( | ||
| 10 | + Double discountPercentage, | ||
| 11 | + LocalDateTime expirationDate | ||
| 12 | + ) { | ||
| 13 | + | ||
| 14 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.dto.response; | ||
| 2 | + | ||
| 3 | + import lombok.Builder; | ||
| 4 | + | ||
| 5 | + import java.time.LocalDateTime; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + @Builder | ||
| 9 | + public record CouponResponse( | ||
| 10 | + Integer id, | ||
| 11 | + String code, | ||
| 12 | + Double discountPercentage, | ||
| 13 | + LocalDateTime expirationDate, | ||
| 14 | + boolean isActive | ||
| 15 | + ) { | ||
| 16 | + | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.entity; | ||
| 2 | + | ||
| 3 | + import jakarta.persistence.Entity; | ||
| 4 | + import jakarta.persistence.GeneratedValue; | ||
| 5 | + import jakarta.persistence.GenerationType; | ||
| 6 | + import jakarta.persistence.Id; | ||
| 7 | + import lombok.*; | ||
| 8 | + | ||
| 9 | + import java.time.LocalDateTime; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + @NoArgsConstructor | ||
| 13 | + @AllArgsConstructor | ||
| 14 | + @Getter | ||
| 15 | + @Setter | ||
| 16 | + @Builder | ||
| 17 | + @Entity | ||
| 18 | + public class Coupon { | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + @Id | ||
| 22 | + @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 23 | + private Integer id; | ||
| 24 | + | ||
| 25 | + private String code; | ||
| 26 | + | ||
| 27 | + private Double discountPercentage; | ||
| 28 | + | ||
| 29 | + private LocalDateTime expirationDate; | ||
| 30 | + | ||
| 31 | + private Boolean isActive; | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.mapper; | ||
| 2 | + | ||
| 3 | + import com.hamzabekkaoui.ecommerceapplication.dto.request.CouponRequest; | ||
| 4 | + import com.hamzabekkaoui.ecommerceapplication.dto.response.CouponResponse; | ||
| 5 | + import com.hamzabekkaoui.ecommerceapplication.entity.Coupon; | ||
| 6 | + import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | + @Service | ||
| 9 | + public class CouponMapper { | ||
| 10 | + | ||
| 11 | + public CouponResponse couponToCouponResponse(Coupon coupon){ | ||
| 12 | + return CouponResponse.builder() | ||
| 13 | + .id(coupon.getId()) | ||
| 14 | + .code(coupon.getCode()) | ||
| 15 | + .discountPercentage(coupon.getDiscountPercentage()) | ||
| 16 | + .expirationDate(coupon.getExpirationDate()) | ||
| 17 | + .isActive(coupon.getIsActive()) | ||
| 18 | + .build(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public Coupon couponRequestToCoupon(CouponRequest couponRequest){ | ||
| 22 | + return Coupon.builder() | ||
| 23 | + .discountPercentage(couponRequest.discountPercentage()) | ||
| 24 | + .expirationDate(couponRequest.expirationDate()) | ||
| 25 | + .build(); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.repository; | ||
| 2 | + | ||
| 3 | + import com.hamzabekkaoui.ecommerceapplication.entity.Coupon; | ||
| 4 | + import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | + | ||
| 6 | + import java.util.Optional; | ||
| 7 | + | ||
| 8 | + public interface CouponRepository extends JpaRepository<Coupon, Integer> { | ||
| 9 | + | ||
| 10 | + Optional<Coupon> findByCode(String couponCode); | ||
| 11 | + | ||
| 12 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + package com.hamzabekkaoui.ecommerceapplication.service; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + import com.hamzabekkaoui.ecommerceapplication.dto.request.CouponRequest; | ||
| 5 | + import com.hamzabekkaoui.ecommerceapplication.dto.response.CouponResponse; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + public interface CouponService extends CrudService<CouponRequest, CouponResponse, Integer>{ | ||
| 9 | + | ||
| 10 | + CouponResponse getCouponByCode(String couponCode); | ||
| 11 | + | ||
| 12 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments