entity/Product
entity/Timestamped
// 관심 상품 등록하기
@PostMapping("/products")
public ProductResponseDto createProduct(@RequestBody ProductRequestDto requestDto) {
// 응답 보내기
return productService.createProduct(requestDto);
}
ProductRequestDto
package com.sparta.myselectshop.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ProductRequestDto {
// 관심상품명
private String title;
// 관심상품 썸네일 image URL
private String image;
// 관심상품 구매링크 URL
private String link;
// 관심상품의 최저가
private int lprice;
}
ProductResponseDto
package com.sparta.myselectshop.dto;
import com.sparta.myselectshop.entity.Product;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
public class ProductResponseDto {
private Long id;
private String title;
private String link;
private String image;
private int lprice;
private int myprice;
public ProductResponseDto(Product product) {
this.id = product.getId();
this.title = product.getTitle();
this.link = product.getLink();
this.image = product.getImage();
this.lprice = product.getLprice();
this.myprice = product.getMyprice();
}
}
public ProductResponseDto createProduct(ProductRequestDto requestDto) {
Product product = productRepository.save(new Product(requestDto));
return new ProductResponseDto(product);
}
// 관심 상품 희망 최저가 등록하기
@PutMapping("/products/{id}")
public ProductResponseDto updateProduct(@PathVariable Long id, @RequestBody ProductMypriceRequestDto requestDto) {
// 응답 보내기
return productService.updateProduct(id, requestDto);
}
관심상품 희망 최저가 업데이트 요청 DTO
ProductMypriceRequestDto
DB 조회 및 수정(Service)
Product Entity 최저 희망가(myprice) 수정(Product)