Skip to content

Commit

Permalink
Merge pull request #166 from UMC-WOWMARKET/feat/last
Browse files Browse the repository at this point in the history
[feat] 주문폼, 참여폼 로드/작성시 판매대상 정보/조건 추가
  • Loading branch information
minji1289 authored Jan 16, 2024
2 parents ba3c7a9 + f7a70c8 commit 38c4980
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@


import lombok.Getter;
import wowmarket.wow_server.detail.project.dto.OrderAnswerDto;

import java.time.LocalDateTime;
import java.util.List;

@Getter
Expand All @@ -14,4 +11,5 @@ public class DemandFormRequestDto {

//추가질문 답변 리스트
List<DemandAnswerDto> demandAnswerDtoList;
}
}

Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package wowmarket.wow_server.detail.demandproject.dto;

import lombok.Getter;
import wowmarket.wow_server.domain.DemandProject;

import java.util.List;

//참여폼 정보 불러오는 Dto

@Getter
public class DemandResponseDto {
private boolean sellToAll;
private List<DemandItemResponseDto> demandItemResponseDtoList;
private List<DemandQuestionResponseDto> demandQuestionResponseDtoList;

public DemandResponseDto(List<DemandItemResponseDto> demandItemResponseDtoList, List<DemandQuestionResponseDto> demandQuestionResponseDtoList) {
public DemandResponseDto(DemandProject demandProject, List<DemandItemResponseDto> demandItemResponseDtoList, List<DemandQuestionResponseDto> demandQuestionResponseDtoList) {
this.sellToAll = demandProject.isSellToAll();
this.demandItemResponseDtoList = demandItemResponseDtoList;
this.demandQuestionResponseDtoList = demandQuestionResponseDtoList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ public ResponseEntity createDemandForm(Long demand_project_id, DemandFormRequest
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST));

System.out.print("here");
//* 사용자의 대학교가 수요조사 프로젝트의 대학교와 일치하지 않으면 -> 추후 수정될 조건 *
if (!Objects.equals(user.getUniv(), demandProject.getUser().getUniv()))

if(!demandProject.isSellToAll()) //전체대상 판매인 수요조사 프로젝트가 아닌 경우,
{
//에러 반환
return new ResponseEntity(HttpStatus.BAD_REQUEST);
//* 사용자의 대학교가 수요조사 프로젝트의 대학교와 일치하지 않으면 -> 추후 수정될 조건 *
if (!Objects.equals(user.getUniv(), demandProject.getUser().getUniv())) {
//에러 반환
return new ResponseEntity(HttpStatus.UNAUTHORIZED); //401 Unauthorized: 전체 대상 판매가 아닌 경우, 사용자와 판매자 대학교 일치 x
}
}

//이미 수요조사폼을 작성한 사용자의 경우, 작성 못하게하는 로직
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public DemandItemService(DemandItemRepository itemRepository, DemandProjectRepos
}

public DemandResponseDto getDemandItemInfo(Long demand_project_id){
DemandProject demandProject = demandProjectRepository.findByDemandProject_Id(demand_project_id);

List<DemandItem> itemList = itemRepository.findDemandItemByDemandProject_Id(demand_project_id);
List<DemandItemResponseDto> itemResponseDtoList =
itemList.stream()
Expand All @@ -42,7 +44,7 @@ public DemandResponseDto getDemandItemInfo(Long demand_project_id){
demandQuestions.stream()
.map(DemandQuestionResponseDto::new)
.toList();
return new DemandResponseDto(itemResponseDtoList, demandQuestionResponseDtoList);
return new DemandResponseDto(demandProject, itemResponseDtoList, demandQuestionResponseDtoList);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

@Getter
public class OrderResponseDto {
//판매대상
private boolean sellToAll;

//수령방법
private String receive_type; //수령방법: [택배배송/직접수령]
private String receive_address; //직접수령시 픽업장소
Expand All @@ -24,6 +27,7 @@ public class OrderResponseDto {
private List<OrderQuestionResponseDto> orderQuestionResponseDtoList;

public OrderResponseDto(Project project, List<ItemResponseDto> itemResponseDtoList, List<OrderQuestionResponseDto> orderQuestionResponseDtoList) {
this.sellToAll = project.isSellToAll();
this.receive_type=project.getReceive_type().toString();
this.receive_address=project.getReceive_address();
this.delivery_fee=project.getDelivery_fee();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public ResponseEntity createOrderForm(Long project_id, OrderFormRequestDto reque
User user = userRepository.findByEmail(SecurityUtil.getLoginUsername())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST));

//사용자의 대학교가 프로젝트의 대학교와 일치하지 않으면
if (!Objects.equals(user.getUniv(), project.getUser().getUniv()))
if(!project.isSellToAll()) //전체대상 판매인 프로젝트가 아닌 경우,
{
//에러 반환
return new ResponseEntity(HttpStatus.BAD_REQUEST);
//사용자의 대학교가 프로젝트의 대학교와 일치하지 않으면
if (!Objects.equals(user.getUniv(), project.getUser().getUniv())) {
//에러 반환
return new ResponseEntity(HttpStatus.UNAUTHORIZED); //401 Unauthorized: 전체 대상 판매가 아닌 경우, 사용자와 판매자 대학교 일치 x
}
}

Orders order = Orders.builder()
Expand Down

0 comments on commit 38c4980

Please sign in to comment.