Skip to content

Commit

Permalink
fix: requestBody -> requestParam 수정
Browse files Browse the repository at this point in the history
related to: #16
  • Loading branch information
heejjinkim committed Oct 11, 2024
1 parent 99cc179 commit b005618
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package com._119.wepro.review.dto.request;

import com._119.wepro.global.enums.CategoryType;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class QuestionRequest {
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class QuestionGetRequest{

private List<CategoryType> categories;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com._119.wepro.review.presentation;

import com._119.wepro.global.util.SecurityUtil;
import com._119.wepro.review.dto.request.QuestionRequest.*;
import com._119.wepro.review.dto.response.QuestionResponse.*;
import com._119.wepro.global.enums.CategoryType;
import com._119.wepro.review.dto.response.QuestionResponse.QuestionGetResponse;
import com._119.wepro.review.service.QuestionService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -19,12 +18,11 @@
public class QuestionController {

private final QuestionService questionService;
private final SecurityUtil securityUtil;

@Operation(summary = "카테고리에 해당하는 질문들 반환 API")
@GetMapping("/categories")
public ResponseEntity<QuestionGetResponse> getQuestionsInCategories(@RequestBody @Valid QuestionGetRequest request){
securityUtil.getCurrentMemberId();
return ResponseEntity.ok(questionService.getQuestionsInCategories(request));
public ResponseEntity<QuestionGetResponse> getQuestionsInCategories(
@RequestParam List<CategoryType> categoryTypes) {
return ResponseEntity.ok(questionService.getQuestionsInCategories(categoryTypes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import com._119.wepro.global.exception.errorcode.ReviewErrorCode;
import com._119.wepro.review.domain.Question;
import com._119.wepro.review.domain.repository.QuestionRepository;
import com._119.wepro.review.dto.request.QuestionRequest.*;
import com._119.wepro.review.dto.response.QuestionResponse.*;
import com._119.wepro.review.dto.response.QuestionResponse.QuestionGetResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -17,10 +16,9 @@ public class QuestionService {

private final QuestionRepository questionRepository;

public QuestionGetResponse getQuestionsInCategories(QuestionGetRequest request) {
List<CategoryType> categories = request.getCategories();
public QuestionGetResponse getQuestionsInCategories(List<CategoryType> categoryTypes) {

List<Question> questions = categories.stream()
List<Question> questions = categoryTypes.stream()
.flatMap(category -> questionRepository.findByCategoryType(category).stream())
.toList();
if (questions.isEmpty()) {
Expand Down

0 comments on commit b005618

Please sign in to comment.