-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
34 changes: 27 additions & 7 deletions
34
src/main/java/com/sinabro/sinabro/controller/SurveyController.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,30 +1,50 @@ | ||
package com.sinabro.sinabro.controller; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.sinabro.sinabro.entity.Survey; | ||
import com.sinabro.sinabro.entity.request.SurveyRequest; | ||
import com.sinabro.sinabro.entity.response.SubmitterResultResponse; | ||
import com.sinabro.sinabro.entity.response.SurveyResponse; | ||
import com.sinabro.sinabro.service.SurveyService; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Tag(name = "1. [설문조사]", description = "설문조사 API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/sinabro/api/v1/surveys") | ||
public class SurveyController { | ||
|
||
private final SurveyService surveyService; | ||
@PostMapping("/") | ||
public Survey createSurvey(@Valid @RequestBody SurveyRequest request) { | ||
@Operation(summary = "설문지 생성", description = "첫 설문지를 생성합니다.") | ||
@PostMapping("") | ||
public SurveyResponse createSurvey(@Valid @RequestBody SurveyRequest request) { | ||
return surveyService.createSurvey(request); | ||
} | ||
|
||
// @PostMapping("/{uuid}/answers") | ||
// public SurveyRequest getSurveyAnswers(@PathVariable String uuid) { | ||
// return surveyService.getSurveyAnswers(uuid); | ||
// } | ||
@Operation(summary = "특정 설문지 정답 요청", description = "특정 설문지의 정답을 받아옵니다.") | ||
@GetMapping("/{uuid}/answers") | ||
public SurveyRequest getSurveyAnswers(@PathVariable String uuid) { | ||
return surveyService.getSurveyAnswers(uuid); | ||
} | ||
|
||
@Operation(summary = "설문지 제출자 결과 리스트 요청", description = "제출자들의 결과 정보를 가져옵니다.") | ||
@GetMapping("/{uuid}/results") | ||
public SubmitterResultResponse getSubmitterResults(@PathVariable String uuid) { | ||
return surveyService.getSubmitterResults(uuid); | ||
} | ||
|
||
@Operation(summary = "설문지에 대한 응답 제출", description = "설문지에 대한 응답 제출") | ||
@PostMapping("/{uuid}/submission") | ||
public void createSubmission(@Valid @RequestBody SurveyRequest request, @PathVariable String uuid ) { | ||
surveyService.createSubmission(request, uuid); | ||
} | ||
} |
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,15 @@ | ||
package com.sinabro.sinabro.dto; | ||
|
||
import com.sinabro.sinabro.entity.Submitter; | ||
|
||
public record SubmitterInfo( | ||
String name, | ||
Integer score | ||
) { | ||
public static SubmitterInfo of(Submitter submitter) { | ||
return new SubmitterInfo( | ||
submitter.getName(), | ||
submitter.getScore() | ||
); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/sinabro/sinabro/entity/response/SubmitterResultResponse.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,17 @@ | ||
package com.sinabro.sinabro.entity.response; | ||
|
||
import java.util.List; | ||
|
||
import com.sinabro.sinabro.dto.SubmitterInfo; | ||
|
||
public record SubmitterResultResponse( | ||
String creatorname, | ||
List<SubmitterInfo> submitterInfoList | ||
) { | ||
public static SubmitterResultResponse of (String creatorname, List<SubmitterInfo> submitterInfoList) { | ||
return new SubmitterResultResponse( | ||
creatorname, | ||
submitterInfoList | ||
); | ||
} | ||
} |
11 changes: 10 additions & 1 deletion
11
src/main/java/com/sinabro/sinabro/entity/response/SurveyResponse.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,4 +1,13 @@ | ||
package com.sinabro.sinabro.entity.response; | ||
|
||
public class SurveyResponse { | ||
import com.sinabro.sinabro.entity.Survey; | ||
|
||
public record SurveyResponse( | ||
String url | ||
) { | ||
public static SurveyResponse from(Survey survey) { | ||
return new SurveyResponse( | ||
survey.getUrl() | ||
); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/sinabro/sinabro/repository/CreatorRepository.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,8 +1,12 @@ | ||
package com.sinabro.sinabro.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.sinabro.sinabro.entity.Creator; | ||
import com.sinabro.sinabro.entity.Survey; | ||
|
||
public interface CreatorRepository extends JpaRepository<Creator, Long> { | ||
List<Creator> findBySurvey(Survey survey); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/sinabro/sinabro/repository/SubmitterRepository.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,8 +1,12 @@ | ||
package com.sinabro.sinabro.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.sinabro.sinabro.entity.Submitter; | ||
import com.sinabro.sinabro.entity.Survey; | ||
|
||
public interface SubmitterRepository extends JpaRepository<Submitter, Long> { | ||
List<Submitter> findBySurveyOrderByScoreDesc(Survey survey); | ||
} |
6 changes: 5 additions & 1 deletion
6
src/main/java/com/sinabro/sinabro/repository/SurveyRepository.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,7 +1,11 @@ | ||
package com.sinabro.sinabro.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SurveyRepository extends JpaRepository<com.sinabro.sinabro.entity.Survey, Long> { | ||
import com.sinabro.sinabro.entity.Survey; | ||
|
||
public interface SurveyRepository extends JpaRepository<Survey, Long> { | ||
Optional<Survey> findSurveyByUrl(String url); | ||
} |
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