Skip to content

Step1-상품 관리 기능#27

Open
jeus0630 wants to merge 2 commits into
next-step:jeus0630from
jeus0630:step01
Open

Step1-상품 관리 기능#27
jeus0630 wants to merge 2 commits into
next-step:jeus0630from
jeus0630:step01

Conversation

@jeus0630
Copy link
Copy Markdown

@jeus0630 jeus0630 commented May 8, 2023

별다른 설명이 없어서,
다른 라이브러리와 DB 연동 없이 진행해봤습니다.

잘 부탁 드립니다!

Copy link
Copy Markdown
Member

@Hyeon9mak Hyeon9mak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 제우님, 1단계 미션 고생하셨습니다.
최소 요구사항에 맞춘 간단한 구현!! 👍 👍 사실 이번 미션에서 꼭 DB 가 필요하진 않죠 😄 👍
그래도 유지보수 하기 쉬운 코드를 위해 코멘트를 조금 남겨보았습니다!
궁금하신 점 DM, 코멘트 남겨주세요 🙇‍♂️

Comment on lines +20 to +23
@Controller
@RequestMapping("/admin")
public class AdminController {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RestController@Controller 의 차이는 무엇일까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RestController 에는 @responsebody가 추가되어 있어서
view를 리턴하는게 아니라 JSON을 리턴해요.

Comment thread src/main/java/cart/domain/admin/AdminController.java Outdated
Comment thread src/main/java/cart/domain/admin/AdminController.java
Comment thread src/main/java/cart/domain/admin/AdminController.java
Comment thread src/main/java/cart/domain/admin/AdminController.java Outdated
package cart.domain.global;

public class Product {
private static Integer productId = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ID 는 외부에서 직접 주입 받는게 좋겠어요. Product 의 관심사는 아닌 것 같아요.
  • 원자성 보장을 위해 Atomic 타입을 활용해봐도 좋겠네요 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atomic 타입을 처음 들어봐서 찾아봤는데요,
(https://www.baeldung.com/java-atomic-variables)
setter 가 없으면 외부 수정이 불가능한데, Atomic 사용 이유가 무엇인가요?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼭 setter 를 사용하지 않더라도 생성자를 통해서 주입해줄 수 있을 것 같아요.
atomic 은 동시에 여러 요청이 전달되었을 때 원자성 보장을 위해서 사용합니다.

@RequestMapping("/admin")
public class AdminController {

private final List<Product> products;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID 를 통해 Product 를 조회한다... 는 마치 key 를 통해 value 를 조회한다... 와 비슷해 보이는데요? 😉

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음, 이 부분 말씀 의도를 제가 캐치를 못한거 같아요.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID 를 key 로 사용하고 Product 를 value 로 사용하는 Map 사용은 어떨까요?

@jeus0630 jeus0630 requested a review from Hyeon9mak May 10, 2023 14:59
@RequestMapping("/admin")
public class AdminController {

private final List<Product> products;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID 를 key 로 사용하고 Product 를 value 로 사용하는 Map 사용은 어떨까요?

Comment on lines 41 to 47
@PostMapping("/product")
public String post(
@RequestBody Product product
){
products.add(new Product(product.getName(), product.getImage(), product.getPrice()));
adminService.create(product);
return "admin";
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 요청에서 꼭 admin 페이지를 전달할 필요는 없어보여요.
페이지 뷰에 대한 요청 컨트롤러와 product 관리에 관한 요청 컨트롤러를 분리해보면 어떨까요?

package cart.domain.global;

public class Product {
private static Integer productId = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼭 setter 를 사용하지 않더라도 생성자를 통해서 주입해줄 수 있을 것 같아요.
atomic 은 동시에 여러 요청이 전달되었을 때 원자성 보장을 위해서 사용합니다.

Copy link
Copy Markdown
Member

@Hyeon9mak Hyeon9mak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 제우님! 피드백 빠르게 잘 반영해주셨습니다.
조금만 더 살펴보면 좋을 부분들 코멘트 남겼습니다.
궁금하신 점 DM, 코멘트 남겨주세요 🙇‍♂️

Comment on lines +17 to +19
public void create(Product product) {
products.add(new Product(products.get(products.size() - 1).getId() + 1, product.getName(), product.getImage(), product.getPrice()));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

products.size 에 의존하기보다 ID 를 별개로 생성해서 전달해주는 건 어떨까요?

Comment on lines 3 to 8
public class Product {
private static Integer productId = 1;
private Integer id;
private String name;
private String image;
private Integer price;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Product 는 id 를 통해 나머지 값들의 변화를 추적하므로, id 에 대해 동등성(equals & hash code)을 부여해서 관리해줘도 좋겠네요 😄 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants