Skip to content

Commit 81016a8

Browse files
committed
Added setProductSize endpoint and repository method
1 parent 748f748 commit 81016a8

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

backend-track/week-9/hyf-shop/src/main/java/net/hackyourfuture/hyfshop/product/ProductController.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import jakarta.annotation.Nullable;
44
import lombok.AllArgsConstructor;
55
import net.hackyourfuture.hyfshop.product.dto.ProductResponse;
6-
import org.springframework.web.bind.annotation.GetMapping;
7-
import org.springframework.web.bind.annotation.RequestMapping;
8-
import org.springframework.web.bind.annotation.RequestParam;
9-
import org.springframework.web.bind.annotation.RestController;
6+
import net.hackyourfuture.hyfshop.product.dto.SetSizeRequest;
7+
import org.springframework.web.bind.annotation.*;
108

119
import java.util.List;
1210

@@ -28,5 +26,10 @@ public List<ProductResponse> searchProducts(@Nullable @RequestParam("color") Str
2826
}
2927
return productService.searchProducts(color);
3028
}
29+
30+
@PutMapping("/{id}/size")
31+
public ProductResponse setProductSize(@PathVariable int id, @RequestBody SetSizeRequest request) {
32+
return productService.setProductSize(id, request.size());
33+
}
3134
}
3235

backend-track/week-9/hyf-shop/src/main/java/net/hackyourfuture/hyfshop/product/ProductRepository.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,22 @@ public List<Product> getAllProducts() {
2828

2929
}
3030

31+
public Product findById(int id) {
32+
return jdbcClient
33+
.sql("SELECT id, title, price, category FROM products WHERE id=:id")
34+
.param("id", id)
35+
.query(PRODUCT_ROW_MAPPER)
36+
.single();
37+
38+
}
39+
3140
public List<Product> findByColor(String color) {
3241
// TODO: Implement
3342
throw new UnsupportedOperationException("Not implemented yet");
3443
}
44+
45+
public Product setSize(int id, String size) {
46+
// TODO: Implement
47+
throw new UnsupportedOperationException("Not implemented yet");
48+
}
3549
}

backend-track/week-9/hyf-shop/src/main/java/net/hackyourfuture/hyfshop/product/ProductService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public List<ProductResponse> getAllProducts() {
1818
public List<ProductResponse> searchProducts(String color) {
1919
return productRepository.findByColor(color).stream().map(ProductResponse::from).toList();
2020
}
21+
22+
public ProductResponse setProductSize(int id, String size) {
23+
productRepository.setSize(id, size);
24+
return ProductResponse.from(productRepository.findById(id));
25+
}
2126
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package net.hackyourfuture.hyfshop.product.dto;
2+
3+
public record SetSizeRequest(String size) { }

0 commit comments

Comments
 (0)