Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REST API for managing football players built with Rust and Rocket. Implements CR
## Tech Stack

- **Language**: Rust 2024 Edition (enforced via `rust-toolchain.toml`)
- **Framework**: Rocket 0.5 (async)
- **Framework**: Rocket 0.5.1 (async)
- **Serialization**: Serde (JSON)
- **Unique IDs**: uuid (v4 + serde features)
- **ORM / Migrations**: Diesel (SQLite + r2d2 features) + diesel_migrations; `embed_migrations!()` runs pending migrations on startup
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Once the application is running, you can access:

- **API Server**: `http://localhost:9000`
- **Health Check**: `http://localhost:9000/health`
- **Swagger UI**: `http://localhost:9000/swagger-ui/`

## Containers

Expand Down Expand Up @@ -197,8 +198,10 @@ docker pull ghcr.io/nanotaboada/rust-samples-rocket-restful:latest
## Environment Variables

```bash
# Database storage path (default: ./storage/players-sqlite3.db)
STORAGE_PATH=./storage/players-sqlite3.db
# Database storage path
# Container default (set in Dockerfile): /storage/players-sqlite3.db
# Local dev fallback (no env var set): storage/players-sqlite3.db
STORAGE_PATH=/storage/players-sqlite3.db

# Rocket profile: debug or release (default: debug)
ROCKET_PROFILE=release
Expand Down
142 changes: 125 additions & 17 deletions rest/players.rest
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
### - VS Code: REST Client extension (humao.rest-client)
### - JetBrains IDEs: built-in HTTP Client

@baseUrl = http://localhost:9000
@newSquadNumber = 27
@existingSquadNumber = 23
@baseUrl = http://localhost:9000
@existingId = acc433bf-d505-51fe-831e-45eb44c4d43c
@nonexistentId = 00000000-0000-0000-0000-000000000000
@unknownId = f47ac10b-58cc-4372-a567-0e02b2c3d479
@createdSquadNumber = 27
@existingSquadNumber = 23
@nonexistentSquadNumber = 999
@unknownSquadNumber = 28

# -----------------------------------------------------------------------------

Expand All @@ -15,7 +20,9 @@ GET {{baseUrl}}/health

###

### Create Player
# POST /players ---------------------------------------------------------------

### Create Player (valid body)
# POST /players β†’ 201 Created
POST {{baseUrl}}/players
Content-Type: application/json
Expand All @@ -25,7 +32,28 @@ Content-Type: application/json
"middleName": "",
"lastName": "Lo Celso",
"dateOfBirth": "1996-07-09T00:00:00.000Z",
"squadNumber": 27,
"squadNumber": {{createdSquadNumber}},
"position": "Central Midfield",
"abbrPosition": "CM",
"team": "Real Betis BalompiΓ©",
"league": "La Liga",
"starting11": false
}

###

### Create Player (duplicate squad number)
# POST /players β†’ 409 Conflict
# Requires: "Create Player (valid body)" above to have run first.
POST {{baseUrl}}/players
Content-Type: application/json

{
"firstName": "Giovani",
"middleName": "",
"lastName": "Lo Celso",
"dateOfBirth": "1996-07-09T00:00:00.000Z",
"squadNumber": {{createdSquadNumber}},
"position": "Central Midfield",
"abbrPosition": "CM",
"team": "Real Betis BalompiΓ©",
Expand All @@ -35,26 +63,52 @@ Content-Type: application/json

###

# GET /players ----------------------------------------------------------------

### Get All Players
# GET /players β†’ 200 OK
GET {{baseUrl}}/players

###

### Get Player by ID
# GET /players/:id β†’ 200 OK
GET {{baseUrl}}/players/acc433bf-d505-51fe-831e-45eb44c4d43c
# GET /players/{id} -----------------------------------------------------------

### Get Player by ID (existing)
# GET /players/{id} β†’ 200 OK
GET {{baseUrl}}/players/{{existingId}}

###

### Get Player by ID (nonexistent)
# GET /players/{id} β†’ 404 Not Found
GET {{baseUrl}}/players/{{nonexistentId}}

###

### Get Player by Squad Number
# GET /players/squadnumber/:squadnumber β†’ 200 OK
### Get Player by ID (unknown)
# GET /players/{id} β†’ 404 Not Found
GET {{baseUrl}}/players/{{unknownId}}

###

# GET /players/squadnumber/{squad_number} -------------------------------------

### Get Player by Squad Number (existing)
# GET /players/squadnumber/{squad_number} β†’ 200 OK
GET {{baseUrl}}/players/squadnumber/10

###

### Update Player
# PUT /players/squadnumber/:squadnumber β†’ 200 OK
### Get Player by Squad Number (nonexistent)
# GET /players/squadnumber/{squad_number} β†’ 404 Not Found
GET {{baseUrl}}/players/squadnumber/{{nonexistentSquadNumber}}

###

# PUT /players/squadnumber/{squad_number} -------------------------------------

### Update Player (existing)
# PUT /players/squadnumber/{squad_number} β†’ 204 No Content
PUT {{baseUrl}}/players/squadnumber/{{existingSquadNumber}}
Content-Type: application/json

Expand All @@ -63,7 +117,27 @@ Content-Type: application/json
"middleName": "",
"lastName": "MartΓ­nez",
"dateOfBirth": "1992-09-02T00:00:00.000Z",
"squadNumber": 23,
"squadNumber": {{existingSquadNumber}},
"position": "Goalkeeper",
"abbrPosition": "GK",
"team": "Aston Villa FC",
"league": "Premier League",
"starting11": true
}

###

### Update Player (nonexistent)
# PUT /players/squadnumber/{squad_number} β†’ 404 Not Found
PUT {{baseUrl}}/players/squadnumber/{{nonexistentSquadNumber}}
Content-Type: application/json

{
"firstName": "Emiliano",
"middleName": "",
"lastName": "MartΓ­nez",
"dateOfBirth": "1992-09-02T00:00:00.000Z",
"squadNumber": {{existingSquadNumber}},
"position": "Goalkeeper",
"abbrPosition": "GK",
"team": "Aston Villa FC",
Expand All @@ -73,9 +147,43 @@ Content-Type: application/json

###

### Delete Player
# DELETE /players/squadnumber/:squadnumber β†’ 204 No Content
# Requires Create Player to have been run first.
DELETE {{baseUrl}}/players/squadnumber/{{newSquadNumber}}
### Update Player (unknown)
# PUT /players/squadnumber/{squad_number} β†’ 404 Not Found
PUT {{baseUrl}}/players/squadnumber/{{unknownSquadNumber}}
Content-Type: application/json

{
"firstName": "Emiliano",
"middleName": "",
"lastName": "MartΓ­nez",
"dateOfBirth": "1992-09-02T00:00:00.000Z",
"squadNumber": {{existingSquadNumber}},
"position": "Goalkeeper",
"abbrPosition": "GK",
"team": "Aston Villa FC",
"league": "Premier League",
"starting11": true
}

###

# DELETE /players/squadnumber/{squad_number} ----------------------------------

### Delete Player (existing)
# DELETE /players/squadnumber/{squad_number} β†’ 204 No Content
# Requires: "Create Player (valid body)" above to have run first.
DELETE {{baseUrl}}/players/squadnumber/{{createdSquadNumber}}

###

### Delete Player (nonexistent)
# DELETE /players/squadnumber/{squad_number} β†’ 404 Not Found
DELETE {{baseUrl}}/players/squadnumber/{{nonexistentSquadNumber}}

###

### Delete Player (unknown)
# DELETE /players/squadnumber/{squad_number} β†’ 404 Not Found
DELETE {{baseUrl}}/players/squadnumber/{{unknownSquadNumber}}

###
10 changes: 5 additions & 5 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ log() {
return 0
}

VOLUME_STORAGE_PATH="${STORAGE_PATH:-/storage/players-sqlite3.db}"

log "βœ” Starting container..."

mkdir -p "$(dirname "$VOLUME_STORAGE_PATH")"
STORAGE_PATH="${STORAGE_PATH:-storage/players-sqlite3.db}"

mkdir -p "$(dirname "$STORAGE_PATH")"

if [ ! -f "$VOLUME_STORAGE_PATH" ]; then
if [ ! -f "$STORAGE_PATH" ]; then
Comment thread
coderabbitai[bot] marked this conversation as resolved.
log "⚠️ No existing database file found in volume."
log "πŸ—„οΈ Diesel migrations will initialize the database on first start."
else
log "βœ” Existing database file found at $VOLUME_STORAGE_PATH."
log "βœ” Existing database file found at $STORAGE_PATH."
fi

log "βœ” Ready!"
Expand Down
Loading