Skip to content

Latest commit

 

History

History
173 lines (156 loc) · 3.73 KB

INSTALLATION_GUIDE.md

File metadata and controls

173 lines (156 loc) · 3.73 KB

Index

  1. Prerequisites
  2. Technological Choices
  3. Running the Application
  4. Testing the API
    1. Get all teams (without sorting)
    2. Get all teams (with sorting)
    3. Get team by ID
    4. Create a new team
  5. Running Tests
  6. Connecting to H2 Database

Prerequisites

Java 17 or higher

Technological Choices

  • Spring Boot
  • H2 Database (and in-memory database for testing)
  • Spring Data JPA
  • Spring Boot Starter Validation (for input validation)
  • dependency management: Gradle
  • logging: SLF4J (Logback)
  • Jackson (for JSON serialization/deserialization)
  • JUnit 5 (for unit testing)

Running the Application

To start the application, run the following command:

./gradlew bootRun

For windows

gradlew.bat bootRun

Testing the API

1. Get all teams (without sorting)

GET http://localhost:8080/api/teams?page=0&size=5

2. Get all teams (with sorting)

Sort by name in ascending order

GET http://localhost:8080/api/teams?sortBy=name

Sort by name in descending order and build in ascending order

GET http://localhost:8080/api/teams?page=0&size=10&sortBy=-budget,name

3. Get team by id

GET http://localhost:8080/api/teams/{id}

Example success response

{
  "id": 1,
  "name": "OGC Nice",
  "acronym": "OGCN",
  "budget": 50000000,
  "players": [
    {
      "id": 1,
      "name": "Player 1",
      "position": "Midfielder"
    },
    {
      "id": 2,
      "name": "Player 2",
      "position": "Defender"
    }
  ]
}

Example Error Response (Team Not Found):

{
  "timestamp": "2024-09-10T14:30:00",
  "status": 404,
  "message": "Team with id 9999 not found"
}

4. Create a new team

POST http://localhost:8080/api/teams

Request body

{
  "name": "OGC Nice",
  "acronym": "OGCN",
  "budget": 50000000,
  "players": [
    {
      "name": "Player 1",
      "position": "Midfielder"
    },
    {
      "name": "Player 2",
      "position": "Defender"
    }
  ]
}

Example Success Response:

{
  "id": 1,
  "name": "OGC Nice",
  "acronym": "OGCN",
  "budget": 50000000,
  "players": [
    {
      "id": 1,
      "name": "Player 1",
      "position": "Midfielder"
    },
    {
      "id": 2,
      "name": "Player 2",
      "position": "Defender"
    }
  ]
}

Example Error Response (Validation Errors):

If required fields are missing or invalid

{
  "timestamp": "2024-09-10T14:30:00",
  "status": 400,
  "errors": {
    "name": "Team name is required",
    "budget": "Budget must be a positive value"
  }
}

Running Tests

./gradlew test

For windows

gradlew.bat test

Connecting to H2 Database

http://localhost:8080/h2-console
  • JDBC URL: jdbc:h2:~/equipe-football
  • User Name: sa
  • Password: (empty)

Note: The test database is in-memory and will be destroyed after the application is stopped.