Skip to content

Commit

Permalink
[feat] 수요조사 추가질문 및 소속학교대상 판매여부 추가
Browse files Browse the repository at this point in the history
[feat] 수요조사 추가질문 및 소속학교대상 판매여부 추가
  • Loading branch information
yj-leez authored Jan 11, 2024
2 parents 3c5762d + 3d61da6 commit 1799594
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.DemandProject;
import wowmarket.wow_server.domain.Permission;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -38,11 +39,15 @@ public class RegisterDemandProjectDto {

@NotNull
private List<RegisterItemDto> item;
private List<RegisterQuestionDto> questions;
@NotNull
private LocalDateTime startDate;
@NotNull
private LocalDateTime endDate;

@NotNull
private Boolean sellToAll;



@Builder
Expand All @@ -63,7 +68,9 @@ public DemandProject toEntity(){
.participant_number(0)
.final_achievement_rate(0L)
.isEnd(Boolean.FALSE)
.sellToAll(sellToAll)
.view(0)
.permission(Permission.AWAIT)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.Permission;
import wowmarket.wow_server.domain.Project;
import wowmarket.wow_server.domain.ReceiveType;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -87,6 +88,7 @@ public Project toEntity(){
.isDel(Boolean.FALSE)
.isEnd(Boolean.FALSE)
.final_achievement_rate(0L)
.permission(Permission.AWAIT)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.DemandItem;
import wowmarket.wow_server.domain.DemandQuestion;
import wowmarket.wow_server.domain.OrderQuestion;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class RegisterQuestionDto {

private String question;
private boolean essential;

@Builder
public OrderQuestion toOrderQuestion(){
return OrderQuestion
.builder()
.question(question)
.essential(essential)
.build();
}

@Builder
public DemandQuestion toDemandQuestion(){
return DemandQuestion
.builder()
.question(question)
.essential(essential)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RegisterService {
private final DemandItemRepository demandItemRepository;
private final CategoryRepository categoryRepository;
private final OrderQuestionRepository orderQuestionRepository;
private final DemandQuestionRepository demandQuestionRepository;


public Long registerProject(RegisterProjectDto requestDto, User user) throws Exception {
Expand Down Expand Up @@ -72,6 +73,10 @@ public Long registerDemand(RegisterDemandProjectDto requestDto, User user) throw
if(user != null) demandProject.setUser(user);
else throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "유저를 찾을 수 없습니다"); //유저 없을 시 400 에러 반환

// 소속 학생만 구매 가능하도록 설정했지만 판매자의 학교 인증이 안 됐을 경우
if(!demandProject.isSellToAll() && !user.isUniv_check())
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "학교 인증이 확인되지 않았습니다.");

demandProjectRepository.save(demandProject);

for (int i = 0; i < requestDto.getItem().size(); i++) {
Expand All @@ -80,6 +85,12 @@ public Long registerDemand(RegisterDemandProjectDto requestDto, User user) throw
demandItemRepository.save(demandItem);
}

for (int i = 0; i < requestDto.getQuestions().size(); i++) {
DemandQuestion demandQuestion = requestDto.getQuestions().get(i).toDemandQuestion();
demandQuestion.setDemandProject(demandProject);
demandQuestionRepository.save(demandQuestion);
}

return demandProject.getId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package wowmarket.wow_server.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import wowmarket.wow_server.domain.DemandQuestion;

public interface DemandQuestionRepository extends JpaRepository<DemandQuestion, Long> {
}

0 comments on commit 1799594

Please sign in to comment.