Refactor user account management by replacing User entity with UserAccount, updating UserController and UserService for CRUD operations, and modifying MyBatis mappers accordingly.
This commit is contained in:
@@ -1,48 +1,83 @@
|
||||
package com.gameplatform.server.controller;
|
||||
|
||||
import com.gameplatform.server.model.User;
|
||||
import com.gameplatform.server.service.UserService;
|
||||
import com.gameplatform.server.model.dto.account.AccountCreateRequest;
|
||||
import com.gameplatform.server.model.dto.account.AccountResponse;
|
||||
import com.gameplatform.server.model.dto.account.AccountUpdateRequest;
|
||||
import com.gameplatform.server.model.dto.common.PageResult;
|
||||
import com.gameplatform.server.service.account.AccountService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 用户接口控制器 - 基于UserAccount实体
|
||||
* 提供用户账户的基本CRUD操作
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/users")
|
||||
public class UserController {
|
||||
private final UserService userService;
|
||||
public class UserController {
|
||||
private final AccountService accountService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
public UserController(AccountService accountService) {
|
||||
this.accountService = accountService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取用户账户信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Mono<User> getById(@PathVariable Long id) {
|
||||
return userService.getById(id);
|
||||
public Mono<AccountResponse> getById(@PathVariable Long id) {
|
||||
return accountService.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*/
|
||||
@GetMapping
|
||||
public Flux<User> listAll() {
|
||||
return userService.listAll();
|
||||
public Mono<PageResult<AccountResponse>> list(
|
||||
@RequestParam(value = "userType", required = false) String userType,
|
||||
@RequestParam(value = "status", required = false) String status,
|
||||
@RequestParam(value = "role", required = false) String role,
|
||||
@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "20") Integer size
|
||||
) {
|
||||
return accountService.list(userType, status, role, keyword, page, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新用户账户
|
||||
*/
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public Mono<User> create(@Valid @RequestBody User user) {
|
||||
return userService.create(user);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public Mono<Void> delete(@PathVariable Long id) {
|
||||
return userService.deleteById(id)
|
||||
.filter(Boolean::booleanValue)
|
||||
.then();
|
||||
public Mono<AccountResponse> create(@Valid @RequestBody AccountCreateRequest request) {
|
||||
return accountService.create(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户账户信息
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public Mono<User> update(@PathVariable Long id, @Valid @RequestBody User user) {
|
||||
return userService.update(id, user);
|
||||
public Mono<AccountResponse> update(@PathVariable Long id, @Valid @RequestBody AccountUpdateRequest request) {
|
||||
return accountService.update(id, request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用用户账户
|
||||
*/
|
||||
@PostMapping("/{id}/enable")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public Mono<Void> enable(@PathVariable Long id) {
|
||||
return accountService.setStatus(id, "ENABLED").then();
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用用户账户
|
||||
*/
|
||||
@PostMapping("/{id}/disable")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public Mono<Void> disable(@PathVariable Long id) {
|
||||
return accountService.setStatus(id, "DISABLED").then();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user