Skip to content

fadel233/refuge-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐾 Refuge API - Spring Boot REST API

Description

API REST complète pour la gestion d'un refuge animal, construite avec Spring Boot. Ce projet inclut l'authentification JWT, le cryptage des mots de passe avec BCrypt, la documentation Swagger, et un CRUD complet pour les animaux.

Technologies

  • Java 21
  • Spring Boot 4.0.2
  • Spring Security + JWT (jjwt)
  • Spring Data JPA + Hibernate
  • MySQL (via WAMP)
  • Swagger / SpringDoc OpenAPI
  • BCrypt pour le hashage des mots de passe
  • Maven

Architecture du projet

com.fadel.refugeapi/
├── config/
│   ├── SecurityConfig.java        # Configuration Spring Security
│   ├── JwtFilter.java             # Filtre JWT pour les requêtes
│   └── SwaggerConfig.java         # Configuration Swagger/OpenAPI
├── controller/
│   ├── AuthController.java        # Endpoints d'authentification
│   └── AnimalController.java      # Endpoints CRUD animaux
├── dto/
│   ├── AnimalRequestDTO.java      # DTO requête animal
│   ├── AnimalResponseDTO.java     # DTO réponse animal
│   ├── RegisterDTO.java           # DTO inscription
│   ├── LoginDTO.java              # DTO connexion
│   └── AuthResponseDTO.java       # DTO réponse auth (token)
├── entity/
│   ├── Animal.java                # Entité Animal (JPA)
│   └── User.java                  # Entité User (JPA)
├── mapper/
│   └── AnimalMapper.java          # Conversion DTO <-> Entity
├── repository/
│   ├── AnimalRepository.java      # Repository Animal (JPA)
│   └── UserRepository.java        # Repository User (JPA)
├── service/
│   ├── AnimalService.java         # Logique métier animaux
│   ├── AuthService.java           # Logique métier authentification
│   └── JwtService.java            # Génération et validation JWT
└── RefugeApiApplication.java      # Point d'entrée

Endpoints de l'API

Authentification

Méthode URL Description Auth requise
POST /api/auth/register Inscription Non
POST /api/auth/login Connexion Non

Animaux

Méthode URL Description Auth requise
GET /api/animaux Liste tous les animaux Non
GET /api/animaux/{id} Récupère un animal par ID Non
POST /api/animaux Créer un animal Oui (JWT)
PUT /api/animaux/{id} Modifier un animal Oui (JWT)
DELETE /api/animaux/{id} Supprimer un animal Oui (JWT)

Documentation

URL Description
/swagger-ui.html Interface Swagger interactive
/v3/api-docs Documentation OpenAPI JSON

Installation et lancement

Prérequis

  • Java 21
  • Maven
  • MySQL (WAMP, XAMPP, ou autre)

Étapes

  1. Cloner le dépôt
git clone https://github.com/fadel233/refuge-api.git
cd refuge-api
  1. Créer la base de données MySQL
CREATE DATABASE refugedb;
  1. Configurer la connexion dans src/main/resources/application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/refugedb
spring.datasource.username=root
spring.datasource.password=
  1. Lancer l'application
./mvnw spring-boot:run
  1. Accéder à l'API

Exemples d'utilisation

Inscription

curl -X POST http://localhost:8080/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "fadel@email.com",
    "password": "monMotDePasse",
    "nom": "Fadel"
  }'

Connexion

curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "fadel@email.com",
    "password": "monMotDePasse"
  }'

Créer un animal (avec token JWT)

curl -X POST http://localhost:8080/api/animaux \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer VOTRE_TOKEN_JWT" \
  -d '{
    "nom": "Rex",
    "type": "Chien",
    "age": 5,
    "poids": 25.0
  }'

Lister tous les animaux

curl http://localhost:8080/api/animaux

Sécurité

  • Les mots de passe sont hashés avec BCrypt
  • L'authentification utilise des tokens JWT
  • Les endpoints GET sont publics
  • Les endpoints POST, PUT, DELETE nécessitent un token JWT valide
  • Le token expire après 24 heures

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages