Skip to content
Open
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
4 changes: 3 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ MONGO_SYNCS_COLLECTION_NAME=syncs
MONGO_DATABASE_NAME=chabo-api
MONGO_DSN='mongodb://root:my_password@mongodb:27017/?authSource=admin&ssl=false'

POSTGRES_DSN='postgres://root:my_password@postgresql:5432/chabo-api?sslmode=disable'

SYNC_COOL_DOWN_SECONDS='300'
OPENDATA_API_URL='https://opendata.bordeaux-metropole.fr/api/records/1.0/search?dataset=previsions_pont_chaban&rows=1000&sort=-date_passage&start=0&timezone=Europe%2FParis'
OPENDATA_API_URL='https://opendata.bordeaux-metropole.fr/api/records/1.0/search?dataset=previsions_pont_chaban&rows=1000&sort=-date_passage,fermeture_a_la_circulation&start=0&timezone=Europe%2FParis'
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ go.work
!.env.dev

# IntelliJ
.idea/
.idea/

# Docker compose, ignore all data directories (except .gitkeep)
dev/**/data/*
!dev/**/data/.gitkeep
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"github.vscode-github-actions",
"PKief.material-icon-theme",
"redhat.vscode-yaml",
"ms-azuretools.vscode-docker"
"ms-azuretools.vscode-docker",
"inferrinizzard.prettier-sql-vscode"
]
}
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@
"workbench.preferredDarkColorTheme": "Default Dark Modern",
"workbench.iconTheme": "vs-seti",
"files.autoSave": "onFocusChange",
"cSpell.words": [
"Approximative",
"chabo",
"healthcheck",
"logrus",
"OPENDATA",
"usecases",
"vareversat"
],
}
1 change: 1 addition & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
RUN go install github.com/swaggo/swag/cmd/swag@latest
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.18.2
COPY . .
RUN swag init -d ./internal/api/routers,./ -g main_router.go
30 changes: 28 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
services:
app:
container_name: chabo-api
depends_on:
- postgresql
- mongodb
command: >
sh -c "go run ."
build:
context: .
dockerfile: Dockerfile.dev
Expand All @@ -10,7 +15,7 @@ services:
- "8080:8080"
- "6060:6060"
env_file:
- /.env.dev
- .env.dev
mongodb:
container_name: mongodb
image: mongo:8.0.8
Expand All @@ -23,5 +28,26 @@ services:
postgresql:
container_name: postgresql
image: postgres:17.4
ports:
- "5432:5432"
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: my_password
POSTGRES_DB: chabo-api
volumes:
- postgresqldata:/var/lib/postgresql/data
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:9.2.0
ports:
- "5050:80"
environment:
POSTGRES_PASSWORD: my_password
PGADMIN_DEFAULT_EMAIL: test@test.com
PGADMIN_DEFAULT_PASSWORD: my_password
volumes:
- pgadmindata:/var/lib/pgadmin

