Skip to content

Commit

Permalink
Merge branch 'refactor/be/#118-fix-controller' of github.com:kookmin-…
Browse files Browse the repository at this point in the history
…sw/capstone-2024-30 into feautre/be/#115-CICD
  • Loading branch information
mclub4 committed May 1, 2024
2 parents 207a3e8 + 9ba12ef commit 8403907
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.example.capstone.domain.qna.dto.*;
import com.example.capstone.domain.qna.service.AnswerService;
import com.example.capstone.global.dto.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,44 +24,64 @@ public class AnswerController {
private final JwtTokenProvider jwtTokenProvider;

@PostMapping("/create")
public ResponseEntity<?> createAnswer(/*@RequestHeader String token,*/ @RequestBody AnswerPostRequest request) {
@Operation(summary = "댓글 생성", description = "request 정보를 기반으로 댓글을 생성합니다.")
@ApiResponse(responseCode = "200", description = "생성된 댓글을 반환합니다.")
public ResponseEntity<?> createAnswer(/*@RequestHeader String token,*/
@Parameter(description = "댓글의 구성요소 입니다. 질문글의 id, 작성자, 댓글내용이 필요합니다.", required = true)
@RequestBody AnswerPostRequest request) {
String userId = UUID.randomUUID().toString(); //jwtTokenProvider.extractUUID(token);
AnswerResponse answer = answerService.createAnswer(userId, request);
return ResponseEntity
.ok(new ApiResult<>("Successfully create answer",answer));
}

@GetMapping("/list")
public ResponseEntity<?> listAnswer(@RequestBody AnswerListRequest request) {
@Operation(summary = "댓글 리스트 생성", description = "request 정보를 기반으로 댓글의 리스트를 생성합니다.")
@ApiResponse(responseCode = "200", description = "request 정보를 기반으로 생성된 댓글의 리스트가 반환됩니다.")
public ResponseEntity<?> listAnswer(@Parameter(description = "댓글 리스트 생성을 위한 파라미터 값입니다. 질문글의 id, cursorId, 댓글 정렬 기준( date / like )이 필요합니다.", required = true)
@RequestBody AnswerListRequest request) {
Map<String, Object> response = answerService.getAnswerList(request.questionId(), request.cursorId(), request.sortBy());
return ResponseEntity
.ok(new ApiResult<>("Successfully create answer list", response));
}

@PutMapping("/update")
public ResponseEntity<?> updateAnswer(/*@RequestHeader String token,*/ @RequestBody AnswerPutRequest request) {
@Operation(summary = "댓글 수정", description = "request 정보를 기반으로 댓글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "수정된 댓글의 정보가 반환됩니다.")
public ResponseEntity<?> updateAnswer(/*@RequestHeader String token,*/
@Parameter(description = "댓글 수정을 위한 파라미터입니다. 댓글 id, 질문글 id, 작성자, 댓글 내용이 필요합니다.", required = true)
@RequestBody AnswerPutRequest request) {
String userId = UUID.randomUUID().toString(); //jwtTokenProvider.extractUUID(token);
answerService.updateAnswer(userId, request);
return ResponseEntity
.ok(new ApiResult<>("Successfully update answer", request.questionId()));
}

@DeleteMapping("/erase")
public ResponseEntity<?> eraseAnswer(@RequestBody Long id) {
@Operation(summary = "질문글 삭제", description = "댓글 id를 통해 해당글을 삭제합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200이 반환됩니다.")
public ResponseEntity<?> eraseAnswer( @Parameter(description = "삭제할 댓글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
answerService.eraseAnswer(id);
return ResponseEntity
.ok(new ApiResult<>("Successfully delete answer", 200));
}

@PutMapping("/like")
public ResponseEntity<?> upLikeCount(@RequestBody Long id) {
@Operation(summary = "댓글 추천", description = "해당 id의 댓글을 추천합니다. 현재 추천 댓글 여부를 관리하지 않습니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<?> upLikeCount( @Parameter(description = "추천할 댓글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
answerService.upLikeCountById(id);
return ResponseEntity
.ok(new ApiResult<>("Successfully like answer", 200));
}

@PutMapping("/unlike")
public ResponseEntity<?> downLikeCount(@RequestBody Long id) {
@Operation(summary = "댓글 추천 해제", description = "해당 id의 댓글을 추천 해제합니다. 현재 추천 댓글 여부를 관리하지 않습니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<?> downLikeCount( @Parameter(description = "추천 해제할 댓글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
answerService.downLikeCountById(id);
return ResponseEntity
.ok(new ApiResult<>("Successfully unlike answer", 200));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import com.example.capstone.domain.qna.service.FAQService;
import com.example.capstone.domain.qna.service.ImageService;
import com.example.capstone.global.dto.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Expand All @@ -31,35 +35,49 @@ public class FAQController {

private final JwtTokenProvider jwtTokenProvider;

@PostMapping("/create")
public ResponseEntity<?> createFAQ(@RequestPart FAQPostRequest request,
@RequestPart List<MultipartFile> multipartFileList) {
@PostMapping(value = "/create", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "FAQ글 생성", description = "request 정보를 기반으로 FAQ글을 생성합니다. imgList 정보를 통해 이미지 파일을 업로드 합니다")
@ApiResponse(responseCode = "200", description = "request 정보를 기반으로 생성된 FAQ글과 imgList을 통해 업로드된 이미지 파일의 url 정보가 함께 반환됩니다.")
public ResponseEntity<?> createFAQ( @Parameter(description = "FAQ글 생성을 위한 파라미터입니다. 제목, 작성자, 질문, 답변, 언어, 태그값이 필요합니다.", required = true)
@RequestPart FAQPostRequest request,
@Parameter(description = "FAQ글에 첨부될 이미지입니다. List 형태로 입력되야 합니다.")
@RequestPart(required = false) List<MultipartFile> imgList) {
List<String> urlList = new ArrayList<>();
FAQResponse faq = faqService.createFAQ(request);
if(multipartFileList != null) {
urlList = imageService.upload(multipartFileList, faq.id(), true);
if(imgList != null) {
System.out.println(imgList.size());
urlList = imageService.upload(imgList, faq.id(), true);
}
return ResponseEntity
.ok(new ApiResult<>("Successfully create FAQ", Map.of("content", faq, "imgUrl", urlList)));
}

@GetMapping("/read")
public ResponseEntity<?> readFAQ(@RequestBody Long id) {
@Operation(summary = "FAQ글 읽기", description = "FAQ글을 읽어 반환합니다.")
@ApiResponse(responseCode = "200", description = "FAQ글의 내용이 담긴 content와 첨부이미지 주소가 담긴 imgUrl이 반환됩니다.")
public ResponseEntity<?> readFAQ( @Parameter(description = "읽을 FAQ글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
FAQResponse faqResponse = faqService.getFAQ(id);
List<String> urlList = imageService.getUrlListByFAQId(id);
return ResponseEntity
.ok(new ApiResult<>("Successfully read FAQ", Map.of("content", faqResponse, "imgUrl", urlList)));
}

@PutMapping("/update")
public ResponseEntity<?> updateFAQ(@RequestBody FAQPutRequest request) {
@Operation(summary = "FAQ글 수정", description = "FAQ글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<?> updateFAQ( @Parameter(description = "FAQ글 수정을 위한 파라미터입니다. FAQ글 id, 제목, 작성자, 질문, 답변, 언어, 태그값이 필요합니다.", required = true)
@RequestBody FAQPutRequest request) {
faqService.updateFAQ(request);
return ResponseEntity
.ok(new ApiResult<>("Successfully update FAQ", 200));
}

@DeleteMapping("/erase")
public ResponseEntity<?> eraseFAQ(@RequestBody Long id) {
@Operation(summary = "FAQ글 삭제", description = "FAQ글을 삭제합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<?> eraseFAQ( @Parameter(description = "삭제할 FAQ글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
List<String> urlList = imageService.getUrlListByFAQId(id);
for(String url : urlList) {
imageService.deleteImageFromS3(url);
Expand All @@ -71,7 +89,10 @@ public ResponseEntity<?> eraseFAQ(@RequestBody Long id) {
}

@GetMapping("/list")
public ResponseEntity<?> listFAQ(FAQListRequest request) {
@Operation(summary = "FAQ글의 미리보기 리스트 생성", description = "FAQ글 리스트를 생성하여 반환합니다.")
@ApiResponse(responseCode = "200", description = "FAQ글의 미리보기 리스트가 반환됩니다.")
public ResponseEntity<?> listFAQ( @Parameter(description = "FAQ글 리스트를 생성하기 위한 파라미터입니다. cursorId, 언어, 검색어, 태그값이 필요합니다.", required = true)
@RequestBody FAQListRequest request) {
Map<String, Object> response = faqService.getFAQList(request.cursorId(), request.language(), request.word(), request.tag());
return ResponseEntity
.ok(new ApiResult<>("Successfully create FAQ list", response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import com.example.capstone.domain.qna.service.ImageService;
import com.example.capstone.domain.qna.service.QuestionService;
import com.example.capstone.global.dto.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Expand All @@ -28,9 +32,14 @@ public class QuestionController {
private final ImageService imageService;
private final JwtTokenProvider jwtTokenProvider;

@PostMapping("/create")
public ResponseEntity<?> createQuestion(/*@RequestHeader String token,*/ @RequestPart("content") QuestionPostRequest request,
@RequestPart("imgUrl") List<MultipartFile> imgList) {
@PostMapping(value = "/create", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "질문글 생성", description = "request 정보를 기반으로 질문글을 생성합니다. imgList 정보를 통해 이미지 파일을 업로드 합니다")
@ApiResponse(responseCode = "200", description = "request 정보를 기반으로 생성된 질문글과 imgList을 통해 업로드된 이미지 파일의 url 정보가 함께 반환됩니다.")
public ResponseEntity<?> createQuestion(/*@RequestHeader String token,*/
@Parameter(description = "질문글의 구성 요소 입니다. 제목, 작성자, 본문, 태그, 국가 정보가 들어가야 합니다.", required = true)
@RequestPart QuestionPostRequest request,
@Parameter(description = "질문글에 첨부되는 이미지 파일들 입니다. 여러 파일을 리스트 형식으로 입력해야 합니다.")
@RequestPart(required = false) List<MultipartFile> imgList) {
List<String> urlList = new ArrayList<>();
String userId = UUID.randomUUID().toString();//jwtTokenProvider.extractUUID(token);
QuestionResponse quest = questionService.createQuestion(userId, request);
Expand All @@ -42,23 +51,35 @@ public ResponseEntity<?> createQuestion(/*@RequestHeader String token,*/ @Reques
}

@GetMapping("/read")
public ResponseEntity<?> readQuestion(@RequestParam Long id) {
@Operation(summary = "질문글 불러오기", description = "id를 통해 해당 질문글을 가져옵니다.")
@ApiResponse(responseCode = "200", description = "해당 id의 질문글과 이미지 url을 반환합니다.")
public ResponseEntity<?> readQuestion(
@Parameter(description = "가져올 질문글의 id 입니다.", required = true)
@RequestParam Long id) {
QuestionResponse questionResponse = questionService.getQuestion(id);
List<String> urlList = imageService.getUrlListByQuestionId(id);
return ResponseEntity
.ok(new ApiResult<>("Successfully read question", Map.of("content", questionResponse, "imgUrl", urlList)));
}

@PutMapping("/update")
public ResponseEntity<?> updateQuestion(/*@RequestHeader String token,*/ @RequestBody QuestionPutRequest request) {
@Operation(summary = "질문글 수정", description = "request 정보를 기반으로 질문글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 리턴합니다.")
public ResponseEntity<?> updateQuestion(/*@RequestHeader String token,*/
@Parameter(description = "수정할 질문글의 id와 질문글의 content가 들어갑니다.", required = true)
@RequestBody QuestionPutRequest request) {
String userId = UUID.randomUUID().toString();//jwtTokenProvider.extractUUID(token);
questionService.updateQuestion(userId, request);
return ResponseEntity
.ok(new ApiResult<>("Successfully update question", 200));
}

@DeleteMapping("/erase")
public ResponseEntity<?> eraseQuestion(@RequestParam Long id) {
@Operation(summary = "질문글 삭제", description = "id를 기반으로 해당 질문글을 삭제합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 리턴합니다.")
public ResponseEntity<?> eraseQuestion(
@Parameter(description = "삭제할 질문글의 id 입니다.", required = true)
@RequestParam Long id) {
List<String> urlList = imageService.getUrlListByQuestionId(id);
for(String url : urlList) {
imageService.deleteImageFromS3(url);
Expand All @@ -70,7 +91,11 @@ public ResponseEntity<?> eraseQuestion(@RequestParam Long id) {
}

@GetMapping("/list")
public ResponseEntity<?> listQuestion(@RequestBody QuestionListRequest request) {
@Operation(summary = "질문글 미리보기 리스트 생성", description = "request 정보를 기반으로 페이지네이션이 적용된 질문글 리스트를 반환합니다.")
@ApiResponse(responseCode = "200", description = "request 조건에 맞는 질문글 리스트를 반환합니다.")
public ResponseEntity<?> listQuestion(
@Parameter(description = "질문글 리스트를 위한 cursorId, 검색어 word, 태그값 tag가 필요합니다.", required = true)
@RequestBody QuestionListRequest request) {
Map<String, Object> response = questionService.getQuestionList(request);
return ResponseEntity
.ok(new ApiResult<>("Successfully create question list", response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

Expand All @@ -27,9 +28,9 @@ public class SpeechController {
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "발음평가 매서드", description = "발음평가 음성파일(.wav)과 비교문을 통해 발음평가 결과를 반환합니다.")
@ApiResponse(responseCode = "200", description = "speech-text로 인식된 텍스트, 전체 텍스트 단위 평가 점수, 단어 종합 평가 점수, 각 단어별 평가 내용이 반환됩니다.")
public ResponseEntity<ApiResult<String>> uploadSpeech(@RequestPart("file") MultipartFile file, @RequestPart("context") String context)
public ResponseEntity<ApiResult<Map<String, Object>>> uploadSpeech(@RequestPart("file") MultipartFile file, @RequestPart("context") String context)
throws ExecutionException, InterruptedException, IOException {
CompletableFuture<String> result = speechService.pronunciation(context, file);
CompletableFuture<Map<String, Object>> result = speechService.pronunciation(context, file);
return ResponseEntity
.ok(new ApiResult<>("Successfully get speech result", result.get()));
}
Expand Down
Loading

0 comments on commit 8403907

Please sign in to comment.