Skip to content

Commit

Permalink
Merge pull request #244 from TrandPick/development
Browse files Browse the repository at this point in the history
트렌드픽 배포 v1.1.0
  • Loading branch information
hye-0000 authored Jun 21, 2023
2 parents 2dd978e + 40b74a2 commit 233dd87
Show file tree
Hide file tree
Showing 56 changed files with 1,396 additions and 927 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import project.trendpick_pro.global.rsData.RsData;

import java.util.List;
import java.util.Objects;

@Service
@Transactional(readOnly = true)
Expand All @@ -30,7 +31,7 @@ public RsData<Long> register(Member member, Long askId, AnswerForm answerForm) {
Ask ask = askRepository.findById(askId).orElseThrow(
() -> new IllegalArgumentException("해당 문의는 없는 문의입니다.")
);
if (member.getBrand() != ask.getProduct().getBrand().getName())
if (!member.getBrand().equals(ask.getProduct().getBrand().getName()))
return RsData.of("F-1", "타 브랜드 상품에 대한 문의글에는 답변 권한이 없습니다.");

Answer answer = Answer.write(ask, answerForm);
Expand All @@ -44,7 +45,7 @@ public RsData<Long> delete(Member member, Long answerId) {
() -> new IllegalArgumentException("해당 답변은 없는 답변입니다.")
);

if(answer.getAsk().getAuthor().getBrand() != member.getBrand())
if(!answer.getAsk().getAuthor().getBrand().equals(member.getBrand()))
return RsData.of("F-1", "접근 권한이 없습니다.");
answerRepository.delete(answer);
answer.getAsk().getAnswerList().remove(answer);
Expand All @@ -56,7 +57,7 @@ public RsData<Long> modify(Member member, Long answerId, AnswerForm answerForm)
() -> new IllegalArgumentException("해당 답변은 없는 답변입니다.")
);

