change package,change message_code
Test Workflow / test (push) Waiting to run

This commit is contained in:
vladp
2025-12-10 19:12:54 +07:00
parent 76da2e94c9
commit a30b0488e8
60 changed files with 154 additions and 161 deletions
@@ -0,0 +1,37 @@
package ru.soune.nocopy.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ru.soune.nocopy.entity.AuthToken;
import ru.soune.nocopy.exception.TokenNotFoundException;
import ru.soune.nocopy.repository.AuthTokenRepository;
import ru.soune.nocopy.service.AuthService;
import java.util.Map;
import java.util.Optional;
@RestController
@RequestMapping("v1/api/auth")
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;
private final AuthTokenRepository authTokenRepository;
@PostMapping("/logout")
public ResponseEntity<?> logout(@RequestHeader("Authorization") String tokenHeader) {
String token = tokenHeader.replace("Bearer ", "");
Optional<AuthToken> opToken = authTokenRepository.findByToken(token);
if (opToken.isEmpty()) {
throw new TokenNotFoundException("Token not found");
}
authService.logout(token);
return ResponseEntity.ok(Map.of("success", true));
}
}