Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring 장바구니 - 2단계] 조동현(후디) 미션 제출합니다. #130

Merged
merged 60 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6de48aa
docs: 2단계 기능 구현 목록 작성
devHudi Jun 6, 2022
1069430
feat: 상품 도메인에 설명, 재고수량 필드 추가
devHudi Jun 6, 2022
44f8494
refactor: 상품을 찾을 수 없을 경우에 대한 예외 추가
devHudi Jun 6, 2022
52f4fae
docs: 기능 구현 목록 반영
devHudi Jun 6, 2022
dc98d78
feat: 액세스 토큰에서 유저 아이디를 추출하는 Argument Resolver 구현
devHudi Jun 6, 2022
a4ce601
refactor: Cart Item API가 유저를 식별할 때 customerName 대신 액세스 토큰으로 식별하도록 변경
devHudi Jun 6, 2022
8124935
refactor: Order API가 유저를 식별할 때 customerName 대신 액세스 토큰으로 식별하도록 변경
devHudi Jun 6, 2022
85a0ec9
docs: 2단계 기능 구현 목록 추가
devHudi Jun 7, 2022
b8f6767
test: 장바구니 및 주문 API에 인가 테스트 추가 (토큰 만료, 토큰 유효하지 않음)
devHudi Jun 7, 2022
a2a0846
docs: 2단계 기능 구현 목록 갱신
devHudi Jun 7, 2022
aba2859
feat: 변경된 명세에 따라 카트 아이템 추가 및 조회 기능 수정
devHudi Jun 7, 2022
9ec5601
feat: 특정 상품이 특정 유저의 장바구니에 존재하는지 여부를 조회하는 API 구현
devHudi Jun 7, 2022
393d7d9
refactor: dto를 요청과 응답에 따라 패키지 분리
devHudi Jun 7, 2022
a7e5756
feat: 장바구니 수정 API 기능 구현
devHudi Jun 7, 2022
3333130
docs: 2단계 기능 구현 목록 변경
devHudi Jun 7, 2022
0e807fd
feat: 장바구니 추가 시 존재하지 않은 제품 ID를 전달받은 경우 404에러가 발생하도록 구현
devHudi Jun 7, 2022
62b4f6f
feat: 장바구니 항목 삭제 시 존재하지 않은 장바구니 항목 ID가 전달되면 404 에러가 발생하도록 수정
devHudi Jun 7, 2022
7fa5bfb
docs: 기능 개선 목록 갱신
devHudi Jun 7, 2022
ba4b053
feat: 주문 추가, 조회 기능을 변경된 기획에 맞게 수정
devHudi Jun 8, 2022
a0b80fe
feat: 카트 아이템 수정 시 요청한 카트 아이템의 productId 와, Body 의 productId 가 다를 경우 4…
devHudi Jun 8, 2022
5a6fd00
refactor: Dao에 대한 인터페이스 추가
devHudi Jun 8, 2022
9fb21e8
refactor: ResponseEntity에 제네릭 타입 추가
devHudi Jun 8, 2022
7d74ce3
refactor: cartId를 cartItemId로 변경
devHudi Jun 8, 2022
6842fb2
refactor: single_order 테이블을 orders로, order_product 테이블을 order_detail로 변경
devHudi Jun 8, 2022
c6e0af3
refactor: SQL내의 대문자로 되어있는 테이블이름을 소문자로 변경
devHudi Jun 8, 2022
3d22fc9
refactor: schema.sql 에서 외래키를 설정할 때 alter table 대신 create table 에서 외래키…
devHudi Jun 8, 2022
b957caf
chore: mysql-connector-java 의존성 추가
devHudi Jun 8, 2022
4e87602
fix: 테이블명을 소문자로 변경
devHudi Jun 8, 2022
270d77d
refactor: 불필요한 출력 로직 제거
devHudi Jun 8, 2022
202aff9
feat: 회원 요청과 응답 DTO의 depth 제거
devHudi Jun 8, 2022
8b8e89f
feat: zoneCode와 ZoneCode를 zonecode, Zonecode로 변경
devHudi Jun 8, 2022
c07cca7
feat: 전체 장바구니 조회시 ID 필드를 id에서 cartItemId로 변경
devHudi Jun 8, 2022
a6d7807
feat: 이미 장바구니에 담긴 상품을 또다시 등록하면 400에러가 발생하도록 구현
devHudi Jun 8, 2022
54fab62
feat: 에러 반환을 문자열 대신 ErrorResponse로 하도록 개선
devHudi Jun 8, 2022
f72463b
feat: 회원가입 시 이미 이메일이 존재하는 경우 400 에러 발생
devHudi Jun 8, 2022
4f54ff4
refactor: API 문서에 따라 토큰 발급 응답값의 회원 ID필드를 customerId에서 userId로 변경
devHudi Jun 8, 2022
b835c77
fix: preflight 대응 위해 AuthInterceptor preHandle 메소드 수정
devHudi Jun 8, 2022
4e4cd9b
refactor: JdbcCartItemDao에 SimpleJdbcInsert 사용하여 코드 개선
devHudi Jun 8, 2022
adef1f1
refactor: CustomerDao의 조회 메서드에서 EmptyResultDataAccessException을 Custo…
devHudi Jun 8, 2022
22a3c36
test: 인수 테스트 최적화
devHudi Jun 8, 2022
9ccb697
refactor: OrdersDao와 OrderDetailDao 분리
devHudi Jun 8, 2022
0c4ab1b
refactor: JdbcOrdersDao 리팩토링
devHudi Jun 8, 2022
f7a2d0c
refactor: JdbcProductDao 리팩토링
devHudi Jun 8, 2022
d5199a3
refactor: auth 패키지와 shoppingcart 패키지의 Config를 병합
devHudi Jun 8, 2022
60e106a
docs: 기능 구현 목록 개선
devHudi Jun 9, 2022
38f6e7f
feat: schema에 on delete 제약 조건 추가
devHudi Jun 9, 2022
d79ef38
fix: 빈 BirthDay의 value를 null로 설정
devHudi Jun 9, 2022
f7e3a5b
refactor: ProductRepository 구현
devHudi Jun 10, 2022
7878409
refactor: OrderRepository 구현
devHudi Jun 11, 2022
3d4b09d
refactor: CustomerRepository 구현
devHudi Jun 11, 2022
b75374c
refactor: CartItemRepository 구현
devHudi Jun 11, 2022
a1e45dc
refactor: 단건 조회시 DAO가 Optional을 반환하도록 개선
devHudi Jun 11, 2022
956ee2f
refactor: 일관적이지 않게 사용된 final 키워드 제거 (파라미터 및 지역변수)
devHudi Jun 11, 2022
946516f
refactor: final 키워드 추가
devHudi Jun 11, 2022
bc35f65
refactor: 사용되지 않는 코드 제거
devHudi Jun 11, 2022
19c820a
refactor: Id 도메인 제거
devHudi Jun 11, 2022
58bcd51
refactor: Spring Security 의존성 제거
devHudi Jun 11, 2022
81b1c5d
refactor: RowMapper를 상수로 변경
devHudi Jun 11, 2022
629133f
refactor: 컬럼이름을 상수로 분리
devHudi Jun 11, 2022
0f6eaaf
refactor: DTO의 생성자 파라미터로 도메인 객체를 전달하여 DTO를 생성할 수 있도록 개선
devHudi Jun 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:4.4.0'
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/woowacourse/SecurityConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public boolean supportsParameter(MethodParameter parameter) {

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
String accessToken = AuthorizationExtractor.extract((HttpServletRequest) webRequest.getNativeRequest());
return Long.parseLong(jwtTokenProvider.getPayload(accessToken));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/woowacourse/auth/dto/TokenResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class TokenResponse {
private String accessToken;
private int userId;
private long userId;

public TokenResponse() {
}

public TokenResponse(String accessToken, int userId) {
public TokenResponse(String accessToken, long userId) {
this.accessToken = accessToken;
this.userId = userId;
}
Expand All @@ -16,7 +16,7 @@ public String getAccessToken() {
return accessToken;
}

public int getUserId() {
public long getUserId() {
return userId;
}

Expand Down
32 changes: 16 additions & 16 deletions src/main/java/woowacourse/auth/service/AuthService.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
package woowacourse.auth.service;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import woowacourse.auth.dto.TokenRequest;
import woowacourse.auth.dto.TokenResponse;
import woowacourse.auth.exception.authentication.LoginFailedException;
import woowacourse.auth.support.JwtTokenProvider;
import woowacourse.shoppingcart.dao.CustomerDao;
import woowacourse.shoppingcart.domain.customer.Customer;
import woowacourse.shoppingcart.domain.customer.Password;
import woowacourse.shoppingcart.entity.CustomerEntity;
import woowacourse.shoppingcart.repository.CustomerRepository;

@Service
public class AuthService {
private final CustomerDao customerDao;
private final CustomerRepository customerRepository;
private final JwtTokenProvider jwtTokenProvider;

public AuthService(CustomerDao customerDao, JwtTokenProvider jwtTokenProvider) {
this.customerDao = customerDao;
public AuthService(CustomerRepository customerRepository, JwtTokenProvider jwtTokenProvider) {
this.customerRepository = customerRepository;
this.jwtTokenProvider = jwtTokenProvider;
}

public void validateToken(String accessToken) {
jwtTokenProvider.validateToken(accessToken);
}

public TokenResponse generateToken(TokenRequest tokenRequest) {
String email = tokenRequest.getEmail();
String password = tokenRequest.getPassword();
validateEmailExisting(email);
CustomerEntity customerEntity = customerDao.findByEmail(email);
validatePassword(password, customerEntity);

int customerId = customerEntity.getId();
Customer customer = customerRepository.findByEmail(email);
validatePassword(password, customer);

long customerId = customer.getId();
String token = jwtTokenProvider.createToken(String.valueOf(customerId));

return new TokenResponse(token, customerId);
}

public void validateToken(String accessToken) {
jwtTokenProvider.validateToken(accessToken);
}

private void validateEmailExisting(String email) {
if (!customerDao.existsByEmail(email)) {
if (!customerRepository.existsByEmail(email)) {
throw new LoginFailedException();
}
}

private void validatePassword(String password, CustomerEntity customerEntity) {
Password cipherPassword = new Password(customerEntity.getPassword(), new BCryptPasswordEncoder());
private void validatePassword(String password, Customer customer) {
Password cipherPassword = customer.getPassword();
boolean isValid = cipherPassword.matches(password);

if (!isValid) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package woowacourse.auth.support;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;

public class AuthorizationExtractor {
public static final String AUTHORIZATION = "Authorization";
public static String BEARER_TYPE = "Bearer";
public static final String BEARER_TYPE = "Bearer";
public static final String ACCESS_TOKEN_TYPE = AuthorizationExtractor.class.getSimpleName() + ".ACCESS_TOKEN_TYPE";

public static String extract(HttpServletRequest request) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/woowacourse/auth/support/JwtTokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class JwtTokenProvider {
private final SecretKey secretKey;
private final long validityInMilliseconds;

public JwtTokenProvider(@Value("${security.jwt.token.secret-key}") final String secretKey,
@Value("${security.jwt.token.expire-length}") final long validityInMilliseconds) {
public JwtTokenProvider(@Value("${security.jwt.token.secret-key}") String secretKey,
@Value("${security.jwt.token.expire-length}") long validityInMilliseconds) {
this.secretKey = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8));
this.validityInMilliseconds = validityInMilliseconds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public ResponseEntity<ErrorResponse> handle() {
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleInvalidRequest(final BindingResult bindingResult) {
final List<FieldError> fieldErrors = bindingResult.getFieldErrors();
final FieldError mainError = fieldErrors.get(0);
public ResponseEntity<ErrorResponse> handleInvalidRequest(BindingResult bindingResult) {
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
FieldError mainError = fieldErrors.get(0);

return ResponseEntity.badRequest().body(new ErrorResponse(mainError.getDefaultMessage()));
}
Expand All @@ -77,7 +77,7 @@ public ResponseEntity<ErrorResponse> handleInvalidArgument(RuntimeException e) {
HttpMessageNotReadableException.class,
ConstraintViolationException.class,
})
public ResponseEntity<ErrorResponse> handleInvalidRequest(final RuntimeException e) {
public ResponseEntity<ErrorResponse> handleInvalidRequest(RuntimeException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(e.getMessage()));
}

Expand All @@ -88,7 +88,7 @@ public ResponseEntity<ErrorResponse> handleInvalidRequest(final RuntimeException
InvalidOrderException.class,
NotInCustomerCartItemException.class,
})
public ResponseEntity<ErrorResponse> handleInvalidAccess(final RuntimeException e) {
public ResponseEntity<ErrorResponse> handleInvalidAccess(RuntimeException e) {
return ResponseEntity.badRequest().body(new ErrorResponse(e.getMessage()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@
public class CartItemController {
private final CartService cartService;

public CartItemController(final CartService cartService) {
public CartItemController(CartService cartService) {
this.cartService = cartService;
}

@GetMapping
public ResponseEntity<List<CartItemResponse>> getCartItems(@CustomerId final Long customerId) {
public ResponseEntity<List<CartItemResponse>> getCartItems(@CustomerId Long customerId) {
return ResponseEntity.ok().body(cartService.findCartItemsByCustomerId(customerId));
}

@PostMapping
public ResponseEntity<Void> addCartItem(@RequestBody final CartItemRequest cartItemRequest,
@CustomerId final Long customerId) {
final Long cartItemId = cartService.addCart(cartItemRequest, customerId);
final URI responseLocation = ServletUriComponentsBuilder
public ResponseEntity<Void> addCartItem(@RequestBody CartItemRequest cartItemRequest, @CustomerId Long customerId) {
Long cartItemId = cartService.addCart(cartItemRequest, customerId);
URI responseLocation = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{cartItemId}")
.buildAndExpand(cartItemId)
Expand All @@ -45,22 +44,22 @@ public ResponseEntity<Void> addCartItem(@RequestBody final CartItemRequest cartI
}

@DeleteMapping("/{cartItemId}")
public ResponseEntity<Void> deleteCartItem(@CustomerId final Long customerId, @PathVariable final Long cartItemId) {
public ResponseEntity<Void> deleteCartItem(@CustomerId Long customerId, @PathVariable Long cartItemId) {
cartService.deleteCart(customerId, cartItemId);
return ResponseEntity.noContent().build();
}

@PutMapping("/{cartItemId}")
public ResponseEntity<Void> updateCartItem(@RequestBody final CartItemRequest cartItemRequest,
@PathVariable final Long cartItemId,
@CustomerId final Long customerId) {
public ResponseEntity<Void> updateCartItem(@RequestBody CartItemRequest cartItemRequest,
@PathVariable Long cartItemId,
@CustomerId Long customerId) {
cartService.updateCartItem(customerId, cartItemId, cartItemRequest);
return ResponseEntity.noContent().build();
}

@GetMapping("/{productId}")
Copy link

Choose a reason for hiding this comment

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

해당 url도 함께 고민해보면 좋을 것 같아요!! path parameter를 쓰는게 적절한지 한번 고민해보면 좋을 것 같습니다 :)

Copy link
Author

Choose a reason for hiding this comment

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

말씀해주신 API는 특정 유저의 장바구니에 productId 에 해당하는 제품을 담고 있는지 알려주는 API 입니다! 저는 Path Parameter가 제외된 구현을 떠올리기 어려운데, 어떻게 하면 Path Parameter 를 사용하지 않고 구현할 수 있을까요??

Copy link

Choose a reason for hiding this comment

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

제가 이 부분에 대한 피드백을 빠트렸군요.. ㅠㅠ query parameter를 사용해서 전달하면 좀 더 좋을 것 같아요!! path parameter는 주로 리소스의 위치를 나타내는 경향이 있는데 그런 파라미터로 적절하지 않을 경우는 query parameter를 사용하면 좋은 것 같습니다

public ResponseEntity<ProductExistingInCartResponse> checkIsProductExisting(@CustomerId final Long customerId,
@PathVariable final Long productId) {
public ResponseEntity<ProductExistingInCartResponse> checkIsProductExisting(@CustomerId Long customerId,
@PathVariable Long productId) {
ProductExistingInCartResponse productExisting = cartService.isProductExisting(customerId, productId);
return ResponseEntity.ok(productExisting);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CustomerController(CustomerService customerService) {

@PostMapping("/customers")
public ResponseEntity<Void> createCustomer(@RequestBody CustomerRequest customerRequest) {
int id = customerService.create(customerRequest);
long id = customerService.create(customerRequest);
return ResponseEntity.created(URI.create("/api/customers/" + id)).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import woowacourse.auth.controller.CustomerId;
import woowacourse.shoppingcart.dto.request.OrderRequest;
import woowacourse.shoppingcart.dto.response.OrderResponse;
import woowacourse.shoppingcart.service.OrderService;
import woowacourse.shoppingcart.dto.request.OrdersRequest;
import woowacourse.shoppingcart.dto.response.OrdersResponse;
import woowacourse.shoppingcart.service.OrdersService;

@Validated
@RestController
@RequestMapping("/api/customers/orders")
public class OrderController {
private final OrderService orderService;
private final OrdersService ordersService;

public OrderController(final OrderService orderService) {
this.orderService = orderService;
public OrderController(final OrdersService ordersService) {
this.ordersService = ordersService;
}

@PostMapping
public ResponseEntity<Void> addOrder(@CustomerId final Long customerId,
@RequestBody final List<OrderRequest> orderDetails) {
final Long orderId = orderService.addOrder(orderDetails, customerId);
public ResponseEntity<Void> addOrder(@CustomerId Long customerId, @RequestBody List<OrdersRequest> orderDetails) {
Long orderId = ordersService.addOrder(orderDetails, customerId);
return ResponseEntity.created(URI.create("/api/customers/orders/" + orderId)).build();
}

@GetMapping("/{orderId}")
public ResponseEntity<OrderResponse> findOrder(@CustomerId final Long customerId,
@PathVariable final Long orderId) {
OrderResponse orderResponse = orderService.findOrderById(customerId, orderId);
return ResponseEntity.ok(orderResponse);
public ResponseEntity<OrdersResponse> findOrder(@CustomerId Long customerId, @PathVariable Long orderId) {
OrdersResponse ordersResponse = ordersService.findOrdersById(customerId, orderId);
return ResponseEntity.ok(ordersResponse);
}

@GetMapping
public ResponseEntity<List<OrderResponse>> findOrders(@CustomerId final Long customerId) {
List<OrderResponse> orderResponses = orderService.findOrdersByCustomerId(customerId);
return ResponseEntity.ok(orderResponses);
public ResponseEntity<List<OrdersResponse>> findOrders(@CustomerId Long customerId) {
List<OrdersResponse> ordersResponses = ordersService.findOrdersByCustomerId(customerId);
return ResponseEntity.ok(ordersResponses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ProductController {

private final ProductService productService;

public ProductController(final ProductService productService) {
public ProductController(ProductService productService) {
this.productService = productService;
}

Expand All @@ -32,22 +32,22 @@ public ResponseEntity<List<Product>> products() {
}

@PostMapping
public ResponseEntity<Void> add(@Validated(Request.allProperties.class) @RequestBody final Product product) {
final Long productId = productService.addProduct(product);
final URI uri = ServletUriComponentsBuilder
public ResponseEntity<Void> add(@Validated(Request.allProperties.class) @RequestBody Product product) {
Long productId = productService.addProduct(product);
URI uri = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/" + productId)
.build().toUri();
return ResponseEntity.created(uri).build();
}

@GetMapping("/{productId}")
public ResponseEntity<Product> product(@PathVariable final Long productId) {
public ResponseEntity<Product> product(@PathVariable Long productId) {
return ResponseEntity.ok(productService.findProductById(productId));
}

@DeleteMapping("/{productId}")
public ResponseEntity<Void> delete(@PathVariable final Long productId) {
public ResponseEntity<Void> delete(@PathVariable Long productId) {
productService.deleteProductById(productId);
return ResponseEntity.noContent().build();
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/woowacourse/shoppingcart/dao/AddressDao.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package woowacourse.shoppingcart.dao;

import java.util.Optional;
import woowacourse.shoppingcart.entity.AddressEntity;

public interface AddressDao {
void save(AddressEntity addressEntity);
void save(long customerId, AddressEntity addressEntity);

AddressEntity findById(int id);
Optional<AddressEntity> findById(long customerId);

void update(AddressEntity addressEntity);
void update(long customerId, AddressEntity addressEntity);

void delete(int customerId);
void delete(long customerId);
}
3 changes: 2 additions & 1 deletion src/main/java/woowacourse/shoppingcart/dao/CartItemDao.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package woowacourse.shoppingcart.dao;

import java.util.List;
import java.util.Optional;
import woowacourse.shoppingcart.domain.CartItem;
import woowacourse.shoppingcart.entity.CartItemEntity;

public interface CartItemDao {
Copy link

Choose a reason for hiding this comment

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

dao를 인터페이스로 분리한 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

나중에는 jdbc를 사용하지 않고 데이터베이스에 접근하는 구현체가 있을수도 있겠다는 생각에 만들어두었는데, 오버엔지니어링 같기도하고, DAO 계층에만 인터페이스를 만들어둔것이 일관성이 없어 보이기도 합니다!.. 스티치는 어떻게 생각하시나요?

Copy link

Choose a reason for hiding this comment

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

저같은 경우에는 예상되어지는 부분에 대한 추상화는 진행하지만 그렇지 않은 부분에 대해서는 최대한 오버엔지니어링을 피하려고 하고 있어요!! 후디가 작성한 코드에서 추후 다른 DB 리소스를 붙일 상황이 예상된다거나 그러한 요구사항이 추후 존재한다는 걸 알고 있다면 지금의 추상화는 좋다고 생각해요!! 하지만 '혹시 모르니깐'의 개발은 오버엔지니어링의 시작점이라고 생각합니다!!

지금 다양한 방법으로 시도해보고 수정해보는 것은 좋다고 생각해요!! 제가 리뷰를 남긴 이유도 정말 어떠한 이유가 존재해서 인터페이스로 분리한 것인지 궁금해서 여쭤본 것이었습니다 :)

CartItemEntity findById(Long cartItemId);
Optional<CartItemEntity> findById(Long cartItemId);

List<CartItemEntity> findAllByCustomerId(Long customerId);

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/woowacourse/shoppingcart/dao/CustomerDao.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package woowacourse.shoppingcart.dao;

import java.util.Optional;
import woowacourse.shoppingcart.entity.CustomerEntity;

public interface CustomerDao {
int save(CustomerEntity customerEntity);
long save(CustomerEntity customerEntity);

CustomerEntity findById(int id);
Optional<CustomerEntity> findById(long id);

CustomerEntity findByEmail(String email);
Optional<CustomerEntity> findByEmail(String email);

void update(int id, CustomerEntity customerEntity);
void update(long id, CustomerEntity customerEntity);

void delete(int id);
void delete(long id);

boolean existsById(long id);

Expand Down
Loading