I have a Coupon Table in the database so there are CouponEntity and CouponDto in the application. My question is about handling two endpoints with one Dto. for example, I have create and update endpoints, both of them use CouponDto. There is a business role that I can't update code property of the coupon entity. How to ignore it if the client passes this property in the request?
If I use @JsonIgnore, the property will be ignored in both the endpoints that I need to get it in create API. I used groups for validations and separate validations from each other, but @JsonIgnore can not be set sometimes.
For create a coupon:
@PostMapping("/create")
public ResponseEntity<?> createCoupon(@RequestBody CouponCodeDTO couponCodeDTO) {
return ResponseEntity.ok(couponService.create(couponCodeDTO));
}
For update a coupon:
@PutMapping("/update/{id}")
public ResponseEntity<?> updateCoupon(
@PathVariable Long id, @RequestBody CouponCodeDTO couponCodeDTO
) {
return ResponseEntity.ok(couponService.update(id, couponCodeDTO));
}
And CouponDto:
public class CouponCodeDto extends BaseDto<Integer> {
@NotBlank
private String code;
private Integer availableCount;
@NotNull
private LocalDate startDate;
...
}