91 lines
3.4 KiB
Java
91 lines
3.4 KiB
Java
package com.emotion.controller;
|
|
|
|
import com.emotion.common.PageResult;
|
|
import com.emotion.common.Result;
|
|
import com.emotion.dto.request.guest.GuestUserCreateRequest;
|
|
import com.emotion.dto.request.guest.GuestUserPageRequest;
|
|
import com.emotion.dto.request.guest.GuestUserUpdateRequest;
|
|
import com.emotion.dto.response.guest.GuestUserResponse;
|
|
import com.emotion.service.GuestUserService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
/**
|
|
* 访客用户控制器
|
|
*
|
|
* @author huazhongmin
|
|
* @date 2025-09-08
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/guestUser")
|
|
@Tag(name = "访客用户管理", description = "访客用户的查询、创建、更新和删除接口")
|
|
public class GuestUserController {
|
|
|
|
@Autowired
|
|
private GuestUserService guestUserService;
|
|
|
|
/**
|
|
* 分页查询访客用户
|
|
*/
|
|
@Operation(summary = "分页查询访客用户", description = "分页查询访客用户列表。")
|
|
@GetMapping(value = "/page")
|
|
public Result<PageResult<GuestUserResponse>> getPage(@Validated GuestUserPageRequest request) {
|
|
PageResult<GuestUserResponse> pageResult = guestUserService.getPageWithResponse(request);
|
|
return Result.success(pageResult);
|
|
}
|
|
|
|
/**
|
|
* 根据ID获取访客用户
|
|
*/
|
|
@Operation(summary = "获取访客详情", description = "根据 ID 获取访客用户的详细信息。")
|
|
@GetMapping(value = "/detail")
|
|
public Result<GuestUserResponse> getById(@Parameter(description = "访客 ID") @RequestParam String id) {
|
|
GuestUserResponse response = guestUserService.getGuestUserResponseById(id);
|
|
if (response == null) {
|
|
return Result.notFound("访客用户不存在");
|
|
}
|
|
return Result.success(response);
|
|
}
|
|
|
|
/**
|
|
* 创建访客用户
|
|
*/
|
|
@Operation(summary = "创建访客用户", description = "创建一个新的访客用户。")
|
|
@PostMapping(value = "/create")
|
|
public Result<GuestUserResponse> create(@Valid @RequestBody GuestUserCreateRequest request) {
|
|
GuestUserResponse response = guestUserService.createGuestUserWithResponse(request);
|
|
return Result.success(response);
|
|
}
|
|
|
|
/**
|
|
* 更新访客用户
|
|
*/
|
|
@Operation(summary = "更新访客用户", description = "修改已有访客用户的信息。")
|
|
@PutMapping(value = "/update")
|
|
public Result<GuestUserResponse> update(@Valid @RequestBody GuestUserUpdateRequest request) {
|
|
GuestUserResponse response = guestUserService.updateGuestUserWithResponse(request);
|
|
if (response == null) {
|
|
return Result.notFound("访客用户不存在");
|
|
}
|
|
return Result.success(response);
|
|
}
|
|
|
|
/**
|
|
* 删除访客用户
|
|
*/
|
|
@Operation(summary = "删除访客用户", description = "删除指定的访客用户。")
|
|
@DeleteMapping(value = "/delete")
|
|
public Result<Void> delete(@Parameter(description = "访客 ID") @RequestParam String id) {
|
|
boolean deleted = guestUserService.deleteGuestUser(id);
|
|
if (!deleted) {
|
|
return Result.error("删除失败");
|
|
}
|
|
return Result.success();
|
|
}
|
|
} |