Skip to content

Commit

Permalink
feat: cart error-fix core-module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Jul 24, 2024
1 parent f4712a3 commit 19c9e5b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class Cart {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "item_id")
@Column(name = "cart_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -25,4 +25,8 @@ public class Cart {
private Menu menu;

private Integer quantity;

public void setCartQuantity(Integer quantity) {
this.quantity = quantity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.likelion.coremodule.cart.exception;

import com.likelion.commonmodule.exception.common.ApiResponse;
import com.likelion.commonmodule.exception.common.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum CartErrorCode implements BaseErrorCode {

NO_CART_INFO(HttpStatus.BAD_REQUEST, "2000", "장바구니 안에 상품이 존재하지 않습니다.");

private final HttpStatus httpStatus;
private final String code;
private final String message;


@Override
public ApiResponse<Void> getErrorResponse() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.likelion.coremodule.cart.exception;

import com.likelion.commonmodule.exception.common.BaseErrorCode;
import lombok.Getter;

@Getter
public class CartException extends RuntimeException {

private final BaseErrorCode errorCode;

private final Throwable cause;

public CartException(BaseErrorCode errorCode) {
this.errorCode = errorCode;
this.cause = null;
}

public CartException(BaseErrorCode errorCode, Throwable cause) {
this.errorCode = errorCode;
this.cause = cause;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ public interface CartRepository extends JpaRepository<Cart, Long> {

List<Cart> findCartsByUserUserId(Long userId);

int countCartsByUserUserIdAndMenuId(Long userId, Long menuId);

Cart findCartByUserUserIdAndId(Long userId, Long cartId);

void deleteCartByIdAndUserUserId(Long cartId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public List<Cart> findCartsByUserId(Long userId) {
return cartRepository.findCartsByUserUserId(userId);
}

public int findCartByUserIdAndMenuId(Long userId, Long menuId) {
return cartRepository.countCartsByUserUserIdAndMenuId(userId, menuId);
}

public Cart findCartByUserIdAndCartId(Long userId, Long cartId) {
return cartRepository.findCartByUserUserIdAndId(userId, cartId);
}

public void deleteCartByUserIdAndCartId(Long userId, Long cartId) {

cartRepository.deleteCartByIdAndUserUserId(cartId, userId);
Expand Down

0 comments on commit 19c9e5b

Please sign in to comment.