Add admin client endpoints

This commit is contained in:
litoral05
2026-06-03 10:22:41 +01:00
parent cf0f79d0ff
commit b67214f4d6
5 changed files with 90 additions and 0 deletions
@@ -0,0 +1,28 @@
package com.litoralregas.backend_gateway.client;
import com.litoralregas.backend_gateway.client.dto.ClientResponse;
import com.litoralregas.backend_gateway.client.dto.CreateClientRequest;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/admin/clients")
public class ClientController {
private final ClientService clientService;
public ClientController(ClientService clientService) {
this.clientService = clientService;
}
@PostMapping
public ClientResponse create(@RequestBody CreateClientRequest request) {
return clientService.create(request);
}
@GetMapping
public List<ClientResponse> findAll() {
return clientService.findAll();
}
}
@@ -0,0 +1,45 @@
package com.litoralregas.backend_gateway.client;
import com.litoralregas.backend_gateway.client.dto.ClientResponse;
import com.litoralregas.backend_gateway.client.dto.CreateClientRequest;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ClientService {
private final ClientRepository clientRepository;
public ClientService(ClientRepository clientRepository) {
this.clientRepository = clientRepository;
}
public ClientResponse create(CreateClientRequest request) {
ClientEntity client = new ClientEntity();
client.setName(request.name());
client.setBackendBaseUrl(request.backendBaseUrl());
client.setEnabled(true);
ClientEntity saved = clientRepository.save(client);
return toResponse(saved);
}
public List<ClientResponse> findAll() {
return clientRepository.findAll()
.stream()
.map(this::toResponse)
.toList();
}
private ClientResponse toResponse(ClientEntity client) {
return new ClientResponse(
client.getId(),
client.getName(),
client.getBackendBaseUrl(),
client.isEnabled(),
client.getCreatedAt()
);
}
}
@@ -0,0 +1,10 @@
package com.litoralregas.backend_gateway.client.dto;
public record ClientResponse(
Long id,
String name,
String backendBaseUrl,
boolean enabled,
String createdAt
) {
}
@@ -0,0 +1,7 @@
package com.litoralregas.backend_gateway.client.dto;
public record CreateClientRequest(
String name,
String backendBaseUrl
) {
}