Skip to content

Commit

Permalink
Merge pull request #104 from Tea-Bliss/dev
Browse files Browse the repository at this point in the history
Main PR
  • Loading branch information
mun9659 authored Jun 24, 2024
2 parents a3a1026 + d1d21d7 commit ce04d42
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import store.teabliss.survey.dto.SurveyResponse;
import store.teabliss.survey.service.SurveyService;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Tag(name = "설문조사 API")
Expand All @@ -32,8 +34,17 @@ public ResponseEntity<SurveyResponse> createSurvey(
return ResponseEntity.ok(SurveyResponse.ok("정상적으로 설문조사가 등록되었습니다.", id));
}

@GetMapping("/")
@Operation(summary = "설문조사 리스트 조회", description = "설문조사 리스트 조회 API")
public ResponseEntity<SurveyResponse> getSurvey() {

List<SurveyDto> surveys = surveyService.findBySurveys();

return ResponseEntity.ok(SurveyResponse.ok(surveys));
}

@GetMapping("/{id}")
@Operation(summary = "설문조사 조회", description = "설문조사 조회 API")
@Operation(summary = "설문조사 단일 조회", description = "설문조사 단일 조회 API")
public ResponseEntity<SurveyResponse> getSurvey(
@PathVariable Long id
) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/store/teabliss/survey/mapper/SurveyMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import org.apache.ibatis.annotations.Mapper;
import store.teabliss.survey.entity.Survey;

import java.util.List;

@Mapper
public interface SurveyMapper {

Long createSurvey(Survey survey);

List<Survey> findBySurveys();
Survey findById(Long id);

}
24 changes: 24 additions & 0 deletions src/main/java/store/teabliss/survey/service/SurveyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import store.teabliss.tea.entity.Tea;
import store.teabliss.tea.mapper.TeaMapper;

import java.util.ArrayList;
import java.util.List;

@Service
Expand All @@ -25,6 +26,29 @@ public Long createSurvey(Long memId, SurveyCreateDto surveyCreateDto) {
return surveyMapper.createSurvey(survey);
}

public List<SurveyDto> findBySurveys() {
List<SurveyDto> surveyDtos = new ArrayList<>();

List<Survey> surveys = surveyMapper.findBySurveys();

for(Survey s : surveys) {
Tea tea = Tea.builder()
.priceStart(s.getSale())
.priceEnd(s.getSale() + 10000)
.category(s.getCategory())
.caffeine(s.getCaffeine().equals("N"))
.build();

List<Tea> teas = teaMapper.surveyRecommendTea(tea);

SurveyDto surveyDto = SurveyDto.of(s, teas);

surveyDtos.add(surveyDto);
}

return surveyDtos;
}

public SurveyDto findById(Long id) {

Survey survey = surveyMapper.findById(id);
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/mapper/SurveyMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
VALUES (#{taste}, #{sale}, #{category}, #{caffeine}, #{memId})
</insert>

<select id="findBySurveys">
SELECT
*
FROM SURVEY
WHERE 1=1
ORDER BY create_dt DESC
</select>

<select id="findById" parameterType="Long">
SELECT
taste,
Expand Down

0 comments on commit ce04d42

Please sign in to comment.