if(answer.getAsk().getAuthor().getBrand() != member.getBrand())
if(!Objects.equals(answer.getAsk().getAuthor().getBrand(), member.getBrand()))
return RsData.of("F-1", "접근 권한이 없습니다.");
answer.update(answerForm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class AskResponse {

private Long askId;
private Long productId;
private String productName;
private String memberName;
private Long memberId;
private String title;
Expand All @@ -27,9 +28,10 @@ public class AskResponse {

@QueryProjection
@Builder
public AskResponse(Long askId, Long productId, String memberName, Long memberId, String title,String content, String status, LocalDateTime createdDate) {
public AskResponse(Long askId, Long productId, String productName, String memberName, Long memberId, String title,String content, String status, LocalDateTime createdDate) {
this.askId = askId;
this.productId = productId;
this.productName = productName;
this.memberName = memberName;
this.memberId = memberId;
this.title = title;
Expand All @@ -44,6 +46,7 @@ public static AskResponse of (Ask ask) {
.memberName(ask.getAuthor().getUsername())
.memberId(ask.getAuthor().getId())
.productId(ask.getProduct().getId())
.productName(ask.getProduct().getName())
.title(ask.getTitle())
.content(ask.getContent())
.status(ask.getStatus().getValue())
Expand All @@ -52,6 +55,6 @@ public static AskResponse of (Ask ask) {
}

public static Page<AskResponse> of(Page<Ask> asks){
return asks.map(ask -> AskResponse.of(ask));
return asks.map(AskResponse::of);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Page<AskResponse> findAllByProductId(Long productId, Pageable pageable) {
.select(new QAskResponse(
ask.id,
product.id,
product.name,
member.username,
member.id,
ask.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public String addItemToCart(CartItemRequest cartItemRequests, Model model) {
}


@PreAuthorize("hasAuthority({'MEMBER'})")
@PostMapping("/add")
public String addItem(@ModelAttribute @Valid CartItemRequest cartItemRequests, Model model) {
if(!rq.checkLogin())
return rq.historyBack("로그인 후 이용하실 수 있습니다.");
RsData<CartItemResponse> cartItemResponse = cartService.addItemToCart(rq.CheckMember().get(), cartItemRequests);
if(cartItemResponse.isFail()){
rq.redirectWithMsg("/trendpick/products/list?main-category=상의",cartItemResponse);
return rq.redirectWithMsg("/trendpick/products/list?main-category=상의",cartItemResponse);
}
model.addAttribute("cartItemResponse", cartItemResponse);
return rq.redirectWithMsg("/trendpick/usr/cart/list", "상품이 추가되었습니다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package project.trendpick_pro.domain.cart.entity;

import jakarta.persistence.*;
import lombok.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import project.trendpick_pro.domain.cart.entity.dto.request.CartItemRequest;
import project.trendpick_pro.domain.orders.entity.Order;
import project.trendpick_pro.domain.product.entity.Product;

import java.time.LocalDate;

@Entity
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CartItem {

Expand All @@ -21,11 +24,13 @@ public class CartItem {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cart_id")
private Cart cart;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id")
private Product product;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private Order order;
private int quantity; // 해당 상품 수량

@DateTimeFormat(pattern = "yyyy-mm-dd")
Expand Down Expand Up @@ -57,4 +62,8 @@ public void update(int quantity){
this.quantity=quantity;
this.cart.updateTotalCount();
}
public void connectOrder(Order order) {
this.order = order;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@
import project.trendpick_pro.domain.cart.repository.CartItemRepository;
import project.trendpick_pro.domain.cart.repository.CartRepository;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.member.repository.MemberRepository;
import project.trendpick_pro.domain.orders.entity.Order;
import project.trendpick_pro.domain.orders.service.OrderService;
import project.trendpick_pro.domain.product.entity.Product;
import project.trendpick_pro.domain.product.repository.ProductRepository;
import project.trendpick_pro.domain.product.service.ProductService;
import project.trendpick_pro.domain.tags.favoritetag.service.FavoriteTagService;
import project.trendpick_pro.domain.tags.tag.entity.type.TagType;
import project.trendpick_pro.global.rsData.RsData;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class CartService {

private final CartRepository cartRepository;
private final MemberRepository memberRepository;
private final ProductRepository productRepository;
private final CartItemRepository cartItemRepository;

private final ProductService productService;
private final FavoriteTagService favoriteTagService;


Expand All @@ -52,7 +54,7 @@ public List<CartItem> CartView(Cart cart) {
@Transactional
public RsData<CartItemResponse> addItemToCart(Member member, CartItemRequest cartItemRequest) {
Cart cart = cartRepository.findByMemberId(member.getId());
Product product = productRepository.findById(cartItemRequest.getProductId()).orElse(null);
Product product = productService.findById(cartItemRequest.getProductId());
if (product == null) {
return RsData.of("F-1", "해당상품을 찾을 수 없습니다.");
}
Expand Down Expand Up @@ -106,7 +108,7 @@ public List<CartItem> findCartItems(Member member, List<Long> cartItemIdList) {

for (Long id : cartItemIdList) {
for (CartItem item : cartItemRepository.findByProductId(id)) {
if (item.getCart().getId() == cart.getId()) {
if (Objects.equals(item.getCart().getId(), cart.getId())) {
cartItemList.add(item);
}
}
Expand All @@ -115,8 +117,9 @@ public List<CartItem> findCartItems(Member member, List<Long> cartItemIdList) {
}

@Transactional
public void deleteAll(List<CartItem> cartItemIdList) {
cartItemRepository.deleteAllInBatch(cartItemIdList);
public void deleteCartItemsByOrder(Order order) {
List<CartItem> cartItems = order.getCartItems();
cartItemRepository.deleteAllInBatch(cartItems);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ public Boolean CheckAdminHtml() {
public Boolean checkAdminOrBrandAdminHtml(){
if(!checkLogin()) //로그인 안되있으면 false
return false;
if(CheckLogin().get().getRole().equals(RoleType.MEMBER)) //Member면 false
return false;
return true;
//Member면 false
return !CheckLogin().get().getRole().equals(RoleType.MEMBER);
}

public Boolean CheckBrandAdminHtml() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public class Delivery extends BaseTimeEntity {

@OneToOne(mappedBy = "delivery", fetch = FetchType.LAZY)
private Order order;

private String address;

@Enumerated(EnumType.STRING)
private DeliveryState state;

Expand All @@ -28,4 +30,7 @@ public Delivery(String address){
state = DeliveryState.READY; //주문과 함께 생성시 초기에는 준비중.
}

public void canceledDelivery(){
state = DeliveryState.CANCELED;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package project.trendpick_pro.domain.delivery.entity;

public enum DeliveryState {
READY, DELIVERY_ING, COMPLETED
READY, DELIVERY_ING, COMPLETED, CANCELED
//준비,배송중,배송완료
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import project.trendpick_pro.domain.member.entity.form.AddressForm;
import project.trendpick_pro.domain.member.entity.form.JoinForm;
import project.trendpick_pro.domain.member.service.MemberService;
import project.trendpick_pro.domain.recommend.service.RecommendService;
import project.trendpick_pro.domain.tags.tag.service.TagService;
import project.trendpick_pro.global.basedata.tagname.service.TagNameService;
import project.trendpick_pro.global.rsData.RsData;
Expand All @@ -32,6 +33,7 @@ public class MemberController {

private final MemberService memberService;
private final TagNameService tagNameService;
private final RecommendService recommendService;

private final Rq rq;

Expand All @@ -48,9 +50,11 @@ public String register(JoinForm joinForm, Model model) {
public String register(@ModelAttribute @Valid JoinForm joinForm) {

RsData<Member> member = memberService.register(joinForm);
if (member.isFail()) {
if (member.isFail())
return rq.historyBack(member);
}

if(member.getData().getRole().getValue().equals("MEMBER"))
recommendService.select(member.getData().getEmail());

return rq.redirectWithMsg("/trendpick/member/login", member);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import project.trendpick_pro.domain.member.entity.form.JoinForm;
import project.trendpick_pro.domain.member.exception.MemberNotFoundException;
import project.trendpick_pro.domain.member.repository.MemberRepository;
import project.trendpick_pro.domain.recommend.service.RecommendService;
import project.trendpick_pro.domain.tags.favoritetag.entity.FavoriteTag;
import project.trendpick_pro.domain.tags.tag.entity.dto.request.TagRequest;
import project.trendpick_pro.global.rsData.RsData;
Expand All @@ -25,6 +26,7 @@ public class MemberService {

private final PasswordEncoder passwordEncoder;
private final MemberRepository memberRepository;
private final RecommendService recommendService;

private final BrandService brandService;

Expand Down Expand Up @@ -79,7 +81,8 @@ public RsData<Member> register(JoinForm joinForm) {
member.changeTags(favoriteTags);
}

memberRepository.save(member);
Member savedMember = memberRepository.save(member);
recommendService.select(savedMember.getEmail());

return RsData.of("S-1", "회원가입이 완료되었습니다.", member);
}
Expand Down
Loading

0 comments on commit 233dd87

Please sign in to comment.