Skip to content

Commit

Permalink
📝 docs: controller design
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerohertz committed Oct 30, 2024
1 parent 7aa9e75 commit 910fb95
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

- [Package 구조](docs/package-structure.md)
- [Service layer 개발 방법](docs/service.md)
- [Controller 개발 방법](docs/controller.md)
- [Docker Compose 사용 방법](docs/docker-compose.md)
- [Kubernetes 사용 방법](docs/kubernetes.md)
28 changes: 28 additions & 0 deletions docs/controller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Controller 규약

```java
@ResponseStatus(HttpStatus.OK) // 정상적 응답에 대한 HTTP status 작성
@GetMapping("/${URI}") // API 접근 URI 명시
@Operation(summary = "${SUMMARY}", description = "${DESCRIPTION}") // Swagger 내 문서화를 위한 설명 작성
// Controller의 모든 응답에 ApiResponseDto class 사용
// Generic을 통해 응답의 data type 명시
public ApiResponseDto<T> methodName(
HttpServletRequest request, // 직접적인 요청 정보가 필요할 때 사용
@RequestParam String param1, // 쿼리 스트링 또는 폼 데이터의 요청 파라미터
@PathVariable Long param2, // URL 경로의 변수 매핑
@RequestBody Dto param3, // 요청 본문(JSON 등)을 객체로 받음
HttpServletResponse response // 직접적인 응답 설정이 필요할 때 사용
) {
// Request header 사용 예시
String authHeader = request.getHeader("Authorization");

// 결과를 위한 business logic 실행
T data = domainService.businessLogic();

// Response header 추가 예시
response.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);

// 정상적인 응답 시 사용할 HTTP status 및 응답 data
return ApiResponseDto.success(HttpStatus.OK.value(), data);
}
```

0 comments on commit 910fb95

Please sign in to comment.