diff --git a/src/main/java/wowmarket/wow_server/register/dto/RegisterDemandProjectDto.java b/src/main/java/wowmarket/wow_server/register/dto/RegisterDemandProjectDto.java index 627a402..d2362a5 100644 --- a/src/main/java/wowmarket/wow_server/register/dto/RegisterDemandProjectDto.java +++ b/src/main/java/wowmarket/wow_server/register/dto/RegisterDemandProjectDto.java @@ -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; @@ -38,11 +39,15 @@ public class RegisterDemandProjectDto { @NotNull private List item; + private List questions; @NotNull private LocalDateTime startDate; @NotNull private LocalDateTime endDate; + @NotNull + private Boolean sellToAll; + @Builder @@ -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(); } diff --git a/src/main/java/wowmarket/wow_server/register/dto/RegisterProjectDto.java b/src/main/java/wowmarket/wow_server/register/dto/RegisterProjectDto.java index e60c1d7..b74af30 100644 --- a/src/main/java/wowmarket/wow_server/register/dto/RegisterProjectDto.java +++ b/src/main/java/wowmarket/wow_server/register/dto/RegisterProjectDto.java @@ -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; @@ -87,6 +88,7 @@ public Project toEntity(){ .isDel(Boolean.FALSE) .isEnd(Boolean.FALSE) .final_achievement_rate(0L) + .permission(Permission.AWAIT) .build(); } } diff --git a/src/main/java/wowmarket/wow_server/register/dto/RegisterQuestionDto.java b/src/main/java/wowmarket/wow_server/register/dto/RegisterQuestionDto.java index 4cd4857..9bb508f 100644 --- a/src/main/java/wowmarket/wow_server/register/dto/RegisterQuestionDto.java +++ b/src/main/java/wowmarket/wow_server/register/dto/RegisterQuestionDto.java @@ -5,6 +5,7 @@ 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 @@ -12,13 +13,25 @@ @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(); } } diff --git a/src/main/java/wowmarket/wow_server/register/service/RegisterService.java b/src/main/java/wowmarket/wow_server/register/service/RegisterService.java index 02db926..dbbd8ec 100644 --- a/src/main/java/wowmarket/wow_server/register/service/RegisterService.java +++ b/src/main/java/wowmarket/wow_server/register/service/RegisterService.java @@ -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 { @@ -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++) { @@ -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(); } } diff --git a/src/main/java/wowmarket/wow_server/repository/DemandQuestionRepository.java b/src/main/java/wowmarket/wow_server/repository/DemandQuestionRepository.java new file mode 100644 index 0000000..8befd5e --- /dev/null +++ b/src/main/java/wowmarket/wow_server/repository/DemandQuestionRepository.java @@ -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 { +}