Skip to content

Commit

Permalink
빌드 에러 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
minji1289 committed Jan 3, 2024
1 parent 1660652 commit 18f94d2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,41 @@ public DemandDetailService(DemandDetailRepository demandDetailRepository, Demand

public ResponseEntity createDemandForm(Long demand_project_id, List<DemandDetailRequestDto> requestDto)
{
User user = userRepository.findByEmail(SecurityUtil.getLoginUsername())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST));
DemandProject demandProject = demandProjectRepository.findByDemandProject_Id(demand_project_id);

//사용자의 대학교가 수요조사 프로젝트의 대학교와 일치하지 않으면
if (!Objects.equals(user.getUniv(), demandProject.getUser().getUniv()))
{
//에러 반환
return new ResponseEntity(HttpStatus.BAD_REQUEST); //400
}


List<DemandItem> demandItems= demandItemRepository.findDemandItemByDemandProject_Id(demand_project_id);
//이미 수요조사폼을 작성한 사용자의 경우
for (int i = 0; i < demandItems.size(); i++) {
if (demandDetailRepository.existsByUserIdAndDemandItemId(user.getId(), demandItems.get(i).getId()))
{
return new ResponseEntity(HttpStatus.FORBIDDEN); //403: Forbidden
}
}

for (int i = 0; i < requestDto.size(); i++) {
DemandItem demandItem = itemRepository.findDemandItemById(requestDto.get(i).getDemandItemId()); //프론트에서 demand_item_id 받아오기
int count = requestDto.get(i).getCount();

DemandDetail demandDetail = DemandDetail.builder()
.user(user) //User user
.demandItem(demandItem) //DemandItem demandItem
.count(count) //int Count
.build();
demandDetailRepository.save(demandDetail);
}

//참여인원 업데이트
demandProjectRepository.updateParticipantNumber(demand_project_id);
// User user = userRepository.findByEmail(SecurityUtil.getLoginUsername())
// .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST));
// DemandProject demandProject = demandProjectRepository.findByDemandProject_Id(demand_project_id);
//
// //사용자의 대학교가 수요조사 프로젝트의 대학교와 일치하지 않으면
// if (!Objects.equals(user.getUniv(), demandProject.getUser().getUniv()))
// {
// //에러 반환
// return new ResponseEntity(HttpStatus.BAD_REQUEST); //400
// }
//
//
// List<DemandItem> demandItems= demandItemRepository.findDemandItemByDemandProject_Id(demand_project_id);
// //이미 수요조사폼을 작성한 사용자의 경우
// for (int i = 0; i < demandItems.size(); i++) {
// if (demandDetailRepository.existsByUserIdAndDemandItemId(user.getId(), demandItems.get(i).getId()))
// {
// return new ResponseEntity(HttpStatus.FORBIDDEN); //403: Forbidden
// }
// }
//
// for (int i = 0; i < requestDto.size(); i++) {
// DemandItem demandItem = itemRepository.findDemandItemById(requestDto.get(i).getDemandItemId()); //프론트에서 demand_item_id 받아오기
// int count = requestDto.get(i).getCount();
//
// DemandDetail demandDetail = DemandDetail.builder()
// .user(user) //User user
// .demandItem(demandItem) //DemandItem demandItem
// .count(count) //int Count
// .build();
// demandDetailRepository.save(demandDetail);
// }
//
// //참여인원 업데이트
// demandProjectRepository.updateParticipantNumber(demand_project_id);

return new ResponseEntity(HttpStatus.OK);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/wowmarket/wow_server/domain/DemandDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class DemandDetail extends BaseEntity{
private int count;

@Builder
public DemandDetail(User user, DemandItem demandItem, int count){
this.user = user;
public DemandDetail(DemandOrder demandOrder, DemandItem demandItem, int count){
this.demandOrder = demandOrder;
this.demandItem = demandItem;
this.count = count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Optional;

public interface DemandDetailRepository extends JpaRepository<DemandDetail, Long> {
boolean existsByUser_Id(Long buyer_id);

boolean existsByUserIdAndDemandItemId(Long user_id, Long demand_item_id);
// boolean existsByUser_Id(Long buyer_id);
//
// boolean existsByUserIdAndDemandItemId(Long user_id, Long demand_item_id);
}

0 comments on commit 18f94d2

Please sign in to comment.