|
| 1 | +package resource; |
| 2 | + |
| 3 | +import jakarta.ws.rs.GET; |
| 4 | +import jakarta.ws.rs.Path; |
| 5 | +import jakarta.ws.rs.Produces; |
| 6 | +import jakarta.ws.rs.core.MediaType; |
| 7 | + |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +@Path("/api") |
| 12 | +public class ApiResource { |
| 13 | + |
| 14 | + @GET |
| 15 | + @Produces(MediaType.APPLICATION_JSON) // Indica que o retorno será em formato JSON |
| 16 | + public Map<String, Object> getApiDescription() { |
| 17 | + Map<String, Object> description = new HashMap<>(); |
| 18 | + description.put("welcome", "Welcome to the Tech Mech API!"); |
| 19 | + description.put("API status", "Running"); |
| 20 | + description.put("description", "Below are the available routes for managing clients:"); |
| 21 | + |
| 22 | + Map<String, Object> routes = new HashMap<>(); |
| 23 | + |
| 24 | + routes.put("GET /api/clients", Map.of( |
| 25 | + "description", "Retrieve all registered clients.", |
| 26 | + "response", "List of clients in JSON format." |
| 27 | + )); |
| 28 | + |
| 29 | + routes.put("GET /api/clients/{cpf}", Map.of( |
| 30 | + "description", "Retrieve client details by CPF.", |
| 31 | + "pathParameter", Map.of("cpf", "Client's CPF (e.g., 12345678900)."), |
| 32 | + "response", "JSON object containing client details." |
| 33 | + )); |
| 34 | + |
| 35 | + routes.put("POST /api/clients", Map.of( |
| 36 | + "description", "Add a new client.", |
| 37 | + "requestBody", Map.of( |
| 38 | + "name", "Client's name (String)", |
| 39 | + "cpf", "Client's CPF (String)", |
| 40 | + "password", "Client's password (String)", |
| 41 | + "phone", "Client's phone number (String)" |
| 42 | + ), |
| 43 | + "response", "Success message with client ID." |
| 44 | + )); |
| 45 | + |
| 46 | + routes.put("PUT /api/clients/{cpf}", Map.of( |
| 47 | + "description", "Update existing client details.", |
| 48 | + "pathParameter", Map.of("cpf", "Client's CPF to update."), |
| 49 | + "requestBody", "JSON object with updated client data.", |
| 50 | + "response", "Success message indicating the update status." |
| 51 | + )); |
| 52 | + |
| 53 | + routes.put("DELETE /api/clients/{cpf}", Map.of( |
| 54 | + "description", "Delete a client by CPF.", |
| 55 | + "pathParameter", Map.of("cpf", "Client's CPF to delete."), |
| 56 | + "response", "Success message indicating the deletion status." |
| 57 | + )); |
| 58 | + |
| 59 | + description.put("routes", routes); |
| 60 | + description.put("note", "Use these endpoints to manage client information effectively. Ensure proper authentication and authorization when integrating this API."); |
| 61 | + |
| 62 | + return description; |
| 63 | + } |
| 64 | +} |
0 commit comments