docs: 添加 Javadoc

This commit is contained in:
2026-01-09 09:17:01 +08:00
parent a526ac795d
commit a8c349bd75
14 changed files with 154 additions and 89 deletions
+2 -2
View File
@@ -64,8 +64,8 @@ app:
# 允许的请求头列表 # 允许的请求头列表
allowed-headers: Content-Type allowed-headers: Content-Type
# 允许的请求方法列表(Ref org.springframework.http.HttpMethod # 允许的请求方法列表(Ref org.springframework.http.HttpMethod
# 2025.11.6注 # Spring HttpMethod 并非 enum class,因此在此处使用小写请求方式会导致在请求头中存在 Origin 时出现 Invalid
# 由于 Spring 解析问题,在此处使用小写的情况下会导致在请求头中存在 Origin 时出现 Invalid CORS Request 的问题,请务必使用大写 # CORS Request 的问题,请务必使用大写
allowed-methods: allowed-methods:
- GET - GET
- POST - POST
@@ -1,57 +0,0 @@
package com.onixbyte.helix.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
/**
* Configuration class for Spring WebFlux reactive web components.
* <p>
* This configuration class provides beans for reactive web programming components within the Helix
* application. It configures WebClient instances and other reactive web-related components that
* enable non-blocking, asynchronous HTTP communication with external services.
* <p>
* The configuration supports:
* <ul>
* <li>Reactive HTTP client configuration</li>
* <li>Non-blocking I/O operations</li>
* <li>Asynchronous request/response handling</li>
* </ul>
*
* @author zihluwang
* @since 1.0.0
* @see WebClient
* @see Configuration
*/
@Configuration
public class WebFluxConfig {
/**
* Creates a reactive WebClient for HTTP communication with external services.
* <p>
* This method configures a {@link WebClient} instance that provides a modern, reactive approach
* to HTTP client operations. The WebClient supports non-blocking I/O and is built on top of
* Reactor Netty, making it suitable for high-performance, scalable applications.
* <p>
* The client is configured with default settings and can be used throughout the application for
* making HTTP requests to external APIs, microservices, or other web resources in a reactive,
* non-blocking manner.
* <p>
* Key features:
* <ul>
* <li>Non-blocking I/O operations</li>
* <li>Reactive streams support</li>
* <li>Built-in support for JSON serialisation/deserialisation</li>
* <li>Configurable timeouts and retry mechanisms</li>
* </ul>
*
* @return a configured {@link WebClient} instance for reactive HTTP operations
* @see WebClient
* @see WebClient.Builder
*/
@Bean
public WebClient webClient() {
return WebClient.builder()
.build();
}
}
@@ -13,11 +13,10 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
/** /**
* REST controller for file storage operations. Provides endpoints for uploading, downloading, and * This controller provides entry points that manipulates assets.
* deleting assets using the configured storage service.
* *
* @author zihluwang * @author zihluwang
* @since 1.0.0 * @author siujamo
*/ */
@RestController @RestController
@RequestMapping("/assets") @RequestMapping("/assets")
@@ -17,6 +17,12 @@ import org.springframework.web.bind.annotation.*;
import java.time.Duration; import java.time.Duration;
/**
* This controller provides entry points making user authorised.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/auth") @RequestMapping("/auth")
public class AuthController { public class AuthController {
@@ -57,11 +63,21 @@ public class AuthController {
.body(userService.getDetail(user)); .body(userService.getDetail(user));
} }
/**
* Get whether the registration function is enabled.
*
* @return {@code true} if registration function is enabled, otherwise {@code false}
*/
@GetMapping("/register-enabled") @GetMapping("/register-enabled")
public boolean getRegisterEnabled() { public boolean getRegisterEnabled() {
return authService.getRegisterEnabled(); return authService.getRegisterEnabled();
} }
/**
* Perform log out.
*
* @return a response that remove the authentication from cookie
*/
@GetMapping("/logout") @GetMapping("/logout")
public ResponseEntity<Void> logout() { public ResponseEntity<Void> logout() {
var cookie = authService.buildCookie(TokenConstant.TOKEN_NAME, "", Duration.ZERO); var cookie = authService.buildCookie(TokenConstant.TOKEN_NAME, "", Duration.ZERO);
@@ -7,12 +7,15 @@ import com.onixbyte.helix.domain.web.request.QueryAuthorityRequest;
import com.onixbyte.helix.service.AuthorityService; import com.onixbyte.helix.service.AuthorityService;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; /**
* This controller provides entry points for manipulate authorities.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/authorities") @RequestMapping("/authorities")
public class AuthorityController { public class AuthorityController {
@@ -23,6 +26,14 @@ public class AuthorityController {
this.authorityService = authorityService; this.authorityService = authorityService;
} }
/**
* Get authorities by page.
*
* @param pageNum current page num
* @param pageSize page size
* @param request query parameters
* @return a page contains authority data of the specified page
*/
@GetMapping @GetMapping
public Page<Authority> getAuthorities( public Page<Authority> getAuthorities(
@RequestParam(required = false, defaultValue = "1") Integer pageNum, @RequestParam(required = false, defaultValue = "1") Integer pageNum,
@@ -33,11 +44,23 @@ public class AuthorityController {
return authorityService.getAuthorities(pageRequest, request); return authorityService.getAuthorities(pageRequest, request);
} }
/**
* Add an authority.
*
* @param request authority specs
* @return created authority
*/
@PostMapping @PostMapping
public Authority addAuthority(@Validated @RequestBody AddAuthorityRequest request) { public Authority addAuthority(@Validated @RequestBody AddAuthorityRequest request) {
return authorityService.addAuthority(request); return authorityService.addAuthority(request);
} }
/**
* Edit an authority.
*
* @param request authority specs
* @return edited authority
*/
@PutMapping @PutMapping
public Authority editAuthority(@Validated @RequestBody EditAuthorityRequest request) { public Authority editAuthority(@Validated @RequestBody EditAuthorityRequest request) {
return authorityService.editAuthority(request); return authorityService.editAuthority(request);
@@ -10,6 +10,12 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Optional; import java.util.Optional;
/**
* This controller provides entry points to get captcha images.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/captcha") @RequestMapping("/captcha")
public class CaptchaController { public class CaptchaController {
@@ -21,6 +27,11 @@ public class CaptchaController {
this.captchaService = captchaService; this.captchaService = captchaService;
} }
/**
* Get captcha image and captcha uuid.
*
* @return captcha response, contains the uuid of the captcha and image BASE64
*/
@GetMapping @GetMapping
public ResponseEntity<CaptchaResponse> getCaptcha() { public ResponseEntity<CaptchaResponse> getCaptcha() {
var captchaTuple = captchaService.buildCaptcha(); var captchaTuple = captchaService.buildCaptcha();
@@ -10,6 +10,12 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
/**
* This controller provides entry points that manipulates departments.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/departments") @RequestMapping("/departments")
public class DepartmentController { public class DepartmentController {
@@ -13,22 +13,10 @@ import java.time.LocalDateTime;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Global exception handler for the Helix application. * This controller advise will catch some business exception which produced when performing actions.
* <p>
* This controller advice provides centralised exception handling across all controllers in
* the application. It intercepts exceptions thrown during request processing and converts them into
* appropriate HTTP responses with standardised error formats.
* <p>
* The controller handles various types of exceptions including:
* <ul>
* <li>Business logic exceptions ({@link BizException})</li>
* <li>Bean validation constraint violations ({@link ConstraintViolationException})</li>
* </ul>
* <p>
* All error responses are formatted consistently using {@link BizExceptionResponse} to provide a
* uniform API error structure for client applications.
* *
* @author zihluwang * @author zihluwang
* @author siujamo
* @see BizException * @see BizException
* @see BizExceptionResponse * @see BizExceptionResponse
* @see RestControllerAdvice * @see RestControllerAdvice
@@ -10,6 +10,12 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
/**
* This controller provides entry points to manipulate menus.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/menus") @RequestMapping("/menus")
public class MenuController { public class MenuController {
@@ -21,6 +27,11 @@ public class MenuController {
this.menuService = menuService; this.menuService = menuService;
} }
/**
* Get menu tree.
*
* @return available menu tree for the current user
*/
@GetMapping @GetMapping
public List<TreeNode<Menu>> getMenuTree() { public List<TreeNode<Menu>> getMenuTree() {
return menuService.getMenuTree(); return menuService.getMenuTree();
@@ -11,6 +11,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/**
* This controller provides entry points to manipulate positions.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/positions") @RequestMapping("/positions")
public class PositionController { public class PositionController {
@@ -22,6 +28,13 @@ public class PositionController {
this.positionService = positionService; this.positionService = positionService;
} }
/**
* Get position data paginated.
*
* @param pageNum current page num
* @param pageSize page size
* @return paginated position data
*/
@GetMapping @GetMapping
public Page<Position> getPositions( public Page<Position> getPositions(
@RequestParam(required = false, defaultValue = "1") Integer pageNum, @RequestParam(required = false, defaultValue = "1") Integer pageNum,
@@ -13,6 +13,12 @@ import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
/**
* This controller provides entry points to manipulate roles.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/roles") @RequestMapping("/roles")
public class RoleController { public class RoleController {
@@ -1,11 +1,14 @@
package com.onixbyte.helix.controller; package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.entity.Setting;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/**
* This controller provides entry points to manipulate settings.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping @RequestMapping
public class SettingController { public class SettingController {
@@ -1,9 +1,10 @@
package com.onixbyte.helix.controller; package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.web.request.AddUserRequest; import com.onixbyte.helix.domain.web.request.AddUserRequest;
import com.onixbyte.helix.domain.web.request.EditUserRequest;
import com.onixbyte.helix.domain.web.request.QueryUserRequest; import com.onixbyte.helix.domain.web.request.QueryUserRequest;
import com.onixbyte.helix.domain.web.request.ResetPasswordRequest; import com.onixbyte.helix.domain.web.request.ResetPasswordRequest;
import com.onixbyte.helix.domain.web.request.EditUserRequest; import com.onixbyte.helix.domain.web.response.ActionResponse;
import com.onixbyte.helix.domain.web.response.UserDetailResponse; import com.onixbyte.helix.domain.web.response.UserDetailResponse;
import com.onixbyte.helix.service.UserService; import com.onixbyte.helix.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +16,12 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
/**
* This controller provides entry points to manipulate users.
*
* @author zihluwang
* @author siujamo
*/
@RestController @RestController
@RequestMapping("/users") @RequestMapping("/users")
public class UserController { public class UserController {
@@ -56,29 +63,53 @@ public class UserController {
return userService.getUserDetailByUserId(userId); return userService.getUserDetailByUserId(userId);
} }
/**
* Add a new user.
*
* @param request user to be added
* @return added user
*/
@PostMapping @PostMapping
@PreAuthorize("hasAnyAuthority('system:user:write')") @PreAuthorize("hasAnyAuthority('system:user:write')")
public UserDetailResponse addUser(@Validated @RequestBody AddUserRequest request) { public UserDetailResponse addUser(@Validated @RequestBody AddUserRequest request) {
return userService.addUser(request); return userService.addUser(request);
} }
/**
* Edit a user.
*
* @param request user to be edited
* @return edited user
*/
@PutMapping @PutMapping
public ResponseEntity<Void> editUser(@Validated @RequestBody EditUserRequest request) { public ResponseEntity<Void> editUser(@Validated @RequestBody EditUserRequest request) {
userService.updateUser(request); userService.updateUser(request);
return ResponseEntity.ok(null); return ResponseEntity.ok(null);
} }
/**
* Reset user's password.
*
* @param request reset password request, contains ID of the user and new password
* @return action response
*/
@PreAuthorize("hasAnyAuthority('system:user:reset-password')") @PreAuthorize("hasAnyAuthority('system:user:reset-password')")
@PatchMapping("/reset-password") @PatchMapping("/reset-password")
public ResponseEntity<Void> resetPassword(@Validated @RequestBody ResetPasswordRequest request) { public ActionResponse resetPassword(@Validated @RequestBody ResetPasswordRequest request) {
userService.resetPassword(request); userService.resetPassword(request);
return ResponseEntity.ok(null); return ActionResponse.success("密码修改成功");
} }
/**
* Delete a user.
*
* @param userId ID of the user to be deleted
* @return action response
*/
@PreAuthorize("hasAnyAuthority('system:user:write')") @PreAuthorize("hasAnyAuthority('system:user:write')")
@DeleteMapping("/{userId:\\d+}") @DeleteMapping("/{userId:\\d+}")
public ResponseEntity<Void> deleteUser(@PathVariable Long userId) { public ActionResponse deleteUser(@PathVariable Long userId) {
userService.deleteUser(userId); userService.deleteUser(userId);
return ResponseEntity.ok(null); return ActionResponse.success("删除成功");
} }
} }
@@ -0,0 +1,15 @@
package com.onixbyte.helix.domain.web.response;
public record ActionResponse(
String message,
boolean success
) {
public static ActionResponse success(String message) {
return new ActionResponse(message, true);
}
public static ActionResponse failed(String message) {
return new ActionResponse(message, false);
}
}