feat : thêm swagger
This commit is contained in:
parent
4558b1e97d
commit
969362e4cc
|
|
@ -15,6 +15,7 @@ dependencies {
|
|||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.4.0'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web:3.4.0'
|
||||
implementation 'org.projectlombok:lombok:1.18.38'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'
|
||||
implementation('org.springframework.boot:spring-boot-starter:3.4.0') {
|
||||
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ package com.vega.hrm.controller;
|
|||
|
||||
import com.vega.hrm.core.models.responses.BaseResponse;
|
||||
import com.vega.hrm.service.GoogleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -12,17 +15,22 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("api/google/user")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Auth - Google", description = "Luồng OAuth2 với Google phục vụ xác thực người dùng")
|
||||
public class GoogleController {
|
||||
|
||||
private final GoogleService googleService;
|
||||
|
||||
@GetMapping("/get-auth-url")
|
||||
@Operation(summary = "Sinh URL đăng nhập Google", description = "Tạo URL xác thực Google OAuth2 với các scope đã cấu hình.")
|
||||
public ResponseEntity<BaseResponse<String>> getGoogleAuthUrl(){
|
||||
return ResponseEntity.ok(googleService.getGoogleAuthUrl());
|
||||
}
|
||||
|
||||
@GetMapping("callback")
|
||||
public ResponseEntity<BaseResponse<Boolean>> googleCallback(@RequestParam("code") String code){
|
||||
@Operation(summary = "Xử lý callback Google", description = "Nhận mã ủy quyền từ Google và hoàn tất trao đổi token.")
|
||||
public ResponseEntity<BaseResponse<Boolean>> googleCallback(
|
||||
@Parameter(description = "Mã ủy quyền trả về bởi Google sau khi người dùng đồng ý.")
|
||||
@RequestParam("code") String code){
|
||||
return ResponseEntity.ok(googleService.googleCallback(code));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.vega.hrm.core.models.responses.BaseResponse;
|
|||
import com.vega.hrm.request.user.CreateUserRequest;
|
||||
import com.vega.hrm.request.user.LoginRequest;
|
||||
import com.vega.hrm.service.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
|
@ -14,15 +16,18 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("api/auth/user")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Auth - User", description = "Các API liên quan đến xác thực và quản lý người dùng nội bộ")
|
||||
public class UserController {
|
||||
private final UserService userService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "Đăng nhập", description = "Nhận thông tin phiên đăng nhập và token bảo mật.")
|
||||
public ResponseEntity<BaseResponse<Object>> login(@RequestBody LoginRequest request) {
|
||||
return ResponseEntity.ok(userService.login(request));
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
@Operation(summary = "Tạo người dùng nội bộ", description = "Tạo tài khoản quản trị viên/nhân sự mới.")
|
||||
public ResponseEntity<BaseResponse<Boolean>> insert(@RequestBody CreateUserRequest request) {
|
||||
return ResponseEntity.ok(userService.insert(request));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ vega.jpa.repository.basePackage=com.vega.hrm.core.repositories
|
|||
vega.jpa.entity.basePackage=com.vega.hrm.core.entities
|
||||
spring.config.import=file:config/shared.properties
|
||||
logging.config=file:config/log4j2.properties
|
||||
springdoc.api-docs.path=/api-docs/auth
|
||||
springdoc.swagger-ui.path=/swagger-ui/auth
|
||||
springdoc.swagger-ui.operations-sorter=method
|
||||
springdoc.swagger-ui.tags-sorter=alpha
|
||||
|
||||
|
|
|
|||
|
|
@ -28,14 +28,21 @@ import org.springframework.web.filter.OncePerRequestFilter;
|
|||
@RequiredArgsConstructor
|
||||
public class AuthorizationFilter extends OncePerRequestFilter {
|
||||
|
||||
private static final List<String> EXCLUDE_URIS = List.of("/api/auth/user/login","/api/google/user/callback");
|
||||
private static final List<String> EXCLUDE_URIS = List.of(
|
||||
"/api/auth/user/login",
|
||||
"/api/google/user/callback",
|
||||
"/swagger-ui/auth.html",
|
||||
"/swagger-ui/swagger-ui/index.html",
|
||||
"/api-docs/auth",
|
||||
"/api-docs/report"
|
||||
);
|
||||
private final RedisService redisService;
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) {
|
||||
try {
|
||||
var uri = request.getRequestURI();
|
||||
if (EXCLUDE_URIS.contains(uri) || uri.contains("actuator")) {
|
||||
if (EXCLUDE_URIS.contains(uri) || uri.contains("actuator") || uri.contains("swagger") || uri.contains("api-docs")) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ dependencies {
|
|||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.4.0'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web:3.4.0'
|
||||
implementation 'org.projectlombok:lombok:1.18.38'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'
|
||||
implementation('org.springframework.boot:spring-boot-starter:3.4.0') {
|
||||
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import com.vega.hrm.core.dto.GoogleOAuthConfig;
|
|||
import com.vega.hrm.core.models.responses.BaseResponse;
|
||||
import com.vega.hrm.report.request.GetDragRevenueRequest;
|
||||
import com.vega.hrm.report.serivce.CreateReportingJobService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
@ -18,11 +20,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("api/report/google")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Report - Google", description = "API đồng bộ báo cáo từ YouTube Reporting API")
|
||||
public class ReportGoogleController {
|
||||
|
||||
private final CreateReportingJobService createReportingJob;
|
||||
private final GoogleOAuthConfig googleOAuthConfig;
|
||||
|
||||
@GetMapping("/youtube/demo")
|
||||
@Operation(summary = "Khởi tạo job demo YouTube", description = "Thực thi job báo cáo mẫu với cấu hình được lưu trữ trong hệ thống.")
|
||||
public ResponseEntity<BaseResponse<Boolean>> getRevenue(GetDragRevenueRequest getDragRevenueRequest)
|
||||
throws GeneralSecurityException, IOException {
|
||||
var tokenStore = new TokenStore();
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ vega.jpa.repository.basePackage=com.vega.hrm.core.repositories
|
|||
vega.jpa.entity.basePackage=com.vega.hrm.core.entities
|
||||
spring.config.import=file:config/shared.properties
|
||||
logging.config=file:config/log4j2.properties
|
||||
springdoc.api-docs.path=/api-docs/report
|
||||
springdoc.swagger-ui.path=/swagger-ui/report
|
||||
springdoc.swagger-ui.operations-sorter=method
|
||||
springdoc.swagger-ui.tags-sorter=alpha
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user