Skip to content

Commit 38ab213

Browse files
committed
feat: 활동 연혁 API 컨트롤러 구현 (DASOMBE-15)
1 parent 8f497a7 commit 38ab213

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package dmu.dasom.api.domain.activity.controller;
2+
3+
import dmu.dasom.api.domain.activity.dto.GroupedActivityHistoryDto;
4+
import dmu.dasom.api.domain.activity.service.ActivityHistoryService;
5+
import dmu.dasom.api.domain.common.exception.ErrorResponse;
6+
import io.swagger.v3.oas.annotations.Operation;
7+
import io.swagger.v3.oas.annotations.media.Content;
8+
import io.swagger.v3.oas.annotations.media.ExampleObject;
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
13+
import lombok.RequiredArgsConstructor;
14+
import org.springframework.http.ResponseEntity;
15+
import org.springframework.web.bind.annotation.GetMapping;
16+
import org.springframework.web.bind.annotation.RequestMapping;
17+
import org.springframework.web.bind.annotation.RestController;
18+
19+
import java.util.List;
20+
21+
@RestController
22+
@RequestMapping("/api/activity/histories")
23+
@RequiredArgsConstructor
24+
@Tag(name = "Activity History API", description = "활동 연혁 API")
25+
public class ActivityHistoryController {
26+
27+
private final ActivityHistoryService historyService;
28+
29+
@Operation(summary = "활동 연혁 전체 조회", description = "모든 활동 연혁을 연도별, 섹션별로 그룹화하여 조회합니다.")
30+
@ApiResponses(value = {
31+
@ApiResponse(responseCode = "200", description = "활동 연혁 전체 조회 성공"),
32+
@ApiResponse(responseCode = "405", description = "허용되지 않은 요청 방식",
33+
content = @Content(
34+
mediaType = "application/json",
35+
schema = @Schema(implementation = ErrorResponse.class),
36+
examples = {
37+
@ExampleObject(
38+
name = "허용되지 않은 메서드",
39+
value = "{ \"code\": \"C007\", \"message\": \"허용되지 않은 요청 방식입니다.\" }"
40+
)
41+
}
42+
)),
43+
@ApiResponse(responseCode = "500", description = "서버 내부 오류",
44+
content = @Content(
45+
mediaType = "application/json",
46+
schema = @Schema(implementation = ErrorResponse.class),
47+
examples = {
48+
@ExampleObject(
49+
name = "서버 문제 발생",
50+
value = "{ \"code\": \"C009\", \"message\": \"서버에 문제가 발생하였습니다.\" }"
51+
)
52+
}
53+
))
54+
})
55+
@GetMapping
56+
public ResponseEntity<List<GroupedActivityHistoryDto>> getAllHistories() {
57+
return ResponseEntity.ok(historyService.getAllHistories());
58+
}
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package dmu.dasom.api.domain.activity.controller;
2+
3+
import dmu.dasom.api.domain.activity.dto.ActivityHistoryRequestDto;
4+
import dmu.dasom.api.domain.activity.dto.ActivityHistoryResponseDto;
5+
import dmu.dasom.api.domain.activity.service.ActivityHistoryService;
6+
import dmu.dasom.api.domain.common.exception.ErrorResponse;
7+
import io.swagger.v3.oas.annotations.Operation;
8+
import io.swagger.v3.oas.annotations.media.Content;
9+
import io.swagger.v3.oas.annotations.media.ExampleObject;
10+
import io.swagger.v3.oas.annotations.media.Schema;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
12+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
13+
import io.swagger.v3.oas.annotations.tags.Tag;
14+
import jakarta.validation.Valid;
15+
import jakarta.validation.constraints.Min;
16+
import lombok.RequiredArgsConstructor;
17+
import org.springframework.http.ResponseEntity;
18+
import org.springframework.web.bind.annotation.*;
19+
20+
@RestController
21+
@RequestMapping("/api/admin/activity/histories")
22+
@RequiredArgsConstructor
23+
@Tag(name = "ADMIN - Activity History API", description = "어드민 활동 연혁 관리 API")
24+
public class AdminActivityHistoryController {
25+
26+
private final ActivityHistoryService historyService;
27+
28+
@Operation(summary = "활동 연혁 생성")
29+
@ApiResponses(value = {
30+
@ApiResponse(responseCode = "201", description = "활동 연혁 생성 성공"),
31+
@ApiResponse(responseCode = "400", description = "요청 값 유효성 검사 실패", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "유효성 검사 실패", value = "{ \"code\": \"C007\", \"message\": \"요청한 값이 올바르지 않습니다.\" }"))),
32+
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "인증 실패", value = "{ \"code\": \"C001\", \"message\": \"인증되지 않은 사용자입니다.\" }"))),
33+
@ApiResponse(responseCode = "403", description = "접근 권한 없음 (ADMIN이 아님)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "권한 없음", value = "{ \"code\": \"C002\", \"message\": \"접근 권한이 없습니다.\" }"))),
34+
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "서버 문제 발생", value = "{ \"code\": \"C009\", \"message\": \"서버에 문제가 발생하였습니다.\" }")))
35+
})
36+
@PostMapping
37+
public ResponseEntity<ActivityHistoryResponseDto> createHistory(@Valid @RequestBody ActivityHistoryRequestDto requestDto) {
38+
return ResponseEntity.status(201).body(historyService.createHistory(requestDto));
39+
}
40+
41+
@Operation(summary = "활동 연혁 수정")
42+
@ApiResponses(value = {
43+
@ApiResponse(responseCode = "200", description = "활동 연혁 수정 성공"),
44+
@ApiResponse(responseCode = "400", description = "요청 값 유효성 검사 실패", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "유효성 검사 실패", value = "{ \"code\": \"C007\", \"message\": \"요청한 값이 올바르지 않습니다.\" }"))),
45+
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "인증 실패", value = "{ \"code\": \"C001\", \"message\": \"인증되지 않은 사용자입니다.\" }"))),
46+
@ApiResponse(responseCode = "403", description = "접근 권한 없음 (ADMIN이 아님)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "권한 없음", value = "{ \"code\": \"C002\", \"message\": \"접근 권한이 없습니다.\" }"))),
47+
@ApiResponse(responseCode = "404", description = "수정할 리소스를 찾을 수 없음", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "조회 결과 없음", value = "{ \"code\": \"C010\", \"message\": \"해당 리소스를 찾을 수 없습니다.\" }"))),
48+
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "서버 문제 발생", value = "{ \"code\": \"C009\", \"message\": \"서버에 문제가 발생하였습니다.\" }")))
49+
})
50+
@PutMapping("/{id}")
51+
public ResponseEntity<ActivityHistoryResponseDto> updateHistory(
52+
@PathVariable @Min(1) Long id,
53+
@Valid @RequestBody ActivityHistoryRequestDto requestDto
54+
) {
55+
return ResponseEntity.ok(historyService.updateHistory(id, requestDto));
56+
}
57+
58+
@Operation(summary = "활동 연혁 삭제")
59+
@ApiResponses(value = {
60+
@ApiResponse(responseCode = "200", description = "활동 연혁 삭제 성공"),
61+
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "인증 실패", value = "{ \"code\": \"C001\", \"message\": \"인증되지 않은 사용자입니다.\" }"))),
62+
@ApiResponse(responseCode = "403", description = "접근 권한 없음 (ADMIN이 아님)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "권한 없음", value = "{ \"code\": \"C002\", \"message\": \"접근 권한이 없습니다.\" }"))),
63+
@ApiResponse(responseCode = "404", description = "삭제할 리소스를 찾을 수 없음", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "조회 결과 없음", value = "{ \"code\": \"C010\", \"message\": \"해당 리소스를 찾을 수 없습니다.\" }"))),
64+
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class), examples = @ExampleObject(name = "서버 문제 발생", value = "{ \"code\": \"C009\", \"message\": \"서버에 문제가 발생하였습니다.\" }")))
65+
})
66+
@DeleteMapping("/{id}")
67+
public ResponseEntity<Void> deleteHistory(@PathVariable Long id) {
68+
historyService.deleteHistory(id);
69+
return ResponseEntity.noContent().build(); // 삭제 성공 시에는 204 No Content가 더 명확합니다.
70+
}
71+
}

0 commit comments

Comments
 (0)