volumes:
mongodata:
postgresqldata:
pgadmindata:
1 change: 1 addition & 0 deletions db/migrations/000001_create_syncs_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS syncs;
9 changes: 9 additions & 0 deletions db/migrations/000001_create_syncs_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE
IF NOT EXISTS syncs (
sync_id INTEGER GENERATED ALWAYS AS IDENTITY,
item_count INTEGER NOT NULL,
duration INTEGER NOT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,

PRIMARY KEY(sync_id)
);
1 change: 1 addition & 0 deletions db/migrations/000002_create_boats_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS boats;
7 changes: 7 additions & 0 deletions db/migrations/000002_create_boats_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE
IF NOT EXISTS boats (
boat_id INTEGER GENERATED ALWAYS AS IDENTITY,
name TEXT UNIQUE NOT NULL,

PRIMARY KEY(boat_id)
);
1 change: 1 addition & 0 deletions db/migrations/000003_create_forecasts_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS forecasts;
11 changes: 11 additions & 0 deletions db/migrations/000003_create_forecasts_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE
IF NOT EXISTS forecasts (
forecast_id TEXT,
closing_event_name TEXT,
closing_duration_min INTEGER NOT NULL,
circulation_closing_date TIMESTAMPTZ NOT NULL,
circulation_reopening_date TIMESTAMPTZ NOT NULL,
is_traffic_fully_closed BOOLEAN NOT NULL,

PRIMARY KEY(forecast_id)
);
1 change: 1 addition & 0 deletions db/migrations/000004_create_forecasts_boats_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS boats;
15 changes: 15 additions & 0 deletions db/migrations/000004_create_forecasts_boats_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE
IF NOT EXISTS forecasts_boats (
forecast_id TEXT,
boat_id INTEGER,
is_leaving_dock BOOLEAN NOT NULL,
approximative_crossing_date TIMESTAMPTZ NOT NULL,

PRIMARY KEY(forecast_id, boat_id),
CONSTRAINT fk_forecast
FOREIGN KEY(forecast_id)
REFERENCES forecasts(forecast_id),
CONSTRAINT fk_boat
FOREIGN KEY(boat_id)
REFERENCES boats(boat_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS static_boat_data;
9 changes: 9 additions & 0 deletions db/migrations/000005_create_static_boat_data_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE
IF NOT EXISTS static_boat_data (
boat_id INTEGER GENERATED ALWAYS AS IDENTITY,
name TEXT UNIQUE NOT NULL,
imo INTEGER,
mmsi INTEGER,

PRIMARY KEY(boat_id)
);
42 changes: 42 additions & 0 deletions db/migrations/000006_populate_boat_static_data.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
INSERT INTO static_boat_data (name, imo, mmsi) VALUES
('FRIDJTOF NANSEN', 9813084, 257088070),
('AZAMARA QUEST', 9210218, 256216000),
('MARINA', 9438066, 538003668),
('CRYSTAL SERENITY', 9243667, 311536000),
('LE LYRIAL', 9704130, 578000800),
('SPIRIT OF DISCOVERY', 9802683, 232021171),
('BALMORAL', 8506294, 308785000),
('EUROPA', 9183855, 215767000),
('SILVER DAWN', 9857937, 311001044),
('STAR PRIDE', 8707343, 311084000),
('LE BELLOT', 9852418, 578001500),
('PANTHERE', 8021713, NULL),
('SILVER SPIRIT', 9437866, 311022500),
('SPIRIT OF ADVENTURE', 9818084, 232026551),
('HANSEATIC SPRIT', 9857640, 215973000),
('GLYCINE', 4545838, NULL),
('OCEANIA VISTA', 9876957, 538009952),
('EGLANTINE', NULL, 227576220),
('WORLD VOYAGER', 9871529, 255806150),
('AIDASOL', 9490040, 247302900),
('SEADREAM II', 8203440, 308311000),
('EUROPA 2', 9616230, 229378000),
('AZAMARA ONWARD', 9187887, 229765000),
('JAGUAR', 1007756, 319295000),
('ILMA', 9967586, 256343000),
('AZAMARA JOURNEY', 9200940, 256204000),
('ALTAIR', 9806550, 319185200),
('SEVEN SEAS VOYAGEUR', 9247144, 311513000),
('CHACAL', 8944355, 227801800),
('LE BOREAL', 9502506, 578000500),
('HANSEATIC SPIRIT', 9857640, 215973000),
('SEVEN SEAS MARINER', 9210139, 311622000),
('SEVEN SEAS GRANDEUR', 9877444, 538010706),
('SEABOURN SOJOURN', 9417098, 311027100),
('SILVER WIND', 8903935, 308814000),
('SEUDRE DF32', NULL, 228074600),
('AMADEA', 8913162, 308445000),
('STAR LEGEND', 9008598, 311085000),
('SIRENA', 9187899, 538006842)
ON CONFLICT (name)
DO NOTHING;
5 changes: 5 additions & 0 deletions db/queries/001_select_all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT b.name, f.circulation_closing_date AT TIME ZONE 'Europe/Paris', f.circulation_reopening_date, fb.is_leaving
FROM boats AS b
INNER JOIN forecasts_boats AS fb ON b.boat_id = fb.boat_id
INNER JOIN forecasts AS f ON f.forecast_id = fb.forecast_id
ORDER BY f.circulation_closing_date;
52 changes: 28 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,67 +1,71 @@
module github.com/vareversat/chabo-api

go 1.22
go 1.23.0

toolchain go1.24.2

require (
github.com/getsentry/sentry-go v0.32.0
github.com/getsentry/sentry-go/gin v0.32.0
github.com/gin-gonic/gin v1.10.0
github.com/jackc/pgx/v5 v5.7.4
github.com/stretchr/testify v1.10.0
github.com/swaggo/files v1.0.1
go.mongodb.org/mongo-driver v1.17.3
)

require (
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sync v0.13.0 // indirect
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/bytedance/sonic v1.11.9 // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/bytedance/sonic v1.13.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/go-playground/validator/v10 v10.26.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/sirupsen/logrus v1.9.3
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.4
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/arch v0.16.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/tools v0.32.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading