diff --git a/README.md b/README.md index bdc6f58b1..6220ccd19 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,9 @@ The API is a Spring based application to suit the needs of a LAN-party. ### Docker The postgres install can be quite a hassle, docker can also be used for this. -After docker is installed, create a postgres container: `docker run --name lancie_postgres -p 5432:5432 -d postgres`. -Connect to the running container with `docker exec -tiu postgres lancie_postgres psql` and create a new database with `CREATE DATABASE lancie-dev;`. +After docker is installed, create a postgres container: `docker run --name lancie_postgres -e POSTGRES_DB=areafiftylan -p 5432:5432 -d postgres`. +This creates a new database called "areafiftylan". +You can connect to this database on localhost:5432 with user `postgres` and blank password. This is everything you need to initially start the LANcie-API, if, at any later point, you need to connect to the database, you can enter `docker exec -tiu postgres lancie_postgres psql -d lancie-dev`. The next time you want to start developing, a `docker start lancie_postgres` is enough. To stop the container again, `docker stop lancie_postgres` will do. diff --git a/build.gradle b/build.gradle index 34e5937ed..3494521c0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,11 @@ plugins { - id 'org.springframework.boot' version '2.1.9.RELEASE' + id 'org.springframework.boot' version '2.2.2.RELEASE' id 'io.spring.dependency-management' version '1.0.8.RELEASE' id 'java' id 'idea' id 'eclipse' id 'jacoco' + id "io.freefair.lombok" version "4.1.6" } jar { @@ -35,13 +36,9 @@ dependencies { compile("org.springframework.boot:spring-boot-starter-json") compile("org.flywaydb:flyway-core") - compile("com.google.guava:guava:23.5-jre") + compile("com.google.guava:guava:28.1-jre") compile("nl.stil4m:mollie-api:2.7.0") compile("net.logstash.logback:logstash-logback-encoder:4.11") - compile("javax.xml.bind:jaxb-api:2.3.0") - - compileOnly("org.projectlombok:lombok:1.18.2") - annotationProcessor("org.projectlombok:lombok:1.18.2") runtime("org.hsqldb:hsqldb") runtime("org.postgresql:postgresql") diff --git a/src/main/java/ch/wisv/areafiftylan/products/model/order/Order.java b/src/main/java/ch/wisv/areafiftylan/products/model/order/Order.java index c6a2d1149..037404fb9 100644 --- a/src/main/java/ch/wisv/areafiftylan/products/model/order/Order.java +++ b/src/main/java/ch/wisv/areafiftylan/products/model/order/Order.java @@ -32,6 +32,7 @@ @Entity @Getter +@Table(name = "orders") public class Order { @Id diff --git a/src/main/java/ch/wisv/areafiftylan/users/model/User.java b/src/main/java/ch/wisv/areafiftylan/users/model/User.java index f9896660f..5770697c6 100644 --- a/src/main/java/ch/wisv/areafiftylan/users/model/User.java +++ b/src/main/java/ch/wisv/areafiftylan/users/model/User.java @@ -40,7 +40,7 @@ @Data @RequiredArgsConstructor @NoArgsConstructor -@Table(uniqueConstraints = { @UniqueConstraint(name = "email", columnNames = { "email" }) }) +@Table(name = "users", uniqueConstraints = { @UniqueConstraint(name = "email", columnNames = { "email" }) }) public class User implements Serializable, UserDetails { @NonNull diff --git a/src/main/java/ch/wisv/areafiftylan/utils/TestDataCleaner.java b/src/main/java/ch/wisv/areafiftylan/utils/TestDataCleaner.java new file mode 100644 index 000000000..946d6c9d3 --- /dev/null +++ b/src/main/java/ch/wisv/areafiftylan/utils/TestDataCleaner.java @@ -0,0 +1,22 @@ +package ch.wisv.areafiftylan.utils; + +import lombok.extern.slf4j.Slf4j; +import org.flywaydb.core.Flyway; +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +@Profile("dev") +public class TestDataCleaner implements FlywayMigrationStrategy { + + @Override + public void migrate(Flyway flyway) { + log.debug("Cleaning data"); + flyway.clean(); + log.debug("Initalizing migrations"); + flyway.migrate(); + } + +} diff --git a/src/main/java/ch/wisv/areafiftylan/utils/TestDataRunner.java b/src/main/java/ch/wisv/areafiftylan/utils/TestDataRunner.java index f24727101..95e75a926 100644 --- a/src/main/java/ch/wisv/areafiftylan/utils/TestDataRunner.java +++ b/src/main/java/ch/wisv/areafiftylan/utils/TestDataRunner.java @@ -49,8 +49,9 @@ import ch.wisv.areafiftylan.web.tournament.model.TournamentType; import ch.wisv.areafiftylan.web.tournament.service.TournamentRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.annotation.Profile; +import org.springframework.context.event.EventListener; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Component; @@ -63,7 +64,7 @@ @Component @Profile("dev") -public class TestDataRunner implements CommandLineRunner { +public class TestDataRunner { private final UserRepository accountRepository; private final TicketRepository ticketRepository; private final SeatService seatService; @@ -104,8 +105,8 @@ public TestDataRunner(UserRepository accountRepository, TicketRepository ticketR this.tournamentRepository = tournamentRepository; } - @Override - public void run(String... evt) throws Exception { + @EventListener(ApplicationStartedEvent.class) + public void insertTestData() { //region Users LocalDate localDate = LocalDate.of(2000, 1, 2); diff --git a/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171201140920__add_subscription_table.java b/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171201140920__add_subscription_table.java deleted file mode 100644 index 9e3eb91b9..000000000 --- a/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171201140920__add_subscription_table.java +++ /dev/null @@ -1,11 +0,0 @@ -package ch.wisv.areafiftylan.utils.db.migration; - -import org.flywaydb.core.api.migration.spring.SpringJdbcMigration; -import org.springframework.jdbc.core.JdbcTemplate; - -public class V20171201140920__add_subscription_table implements SpringJdbcMigration { - @Override - public void migrate(JdbcTemplate jdbcTemplate) throws Exception { - jdbcTemplate.execute("CREATE TABLE \"subscription\" (\"id\" BIGINT, \"email\" VARCHAR(255) UNIQUE, PRIMARY KEY (id));"); - } -} diff --git a/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171201153120__rename_taken_to_locked.java b/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171201153120__rename_taken_to_locked.java deleted file mode 100644 index 9fbb10812..000000000 --- a/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171201153120__rename_taken_to_locked.java +++ /dev/null @@ -1,12 +0,0 @@ -package ch.wisv.areafiftylan.utils.db.migration; - -import org.flywaydb.core.api.migration.spring.SpringJdbcMigration; -import org.springframework.jdbc.core.JdbcTemplate; - -public class V20171201153120__rename_taken_to_locked implements SpringJdbcMigration { - - @Override - public void migrate(JdbcTemplate jdbcTemplate) throws Exception { - jdbcTemplate.execute("ALTER TABLE \"seat\" RENAME taken TO locked;"); - } -} diff --git a/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171208163050__add_banner.java b/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171208163050__add_banner.java deleted file mode 100644 index 900f5de41..000000000 --- a/src/main/java/ch/wisv/areafiftylan/utils/db/migration/V20171208163050__add_banner.java +++ /dev/null @@ -1,15 +0,0 @@ -package ch.wisv.areafiftylan.utils.db.migration; - -import org.flywaydb.core.api.migration.spring.SpringJdbcMigration; -import org.springframework.jdbc.core.JdbcTemplate; - -public class V20171208163050__add_banner implements SpringJdbcMigration { - @Override - public void migrate(JdbcTemplate jdbcTemplate) throws Exception { - jdbcTemplate.execute("CREATE TABLE banner (" + - "id bigint NOT NULL CONSTRAINT banner_pkey PRIMARY KEY, " + - "end_date DATE, " + - "start_date DATE, " + - "text VARCHAR(255))"); - } -} diff --git a/src/main/resources/config/application-createsql.yml b/src/main/resources/config/application-createsql.yml new file mode 100644 index 000000000..71ac9cd7e --- /dev/null +++ b/src/main/resources/config/application-createsql.yml @@ -0,0 +1,12 @@ +spring: + flyway: + enabled: false + jpa: + properties: + javax: + persistence: + schema-generation: + create-source: metadata + scripts: + action: create + create-target: src/main/resources/ddl_jpa_creation.sql \ No newline at end of file diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index 07c749d88..aeb84d0fa 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -1,6 +1,3 @@ -spring.flyway.enabled: false -spring.jpa.hibernate.ddl-auto: create - ## AREA FIFTYLAN SETTINGS a5l: paymentReturnUrl: https://localhost:5100/order-check @@ -19,3 +16,12 @@ a5l: orderKeepAlive: 15 ratelimit: enabled: false + +logging: + level: + ch.wisv.areafiftylan: DEBUG + +management: + health: + mail: + enabled: false diff --git a/src/main/resources/config/application-production.yml b/src/main/resources/config/application-production.yml index a070728dd..2e9b10d27 100644 --- a/src/main/resources/config/application-production.yml +++ b/src/main/resources/config/application-production.yml @@ -1,8 +1,6 @@ -spring.jpa.hibernate.ddl-auto: validate -spring.jpa.properties.hibernate.hbm2ddl.auto: none - logging: - file: /tmp/logs/lancie-api.log + file: + name: /tmp/logs/lancie-api.log ## AREA FIFTYLAN SETTINGS a5l: @@ -15,6 +13,7 @@ a5l: sender: LANcie contact: LANcie confirmUrl: https://areafiftylan.nl/register-confirm + year: 2020 ratelimit: enabled: true minute: 10 @@ -23,7 +22,3 @@ a5l: ticketLimit: 220 orderKeepAlive: 15 year: 2019 -spring: - flyway: - enabled: true - locations: ch/wisv/areafiftylan/utils/db/migration diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 0ddedd87b..b6fde3f8e 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -3,26 +3,14 @@ spring: main: allow-bean-definition-overriding: true thymeleaf: - check-template-location: true - prefix: classpath:/templates/ - suffix: .html mode: HTML5 encoding: UTF-8 - servlet: - content-type: text/html - - datasource.driverClassName: org.postgresql.Driver - data.jpa.repositories.enabled: true jpa: show-sql: false - database-platform: org.hibernate.dialect.PostgreSQLDialect - generate-ddl: true - properties: - hibernate.default_schema: public - - jackson: - date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat + hibernate: + ddl-auto: validate + open-in-view: true logging: level: @@ -31,7 +19,8 @@ logging: org.hibernate.SQL: ERROR pattern: console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" - file: logs/lancie-api.log + file: + name: logs/lancie-api.log server: port: 9000 @@ -45,4 +34,4 @@ management: base-path: /management endpoint: logfile: - enabled: true \ No newline at end of file + enabled: true diff --git a/src/main/resources/db/migration/V1_0__init.sql b/src/main/resources/db/migration/V1_0__init.sql new file mode 100644 index 000000000..a63cbb4ef --- /dev/null +++ b/src/main/resources/db/migration/V1_0__init.sql @@ -0,0 +1,66 @@ +create sequence hibernate_sequence start 1 increment 1; +create table authentication_token (id int8 not null, primary key (id)); +create table banner (id int8 not null, end_date date, start_date date, text text, primary key (id)); +create table committee_member (position int8 not null, function varchar(255), icon varchar(255), name varchar(255), primary key (position)); +create table consumption (id int8 not null, name varchar(255), primary key (id)); +create table consumption_map (id int8 not null, ticket_id int8, primary key (id)); +create table consumption_map_consumptions_made (consumption_map_id int8 not null, consumptions_made_id int8 not null); +create table expired_order (id int8 not null, created_at varchar(255), created_by varchar(255), expired_at varchar(255), number_of_tickets int4 not null, primary key (id)); +create table faq_pair (id int8 not null, answer text, question varchar(255), primary key (id)); +create table orders (id int8 not null, creation_date_time timestamp, reference varchar(255), status int4, user_id int8, primary key (id)); +create table orders_tickets (order_id int8 not null, tickets_id int8 not null, primary key (order_id, tickets_id)); +create table password_reset_token (id int8 not null, primary key (id)); +create table profile (id int8 not null, address varchar(255), birthday date, city varchar(255), display_name varchar(255), first_name varchar(255), gender int4, last_name varchar(255), notes varchar(255), phone_number varchar(255), zipcode varchar(255), primary key (id)); +create table rfidlink (id int8 not null, rfid varchar(255), ticket_id int8, primary key (id)); +create table seat (id int8 not null, locked boolean not null, seat_group varchar(255), seat_number int4 not null, ticket_id int8, primary key (id)); +create table sponsor (id int8 not null, image_name varchar(255), name varchar(255), type int4, website varchar(255), primary key (id)); +create table subscription (id int8 not null, email varchar(255), primary key (id)); +create table team (id int8 not null, size int4 not null, team_name varchar(255) not null, captain_id int8 not null, primary key (id)); +create table team_members (team_id int8 not null, members_id int8 not null, primary key (team_id, members_id)); +create table team_invite_token (id int8 not null, team_id int8 not null, primary key (id)); +create table ticket (id int8 not null, valid boolean not null, owner_id int8, type_id int8, primary key (id)); +create table ticket_enabled_options (ticket_id int8 not null, enabled_options_id int8 not null, primary key (ticket_id, enabled_options_id)); +create table ticket_option (id int8 not null, name varchar(255), price float4 not null, primary key (id)); +create table ticket_transfer_token (id int8 not null, ticket_id int8 not null, primary key (id)); +create table ticket_type (id int8 not null, buyable boolean not null, deadline timestamp, name varchar(255), number_available int4 not null, price float4 not null, text varchar(255), primary key (id)); +create table ticket_type_possible_options (ticket_type_id int8 not null, possible_options_id int8 not null, primary key (ticket_type_id, possible_options_id)); +create table token (id int8 not null, expirable BOOLEAN DEFAULT TRUE not null, expiry_date timestamp, revoked BOOLEAN DEFAULT FALSE not null, token varchar(255), used BOOLEAN DEFAULT FALSE not null, user_id int8 not null, primary key (id)); +create table tournament (id int8 not null, button_image_path varchar(255), button_title varchar(255), description text, format varchar(255), header_title varchar(255), type int4, sponsor_id int8, primary key (id)); +create table tournament_prize (tournament_id int8 not null, prizes varchar(255)); +create table user_role (user_id int8 not null, roles varchar(255)); +create table users (id int8 not null, account_non_expired boolean not null, account_non_locked boolean not null, credentials_non_expired boolean not null, email varchar(255) not null, enabled boolean not null, password_hash varchar(255) not null, profile_id int8, primary key (id)); +create table verification_token (id int8 not null, primary key (id)); +alter table if exists orders_tickets add constraint UK_lxwrvh4y2ons9ohgu50msfbly unique (tickets_id); +alter table if exists seat add constraint seatConstraint unique (seat_group, seat_number); +alter table if exists subscription add constraint UK_r9kv3a5fkv7vnvu8bbpulavmk unique (email); +alter table if exists team add constraint teamName unique (team_name); +alter table if exists users add constraint email unique (email); +alter table if exists authentication_token add constraint FKdbv62go71ree32qv0bm6gqam2 foreign key (id) references token; +alter table if exists consumption_map add constraint FKsrrxfhrofqjjcsb860h16dpop foreign key (ticket_id) references ticket; +alter table if exists consumption_map_consumptions_made add constraint FKag9n6oxcuocwnc1yc9tr1w3cw foreign key (consumptions_made_id) references consumption; +alter table if exists consumption_map_consumptions_made add constraint FKqrs02quftjk84a7uojo36wokd foreign key (consumption_map_id) references consumption_map; +alter table if exists orders add constraint FK32ql8ubntj5uh44ph9659tiih foreign key (user_id) references users; +alter table if exists orders_tickets add constraint FK4fqm8urjjqfiwct4oj14xkfrl foreign key (tickets_id) references ticket; +alter table if exists orders_tickets add constraint FKjoggp5iyq5fqbtxi5r1m2wlty foreign key (order_id) references orders; +alter table if exists password_reset_token add constraint FKri9g6njpisvtpqe430bynv4lq foreign key (id) references token; +alter table if exists rfidlink add constraint FK2f30uyki11lmtg56q0cbqw6pk foreign key (ticket_id) references ticket; +alter table if exists seat add constraint FK8ngrgsadp7q1lcakg3kkdmvqj foreign key (ticket_id) references ticket; +alter table if exists team add constraint FKb1pjk4pg0yi1qvw0i7pvfy3us foreign key (captain_id) references users; +alter table if exists team_members add constraint FK4rl09ugxbntgyfhogal3s67ji foreign key (members_id) references users; +alter table if exists team_members add constraint FKb3toat7ors5scfmd3n69dhmr1 foreign key (team_id) references team; +alter table if exists team_invite_token add constraint FKa5gxt5guatw99qkswjf6pkbl3 foreign key (team_id) references team; +alter table if exists team_invite_token add constraint FK3597euynm1cuvaltyyprwjm4e foreign key (id) references token; +alter table if exists ticket add constraint FKjgquudbb9q93fl5odb28lmscj foreign key (owner_id) references users; +alter table if exists ticket add constraint FKnk40xmmqnx78naomux703i9vs foreign key (type_id) references ticket_type; +alter table if exists ticket_enabled_options add constraint FKmyjy3uibhokscu0a12b0kciwr foreign key (enabled_options_id) references ticket_option; +alter table if exists ticket_enabled_options add constraint FKdi94eaxwrpnpightqkyg3okse foreign key (ticket_id) references ticket; +alter table if exists ticket_transfer_token add constraint FKf2oeyewgv1csjxaag5c0weoa1 foreign key (ticket_id) references ticket; +alter table if exists ticket_transfer_token add constraint FK6b9awma746y1u2kc25hifqs0s foreign key (id) references token; +alter table if exists ticket_type_possible_options add constraint FKc0rw0dtfj7duebxsni3l6u084 foreign key (possible_options_id) references ticket_option; +alter table if exists ticket_type_possible_options add constraint FKgihp1b7p36hygc2ar4ilodgef foreign key (ticket_type_id) references ticket_type; +alter table if exists token add constraint FKj8rfw4x0wjjyibfqq566j4qng foreign key (user_id) references users; +alter table if exists tournament add constraint FK3yc1a3c3e0cvydcrgl4ih0rne foreign key (sponsor_id) references sponsor; +alter table if exists tournament_prize add constraint FKex38yydummrcremcnmlff60su foreign key (tournament_id) references tournament; +alter table if exists user_role add constraint FKj345gk1bovqvfame88rcx7yyx foreign key (user_id) references users; +alter table if exists users add constraint FK5q3e9303ap1wvtia6sft7ht1s foreign key (profile_id) references profile; +alter table if exists verification_token add constraint FK92nvkrl137qsd36ryx66f1mfe foreign key (id) references token; \ No newline at end of file