-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat-be(dashboard): 특정 동아리의 대시보드(공고) 생성 API 구현 (#215)
authored-by: Do Yeop Kim <113661364+Dobby-Kim@users.noreply.github.com>
- Loading branch information
1 parent
8330765
commit ac97e15
Showing
26 changed files
with
560 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/com/cruru/applyform/controller/dto/ApplyFormCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cruru.applyform.controller.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotBlank; | ||
import java.time.LocalDateTime; | ||
|
||
public record ApplyFormCreateRequest( | ||
@NotBlank(message = "제목은 필수 값입니다.") | ||
String title, | ||
|
||
@JsonProperty("posting_content") | ||
String postingContent, | ||
|
||
@NotBlank(message = "시작 날짜는 필수 값입니다.") | ||
LocalDateTime startDate, | ||
|
||
@NotBlank(message = "종료 날짜는 필수 값입니다.") | ||
LocalDateTime dueDate | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/cruru/choice/controller/dto/ChoiceCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.cruru.choice.controller.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record ChoiceCreateRequest( | ||
@NotBlank(message = "객관식 질문의 선택지는 필수 값입니다.") | ||
String choice, | ||
|
||
@JsonProperty("order_index") | ||
int orderIndex | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/cruru/choice/exception/ChoiceEmptyBadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.choice.exception; | ||
|
||
import com.cruru.advice.badrequest.BadRequestException; | ||
|
||
public class ChoiceEmptyBadRequestException extends BadRequestException { | ||
|
||
private static final String MESSAGE = "객관식 질문에는 1개 이상의 객관식 선택지를 포함해야합니다."; | ||
|
||
public ChoiceEmptyBadRequestException() { | ||
super(MESSAGE); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/cruru/choice/exception/ChoiceIllegalSaveException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.choice.exception; | ||
|
||
import com.cruru.advice.badrequest.BadRequestException; | ||
|
||
public class ChoiceIllegalSaveException extends BadRequestException { | ||
|
||
private static final String MESSAGE = "선택지를 저장할 수 없는 질문입니다."; | ||
|
||
public ChoiceIllegalSaveException() { | ||
super(MESSAGE); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
backend/src/main/java/com/cruru/choice/service/ChoiceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.cruru.choice.service; | ||
|
||
import com.cruru.choice.controller.dto.ChoiceCreateRequest; | ||
import com.cruru.choice.domain.Choice; | ||
import com.cruru.choice.domain.repository.ChoiceRepository; | ||
import com.cruru.choice.exception.ChoiceEmptyBadRequestException; | ||
import com.cruru.choice.exception.ChoiceIllegalSaveException; | ||
import com.cruru.question.domain.Question; | ||
import com.cruru.question.domain.repository.QuestionRepository; | ||
import com.cruru.question.exception.QuestionNotFoundException; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ChoiceService { | ||
|
||
private final ChoiceRepository choiceRepository; | ||
private final QuestionRepository questionRepository; | ||
|
||
@Transactional | ||
public List<Choice> createAll(List<ChoiceCreateRequest> requests, long questionId) { | ||
Question targetQuestion = questionRepository.findById(questionId) | ||
.orElseThrow(QuestionNotFoundException::new); | ||
|
||
if (!targetQuestion.hasChoice()) { | ||
throw new ChoiceIllegalSaveException(); | ||
} | ||
if (requests.isEmpty()) { | ||
throw new ChoiceEmptyBadRequestException(); | ||
} | ||
return choiceRepository.saveAll(toChoices(requests, targetQuestion)); | ||
} | ||
|
||
private List<Choice> toChoices(List<ChoiceCreateRequest> requests, Question question) { | ||
return requests.stream() | ||
.map(request -> new Choice(request.choice(), request.orderIndex(), question)) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 24 additions & 2 deletions
26
backend/src/main/java/com/cruru/dashboard/controller/dto/DashboardCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
package com.cruru.dashboard.controller.dto; | ||
|
||
import com.cruru.question.controller.dto.QuestionCreateRequest; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonFormat.Shape; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record DashboardCreateRequest( | ||
@NotBlank(message = "대시보드 이름은 필수 값입니다.") | ||
String name | ||
@NotBlank(message = "공고 제목은 필수 값입니다.") | ||
String title, | ||
|
||
@JsonProperty("posting_content") | ||
String postingContent, | ||
|
||
List<QuestionCreateRequest> questions, | ||
|
||
@NotNull(message = "시작 날짜는 필수 값입니다.") | ||
@JsonFormat(shape = Shape.STRING) | ||
@JsonProperty("start_date") | ||
LocalDateTime startDate, | ||
|
||
@NotNull(message = "종료 날짜는 필수 값입니다.") | ||
@JsonFormat(shape = Shape.STRING) | ||
@JsonProperty("due_date") | ||
LocalDateTime dueDate | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.