From 3d61da6fc662ac104ec025b4473742c2773a030b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98yj-leez=E2=80=99?= Date: Thu, 11 Jan 2024 19:26:40 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=88=98=EC=9A=94=EC=A1=B0=EC=82=AC?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=EC=A7=88=EB=AC=B8=20=EB=B0=8F=20=EC=86=8C?= =?UTF-8?q?=EC=86=8D=ED=95=99=EA=B5=90=EB=8C=80=EC=83=81=20=ED=8C=90?= =?UTF-8?q?=EB=A7=A4=EC=97=AC=EB=B6=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../register/dto/RegisterDemandProjectDto.java | 7 +++++++ .../wow_server/register/dto/RegisterProjectDto.java | 2 ++ .../register/dto/RegisterQuestionDto.java | 13 +++++++++++++ .../register/service/RegisterService.java | 11 +++++++++++ .../repository/DemandQuestionRepository.java | 7 +++++++ 5 files changed, 40 insertions(+) create mode 100644 src/main/java/wowmarket/wow_server/repository/DemandQuestionRepository.java 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 { +}