From 577b80d3c8771f6a8de916992d6a97f3293f4bc6 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Thu, 27 Jun 2024 03:14:50 +0900 Subject: [PATCH 01/35] =?UTF-8?q?docs=20:=20=EA=B5=AC=ED=98=84=ED=95=A0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EB=AA=85=EC=84=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cafde8a2c..e96cb3e4e 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -# spring-gift-product \ No newline at end of file +# spring-gift-product + +구현할 기능 목록 + +상품 정보 DTO - record로 구현 (gift.web.dto.Product) + +HTTP API - ProductController (gift.web.ProductController) + +- PUT +- GET +- POST / PATCH +- DELETE From 526556b1a4cc3f91a7b7da44996ddb86e353eb4e Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 00:47:53 +0900 Subject: [PATCH 02/35] =?UTF-8?q?feat=20:=20=EC=83=81=ED=92=88=20DTO=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/Product.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/gift/web/dto/Product.java diff --git a/src/main/java/gift/web/dto/Product.java b/src/main/java/gift/web/dto/Product.java new file mode 100644 index 000000000..51454c09c --- /dev/null +++ b/src/main/java/gift/web/dto/Product.java @@ -0,0 +1,4 @@ +package gift.web.dto; + +public record Product(long id, String name, long price, String imageUrl) { +} From 6e6515ea08cab2da4fb4ed25be10e7b22174df53 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 00:48:03 +0900 Subject: [PATCH 03/35] =?UTF-8?q?feat=20:=20HTTP=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/gift/web/ProductController.java diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java new file mode 100644 index 000000000..c7d4e828d --- /dev/null +++ b/src/main/java/gift/web/ProductController.java @@ -0,0 +1,57 @@ +package gift.web; + +import gift.web.dto.Product; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController //컨트롤러를 JSON을 반환하는 컨트롤러로 만들어줌 +@RequestMapping("/api/products") +public class ProductController { + + private final Map products = new HashMap<>(); + + @GetMapping + public ResponseEntity> getProducts() { + // 여기에는 products 전체 상품을 리턴 + return new ResponseEntity<>(List.copyOf(products.values()), HttpStatus.OK); + } + + // products/{상품번호}의 GetMapping + @GetMapping("/{id}") //Query Param과 Path Variable 사용의 차이점 알아보기 + public ResponseEntity getProduct(@PathVariable Long id) { + if(products.containsKey(id)) return new ResponseEntity<>(products.get(id), HttpStatus.OK); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + @PostMapping + public ResponseEntity createProduct(@RequestBody Product product) { //RequestBody와 RequestParam의 차이점 알아보기 + products.put(product.id(), product); + return new ResponseEntity<>(product, HttpStatus.CREATED); + } + + // PUT은 업데이트시 존재하지 않는다면, 생성을 하게 되는데, POST와의 차이점?이 뭔 지 알아보기 + // PUT 구현 + @PutMapping("/{id}") + public ResponseEntity updateProduct(@PathVariable Long id, @RequestBody Product product) { + boolean exists = products.containsKey(id); + products.put(id, product); + + if(exists) { + return ResponseEntity.ok(product); + } + return ResponseEntity.status(HttpStatus.CREATED).body(product); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteProduct(@PathVariable Long id) { + if(products.containsKey(id)) { + products.remove(id); + return ResponseEntity.ok("Delete Success"); + } + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Product Not Found"); + } +} From 41ac09c77a1bf8e7f1a97ea2aaffa2695811fdcd Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 00:48:41 +0900 Subject: [PATCH 04/35] =?UTF-8?q?feat=20:=20ControllerTest=20JUnit=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/gift/web/ProductControllerTest.java | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/test/java/gift/web/ProductControllerTest.java diff --git a/src/test/java/gift/web/ProductControllerTest.java b/src/test/java/gift/web/ProductControllerTest.java new file mode 100644 index 000000000..65b44a4f1 --- /dev/null +++ b/src/test/java/gift/web/ProductControllerTest.java @@ -0,0 +1,124 @@ +package gift.web; + +import com.fasterxml.jackson.databind.ObjectMapper; +import gift.web.dto.Product; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; + +import java.util.HashMap; +import java.util.Map; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(ProductController.class) +public class ProductControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private ProductController productController; + + private Map products; + + @BeforeEach + void setup() { + products = new HashMap<>(); + + products.put(1L, new Product(1L, "Test Product 1", 100L, "http://example.com/1.jpg")); + products.put(2L, new Product(2L, "Test Product 2", 200L, "http://example.com/2.jpg")); + + ReflectionTestUtils.setField(productController, "products", products); + + mockMvc = MockMvcBuilders.standaloneSetup(productController).build(); + } + + @Test + void testGetProducts() throws Exception { + mockMvc.perform(get("/api/products") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + } + + @Test + void testGetProduct() throws Exception { + products.put(1L, new Product(1L, "Test Product 1", 100L, "http://example.com/1.jpg")); + + mockMvc.perform(get("/api/products/1")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value(1)) + .andExpect(jsonPath("$.name").value("Test Product 1")); + } + + @Test + void testGetProductNotFound() throws Exception { + mockMvc.perform(get("/api/products/999") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()); + } + + @Test + void testCreateProduct() throws Exception { + Product newProduct = new Product(3L, "New Product", 300L, "http://example.com/3.jpg"); + + mockMvc.perform(post("/api/products") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(newProduct))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.id").value(3)) + .andExpect(jsonPath("$.name").value("New Product")); + } + + @Test + void testUpdateProduct() throws Exception { + products.put(1L, new Product(1L, "Test Product 1", 100L, "http://example.com/1.jpg")); + + Product updatedProduct = new Product(1L, "Updated Product", 150L, "http://example.com/1.jpg"); + + mockMvc.perform(put("/api/products/1") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(updatedProduct))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value(1)) + .andExpect(jsonPath("$.name").value("Updated Product")); + } + + @Test + void testCreateProductWithPut() throws Exception { + Product newProduct = new Product(4L, "New Product with PUT", 400L, "http://example.com/4.jpg"); + + mockMvc.perform(put("/api/products/4") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(newProduct))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.id").value(4)) + .andExpect(jsonPath("$.name").value("New Product with PUT")); + } + + @Test + void testDeleteProduct() throws Exception { + mockMvc.perform(delete("/api/products/1") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string("Delete Success")); + } + + @Test + void testDeleteProductNotFound() throws Exception { + mockMvc.perform(delete("/api/products/999") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(content().string("Product Not Found")); + } +} From 278b54dc07034c15185291083deb9b3aa35aab90 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 03:55:10 +0900 Subject: [PATCH 05/35] =?UTF-8?q?style=20:=20README=20=EC=98=A4=EC=9E=90?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e96cb3e4e..33aadf058 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ 구현할 기능 목록 +## step1 + 상품 정보 DTO - record로 구현 (gift.web.dto.Product) HTTP API - ProductController (gift.web.ProductController) -- PUT +- POST - GET -- POST / PATCH +- PUT / PATCH - DELETE From ba85a3c1ed4e40d5728b242990a5be5aef5d465b Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 03:59:48 +0900 Subject: [PATCH 06/35] =?UTF-8?q?style=20:=20README=20=EC=98=A4=EC=9E=90?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 33aadf058..f008cc064 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,5 @@ HTTP API - ProductController (gift.web.ProductController) - GET - PUT / PATCH - DELETE + +## step2 From 557c97898b8479d6f30c720fc25a0ebcddc54b71 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 04:19:31 +0900 Subject: [PATCH 07/35] =?UTF-8?q?docs=20:=20[step2]=20README=20Step2=20?= =?UTF-8?q?=EB=AA=85=EC=84=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index f008cc064..272478479 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,10 @@ HTTP API - ProductController (gift.web.ProductController) - DELETE ## step2 + +상품을 조회, 추가, 수정, 삭제할 수 있는 관리자 화면을 구현한다. + +Thymeleaf를 사용해, HTML 폼 전송을 이용한 페이지 이동을 기반으로 구현 + +* ProductController로 view를 반환하도록 재작성 +* index(product) html, create update html 작성 From 05b42f10a4047a2e1d8635606673be6a9ce572f4 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 04:36:43 +0900 Subject: [PATCH 08/35] =?UTF-8?q?feat=20:=20[step2]=20GET=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index c7d4e828d..c399d12f1 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -6,18 +6,20 @@ import java.util.Map; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; -@RestController //컨트롤러를 JSON을 반환하는 컨트롤러로 만들어줌 +@Controller @RequestMapping("/api/products") public class ProductController { private final Map products = new HashMap<>(); @GetMapping - public ResponseEntity> getProducts() { - // 여기에는 products 전체 상품을 리턴 - return new ResponseEntity<>(List.copyOf(products.values()), HttpStatus.OK); + public String getProducts(Model model) { + model.addAttribute("data", products.values()); + return "products"; } // products/{상품번호}의 GetMapping From b9b54e3cccc730df58b2c2f8a88e18c5828bb744 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 05:31:22 +0900 Subject: [PATCH 09/35] =?UTF-8?q?feat=20:=20[step2]=20Product=20Detail=20G?= =?UTF-8?q?ET=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index c399d12f1..fa8a075fa 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -24,9 +24,9 @@ public String getProducts(Model model) { // products/{상품번호}의 GetMapping @GetMapping("/{id}") //Query Param과 Path Variable 사용의 차이점 알아보기 - public ResponseEntity getProduct(@PathVariable Long id) { - if(products.containsKey(id)) return new ResponseEntity<>(products.get(id), HttpStatus.OK); - return new ResponseEntity<>(HttpStatus.NOT_FOUND); + public String getProduct(@PathVariable Long id, Model model) { + if(products.containsKey(id)) model.addAttribute("product", products.get(id)); + return "products"; } @PostMapping From 5eaa188d88ed38835fa5fa377bee4f91194ba550 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 12:33:27 +0900 Subject: [PATCH 10/35] =?UTF-8?q?fix=20:=20[step2]=20ProductController=20?= =?UTF-8?q?=EB=B3=B5=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index fa8a075fa..c7d4e828d 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -6,27 +6,25 @@ import java.util.Map; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; -@Controller +@RestController //컨트롤러를 JSON을 반환하는 컨트롤러로 만들어줌 @RequestMapping("/api/products") public class ProductController { private final Map products = new HashMap<>(); @GetMapping - public String getProducts(Model model) { - model.addAttribute("data", products.values()); - return "products"; + public ResponseEntity> getProducts() { + // 여기에는 products 전체 상품을 리턴 + return new ResponseEntity<>(List.copyOf(products.values()), HttpStatus.OK); } // products/{상품번호}의 GetMapping @GetMapping("/{id}") //Query Param과 Path Variable 사용의 차이점 알아보기 - public String getProduct(@PathVariable Long id, Model model) { - if(products.containsKey(id)) model.addAttribute("product", products.get(id)); - return "products"; + public ResponseEntity getProduct(@PathVariable Long id) { + if(products.containsKey(id)) return new ResponseEntity<>(products.get(id), HttpStatus.OK); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } @PostMapping From 6cd18a32e7eccef8c6eed16c5fbb26e64e36f9d2 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 12:52:58 +0900 Subject: [PATCH 11/35] =?UTF-8?q?feat=20:=20[step2]=20ProductService=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductService.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/gift/web/ProductService.java diff --git a/src/main/java/gift/web/ProductService.java b/src/main/java/gift/web/ProductService.java new file mode 100644 index 000000000..2a2028106 --- /dev/null +++ b/src/main/java/gift/web/ProductService.java @@ -0,0 +1,14 @@ +package gift.web; + +import gift.web.dto.Product; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; +import org.springframework.stereotype.Service; + +@Service +public class ProductService { + private final Map products = new HashMap<>(); + +} From ce558e93d234c59a8584d71230559317a60c0c0d Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:04:39 +0900 Subject: [PATCH 12/35] =?UTF-8?q?feat=20:=20[step2]=20GET=20products=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/gift/web/ProductService.java b/src/main/java/gift/web/ProductService.java index 2a2028106..8bbb69dba 100644 --- a/src/main/java/gift/web/ProductService.java +++ b/src/main/java/gift/web/ProductService.java @@ -10,5 +10,11 @@ @Service public class ProductService { private final Map products = new HashMap<>(); + private final AtomicLong incrementCounter = new AtomicLong(1); // ID를 관리할 변수 + + public List getProducts() { + return List.copyOf(products.values()); + } + } From 731b7e6f539ea85d47fabefb317fe129a4b3f8ee Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:05:02 +0900 Subject: [PATCH 13/35] =?UTF-8?q?feat=20:=20[step2]=20GET=20product=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/gift/web/ProductService.java b/src/main/java/gift/web/ProductService.java index 8bbb69dba..0bc275f47 100644 --- a/src/main/java/gift/web/ProductService.java +++ b/src/main/java/gift/web/ProductService.java @@ -16,5 +16,9 @@ public List getProducts() { return List.copyOf(products.values()); } + public Product getProductById(Long id) { + return products.get(id); + } + } From bfe7fd910745382cae287add8120834734fc8b9a Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:05:28 +0900 Subject: [PATCH 14/35] =?UTF-8?q?feat=20:=20[step2]=20Create=20product=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/gift/web/ProductService.java b/src/main/java/gift/web/ProductService.java index 0bc275f47..70e69cfc5 100644 --- a/src/main/java/gift/web/ProductService.java +++ b/src/main/java/gift/web/ProductService.java @@ -20,5 +20,13 @@ public Product getProductById(Long id) { return products.get(id); } + public Product createProduct(Product product) { + Long id = incrementCounter.getAndIncrement(); // 1씩 증가하는 id + Product newProduct = new Product(id, product.name(), product.price(), product.imageUrl()); + products.put(id, newProduct); + + return newProduct; + } + } From d72b62b00b1343914581af138f9c400f0466eff7 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:05:44 +0900 Subject: [PATCH 15/35] =?UTF-8?q?feat=20:=20[step2]=20Update=20product=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/gift/web/ProductService.java b/src/main/java/gift/web/ProductService.java index 70e69cfc5..94e4286eb 100644 --- a/src/main/java/gift/web/ProductService.java +++ b/src/main/java/gift/web/ProductService.java @@ -28,5 +28,10 @@ public Product createProduct(Product product) { return newProduct; } + public Product updateProduct(Long id, Product product) { + products.put(id, product); + return product; + } + } From 4da57022cd1b748f7bb0133be99dafaac17320ed Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:05:57 +0900 Subject: [PATCH 16/35] =?UTF-8?q?feat=20:=20[step2]=20Delete=20product=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/gift/web/ProductService.java b/src/main/java/gift/web/ProductService.java index 94e4286eb..0a6e26aa3 100644 --- a/src/main/java/gift/web/ProductService.java +++ b/src/main/java/gift/web/ProductService.java @@ -33,5 +33,7 @@ public Product updateProduct(Long id, Product product) { return product; } - + public boolean deleteProduct(Long id) { + return products.remove(id) != null; + } } From 824a71427b0cc6851bf949bbd0dfa038fdcdab51 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:10:29 +0900 Subject: [PATCH 17/35] =?UTF-8?q?refactor=20:=20[step2]=20ProductControlle?= =?UTF-8?q?r=EC=97=90=20ProductService=20=EC=83=9D=EC=84=B1=EC=9E=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index c7d4e828d..f3141cbfd 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -12,7 +12,11 @@ @RequestMapping("/api/products") public class ProductController { - private final Map products = new HashMap<>(); + private final ProductService productService; + + public ProductController(ProductService productService) { + this.productService = productService; + } @GetMapping public ResponseEntity> getProducts() { From 0c7924e73d316388f9b0ed9d6067e9cdd384ef94 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:14:39 +0900 Subject: [PATCH 18/35] =?UTF-8?q?refactor=20:=20[step2]=20getProducts=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index f3141cbfd..f9c17d30b 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -20,8 +20,7 @@ public ProductController(ProductService productService) { @GetMapping public ResponseEntity> getProducts() { - // 여기에는 products 전체 상품을 리턴 - return new ResponseEntity<>(List.copyOf(products.values()), HttpStatus.OK); + return new ResponseEntity<>(productService.getProducts(), HttpStatus.OK); } // products/{상품번호}의 GetMapping From a09d9e6fb47c24bf4e99a885ffca7fb56718359f Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:16:26 +0900 Subject: [PATCH 19/35] =?UTF-8?q?refactor=20:=20[step2]=20getProduct=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index f9c17d30b..8059df178 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -26,7 +26,10 @@ public ResponseEntity> getProducts() { // products/{상품번호}의 GetMapping @GetMapping("/{id}") //Query Param과 Path Variable 사용의 차이점 알아보기 public ResponseEntity getProduct(@PathVariable Long id) { - if(products.containsKey(id)) return new ResponseEntity<>(products.get(id), HttpStatus.OK); + Product product = productService.getProductById(id); + if(product != null) { + return new ResponseEntity<>(product, HttpStatus.OK); + } return new ResponseEntity<>(HttpStatus.NOT_FOUND); } From 28459d60493f54233b1ff0fde4e306fe196fc644 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:16:51 +0900 Subject: [PATCH 20/35] =?UTF-8?q?style=20:=20[step2]=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index 8059df178..21c12ef48 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -25,7 +25,7 @@ public ResponseEntity> getProducts() { // products/{상품번호}의 GetMapping @GetMapping("/{id}") //Query Param과 Path Variable 사용의 차이점 알아보기 - public ResponseEntity getProduct(@PathVariable Long id) { + public ResponseEntity getProductById(@PathVariable Long id) { Product product = productService.getProductById(id); if(product != null) { return new ResponseEntity<>(product, HttpStatus.OK); From f730d4dd754f0665974d09eab489cf2d1549aa37 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:18:16 +0900 Subject: [PATCH 21/35] =?UTF-8?q?refactor=20:=20[step2]=20createProduct=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index 21c12ef48..652c14639 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -34,9 +34,8 @@ public ResponseEntity getProductById(@PathVariable Long id) { } @PostMapping - public ResponseEntity createProduct(@RequestBody Product product) { //RequestBody와 RequestParam의 차이점 알아보기 - products.put(product.id(), product); - return new ResponseEntity<>(product, HttpStatus.CREATED); + public ResponseEntity createProduct(@RequestBody Product product) { + return new ResponseEntity<>(productService.createProduct(product), HttpStatus.CREATED); } // PUT은 업데이트시 존재하지 않는다면, 생성을 하게 되는데, POST와의 차이점?이 뭔 지 알아보기 From 3045378b7542b208073cbe351b44e32ab60a740b Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:19:42 +0900 Subject: [PATCH 22/35] =?UTF-8?q?refactor=20:=20[step2]=20updateProduct=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index 652c14639..041fbcee6 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -42,9 +42,8 @@ public ResponseEntity createProduct(@RequestBody Product product) { // PUT 구현 @PutMapping("/{id}") public ResponseEntity updateProduct(@PathVariable Long id, @RequestBody Product product) { - boolean exists = products.containsKey(id); - products.put(id, product); - + boolean exists = productService.getProductById(id) != null; + productService.updateProduct(id, product); if(exists) { return ResponseEntity.ok(product); } From 0e2855d3830ea02bfac833b7741a10dc2de29a05 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:20:49 +0900 Subject: [PATCH 23/35] =?UTF-8?q?refactor=20:=20[step2]=20deleteProduct=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index 041fbcee6..c30fac5f1 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -52,8 +52,7 @@ public ResponseEntity updateProduct(@PathVariable Long id, @RequestBody Produ @DeleteMapping("/{id}") public ResponseEntity deleteProduct(@PathVariable Long id) { - if(products.containsKey(id)) { - products.remove(id); + if(productService.deleteProduct(id)) { return ResponseEntity.ok("Delete Success"); } return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Product Not Found"); From 387afa47bbc7601ed705a3c662adb5612418481d Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:24:55 +0900 Subject: [PATCH 24/35] =?UTF-8?q?feat=20:=20[step2]=20AdminController=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/AdminController.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/gift/web/dto/AdminController.java diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java new file mode 100644 index 000000000..1a8e7cae4 --- /dev/null +++ b/src/main/java/gift/web/dto/AdminController.java @@ -0,0 +1,8 @@ +package gift.web.dto; + +import org.springframework.stereotype.Controller; + +@Controller +public class AdminController { + +} From 1643f6ec6ca80968aae9e2772567c32200d80d24 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:29:20 +0900 Subject: [PATCH 25/35] =?UTF-8?q?feat=20:=20[step2]=20getProducts=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/AdminController.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index 1a8e7cae4..3c89e118d 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -1,8 +1,21 @@ package gift.web.dto; +import gift.web.ProductService; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; @Controller public class AdminController { + private final ProductService productService; + public AdminController(ProductService productService) { + this.productService = productService; + } + + @GetMapping + public String getProducts(Model model) { + model.getAttribute("products", productService.getProducts()); + return "products"; + } } From dc50ce15dc0f7d5e2c546c6472d4f7d1ddc49afb Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:32:39 +0900 Subject: [PATCH 26/35] =?UTF-8?q?feat=20:=20[step2]=20getProductById=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/AdminController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index 3c89e118d..c0f077719 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -4,8 +4,11 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; @Controller +@RequestMapping("/admin/products") public class AdminController { private final ProductService productService; @@ -18,4 +21,13 @@ public String getProducts(Model model) { model.getAttribute("products", productService.getProducts()); return "products"; } + + @GetMapping("/{id}") + public String getProductById(@PathVariable Long id, Model model) { + Product product = productService.getProductById(id); + if (product != null) { + model.addAttribute("product", product); + } + return "products"; + } } From 34aa0a2e6624660dd10474eaf2fca449768e3796 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:39:24 +0900 Subject: [PATCH 27/35] =?UTF-8?q?feat=20:=20[step2]=20createProduct=20form?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/AdminController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index c0f077719..6a52dee29 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -30,4 +30,9 @@ public String getProductById(@PathVariable Long id, Model model) { } return "products"; } + + @GetMapping("/create") + public String createProduct(Model model) { + return "create"; + } } From 8e6006988363584838bf27f82149d1fcc3fcd588 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:46:36 +0900 Subject: [PATCH 28/35] =?UTF-8?q?feat=20:=20[step2]=20createProduct=20POST?= =?UTF-8?q?=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/AdminController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index 6a52dee29..791fc27d8 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -4,7 +4,9 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @@ -35,4 +37,10 @@ public String getProductById(@PathVariable Long id, Model model) { public String createProduct(Model model) { return "create"; } + + @PostMapping + public String createProduct(@ModelAttribute Product product) { + productService.createProduct(product); + return "redirect:/admin/products"; + } } From daf36c1f0d6303f0b1ad2be31ebab8621a789229 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 13:59:22 +0900 Subject: [PATCH 29/35] =?UTF-8?q?feat=20:=20[step2]=20update=20delete=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/gift/web/dto/AdminController.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index 791fc27d8..d2df8f5e0 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -34,7 +34,7 @@ public String getProductById(@PathVariable Long id, Model model) { } @GetMapping("/create") - public String createProduct(Model model) { + public String createProductForm(Model model) { return "create"; } @@ -43,4 +43,25 @@ public String createProduct(@ModelAttribute Product product) { productService.createProduct(product); return "redirect:/admin/products"; } + + @GetMapping("/edit/{id}") + public String editProductForm(@PathVariable Long id, Model model) { + Product product = productService.getProductById(id); + if (product != null) { + model.addAttribute("product", product); + } + return "edit"; + } + + @PostMapping("/edit/{id}") + public String editProduct(@PathVariable Long id, @ModelAttribute Product product) { + productService.updateProduct(id, product); + return "redirect:/admin/products"; + } + + @PostMapping("/delete/{id}") + public String deleteProduct(@PathVariable Long id) { + productService.deleteProduct(id); + return "redirect:/admin/products"; + } } From 7f3f2394f07f6160ddb02d8ab4fe95b6a0bf36f6 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 14:37:15 +0900 Subject: [PATCH 30/35] =?UTF-8?q?fix=20:=20[step2]=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/dto/AdminController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index d2df8f5e0..08a8b7fae 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -20,7 +20,7 @@ public AdminController(ProductService productService) { @GetMapping public String getProducts(Model model) { - model.getAttribute("products", productService.getProducts()); + model.addAttribute("products", productService.getProducts()); return "products"; } From a75b8036b7f74103273ccbdc2ca0b5236d78b3b8 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 14:37:43 +0900 Subject: [PATCH 31/35] =?UTF-8?q?refactor=20:=20[step2]=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/gift/web/ProductController.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/gift/web/ProductController.java b/src/main/java/gift/web/ProductController.java index c30fac5f1..7cd223e0c 100644 --- a/src/main/java/gift/web/ProductController.java +++ b/src/main/java/gift/web/ProductController.java @@ -1,9 +1,7 @@ package gift.web; import gift.web.dto.Product; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; From 98cfa59f5a9144e328ff6ddf66a5ae6a3b784174 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 14:39:34 +0900 Subject: [PATCH 32/35] =?UTF-8?q?feat=20:=20[step2]=20=EC=83=81=ED=92=88?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EB=B3=B4=EC=97=AC?= =?UTF-8?q?=EC=A3=BC=EB=8A=94=20html=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/products.html | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/resources/templates/products.html diff --git a/src/main/resources/templates/products.html b/src/main/resources/templates/products.html new file mode 100644 index 000000000..f64518ee1 --- /dev/null +++ b/src/main/resources/templates/products.html @@ -0,0 +1,30 @@ + + + + + Products + + + +

