springdoc-openapi 2.8.6 기반으로 모든 API 엔드포인트에 Swagger 어노테이션을 추가하여 API 문서를 자동 생성합니다. - OpenApiConfig: JWT 보안 스킴, 서버 목록, API 정보 설정 - SecurityConfig: swagger-ui 경로 공개 접근 허용 - 7개 Controller: @Tag, @Operation, @ApiResponses, @Parameter 등 (00.시스템, 01.인증, 02~04.관리자, 05.활동, 06.이슈) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
2.7 KiB
Java
59 lines
2.7 KiB
Java
package com.gcsc.guide.controller;
|
|
|
|
import com.gcsc.guide.dto.LoginHistoryResponse;
|
|
import com.gcsc.guide.dto.TrackPageViewRequest;
|
|
import com.gcsc.guide.service.ActivityService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
|
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.responses.ApiResponses;
|
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/activity")
|
|
@RequiredArgsConstructor
|
|
@Tag(name = "05. 활동 기록", description = "페이지 뷰 추적 및 로그인 이력 조회")
|
|
@SecurityRequirement(name = "Bearer JWT")
|
|
public class ActivityController {
|
|
|
|
private final ActivityService activityService;
|
|
|
|
@Operation(summary = "페이지 뷰 기록",
|
|
description = "현재 사용자가 특정 페이지를 조회했음을 기록합니다. 프론트엔드에서 페이지 이동 시 호출합니다.")
|
|
@ApiResponses({
|
|
@ApiResponse(responseCode = "200", description = "기록 성공"),
|
|
@ApiResponse(responseCode = "401", description = "인증 실패", content = @Content)
|
|
})
|
|
@PostMapping("/track")
|
|
public ResponseEntity<Void> trackPageView(
|
|
Authentication authentication,
|
|
@Valid @RequestBody TrackPageViewRequest request) {
|
|
Long userId = (Long) authentication.getPrincipal();
|
|
activityService.trackPageView(userId, request.pagePath());
|
|
return ResponseEntity.ok().build();
|
|
}
|
|
|
|
@Operation(summary = "현재 사용자의 로그인 이력 조회",
|
|
description = "JWT로 인증된 현재 사용자의 최근 로그인 이력(IP, User-Agent, 시간)을 반환합니다.")
|
|
@ApiResponses({
|
|
@ApiResponse(responseCode = "200", description = "조회 성공",
|
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = LoginHistoryResponse.class)))),
|
|
@ApiResponse(responseCode = "401", description = "인증 실패", content = @Content)
|
|
})
|
|
@GetMapping("/login-history")
|
|
public ResponseEntity<List<LoginHistoryResponse>> getLoginHistory(Authentication authentication) {
|
|
Long userId = (Long) authentication.getPrincipal();
|
|
return ResponseEntity.ok(activityService.getLoginHistory(userId));
|
|
}
|
|
}
|