diff --git a/pom.xml b/pom.xml index 7ffcd7e..533c0c3 100644 --- a/pom.xml +++ b/pom.xml @@ -124,7 +124,7 @@ org.flywaydb flyway-core - 9.16.0 + 9.20.0 org.junit.jupiter diff --git a/src/main/java/no/josefushighscore/JosefusHighscore.java b/src/main/java/no/josefushighscore/JosefusHighscore.java index a170528..f8f26ea 100644 --- a/src/main/java/no/josefushighscore/JosefusHighscore.java +++ b/src/main/java/no/josefushighscore/JosefusHighscore.java @@ -2,8 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; -@SpringBootApplication +@SpringBootApplication(exclude = {FlywayAutoConfiguration.class}) public class JosefusHighscore { public static void main(String[] args) { diff --git a/src/main/java/no/josefushighscore/dto/UserDto.java b/src/main/java/no/josefushighscore/dto/UserDto.java index 160ebeb..1df6290 100644 --- a/src/main/java/no/josefushighscore/dto/UserDto.java +++ b/src/main/java/no/josefushighscore/dto/UserDto.java @@ -47,8 +47,14 @@ public UserDto() { } - public static User builder() { - return new User(); + public static UserDto fromUser(User user) { + UserDto dto = new UserDto(); + dto.setUsername(user.getUsername()); + dto.setFirstname(user.getFirstname()); + dto.setLastname(user.getLastname()); + dto.setEmail(user.getEmail()); + + return dto; } public String getFullname() { diff --git a/src/main/java/no/josefushighscore/model/User.java b/src/main/java/no/josefushighscore/model/User.java index 12da4cd..1c4784f 100644 --- a/src/main/java/no/josefushighscore/model/User.java +++ b/src/main/java/no/josefushighscore/model/User.java @@ -6,6 +6,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import no.josefushighscore.dto.UserDto; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -98,6 +99,15 @@ public Collection getAuthorities() { return this.roles.stream().map(SimpleGrantedAuthority::new).collect(toList()); } + public UserDto toDto() { + return new UserDto( + this.getUsername(), + this.getFirstname(), + this.getLastname(), + this.getEmail() + ); + } + @Override public String getPassword() { return this.password; diff --git a/src/main/java/no/josefushighscore/service/UserService.java b/src/main/java/no/josefushighscore/service/UserService.java index 3148084..97ed554 100644 --- a/src/main/java/no/josefushighscore/service/UserService.java +++ b/src/main/java/no/josefushighscore/service/UserService.java @@ -17,7 +17,6 @@ public UserService(UserRegister userRepository) { } public Optional getUserDetails(String username) { - - return this.userRepository.getUserDetails(username); + return userRepository.getUserDetails(username); } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8b86473..8fadd83 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -18,17 +18,6 @@ spring: FAIL_ON_UNKNOWN_PROPERTIES: false ACCEPT_SINGLE_VALUE_AS_ARRAY: true default-property-inclusion: non_empty - flyway: - url: ${spring.datasource.url} - schemas: josefushighscore - enabled: true - locations: classpath:/db/migration - user: ${SUPABASE_JOSEFUS_DB_USER} - password: ${SUPABASE_JOSEFUS_DB_PWD} - jwt: - secret: ${JOSEFUS_JWT_SECRET} - expiration-time: 3600000 - datasource: url: ${SUPABASE_JOSEFUS_DB_URL} username: ${SUPABASE_JOSEFUS_DB_USER} @@ -37,7 +26,20 @@ spring: prepStmtCacheSize: 250 prepStmtCacheSqlLimit: 2048 useServerPrepStmts: true - + flyway: + url: ${spring.datasource.url} + default-schema: josefushighscore + schemas: + - josefushighscore + enabled: true + locations: classpath:db/migration + user: ${SUPABASE_JOSEFUS_DB_USER} + password: ${SUPABASE_JOSEFUS_DB_PWD} + baselineOnMigrate: true + check-location: true + jwt: + secret: ${JOSEFUS_JWT_SECRET} + expiration-time: 3600000 jpa: openInView: false show_sql: false @@ -46,16 +48,23 @@ spring: ddl-auto: update properties: # fixes Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented. - hibernate.jdbc.lob.non_contextual_creation: true - hibernate.default_schema: josefushighscore - + hibernate: + jdbc: + lob: + non_contextual_creation: true + default_schema: josefushighscore data: jpa: repositories.enabled: true - logging: level: - org.springframework.web: INFO - org.springframework.security: Debug - org.hibernate.SQL: debug - org.hibernate.type.descriptor.sql: trace + org: + springframework: + web: INFO + security: INFO + hibernate: + SQL: debug + type: + descriptor: + sql: trace + flywaydb: INFO diff --git a/src/main/resources/db.migration/V0_0_2__create_table_user_roles.sql b/src/main/resources/db.migration/V0_0_2__create_table_user_roles.sql deleted file mode 100644 index da8436a..0000000 --- a/src/main/resources/db.migration/V0_0_2__create_table_user_roles.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE IF NOT EXISTS USER_ROLES ( - user_id bigint NOT NULL, - roles varchar(255) -); \ No newline at end of file diff --git a/src/main/resources/db.migration/V0_1_1__alter_table_user_role.sql b/src/main/resources/db.migration/V0_1_1__alter_table_user_role.sql deleted file mode 100644 index 7644dae..0000000 --- a/src/main/resources/db.migration/V0_1_1__alter_table_user_role.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE USER_ROLES ADD COLUMN role_id bigint NOT NULL; \ No newline at end of file diff --git a/src/main/resources/db.migration/V0_0_1__create_table_user.sql b/src/main/resources/db/migration/V0_0_1__create_table_user.sql similarity index 78% rename from src/main/resources/db.migration/V0_0_1__create_table_user.sql rename to src/main/resources/db/migration/V0_0_1__create_table_user.sql index 843a975..d58b527 100644 --- a/src/main/resources/db.migration/V0_0_1__create_table_user.sql +++ b/src/main/resources/db/migration/V0_0_1__create_table_user.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS USER ( +CREATE TABLE IF NOT EXISTS josefushighscore."user" ( user_id bigint NOT NULL, email varchar(255), firstname varchar(255), diff --git a/src/main/resources/db/migration/V0_0_2__create_table_user_roles.sql b/src/main/resources/db/migration/V0_0_2__create_table_user_roles.sql new file mode 100644 index 0000000..d4caf10 --- /dev/null +++ b/src/main/resources/db/migration/V0_0_2__create_table_user_roles.sql @@ -0,0 +1,4 @@ +CREATE TABLE IF NOT EXISTS josefushighscore.user_roles ( + user_id bigint NOT NULL, + roles varchar(255) +); \ No newline at end of file diff --git a/src/main/resources/db.migration/V0_0_3__create_table_score.sql b/src/main/resources/db/migration/V0_0_3__create_table_score.sql similarity index 78% rename from src/main/resources/db.migration/V0_0_3__create_table_score.sql rename to src/main/resources/db/migration/V0_0_3__create_table_score.sql index 5d5ecd5..f601030 100644 --- a/src/main/resources/db.migration/V0_0_3__create_table_score.sql +++ b/src/main/resources/db/migration/V0_0_3__create_table_score.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS SCORE ( +CREATE TABLE IF NOT EXISTS josefushighscore.score ( score_id bigint NOT NULL, score bigint NOT NULL, created_at timestamp without time zone NOT NULL, diff --git a/src/main/resources/db.migration/V0_0_4__create_table_game.sql b/src/main/resources/db/migration/V0_0_4__create_table_game.sql similarity index 76% rename from src/main/resources/db.migration/V0_0_4__create_table_game.sql rename to src/main/resources/db/migration/V0_0_4__create_table_game.sql index 248b41f..c20fee3 100644 --- a/src/main/resources/db.migration/V0_0_4__create_table_game.sql +++ b/src/main/resources/db/migration/V0_0_4__create_table_game.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS GAME ( +CREATE TABLE IF NOT EXISTS josefushighscore.game ( game_id bigint NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, diff --git a/src/main/resources/db/migration/V0_1_1__alter_table_user_roles.sql b/src/main/resources/db/migration/V0_1_1__alter_table_user_roles.sql new file mode 100644 index 0000000..8c86493 --- /dev/null +++ b/src/main/resources/db/migration/V0_1_1__alter_table_user_roles.sql @@ -0,0 +1 @@ +ALTER TABLE josefushighscore.user_roles ADD COLUMN role_id bigint; \ No newline at end of file diff --git a/src/main/resources/db/migration/V0_1_2__add_supabase_id_to_josefushighscore_user.sql b/src/main/resources/db/migration/V0_1_2__add_supabase_id_to_josefushighscore_user.sql new file mode 100644 index 0000000..2cccb1b --- /dev/null +++ b/src/main/resources/db/migration/V0_1_2__add_supabase_id_to_josefushighscore_user.sql @@ -0,0 +1,7 @@ +-- Add supabase_id column to User table in josefushighscore schema +ALTER TABLE josefushighscore."user" ADD COLUMN supabase_id UUID; + +-- Add foreign key constraint +ALTER TABLE josefushighscore."user" ADD CONSTRAINT fk_user_supabase_id + FOREIGN KEY (supabase_id) + REFERENCES auth.users(id); \ No newline at end of file