Skip to content

Commit

Permalink
feat: Swagger annotation 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
byeon22 committed Jul 15, 2024
1 parent 6871c75 commit 9d60854
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,73 @@
import com.powersupply.PES.answer.dto.AnswerDTO;
import com.powersupply.PES.answer.service.AnswerService;
import com.powersupply.PES.utils.ResponseUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@Tag(name = "Answer", description = "답변 관련 API")
public class AnswerController {

private final AnswerService answerService;

// answerEntity 만들기
@Operation(summary = "답변 생성", description = "사용자가 답변을 생성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "답변 생성 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PostMapping("/api/answer")
public ResponseEntity<AnswerDTO.GetAnswerId> createAnswer(@RequestParam("memberEmail") String email, @RequestParam("problemId") Long problemId) {
public ResponseEntity<AnswerDTO.GetAnswerId> createAnswer(
@Parameter(description = "회원 이메일", example = "[email protected]") @RequestParam("memberEmail") String email,
@Parameter(description = "문제 ID", example = "1") @RequestParam("problemId") Long problemId) {
return ResponseEntity.status(HttpStatus.CREATED).body(answerService.createAnswer(email, problemId));
}

// 질문, 답변 가져오기
@Operation(summary = "질문 및 답변 조회", description = "특정 답변 ID에 대한 질문과 답변을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공(토큰에 문제가 없고 유저를 DB에서 찾을 수 있는 경우)"),
@ApiResponse(responseCode = "404", description = "해당 answerId를 찾을 수 없는 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/api/answer/{answerId}")
public ResponseEntity<AnswerDTO.GetAnswer> getAnswer(@PathVariable Long answerId) {
public ResponseEntity<AnswerDTO.GetAnswer> getAnswer(
@Parameter(description = "답변 ID", example = "1") @PathVariable Long answerId) {
return ResponseEntity.ok().body(answerService.getAnswer(answerId));
}

// 답변하기
@Operation(summary = "답변하기", description = "사용자가 특정 답변 ID에 대해 답변을 작성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "답변 작성 성공"),
@ApiResponse(responseCode = "400", description = "answer 내용이 null인 경우 or 이미 댓글이 있어 수정이 불가능 한 경우"),
@ApiResponse(responseCode = "404", description = "answer의 주인과 토큰이 다른 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PostMapping("/api/answer/{answerId}")
public ResponseEntity<?> postAnswer(@PathVariable Long answerId,
@RequestBody AnswerDTO.AnswerContent dto) {
public ResponseEntity<?> postAnswer(
@Parameter(description = "답변 ID", example = "1") @PathVariable Long answerId,
@RequestBody AnswerDTO.AnswerContent dto) {
answerService.postAnswer(answerId, dto);
return ResponseUtil.successResponse("");
}

// 풀이 보기
@Operation(summary = "풀이 보기", description = "특정 문제 ID에 대한 풀이 목록을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "토큰에 문제가 없고 유저를 DB에서 찾을 수 있는 경우"),
@ApiResponse(responseCode = "204", description = "아직 푼 사람이 없는 경우"),
@ApiResponse(responseCode = "404", description = "problemId가 잘못된 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/api/answerlist/{problemId}")
public ResponseEntity<?> getAnswerList(@PathVariable Long problemId) {
public ResponseEntity<?> getAnswerList(
@Parameter(description = "문제 ID", example = "1") @PathVariable Long problemId) {
return answerService.getAnswerList(problemId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,46 @@

import com.powersupply.PES.comment.dto.CommentDTO;
import com.powersupply.PES.comment.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@Tag(name = "Comment", description = "댓글 관련 API")
public class CommentController {

private final CommentService commentService;

// 댓글 가져오기
@Operation(summary = "댓글 조회", description = "특정 답변 ID에 대한 댓글을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "204", description = "댓글이 없는 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/api/comment/{answerId}")
public ResponseEntity<?> getComment(@PathVariable Long answerId) {
public ResponseEntity<?> getComment(
@Parameter(description = "답변 ID", example = "1") @PathVariable Long answerId) {
return commentService.getComment(answerId);
}

// 댓글 달기
@Operation(summary = "댓글 달기", description = "특정 답변 ID에 대해 댓글을 작성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "토큰에 문제가 없고 유저를 DB에서 찾아 정상적으로 댓글을 생성한 경우"),
@ApiResponse(responseCode = "400", description = "이미 자신의 댓글이 있는 경우"),
@ApiResponse(responseCode = "403", description = "재학생이 아닌 경우 / jwt 문제 / 자신의 답변에 댓글을 단 경우 / 최대 댓글 수 도달"),
@ApiResponse(responseCode = "404", description = "answerId가 잘못된 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PostMapping("/api/comment/{answerId}")
public ResponseEntity<?> createComment(@PathVariable Long answerId,
@RequestBody CommentDTO.CreateComment dto) {
public ResponseEntity<?> createComment(
@Parameter(description = "답변 ID", example = "1") @PathVariable Long answerId,
@RequestBody CommentDTO.CreateComment dto) {
return commentService.createComment(answerId, dto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.powersupply.PES.manage.dto.ManageDTO;
import com.powersupply.PES.member.entity.MemberEntity;
import com.powersupply.PES.manage.service.ManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -13,90 +18,161 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/admin")
@Tag(name = "Manage", description = "관리 기능 API")
public class ManageController {

private final ManageService manageService;

/* ---------- 문제 관리 기능 ---------- */

// 전체 문제 리스트 불러오기
@Operation(summary = "전체 문제 리스트 불러오기", description = "전체 문제 리스트를 불러옵니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/problemlist")
public ResponseEntity<List<ManageDTO.ProblemList>> problemList() {
List<ManageDTO.ProblemList> problemList = manageService.problemList();
return ResponseEntity.ok().body(problemList);
}

// 특정 문제 detail 불러오기
@Operation(summary = "특정 문제 detail 불러오기", description = "특정 문제의 상세 정보를 불러옵니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "404", description = "해당 problemId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/problem/{problemId}")
public ResponseEntity<ManageDTO.ProblemDetail> problemDetail(@PathVariable Long problemId) {
public ResponseEntity<ManageDTO.ProblemDetail> problemDetail(
@Parameter(description = "문제 ID", example = "1") @PathVariable Long problemId) {
return ResponseEntity.ok().body(manageService.problemDetail(problemId));
}

// 문제 등록하기
@Operation(summary = "문제 등록하기", description = "새로운 문제를 등록합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "등록 성공"),
@ApiResponse(responseCode = "403", description = "관리자 권한이 없는 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PostMapping("/problem")
public ResponseEntity<?> postProblem(@RequestBody ManageDTO.ProblemRequestDto requestDto) throws IOException {
return ResponseEntity.ok(manageService.postProblem(requestDto));
}

// 문제 수정하기
@Operation(summary = "문제 수정하기", description = "기존 문제를 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공"),
@ApiResponse(responseCode = "404", description = "해당 problemId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PatchMapping("/problem/{problemId}")
public ResponseEntity<?> patchProblem(@PathVariable Long problemId, @RequestBody ManageDTO.ProblemRequestDto requestDto) {
public ResponseEntity<?> patchProblem(
@Parameter(description = "문제 ID", example = "1") @PathVariable Long problemId,
@RequestBody ManageDTO.ProblemRequestDto requestDto) {
return manageService.patchProblem(problemId, requestDto);
}

/* ---------- 회원 관리 기능 ---------- */

// 전체 멤버 리스트 불러오기
@Operation(summary = "전체 멤버 리스트 불러오기", description = "전체 멤버 리스트를 불러옵니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/memberlist")
public ResponseEntity<List<ManageDTO.MemberList>> list() {
List<ManageDTO.MemberList> memberList = manageService.list();

return ResponseEntity.ok().body(memberList);
}

// 특정 멤버 detail 불러오기
@Operation(summary = "특정 멤버 detail 불러오기", description = "특정 멤버의 상세 정보를 불러옵니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "404", description = "해당 memberId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/member/{memberId}")
public ResponseEntity<ManageDTO.MemberDetail> readDetail(@PathVariable String memberId) {
public ResponseEntity<ManageDTO.MemberDetail> readDetail(
@Parameter(description = "멤버 ID", example = "user123") @PathVariable String memberId) {
return ResponseEntity.ok().body(manageService.readDetail(memberId));
}

// 멤버 삭제하기
@Operation(summary = "멤버 삭제하기", description = "특정 멤버를 삭제합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "삭제 성공"),
@ApiResponse(responseCode = "403", description = "관리자 권한이 없는 경우"),
@ApiResponse(responseCode = "404", description = "해당 memberId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@DeleteMapping("/member/{memberId}")
public ResponseEntity<?> deleteMember(@PathVariable String memberId) {
public ResponseEntity<?> deleteMember(
@Parameter(description = "멤버 ID", example = "user123") @PathVariable String memberId) {
return manageService.deleteMember(memberId);
}

// 멤버 상태 수정하기
@Operation(summary = "멤버 상태 수정하기", description = "특정 멤버의 상태를 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공"),
@ApiResponse(responseCode = "403", description = "관리자 권한이 없는 경우"),
@ApiResponse(responseCode = "404", description = "해당 memberId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PutMapping("/member/{memberId}")
public ResponseEntity<MemberEntity> updateMemberStatus(@PathVariable String memberId, @RequestBody ManageDTO.MemberUpdateRequestDto requestDto) {
public ResponseEntity<MemberEntity> updateMemberStatus(
@Parameter(description = "멤버 ID", example = "user123") @PathVariable String memberId,
@RequestBody ManageDTO.MemberUpdateRequestDto requestDto) {
return ResponseEntity.ok(manageService.updateMemberStatus(memberId, requestDto));
}

/* ---------- 질문 관리 기능 ---------- */

// 문제 별 질문 목록 가져오기
@Operation(summary = "문제 별 질문 목록 가져오기", description = "특정 문제에 대한 질문 목록을 불러옵니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/questionlist/{problemId}")
public ResponseEntity<List<ManageDTO.QuestionList>> questionList(@PathVariable Long problemId) {
public ResponseEntity<List<ManageDTO.QuestionList>> questionList(
@Parameter(description = "문제 ID", example = "1") @PathVariable Long problemId) {
List<ManageDTO.QuestionList> questionList = manageService.questionList(problemId);

return ResponseEntity.ok().body(questionList);
}

// 질문 등록하기
@Operation(summary = "질문 등록하기", description = "특정 문제에 대해 질문을 등록합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "등록 성공"),
@ApiResponse(responseCode = "400", description = "관리자 권한이 없는 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PostMapping("/question/{problemId}")
public ResponseEntity<?> postQuestion(@PathVariable Long problemId, @RequestBody ManageDTO.QuestionRequestDto requestDto) {
public ResponseEntity<?> postQuestion(
@Parameter(description = "문제 ID", example = "1") @PathVariable Long problemId,
@RequestBody ManageDTO.QuestionRequestDto requestDto) {
return ResponseEntity.ok(manageService.postQuestion(problemId, requestDto));
}

// 질문 수정하기
@Operation(summary = "질문 수정하기", description = "기존 질문을 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공"),
@ApiResponse(responseCode = "404", description = "해당 questionId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PatchMapping("/question/{questionId}")
public ResponseEntity<?> patchQuestion(@PathVariable Long questionId, @RequestBody ManageDTO.QuestionRequestDto requestDto) {
public ResponseEntity<?> patchQuestion(
@Parameter(description = "질문 ID", example = "1") @PathVariable Long questionId,
@RequestBody ManageDTO.QuestionRequestDto requestDto) {
return ResponseEntity.ok(manageService.updateQuestion(questionId, requestDto));
}

// 질문 삭제하기
@Operation(summary = "질문 삭제하기", description = "특정 질문을 삭제합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "삭제 성공"),
@ApiResponse(responseCode = "404", description = "해당 questionId가 없을 경우"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@DeleteMapping("/question/{questionId}")
public ResponseEntity<?> deleteQuestion(@PathVariable Long questionId) {
public ResponseEntity<?> deleteQuestion(
@Parameter(description = "질문 ID", example = "1") @PathVariable Long questionId) {
return ResponseEntity.ok(manageService.deleteQuestion(questionId));
}
}
Loading

0 comments on commit 9d60854

Please sign in to comment.