Skip to content

Commit

Permalink
[feat] add TestController for client test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdwns414 committed Mar 5, 2024
1 parent d30a976 commit 173c9da
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.pingle.pingleserver.controller;

import lombok.RequiredArgsConstructor;
import org.pingle.pingleserver.domain.enums.URole;
import org.pingle.pingleserver.repository.UserRepository;
import org.pingle.pingleserver.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Profile({"local", "dev"})
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {
private final JwtUtil jwtUtil;
private final UserRepository userRepository;

@Value("${token-test.key}")
private String key;

@GetMapping("/token/{userId}")
public ResponseEntity<?> getToken(@PathVariable("userId") Long userId,
@RequestHeader(value = "Test-Key", required = false) String testKey){
if (!key.isBlank() && !key.equals(testKey)) {
return ResponseEntity.badRequest().body("Invalid test key");
}
userRepository.findByIdOrThrow(userId);
return ResponseEntity.ok(jwtUtil.generateTokens(userId, URole.USER));
}
}

0 comments on commit 173c9da

Please sign in to comment.