From 8c323f51197c081cb340a242c023ca03e5ed8458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Sun, 2 Nov 2025 13:59:10 +0100 Subject: [PATCH 01/12] feat: add db connection, migration and create tables user and station --- .gitignore | 4 ++ pom.xml | 14 +++- .../fr/host_dcode/vlib/model/Station.java | 72 +++++++++++++++++++ .../java/fr/host_dcode/vlib/model/Status.java | 6 ++ .../java/fr/host_dcode/vlib/model/User.java | 37 ++++++++++ src/main/resources/application.properties | 11 +++ .../V1__Create_tables_User_and_Station.sql | 19 +++++ 7 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 src/main/java/fr/host_dcode/vlib/model/Station.java create mode 100644 src/main/java/fr/host_dcode/vlib/model/Status.java create mode 100644 src/main/java/fr/host_dcode/vlib/model/User.java create mode 100644 src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql diff --git a/.gitignore b/.gitignore index 667aaef..5b19106 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ build/ ### VS Code ### .vscode/ + +### Fichier properties ### +*.properties +src/main/resources/application.properties diff --git a/pom.xml b/pom.xml index bfc3040..5dea947 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,19 @@ spring-boot-starter-test test - + + org.postgresql + postgresql + + + org.flywaydb + flyway-core + + + org.flywaydb + flyway-database-postgresql + + diff --git a/src/main/java/fr/host_dcode/vlib/model/Station.java b/src/main/java/fr/host_dcode/vlib/model/Station.java new file mode 100644 index 0000000..854b2cf --- /dev/null +++ b/src/main/java/fr/host_dcode/vlib/model/Station.java @@ -0,0 +1,72 @@ +package fr.host_dcode.vlib.model; + + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +import java.time.LocalDateTime; + +@Entity +public class Station { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String name; + private String station_code; + private double latitude; + private double longitude; + private String address; + private String city; + private String description; + private LocalDateTime last_update; + + + public Station(){} + + public Station(String name, String stationCode, double latitude, double longitude, String description) { + this.name = name; + this.station_code = stationCode; + this.latitude = latitude; + this.longitude = longitude; + this.description = description; + } + + public String getStationCode(){ + return this.station_code; + } + + public String getName(){ + return this.name; + } + + public void setName(String name){ + this.name = name; + } + + public String getDescription(){ + return this.description; + } + + public void setDescription(String description){ + this.description = description; + } + public Double getLatitude(){ + return this.latitude; + } + public Double getLongitude(){ + return this.longitude; + } + + public String getAddress(){ + return this.address; + } + + private void setAddress(String address){ + this.address = address; + } + + +} diff --git a/src/main/java/fr/host_dcode/vlib/model/Status.java b/src/main/java/fr/host_dcode/vlib/model/Status.java new file mode 100644 index 0000000..f8209e3 --- /dev/null +++ b/src/main/java/fr/host_dcode/vlib/model/Status.java @@ -0,0 +1,6 @@ +package fr.host_dcode.vlib.model; + +public enum Status { + User, + Admin +} diff --git a/src/main/java/fr/host_dcode/vlib/model/User.java b/src/main/java/fr/host_dcode/vlib/model/User.java new file mode 100644 index 0000000..ba201b3 --- /dev/null +++ b/src/main/java/fr/host_dcode/vlib/model/User.java @@ -0,0 +1,37 @@ +package fr.host_dcode.vlib.model; + +import jakarta.persistence.*; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String email; + private String password; + private Status status; + private LocalDateTime created_at; + + + public User(){} + + public User(String email, String password){ + this.email = email; + this.password = password; + } + + public String getEmail(){ + return this.email; + } + + public Status getStatus(){ + return this.status; + } + + + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6b0fade..41a451f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,12 @@ spring.application.name=vlib +spring.datasource.url=jdbc:postgresql://185.166.39.209:5432/vlib_db +spring.datasource.username=vlibadmin +spring.datasource.password=cLX1fgz27ravjV2BE1MxbS1w8uBU9en2B4fUssQC + +spring.jpa.hibernate.ddl-auto=none +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + + +spring.flyway.enabled=true +spring.flyway.locations=classpath:db/migration \ No newline at end of file diff --git a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql new file mode 100644 index 0000000..02407cf --- /dev/null +++ b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql @@ -0,0 +1,19 @@ +CREATE TABLE users ( + id SERIAL PRIMARY KEY, + email VARCHAR(50) NOT NULL, + password VARCHAR(200) NOT NULL, + status VARCHAR(20) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE station ( + id SERIAL PRIMARY KEY, + name VARCHAR(100) NOT NULL, + station_code VARCHAR(20) NOT NULL, + latitude DECIMAL(9,6) NOT NULL, + longitude DECIMAL(9,6) NOT NULL, + address VARCHAR(100), + city VARCHAR(20), + description VARCHAR(300), + last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) \ No newline at end of file From 85fac560ae89da3251b8a9689801c524c8d6c68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Tue, 4 Nov 2025 21:53:11 +0100 Subject: [PATCH 02/12] build: stop tracking application.properties --- .gitignore | 1 + src/main/java/fr/host_dcode/vlib/model/Station.java | 4 ++-- src/main/java/fr/host_dcode/vlib/model/User.java | 2 +- src/main/resources/application.properties | 12 ------------ .../migration/V1__Create_tables_User_and_Station.sql | 2 +- 5 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 src/main/resources/application.properties diff --git a/.gitignore b/.gitignore index 5b19106..933b0bc 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ build/ ### Fichier properties ### *.properties src/main/resources/application.properties +**/application.properties \ No newline at end of file diff --git a/src/main/java/fr/host_dcode/vlib/model/Station.java b/src/main/java/fr/host_dcode/vlib/model/Station.java index 854b2cf..c34db61 100644 --- a/src/main/java/fr/host_dcode/vlib/model/Station.java +++ b/src/main/java/fr/host_dcode/vlib/model/Station.java @@ -12,7 +12,7 @@ public class Station { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; private String station_code; @@ -64,7 +64,7 @@ public String getAddress(){ return this.address; } - private void setAddress(String address){ + public void setAddress(String address){ this.address = address; } diff --git a/src/main/java/fr/host_dcode/vlib/model/User.java b/src/main/java/fr/host_dcode/vlib/model/User.java index ba201b3..7b50762 100644 --- a/src/main/java/fr/host_dcode/vlib/model/User.java +++ b/src/main/java/fr/host_dcode/vlib/model/User.java @@ -9,7 +9,7 @@ public class User { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String email; private String password; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 41a451f..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,12 +0,0 @@ -spring.application.name=vlib -spring.datasource.url=jdbc:postgresql://185.166.39.209:5432/vlib_db -spring.datasource.username=vlibadmin -spring.datasource.password=cLX1fgz27ravjV2BE1MxbS1w8uBU9en2B4fUssQC - -spring.jpa.hibernate.ddl-auto=none -spring.jpa.show-sql=true -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - - -spring.flyway.enabled=true -spring.flyway.locations=classpath:db/migration \ No newline at end of file diff --git a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql index 02407cf..9e53108 100644 --- a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql +++ b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql @@ -16,4 +16,4 @@ CREATE TABLE station ( city VARCHAR(20), description VARCHAR(300), last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP -) \ No newline at end of file +); \ No newline at end of file From dbf6b11c215a0068ca4a2ec7e600c25a5ef72686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Tue, 4 Nov 2025 22:08:49 +0100 Subject: [PATCH 03/12] build: clean .gitignore file --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 933b0bc..c877022 100644 --- a/.gitignore +++ b/.gitignore @@ -34,5 +34,3 @@ build/ ### Fichier properties ### *.properties -src/main/resources/application.properties -**/application.properties \ No newline at end of file From d186cfb2796ad6220242d2fb740e1d60cf246919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:12:10 +0100 Subject: [PATCH 04/12] chore: change station id to use uuid --- src/main/java/fr/host_dcode/vlib/model/Station.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/host_dcode/vlib/model/Station.java b/src/main/java/fr/host_dcode/vlib/model/Station.java index c34db61..a45fa65 100644 --- a/src/main/java/fr/host_dcode/vlib/model/Station.java +++ b/src/main/java/fr/host_dcode/vlib/model/Station.java @@ -10,10 +10,10 @@ @Entity public class Station { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private int id; + @GeneratedValue(strategy = GenerationType.UUID) + private String id; + private String recordId; private String name; private String station_code; private double latitude; @@ -46,6 +46,10 @@ public void setName(String name){ this.name = name; } + public String getRecordId(){ + return this.recordId; + } + public String getDescription(){ return this.description; } From d5e97ccd087c84d8f136f70e8778f9e6aa194039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:13:39 +0100 Subject: [PATCH 05/12] chore: add recordId propertie --- src/main/java/fr/host_dcode/vlib/model/Station.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/host_dcode/vlib/model/Station.java b/src/main/java/fr/host_dcode/vlib/model/Station.java index a45fa65..1859b59 100644 --- a/src/main/java/fr/host_dcode/vlib/model/Station.java +++ b/src/main/java/fr/host_dcode/vlib/model/Station.java @@ -26,8 +26,9 @@ public class Station { public Station(){} - public Station(String name, String stationCode, double latitude, double longitude, String description) { + public Station(String name, String recordId, String stationCode, double latitude, double longitude, String description) { this.name = name; + this.recordId = recordId; this.station_code = stationCode; this.latitude = latitude; this.longitude = longitude; From 44d8ab2108cdeac6a4ad884e412f474ae74f75ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:14:24 +0100 Subject: [PATCH 06/12] chore: delete enum status file --- src/main/java/fr/host_dcode/vlib/model/Status.java | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/main/java/fr/host_dcode/vlib/model/Status.java diff --git a/src/main/java/fr/host_dcode/vlib/model/Status.java b/src/main/java/fr/host_dcode/vlib/model/Status.java deleted file mode 100644 index f8209e3..0000000 --- a/src/main/java/fr/host_dcode/vlib/model/Status.java +++ /dev/null @@ -1,6 +0,0 @@ -package fr.host_dcode.vlib.model; - -public enum Status { - User, - Admin -} From 10355f38fffa18f8aff8ca1854ff90f7ea664ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:14:58 +0100 Subject: [PATCH 07/12] chore: add enum status --- src/main/java/fr/host_dcode/vlib/model/User.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/fr/host_dcode/vlib/model/User.java b/src/main/java/fr/host_dcode/vlib/model/User.java index 7b50762..cbcfc3d 100644 --- a/src/main/java/fr/host_dcode/vlib/model/User.java +++ b/src/main/java/fr/host_dcode/vlib/model/User.java @@ -4,9 +4,14 @@ import java.time.LocalDateTime; + @Entity @Table(name = "users") public class User { + public enum Status { + USER, + ADMIN + } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 824a68a4da0c1b989c396afebe80b816dc6d5323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:15:40 +0100 Subject: [PATCH 08/12] chore: modify the id type to use uuid --- src/main/java/fr/host_dcode/vlib/model/User.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/host_dcode/vlib/model/User.java b/src/main/java/fr/host_dcode/vlib/model/User.java index cbcfc3d..e845fb9 100644 --- a/src/main/java/fr/host_dcode/vlib/model/User.java +++ b/src/main/java/fr/host_dcode/vlib/model/User.java @@ -14,8 +14,8 @@ public enum Status { } @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private int id; + @GeneratedValue(strategy = GenerationType.UUID) + private String id; private String email; private String password; private Status status; From e8e4ce7e61d985d3ede7376c38adcb86d416e6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:17:01 +0100 Subject: [PATCH 09/12] chore: modify id type to use varchar --- .../migration/V1__Create_tables_User_and_Station.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql index 9e53108..b928cbd 100644 --- a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql +++ b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql @@ -1,9 +1,9 @@ CREATE TABLE users ( - id SERIAL PRIMARY KEY, - email VARCHAR(50) NOT NULL, - password VARCHAR(200) NOT NULL, - status VARCHAR(20) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + id VARCHAR(40) PRIMARY KEY, + email VARCHAR(50) NOT NULL, + password VARCHAR(200) NOT NULL, + status VARCHAR(20) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE station ( From 8ea09eec79a009466ada1255ec215d4b4cb50266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= Date: Wed, 12 Nov 2025 20:17:43 +0100 Subject: [PATCH 10/12] chore: add recordid column in station table --- .../V1__Create_tables_User_and_Station.sql | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql index b928cbd..c08d757 100644 --- a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql +++ b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql @@ -7,13 +7,14 @@ CREATE TABLE users ( ); CREATE TABLE station ( - id SERIAL PRIMARY KEY, - name VARCHAR(100) NOT NULL, - station_code VARCHAR(20) NOT NULL, - latitude DECIMAL(9,6) NOT NULL, - longitude DECIMAL(9,6) NOT NULL, - address VARCHAR(100), - city VARCHAR(20), - description VARCHAR(300), - last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP + id VARCHAR(40) PRIMARY KEY, + recordId VARCHAR(100) NOT NULL, + name VARCHAR(100) NOT NULL, + station_code VARCHAR(20) NOT NULL, + latitude DECIMAL(9,6) NOT NULL, + longitude DECIMAL(9,6) NOT NULL, + address VARCHAR(100), + city VARCHAR(20), + description VARCHAR(300), + last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); \ No newline at end of file From b52dc2aa30d2902bb12ad23554d23279040027f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= <129305476+SHACRAM@users.noreply.github.com> Date: Wed, 12 Nov 2025 12:59:43 -0800 Subject: [PATCH 11/12] chore : add unique constrain on email propertie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sébastien Lotten <129305476+SHACRAM@users.noreply.github.com> --- .../db/migration/V1__Create_tables_User_and_Station.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql index c08d757..215b6a3 100644 --- a/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql +++ b/src/main/resources/db/migration/V1__Create_tables_User_and_Station.sql @@ -3,7 +3,8 @@ CREATE TABLE users ( email VARCHAR(50) NOT NULL, password VARCHAR(200) NOT NULL, status VARCHAR(20) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + UNIQUE (email) ); CREATE TABLE station ( From ad1a5a4a808d8933428578a5e72d1ec841a3e5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lotten?= <129305476+SHACRAM@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:12:08 -0800 Subject: [PATCH 12/12] chor: add enumType annotation on status column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sébastien Lotten <129305476+SHACRAM@users.noreply.github.com> --- src/main/java/fr/host_dcode/vlib/model/User.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fr/host_dcode/vlib/model/User.java b/src/main/java/fr/host_dcode/vlib/model/User.java index e845fb9..f097a9d 100644 --- a/src/main/java/fr/host_dcode/vlib/model/User.java +++ b/src/main/java/fr/host_dcode/vlib/model/User.java @@ -18,6 +18,7 @@ public enum Status { private String id; private String email; private String password; + @Enumerated(EnumType.STRING) private Status status; private LocalDateTime created_at;