XuqmGroup-Server/im-service/src/main/java/com/xuqm/im/controller/AuthController.java

34 行
1.2 KiB
Java

2026-04-21 22:07:29 +08:00
package com.xuqm.im.controller;
import com.xuqm.common.model.ApiResponse;
import com.xuqm.im.service.ImAccountService;
import jakarta.validation.constraints.NotBlank;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/api/im/auth")
public class AuthController {
private final ImAccountService accountService;
public AuthController(ImAccountService accountService) {
this.accountService = accountService;
}
@PostMapping("/login")
public ResponseEntity<ApiResponse<Map<String, String>>> login(
@RequestParam @NotBlank String appId,
@RequestParam @NotBlank String userId,
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String avatar) {
String token = accountService.loginOrRegister(appId, userId, nickname, avatar);
return ResponseEntity.ok(ApiResponse.success(Map.of("token", token)));
}
}