48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
package com.webgame.webgamebackend.controller;
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
import com.webgame.webgamebackend.common.dto.ApiResponse;
|
|
import com.webgame.webgamebackend.common.dto.account.LoginRequest;
|
|
import com.webgame.webgamebackend.common.dto.account.LoginResponse;
|
|
import com.webgame.webgamebackend.common.dto.account.RegisterRequest;
|
|
import com.webgame.webgamebackend.service.AccountService;
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
/**
|
|
* 账号控制器
|
|
*/
|
|
@Validated
|
|
@RestController
|
|
@RequestMapping("/account")
|
|
@RequiredArgsConstructor
|
|
public class AccountController {
|
|
|
|
private final AccountService accountService;
|
|
|
|
/**
|
|
* 登录
|
|
*/
|
|
@SaIgnore
|
|
@PostMapping("/login")
|
|
public ApiResponse<LoginResponse> login(@Valid @RequestBody LoginRequest request) {
|
|
LoginResponse result = accountService.login(request);
|
|
return ApiResponse.ok(result);
|
|
}
|
|
|
|
/**
|
|
* 注册
|
|
*/
|
|
@SaIgnore
|
|
@PostMapping("/register")
|
|
public ApiResponse<LoginResponse> register(@Valid @RequestBody RegisterRequest request) {
|
|
LoginResponse result = accountService.register(request);
|
|
return ApiResponse.ok(result);
|
|
}
|
|
}
|