상품 목록

+ 새 상품 만들기 + + + + + + + + + + + + + + +
IDNamePriceActions
1상품 이름예시5000https://image.jpg + Edit + Delete +
+ + \ No newline at end of file From 869af5d41646f3860e94b017930ba9d23c579854 Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 14:59:31 +0900 Subject: [PATCH 33/35] =?UTF-8?q?feat=20:=20[step2]=20html=20thymeleaf=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/products.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/resources/templates/products.html b/src/main/resources/templates/products.html index f64518ee1..323eb05f9 100644 --- a/src/main/resources/templates/products.html +++ b/src/main/resources/templates/products.html @@ -15,14 +15,16 @@

상품 목록

Price Actions - - 1 - 상품 이름예시 - 5000 - https://image.jpg + + 1 + 상품 이름예시 + 5000 + https://image.jpg - Edit - Delete + Edit +
+ +
From b70ec2f974bbf41b998b77d23a7c7fd0f842b9bf Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 15:34:34 +0900 Subject: [PATCH 34/35] =?UTF-8?q?feat=20:=20[step2]=20create=20html=20form?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/gift/web/dto/AdminController.java | 3 +- src/main/java/gift/web/dto/Product.java | 2 +- src/main/resources/templates/create.html | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/templates/create.html diff --git a/src/main/java/gift/web/dto/AdminController.java b/src/main/java/gift/web/dto/AdminController.java index 08a8b7fae..84b2481ee 100644 --- a/src/main/java/gift/web/dto/AdminController.java +++ b/src/main/java/gift/web/dto/AdminController.java @@ -35,10 +35,11 @@ public String getProductById(@PathVariable Long id, Model model) { @GetMapping("/create") public String createProductForm(Model model) { + model.addAttribute("product", new Product(1L, "name", 0L, "image.url")); return "create"; } - @PostMapping + @PostMapping("/create") public String createProduct(@ModelAttribute Product product) { productService.createProduct(product); return "redirect:/admin/products"; diff --git a/src/main/java/gift/web/dto/Product.java b/src/main/java/gift/web/dto/Product.java index 51454c09c..92e7f154c 100644 --- a/src/main/java/gift/web/dto/Product.java +++ b/src/main/java/gift/web/dto/Product.java @@ -1,4 +1,4 @@ package gift.web.dto; -public record Product(long id, String name, long price, String imageUrl) { +public record Product(Long id, String name, Long price, String imageUrl) { } diff --git a/src/main/resources/templates/create.html b/src/main/resources/templates/create.html new file mode 100644 index 000000000..06e30befa --- /dev/null +++ b/src/main/resources/templates/create.html @@ -0,0 +1,28 @@ + + + + + Product Create + + + +

상품 생성

+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + \ No newline at end of file From 599165246f7dcf4a872116c1b2760e0173c4e62f Mon Sep 17 00:00:00 2001 From: yoong-saks Date: Fri, 28 Jun 2024 15:51:01 +0900 Subject: [PATCH 35/35] =?UTF-8?q?feat=20:=20[step2]=20edit=20html=20form?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/edit.html | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/resources/templates/edit.html diff --git a/src/main/resources/templates/edit.html b/src/main/resources/templates/edit.html new file mode 100644 index 000000000..97b1ee006 --- /dev/null +++ b/src/main/resources/templates/edit.html @@ -0,0 +1,28 @@ + + + + + Product Create + + + +

상품 수정

+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + \ No newline at end of file