Add admin client endpoints
This commit is contained in:
Binary file not shown.
@@ -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
|
||||
) {
|
||||
}
|
||||
Reference in New Issue
Block a user