Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix[#41] 스웨거 적용 #44

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions jaksim/src/main/java/org/sopt/jaksim/category/api/CategoryApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.sopt.jaksim.category.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.sopt.jaksim.category.dto.CategoryCreateRequest;
import org.sopt.jaksim.global.common.BaseResponse;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Tag(name = "Category 관련 API")
@SecurityRequirement(name = "Authorization")
public interface CategoryApi {

@Operation(
summary = "카테고리 생성 API",
responses = {
@ApiResponse(
responseCode = "201",
description = "요청이 성공했습니다."),

@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),

@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),

@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.")})
public ResponseEntity<BaseResponse<?>> create(@RequestBody CategoryCreateRequest request);



@Operation(
summary = "전체 카테고리, 태스크 조희 API (홈뷰)",
responses = {
@ApiResponse(
responseCode = "201",
description = "요청이 성공했습니다.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),

@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),

@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),

@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),

@ApiResponse(
responseCode = "404",
description = "대상을 찾을 수 없습니다",
content = @Content),

@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),

@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})

public ResponseEntity<BaseResponse<?>> retrieve(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate);

@Operation(
summary = "카테고리 조희 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "요청이 성공했습니다.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "404",
description = "대상을 찾을 수 없습니다",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.")})
ResponseEntity<BaseResponse<?>> getCategoriesByUserId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class CategoryApiController {
public class CategoryApiController implements CategoryApi{
private final CategoryService categoryService;
private final CategoryTaskFacade categoryTaskFacade;

@PostMapping("/categories")
@Override
public ResponseEntity<BaseResponse<?>> create(@RequestBody CategoryCreateRequest request) {
categoryService.create(request);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
}

@GetMapping("/resources")
@Override
public ResponseEntity<BaseResponse<?>> retrieve(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
List<FilteredResourceResponse> response = categoryTaskFacade.getAllResources(startDate, endDate);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, response);
}


@GetMapping("/categories")
@Override
public ResponseEntity<BaseResponse<?>> getCategoriesByUserId() {
List<CategoryCheckResponse> categories = categoryService.getCategoriesByUserId(); // categoryRepository를 통해 데이터베이스에서 특정 사용자의 카테고리를 조회
return ApiResponseUtil.success(SuccessMessage.SUCCESS, categories); // 성공 응답 반환
Expand Down
48 changes: 48 additions & 0 deletions jaksim/src/main/java/org/sopt/jaksim/mset/api/MsetApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.sopt.jaksim.mset.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.sopt.jaksim.global.common.BaseResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;

@Tag(name = "Mset 관련 API")
@SecurityRequirement(name = "Authorization")
public interface MsetApi {
@Operation(
summary = "다른 카테고리에서 모립세트 불러오기 API",
responses = {
@ApiResponse(
responseCode = "201",
description = "요청이 성공했습니다.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "404",
description = "대상을 찾을 수 없습니다",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.")})
public ResponseEntity<BaseResponse<?>> getFromOtherCategory(@PathVariable("categoryId") Long categoryId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.Response;
import org.sopt.jaksim.category.api.CategoryApi;
import org.sopt.jaksim.category.dto.CategoryMsetLinkResponse;
import org.sopt.jaksim.category.facade.CategoryMsetFacade;
import org.sopt.jaksim.global.common.ApiResponseUtil;
Expand All @@ -18,10 +19,11 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class MsetApiController {
public class MsetApiController implements MsetApi {
private final CategoryMsetFacade categoryMsetFacade;

@GetMapping("/mset/categories/{categoryId}")
@Override
public ResponseEntity<BaseResponse<?>> getFromOtherCategory(@PathVariable("categoryId") Long categoryId) {
CategoryMsetLinkResponse response = categoryMsetFacade.getFromOtherCategory(categoryId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, response);
Expand Down
107 changes: 107 additions & 0 deletions jaksim/src/main/java/org/sopt/jaksim/task/api/TaskApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.sopt.jaksim.task.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.sopt.jaksim.global.common.BaseResponse;
import org.sopt.jaksim.task.dto.TaskCreateRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;


@Tag(name = "태스크 관련 API")
@SecurityRequirement(name = "Authorization")
public interface TaskApi {
@Operation(
summary = "URL로 탭 이름 가져오기 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "요청이 성공했습니다.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "요청된 url이 유효하지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.")})
public ResponseEntity<BaseResponse<?>> fetchTitle(@RequestParam("requestUrl") String requestUrl);

@Operation(
summary = "태스크 생성 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "요청이 성공했습니다."),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "404",
description = "대상을 찾을 수 없습니다.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.")})
public ResponseEntity<BaseResponse<?>> create(@PathVariable("categoryId") Long categoryId,
@RequestBody TaskCreateRequest taskCreateRequest);


@Operation(
summary = "태스크 상태 변경 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "요청이 성공했습니다."),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "404",
description = "존재하지 않는 태스크입니다.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.")})
public ResponseEntity<BaseResponse<?>> toggleTaskStatus(@PathVariable("taskId") Long taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class TaskApiController {
public class TaskApiController implements TaskApi{
private final TaskService taskService;

@GetMapping("/fetch-title")
@Override
public ResponseEntity<BaseResponse<?>> fetchTitle(@RequestParam("requestUrl") String requestUrl) {
try {
Document doc = Jsoup.connect(requestUrl).get();
Expand All @@ -40,13 +41,15 @@ public ResponseEntity<BaseResponse<?>> fetchTitle(@RequestParam("requestUrl") St
}

@PostMapping("/categories/{categoryId}")
@Override
public ResponseEntity<BaseResponse<?>> create(@PathVariable("categoryId") Long categoryId,
@RequestBody TaskCreateRequest taskCreateRequest) {
taskService.create(categoryId, taskCreateRequest);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
}

@PatchMapping("/tasks/{taskId}/status")
@Override
public ResponseEntity<BaseResponse<?>> toggleTaskStatus(@PathVariable("taskId") Long taskId) {
taskService.toggleTaskCompletionStatus(taskId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
Expand Down
Loading