Files
velocity-pay-springboot/src/main/java/zw/qantra/tm/domain/controllers/TestController.java

71 lines
2.7 KiB
Java

package zw.qantra.tm.domain.controllers;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import zw.qantra.tm.domain.enums.RequestType;
import zw.qantra.tm.domain.models.Transaction;
import zw.qantra.tm.domain.services.NotificationService;
import zw.qantra.tm.domain.services.TransactionService;
import zw.qantra.tm.domain.services.WorkspaceMigrationService;
@RestController
@RequestMapping("/test")
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class TestController {
private final NotificationService notificationService;
private final TransactionService transactionService;
private final WorkspaceMigrationService workspaceMigrationService;
private static final Logger logger = LoggerFactory.getLogger(TestController.class);
@GetMapping("/test-logs")
public String testLogs() {
logger.trace("This is a TRACE log");
logger.debug("This is a DEBUG log");
logger.info("This is an INFO log");
logger.warn("This is a WARN log");
logger.error("This is an ERROR log");
return "Logs sent to OpenTelemetry!";
}
@PostMapping("/dbtest")
public ResponseEntity<Object> dbtest(@RequestBody Transaction transaction) {
transactionService.save(transaction);
transaction.setType(RequestType.REQUEST);
transactionService.save(transaction);
return ResponseEntity.ok(transaction);
}
@GetMapping("/hello/{email}")
public ResponseEntity<String> helloEndpoint(@PathVariable String email) {
notificationService.sendEmail(email, "Hello", "Hello World!");
return ResponseEntity.ok("Hello World!");
}
@GetMapping("/protected")
public ResponseEntity<String> protectedEndpoint() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = authentication.getName();
return ResponseEntity.ok("Hello " + username + "! This is a protected endpoint.");
}
@GetMapping("/public")
public ResponseEntity<String> publicEndpoint() {
return ResponseEntity.ok("This is a public endpoint - no authentication required!");
}
@PostMapping("/migrate-workspaces")
public ResponseEntity<WorkspaceMigrationService.MigrationResult> migrateWorkspaces() {
WorkspaceMigrationService.MigrationResult result = workspaceMigrationService.migrate();
return ResponseEntity.ok(result);
}
}