| @ -0,0 +1,414 @@ | |||||
| -- Database: chessleague | |||||
| -- DROP DATABASE chessleague; | |||||
| -- CREATE DATABASE chessleague | |||||
| -- WITH | |||||
| -- OWNER = postgres | |||||
| -- ENCODING = 'UTF8' | |||||
| -- LC_COLLATE = 'German_Germany.1252' | |||||
| -- LC_CTYPE = 'German_Germany.1252' | |||||
| -- TABLESPACE = pg_default | |||||
| -- CONNECTION LIMIT = -1; | |||||
| DROP TABLE IF EXISTS "player" CASCADE; | |||||
| DROP TABLE IF EXISTS "player_info" CASCADE; | |||||
| DROP TABLE IF EXISTS "game" CASCADE; | |||||
| DROP TABLE IF EXISTS "game_info" CASCADE; | |||||
| DROP TABLE IF EXISTS "match" CASCADE; | |||||
| DROP TABLE IF EXISTS "matchday" CASCADE; | |||||
| DROP TABLE IF EXISTS "season" CASCADE; | |||||
| CREATE TABLE "player" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "name" varchar NOT NULL, | |||||
| "nickname" varchar NOT NULL, | |||||
| "info" int UNIQUE | |||||
| ); | |||||
| CREATE TABLE "player_info" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "url" varchar | |||||
| ); | |||||
| CREATE TABLE "game" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "match" int NOT NULL, | |||||
| "player1_is_white" boolean NOT NULL, | |||||
| "result" int NOT NULL, | |||||
| "info" int UNIQUE | |||||
| ); | |||||
| CREATE TABLE "game_info" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "format" int, | |||||
| "url" varchar | |||||
| ); | |||||
| CREATE TABLE "match" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "player1" int NOT NULL, | |||||
| "player2" int NOT NULL, | |||||
| "matchday" int NOT NULL | |||||
| ); | |||||
| CREATE TABLE "matchday" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "number" int NOT NULL, | |||||
| "season" int NOT NULL | |||||
| ); | |||||
| CREATE TABLE "season" ( | |||||
| "id" SERIAL PRIMARY KEY, | |||||
| "year_start" int NOT NULL, | |||||
| "year_end" int NOT NULL | |||||
| ); | |||||
| ALTER TABLE "player" ADD FOREIGN KEY ("info") REFERENCES "player_info" ("id"); | |||||
| ALTER TABLE "game" ADD FOREIGN KEY ("match") REFERENCES "match" ("id"); | |||||
| ALTER TABLE "game" ADD FOREIGN KEY ("info") REFERENCES "game_info" ("id"); | |||||
| ALTER TABLE "match" ADD FOREIGN KEY ("player1") REFERENCES "player" ("id"); | |||||
| ALTER TABLE "match" ADD FOREIGN KEY ("player2") REFERENCES "player" ("id"); | |||||
| ALTER TABLE "match" ADD FOREIGN KEY ("matchday") REFERENCES "matchday" ("id"); | |||||
| ALTER TABLE "matchday" ADD FOREIGN KEY ("season") REFERENCES "season" ("id"); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/aprilem262'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Sophia', 'aprilem262', (SELECT id from player_info WHERE url='https://www.chess.com/member/aprilem262') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/friedox'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Friedi', 'friedox', (SELECT id from player_info WHERE url='https://www.chess.com/member/friedox') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/internity'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Albert', 'internity', (SELECT id from player_info WHERE url='https://www.chess.com/member/internity') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/kevske'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Kevin', 'kevske', (SELECT id from player_info WHERE url='https://www.chess.com/member/kevske') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/kochi291'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Marcel', 'Kochi291', (SELECT id from player_info WHERE url='https://www.chess.com/member/kochi291') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/ladyanne26'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Anne', 'LadyAnne26', (SELECT id from player_info WHERE url='https://www.chess.com/member/ladyanne26') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/lakes0'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Florian', 'Lakes0', (SELECT id from player_info WHERE url='https://www.chess.com/member/lakes0') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/maddingladi'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Maddin', 'maddingladi', (SELECT id from player_info WHERE url='https://www.chess.com/member/maddingladi') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/magnus_brother'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Tariq', 'Magnus_brother', (SELECT id from player_info WHERE url='https://www.chess.com/member/magnus_brother') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/mama-lolo'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Malte', 'Mama-Lolo', (SELECT id from player_info WHERE url='https://www.chess.com/member/mama-lolo') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/marcriedlsperger'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Marc', 'marcriedlsperger', (SELECT id from player_info WHERE url='https://www.chess.com/member/marcriedlsperger') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/mistmade03'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Florian', 'Mistmade03', (SELECT id from player_info WHERE url='https://www.chess.com/member/mistmade03') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/moryzzle'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Moritz', 'Moryzzle', (SELECT id from player_info WHERE url='https://www.chess.com/member/moryzzle') ); | |||||
| INSERT INTO "player_info" (url) VALUES ('https://www.chess.com/member/pandroit'); | |||||
| INSERT INTO "player" (name, nickname, info) VALUES ('Peter', 'pandroit', (SELECT id from player_info WHERE url='https://www.chess.com/member/pandroit') ); | |||||
| INSERT INTO "season" (year_start, year_end) VALUES (2020, 2020); | |||||
| INSERT INTO "matchday" (number, season) VALUES (1, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 1, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 8, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 4, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 3, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 6, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 9, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 7, 1); | |||||
| INSERT INTO "matchday" (number, season) VALUES (2, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 11, 2); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 12, 2); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 8, 2); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 4, 2); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 3, 2); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 6, 2); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 9, 2); | |||||
| INSERT INTO "matchday" (number, season) VALUES (3, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 1, 3); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 11, 3); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 12, 3); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 8, 3); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 4, 3); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 3, 3); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 6, 3); | |||||
| INSERT INTO "matchday" (number, season) VALUES (4, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 5, 4); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 10, 4); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 11, 4); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 12, 4); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 8, 4); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 4, 4); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 3, 4); | |||||
| INSERT INTO "matchday" (number, season) VALUES (5, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 1, 5); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 5, 5); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 10, 5); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 11, 5); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 12, 5); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 8, 5); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 4, 5); | |||||
| INSERT INTO "matchday" (number, season) VALUES (6, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 2, 6); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 13, 6); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 5, 6); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 10, 6); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 11, 6); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 12, 6); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 8, 6); | |||||
| INSERT INTO "matchday" (number, season) VALUES (7, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 1, 7); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 2, 7); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 13, 7); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 5, 7); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 10, 7); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 11, 7); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 12, 7); | |||||
| INSERT INTO "matchday" (number, season) VALUES (8, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 7, 8); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 14, 8); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 2, 8); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 13, 8); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 5, 8); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 10, 8); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 11, 8); | |||||
| INSERT INTO "matchday" (number, season) VALUES (9, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 1, 9); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 7, 9); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 14, 9); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 2, 9); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 13, 9); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 5, 9); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 10, 9); | |||||
| INSERT INTO "matchday" (number, season) VALUES (10, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 6, 10); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 9, 10); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 7, 10); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 14, 10); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 2, 10); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 13, 10); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 5, 10); | |||||
| INSERT INTO "matchday" (number, season) VALUES (11, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 1, 11); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 6, 11); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 9, 11); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 7, 11); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 14, 11); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 2, 11); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 13, 11); | |||||
| INSERT INTO "matchday" (number, season) VALUES (12, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 4, 12); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 3, 12); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 6, 12); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 9, 12); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 7, 12); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 14, 12); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 2, 12); | |||||
| INSERT INTO "matchday" (number, season) VALUES (13, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 1, 13); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 4, 13); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 3, 13); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 6, 13); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 9, 13); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 7, 13); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 14, 13); | |||||
| INSERT INTO "matchday" (number, season) VALUES (14, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 12, 14); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 11, 14); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 10, 14); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 5, 14); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 13, 14); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 2, 14); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 14, 14); | |||||
| INSERT INTO "matchday" (number, season) VALUES (15, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 1, 15); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 10, 15); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 5, 15); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 13, 15); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 2, 15); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 14, 15); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 7, 15); | |||||
| INSERT INTO "matchday" (number, season) VALUES (16, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 10, 16); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 5, 16); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 13, 16); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 2, 16); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 14, 16); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 7, 16); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 9, 16); | |||||
| INSERT INTO "matchday" (number, season) VALUES (17, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 1, 17); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 13, 17); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 2, 17); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 14, 17); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 7, 17); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 9, 17); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 6, 17); | |||||
| INSERT INTO "matchday" (number, season) VALUES (18, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 13, 18); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 2, 18); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 14, 18); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 7, 18); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 9, 18); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 6, 18); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 3, 18); | |||||
| INSERT INTO "matchday" (number, season) VALUES (19, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 1, 19); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 14, 19); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 7, 19); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 9, 19); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 6, 19); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 3, 19); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 8, 4, 19); | |||||
| INSERT INTO "matchday" (number, season) VALUES (20, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 14, 20); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 7, 20); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 9, 20); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 6, 20); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 3, 20); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 4, 20); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (12, 8, 20); | |||||
| INSERT INTO "matchday" (number, season) VALUES (21, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 1, 21); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 9, 21); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 6, 21); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 3, 21); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 4, 21); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 8, 21); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (11, 12, 21); | |||||
| INSERT INTO "matchday" (number, season) VALUES (22, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 9, 22); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 6, 22); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 3, 22); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 4, 22); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 8, 22); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 12, 22); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (10, 11, 22); | |||||
| INSERT INTO "matchday" (number, season) VALUES (23, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 1, 23); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 3, 23); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 4, 23); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 8, 23); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 12, 23); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 11, 23); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 5, 10, 23); | |||||
| INSERT INTO "matchday" (number, season) VALUES (24, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 3, 24); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 4, 24); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 8, 24); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 12, 24); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 11, 24); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 10, 24); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (13, 5, 24); | |||||
| INSERT INTO "matchday" (number, season) VALUES (25, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 1, 25); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 8, 25); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 12, 25); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 11, 25); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 10, 25); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 5, 25); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 2, 13, 25); | |||||
| INSERT INTO "matchday" (number, season) VALUES (26, 1); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 1, 8, 26); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 4, 12, 26); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 3, 11, 26); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 6, 10, 26); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 9, 5, 26); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES ( 7, 13, 26); | |||||
| INSERT INTO "match" ("player1", "player2", "matchday") VALUES (14, 2, 26); | |||||
| INSERT INTO "game_info" (format, url) VALUES (10, 'https://www.chess.com/live/game/8722014513'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=2 AND player2=9 AND matchday=1), TRUE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8722014513')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (10, 'https://www.chess.com/live/game/8723231941'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=2 AND player2=9 AND matchday=1), FALSE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8723231941')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (5, 'https://www.chess.com/live/game/8724907847'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=2 AND player2=9 AND matchday=1), TRUE, -1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8724907847')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (5, 'https://www.chess.com/live/game/8725036665'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=2 AND player2=9 AND matchday=1), FALSE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8725036665')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (3, 'https://www.chess.com/live/game/8725614379'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=2 AND player2=9 AND matchday=1), TRUE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8725614379')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (3, 'https://www.chess.com/live/game/8726184583'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=2 AND player2=9 AND matchday=1), FALSE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8726184583')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (10, 'https://www.chess.com/live/game/8616485043'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=14 AND player2=7 AND matchday=1), TRUE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8616485043')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (10, 'https://www.chess.com/live/game/8618149677'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=14 AND player2=7 AND matchday=1), FALSE, -1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8618149677')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (5, 'https://www.chess.com/live/game/8702757001'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=14 AND player2=7 AND matchday=1), FALSE, -1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8702757001')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (5, 'https://www.chess.com/live/game/8705204521'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=14 AND player2=7 AND matchday=1), TRUE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8705204521')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (3, 'https://www.chess.com/live/game/8705796221'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=14 AND player2=7 AND matchday=1), FALSE, -1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8705796221')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (3, 'https://www.chess.com/live/game/8706438057'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=14 AND player2=7 AND matchday=1), TRUE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8706438057')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (10, 'https://www.chess.com/live/game/8617630129'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=10 AND player2=4 AND matchday=1), TRUE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8617630129')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (10, 'https://www.chess.com/live/game/8618225533'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=10 AND player2=4 AND matchday=1), FALSE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8618225533')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (5, 'https://www.chess.com/live/game/8619306585'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=10 AND player2=4 AND matchday=1), TRUE, -1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8619306585')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (5, 'https://www.chess.com/live/game/8619471075'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=10 AND player2=4 AND matchday=1), FALSE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8619471075')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (3, 'https://www.chess.com/live/game/8620078695'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=10 AND player2=4 AND matchday=1), TRUE, -1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8620078695')); | |||||
| INSERT INTO "game_info" (format, url) VALUES (3, 'https://www.chess.com/live/game/8620568591'); | |||||
| INSERT INTO "game" (match, player1_is_white, result, info) VALUES ((SELECT id from match WHERE player1=10 AND player2=4 AND matchday=1), FALSE, 1, (SELECT id from game_info WHERE url='https://www.chess.com/live/game/8620568591')); | |||||
| @ -0,0 +1,40 @@ | |||||
| .about-view { | |||||
| display: block; | |||||
| } | |||||
| .column_header { | |||||
| font-weight: bold; | |||||
| font-size: large; | |||||
| } | |||||
| .big_header { | |||||
| font-weight: bolder; | |||||
| font-size: x-large; | |||||
| } | |||||
| .matchday_grid { | |||||
| --_lumo-grid-border-width: 0; | |||||
| } | |||||
| /*.inner_matchday_layout {*/ | |||||
| /* background-color: white;*/ | |||||
| /*}*/ | |||||
| /*.inner_matchday_layout > th {*/ | |||||
| /* background-color: white;*/ | |||||
| /*}*/ | |||||
| /*:host {*/ | |||||
| /* background-color: white;*/ | |||||
| /*}*/ | |||||
| /*[part~="cell"].matchday_grid {*/ | |||||
| /* background-color: white;*/ | |||||
| /*}*/ | |||||
| /*.matchday_grid .v-grid-cell {*/ | |||||
| /*}*/ | |||||
| /*.matchday_grid .v-grid-tablewrapper{*/ | |||||
| /* border: none;*/ | |||||
| /*}*/ | |||||
| @ -0,0 +1,64 @@ | |||||
| package com.example.application.data.bean; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.Match; | |||||
| import com.example.application.data.entity.Matchday; | |||||
| import com.example.application.data.entity.Player; | |||||
| import java.util.Collection; | |||||
| public class MatchForMatchdayView { | |||||
| private Match match; | |||||
| private Player player1; | |||||
| private Player player2; | |||||
| private Integer score1; | |||||
| private Integer score2; | |||||
| public MatchForMatchdayView(Match match, Player player1, Player player2, Integer score1, Integer score2) { | |||||
| this.match = match; | |||||
| this.player1 = player1; | |||||
| this.player2 = player2; | |||||
| this.score1 = score1; | |||||
| this.score2 = score2; | |||||
| } | |||||
| public Match getMatch() { | |||||
| return match; | |||||
| } | |||||
| public void setMatch(Match match) { | |||||
| this.match = match; | |||||
| } | |||||
| public Player getPlayer1() { | |||||
| return player1; | |||||
| } | |||||
| public void setPlayer1(Player player1) { | |||||
| this.player1 = player1; | |||||
| } | |||||
| public Player getPlayer2() { | |||||
| return player2; | |||||
| } | |||||
| public void setPlayer2(Player player2) { | |||||
| this.player2 = player2; | |||||
| } | |||||
| public Integer getScore1() { | |||||
| return score1; | |||||
| } | |||||
| public void setScore1(Integer score1) { | |||||
| this.score1 = score1; | |||||
| } | |||||
| public Integer getScore2() { | |||||
| return score2; | |||||
| } | |||||
| public void setScore2(Integer score2) { | |||||
| this.score2 = score2; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,77 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "game", schema = "public", catalog = "chessleague") | |||||
| public class Game { | |||||
| private Integer id; | |||||
| private Boolean player1IsWhite; | |||||
| private Integer result; | |||||
| private Match match; | |||||
| private GameInfo gameInfo; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "player1_is_white", nullable = false) | |||||
| public Boolean getPlayer1IsWhite() { | |||||
| return player1IsWhite; | |||||
| } | |||||
| public void setPlayer1IsWhite(Boolean player1IsWhite) { | |||||
| this.player1IsWhite = player1IsWhite; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "result", nullable = false) | |||||
| public Integer getResult() { | |||||
| return result; | |||||
| } | |||||
| public void setResult(Integer result) { | |||||
| this.result = result; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| Game that = (Game) o; | |||||
| return Objects.equals(id, that.id) && Objects.equals(player1IsWhite, that.player1IsWhite) && Objects.equals(result, that.result); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id, player1IsWhite, result); | |||||
| } | |||||
| @ManyToOne(cascade=CascadeType.ALL) | |||||
| @JoinColumn(name = "match", referencedColumnName = "id", nullable = false) | |||||
| public Match getMatch() { | |||||
| return match; | |||||
| } | |||||
| public void setMatch(Match match) { | |||||
| this.match = match; | |||||
| } | |||||
| @OneToOne | |||||
| @JoinColumn(name = "info", referencedColumnName = "id") | |||||
| public GameInfo getGameInfo() { | |||||
| return gameInfo; | |||||
| } | |||||
| public void setGameInfo(GameInfo gameInfo) { | |||||
| this.gameInfo = gameInfo; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,66 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "game_info", schema = "public", catalog = "chessleague") | |||||
| public class GameInfo { | |||||
| private Integer id; | |||||
| private String url; | |||||
| private Game game; | |||||
| private Integer format; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "url", length = -1) | |||||
| public String getUrl() { | |||||
| return url; | |||||
| } | |||||
| public void setUrl(String url) { | |||||
| this.url = url; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "format", nullable = false) | |||||
| public Integer getFormat() { | |||||
| return format; | |||||
| } | |||||
| public void setFormat(Integer format) { | |||||
| this.format = format; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| GameInfo that = (GameInfo) o; | |||||
| return Objects.equals(id, that.id) && Objects.equals(url, that.url) && Objects.equals(format, that.format); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id, url, format); | |||||
| } | |||||
| @OneToOne(mappedBy = "gameInfo") | |||||
| public Game getGame() { | |||||
| return game; | |||||
| } | |||||
| public void setGame(Game game) { | |||||
| this.game = game; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,78 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Collection; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "match", schema = "public", catalog = "chessleague") | |||||
| public class Match { | |||||
| private Integer id; | |||||
| private Collection<Game> games; | |||||
| private Player player1; | |||||
| private Player player2; | |||||
| private Matchday matchday; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| Match that = (Match) o; | |||||
| return Objects.equals(id, that.id); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id); | |||||
| } | |||||
| @OneToMany(mappedBy = "match", fetch = FetchType.EAGER) | |||||
| public Collection<Game> getGames() { | |||||
| return games; | |||||
| } | |||||
| public void setGames(Collection<Game> games) { | |||||
| this.games = games; | |||||
| } | |||||
| @ManyToOne(cascade=CascadeType.ALL) | |||||
| @JoinColumn(name = "player1", referencedColumnName = "id", nullable = false) | |||||
| public Player getPlayer1() { | |||||
| return player1; | |||||
| } | |||||
| public void setPlayer1(Player player1) { | |||||
| this.player1 = player1; | |||||
| } | |||||
| @ManyToOne(cascade=CascadeType.ALL) | |||||
| @JoinColumn(name = "player2", referencedColumnName = "id", nullable = false) | |||||
| public Player getPlayer2() { | |||||
| return player2; | |||||
| } | |||||
| public void setPlayer2(Player player2) { | |||||
| this.player2 = player2; | |||||
| } | |||||
| @ManyToOne(cascade=CascadeType.ALL) | |||||
| @JoinColumn(name = "matchday", referencedColumnName = "id", nullable = false) | |||||
| public Matchday getMatchday() { | |||||
| return matchday; | |||||
| } | |||||
| public void setMatchday(Matchday matchday) { | |||||
| this.matchday = matchday; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,72 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Collection; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "matchday", schema = "public", catalog = "chessleague") | |||||
| public class Matchday { | |||||
| private Integer id; | |||||
| private Integer number; | |||||
| private Collection<Match> matches; | |||||
| private Season season; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "number", nullable = false) | |||||
| public Integer getNumber() { | |||||
| return number; | |||||
| } | |||||
| public void setNumber(Integer number) { | |||||
| this.number = number; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| Matchday that = (Matchday) o; | |||||
| return Objects.equals(id, that.id) && Objects.equals(number, that.number); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id, number); | |||||
| } | |||||
| @OneToMany(mappedBy = "matchday") | |||||
| public Collection<Match> getMatches() { | |||||
| return matches; | |||||
| } | |||||
| public void setMatches(Collection<Match> matches) { | |||||
| this.matches = matches; | |||||
| } | |||||
| @ManyToOne(cascade=CascadeType.ALL) | |||||
| @JoinColumn(name = "season", referencedColumnName = "id", nullable = false) | |||||
| public Season getSeason() { | |||||
| return season; | |||||
| } | |||||
| public void setSeason(Season season) { | |||||
| this.season = season; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return number.toString(); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,93 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Collection; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "player", schema = "public", catalog = "chessleague") | |||||
| public class Player { | |||||
| private Integer id; | |||||
| private String name; | |||||
| private String nickname; | |||||
| private Collection<Match> matchesAsPlayer1; | |||||
| private Collection<Match> matchesAsPlayer2; | |||||
| private PlayerInfo playerInfo; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "name", nullable = false, length = -1) | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "nickname", nullable = false, length = -1) | |||||
| public String getNickname() { | |||||
| return nickname; | |||||
| } | |||||
| public void setNickname(String nickname) { | |||||
| this.nickname = nickname; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| Player that = (Player) o; | |||||
| return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(nickname, that.nickname); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id, name, nickname); | |||||
| } | |||||
| @OneToMany(mappedBy = "player1") | |||||
| public Collection<Match> getMatchesAsPlayer1() { | |||||
| return matchesAsPlayer1; | |||||
| } | |||||
| public void setMatchesAsPlayer1(Collection<Match> matchesAsPlayer1) { | |||||
| this.matchesAsPlayer1 = matchesAsPlayer1; | |||||
| } | |||||
| @OneToMany(mappedBy = "player2") | |||||
| public Collection<Match> getMatchesAsPlayer2() { | |||||
| return matchesAsPlayer2; | |||||
| } | |||||
| public void setMatchesAsPlayer2(Collection<Match> matchesAsPlayer2) { | |||||
| this.matchesAsPlayer2 = matchesAsPlayer2; | |||||
| } | |||||
| @OneToOne | |||||
| @JoinColumn(name = "info", referencedColumnName = "id") | |||||
| public PlayerInfo getPlayerInfo() { | |||||
| return playerInfo; | |||||
| } | |||||
| public void setPlayerInfo(PlayerInfo playerInfo) { | |||||
| this.playerInfo = playerInfo; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return name + " (" + nickname + ")"; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,55 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "player_info", schema = "public", catalog = "chessleague") | |||||
| public class PlayerInfo { | |||||
| private Integer id; | |||||
| private String url; | |||||
| private Player player; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "url", length = -1) | |||||
| public String getUrl() { | |||||
| return url; | |||||
| } | |||||
| public void setUrl(String url) { | |||||
| this.url = url; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| PlayerInfo that = (PlayerInfo) o; | |||||
| return Objects.equals(id, that.id) && Objects.equals(url, that.url); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id, url); | |||||
| } | |||||
| @OneToOne(mappedBy = "playerInfo") | |||||
| public Player getPlayer() { | |||||
| return player; | |||||
| } | |||||
| public void setPlayer(Player player) { | |||||
| this.player = player; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,76 @@ | |||||
| package com.example.application.data.entity; | |||||
| import javax.persistence.*; | |||||
| import java.util.Collection; | |||||
| import java.util.Objects; | |||||
| @Entity | |||||
| @Table(name = "season", schema = "public", catalog = "chessleague") | |||||
| public class Season { | |||||
| private Integer id; | |||||
| private Integer yearStart; | |||||
| private Integer yearEnd; | |||||
| private Collection<Matchday> matchdays; | |||||
| @Id | |||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||||
| @Column(name = "id", nullable = false) | |||||
| public Integer getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Integer id) { | |||||
| this.id = id; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "year_start", nullable = false) | |||||
| public Integer getYearStart() { | |||||
| return yearStart; | |||||
| } | |||||
| public void setYearStart(Integer yearStart) { | |||||
| this.yearStart = yearStart; | |||||
| } | |||||
| @Basic | |||||
| @Column(name = "year_end", nullable = false) | |||||
| public Integer getYearEnd() { | |||||
| return yearEnd; | |||||
| } | |||||
| public void setYearEnd(Integer yearEnd) { | |||||
| this.yearEnd = yearEnd; | |||||
| } | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| Season that = (Season) o; | |||||
| return Objects.equals(id, that.id) && Objects.equals(yearStart, that.yearStart) && Objects.equals(yearEnd, that.yearEnd); | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| return Objects.hash(id, yearStart, yearEnd); | |||||
| } | |||||
| @OneToMany(mappedBy = "season") | |||||
| public Collection<Matchday> getMatchdays() { | |||||
| return matchdays; | |||||
| } | |||||
| public void setMatchdays(Collection<Matchday> matchdays) { | |||||
| this.matchdays = matchdays; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| String s = yearStart.toString(); | |||||
| if (!yearEnd.equals(yearStart)) { | |||||
| s += "/" + yearEnd.toString(); | |||||
| } | |||||
| return s; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,8 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.GameInfo; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface GameInfoRepository extends JpaRepository<GameInfo, Integer> { | |||||
| } | |||||
| @ -0,0 +1,22 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.GameInfo; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| @Service | |||||
| public class GameInfoService extends CrudService<GameInfo, Integer> { | |||||
| private final GameInfoRepository repository; | |||||
| public GameInfoService(@Autowired GameInfoRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected GameInfoRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,7 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface GameRepository extends JpaRepository<Game, Integer> { | |||||
| } | |||||
| @ -0,0 +1,22 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| @Service | |||||
| public class GameService extends CrudService<Game, Integer> { | |||||
| private final GameRepository repository; | |||||
| public GameService(@Autowired GameRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected GameRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,8 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.Match; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface MatchRepository extends JpaRepository<Match, Integer> { | |||||
| } | |||||
| @ -0,0 +1,50 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.bean.MatchForMatchdayView; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.Match; | |||||
| import com.example.application.data.entity.Matchday; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @Service | |||||
| public class MatchService extends CrudService<Match, Integer> { | |||||
| private final MatchRepository repository; | |||||
| public MatchService(@Autowired MatchRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected MatchRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| public List<MatchForMatchdayView> getMatchesForMatchdayView(Matchday matchday) { | |||||
| return repository.findAll().stream() | |||||
| .filter(match -> match.getMatchday().equals(matchday)) | |||||
| .map(match -> new MatchForMatchdayView(match, match.getPlayer1(), match.getPlayer2(), getScore1(match), getScore2(match))) | |||||
| .collect(Collectors.toList()); | |||||
| } | |||||
| private static Integer getScore1(Match match) { | |||||
| int score = 0; | |||||
| for (Game game : match.getGames()) { | |||||
| score += ((game.getPlayer1IsWhite() ? game.getResult() : -game.getResult()) + 1) / 2; | |||||
| } | |||||
| return score; | |||||
| } | |||||
| private static Integer getScore2(Match match) { | |||||
| int score = 0; | |||||
| for (Game game : match.getGames()) { | |||||
| score += ((game.getPlayer1IsWhite() ? -game.getResult() : game.getResult()) + 1) / 2; | |||||
| } | |||||
| return score; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,8 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.Matchday; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface MatchdayRepository extends JpaRepository<Matchday, Integer> { | |||||
| } | |||||
| @ -0,0 +1,31 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Matchday; | |||||
| import com.example.application.data.entity.Season; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @Service | |||||
| public class MatchdayService extends CrudService<Matchday, Integer> { | |||||
| private final MatchdayRepository repository; | |||||
| public MatchdayService(@Autowired MatchdayRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected MatchdayRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| public List<Matchday> getMatchdaysForSeason(Season season) { | |||||
| return repository.findAll().stream() | |||||
| .filter(matchday -> matchday.getSeason().equals(season)) | |||||
| .collect(Collectors.toList()); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,8 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.PlayerInfo; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface PlayerInfoRepository extends JpaRepository<PlayerInfo, Integer> { | |||||
| } | |||||
| @ -0,0 +1,22 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.PlayerInfo; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| @Service | |||||
| public class PlayerInfoService extends CrudService<PlayerInfo, Integer> { | |||||
| private final PlayerInfoRepository repository; | |||||
| public PlayerInfoService(@Autowired PlayerInfoRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected PlayerInfoRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,8 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.Player; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface PlayerRepository extends JpaRepository<Player, Integer> { | |||||
| } | |||||
| @ -0,0 +1,22 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Player; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| @Service | |||||
| public class PlayerService extends CrudService<Player, Integer> { | |||||
| private final PlayerRepository repository; | |||||
| public PlayerService(@Autowired PlayerRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected PlayerRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,8 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Game; | |||||
| import com.example.application.data.entity.Season; | |||||
| import org.springframework.data.jpa.repository.JpaRepository; | |||||
| public interface SeasonRepository extends JpaRepository<Season, Integer> { | |||||
| } | |||||
| @ -0,0 +1,34 @@ | |||||
| package com.example.application.data.service; | |||||
| import com.example.application.data.entity.Season; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import org.vaadin.artur.helpers.CrudService; | |||||
| import java.util.Collection; | |||||
| import java.util.Comparator; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @Service | |||||
| public class SeasonService extends CrudService<Season, Integer> { | |||||
| private final SeasonRepository repository; | |||||
| public SeasonService(@Autowired SeasonRepository repository) { | |||||
| this.repository = repository; | |||||
| } | |||||
| @Override | |||||
| protected SeasonRepository getRepository() { | |||||
| return repository; | |||||
| } | |||||
| public List<Season> getAllSeasonsSorted() { | |||||
| return repository.findAll().stream() | |||||
| .sorted(Comparator.comparingInt(Season::getYearEnd)) | |||||
| .sorted(Comparator.comparingInt(Season::getYearStart)) | |||||
| .collect(Collectors.toList()); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,282 @@ | |||||
| package com.example.application.views.results; | |||||
| import com.example.application.data.bean.MatchForMatchdayView; | |||||
| import com.example.application.data.entity.Matchday; | |||||
| import com.example.application.data.entity.Player; | |||||
| import com.example.application.data.entity.Season; | |||||
| import com.example.application.data.service.MatchService; | |||||
| import com.example.application.data.service.MatchdayService; | |||||
| import com.example.application.data.service.SeasonService; | |||||
| import com.example.application.views.main.MainView; | |||||
| import com.vaadin.flow.component.*; | |||||
| import com.vaadin.flow.component.button.Button; | |||||
| import com.vaadin.flow.component.dependency.CssImport; | |||||
| import com.vaadin.flow.component.grid.ColumnTextAlign; | |||||
| import com.vaadin.flow.component.grid.Grid; | |||||
| import com.vaadin.flow.component.html.Div; | |||||
| import com.vaadin.flow.component.html.Label; | |||||
| import com.vaadin.flow.component.icon.Icon; | |||||
| import com.vaadin.flow.component.icon.VaadinIcon; | |||||
| import com.vaadin.flow.component.orderedlayout.FlexComponent; | |||||
| import com.vaadin.flow.component.orderedlayout.HorizontalLayout; | |||||
| import com.vaadin.flow.component.orderedlayout.VerticalLayout; | |||||
| import com.vaadin.flow.component.select.Select; | |||||
| import com.vaadin.flow.function.ValueProvider; | |||||
| import com.vaadin.flow.router.*; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.lang.NonNull; | |||||
| import org.springframework.lang.Nullable; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| @CssImport("./views/results/results-view.css") | |||||
| @Route(value = "results", layout = MainView.class) | |||||
| @RouteAlias(value = "", layout = MainView.class) | |||||
| @PageTitle("Results") | |||||
| public class ResultsView extends Div implements HasUrlParameter<String> { | |||||
| private final SeasonService seasonService; | |||||
| private final MatchdayService matchdayService; | |||||
| private final MatchService matchService; | |||||
| private String seasonParam; | |||||
| private String matchdayParam; | |||||
| private final Label invalidUrlLabel = new Label(); | |||||
| private final Label matchdayViewHeader = new Label(); | |||||
| private final VerticalLayout outer = new VerticalLayout(); | |||||
| private final HorizontalLayout selectionLayout = new HorizontalLayout(); | |||||
| private final HorizontalLayout outerMatchdaylayout = new HorizontalLayout(); | |||||
| private final VerticalLayout innerMatchdayLayout = new VerticalLayout(); | |||||
| private final List<Season> seasonList = new ArrayList<>(); | |||||
| private final Select<Season> seasonSelect = new Select<>(); | |||||
| private final List<Matchday> matchdayList = new ArrayList<>(); | |||||
| private final Select<Matchday> matchdaySelect = new Select<>(); | |||||
| private final Button prevButton = new Button(new Icon(VaadinIcon.ARROW_LEFT)); | |||||
| private final Button nextButton = new Button(new Icon(VaadinIcon.ARROW_RIGHT)); | |||||
| private final Grid<MatchForMatchdayView> grid = new Grid<>(); | |||||
| public ResultsView(@Autowired SeasonService seasonService, @Autowired MatchdayService matchdayService, @Autowired MatchService matchService) { | |||||
| this.seasonService = seasonService; | |||||
| this.matchdayService = matchdayService; | |||||
| this.matchService = matchService; | |||||
| addClassName("results-view"); | |||||
| configureOuterLayout(); | |||||
| configureSelectionLayout(); | |||||
| configureMatchdayViewLayout(); | |||||
| } | |||||
| private void configureOuterLayout() { | |||||
| add(outer); | |||||
| outer.setAlignItems(FlexComponent.Alignment.CENTER); | |||||
| } | |||||
| private void configureSelectionLayout() { | |||||
| // pretty looks | |||||
| selectionLayout.setWidthFull(); | |||||
| selectionLayout.setAlignItems(FlexComponent.Alignment.CENTER); | |||||
| selectionLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END); | |||||
| selectionLayout.add(new Label("Season:"), seasonSelect, new Label("Matchday:"), matchdaySelect); | |||||
| seasonSelect.addValueChangeListener(seasonSelectValueChangeListener()); | |||||
| matchdaySelect.addValueChangeListener(matchdaySelectValueChangeListener()); | |||||
| // provide data | |||||
| fillSeasonSelectWithData(); | |||||
| } | |||||
| private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Matchday>, Matchday>> matchdaySelectValueChangeListener() { | |||||
| return matchdayChangeEvent -> getUI().ifPresent(ui -> { | |||||
| Season season = seasonSelect.getValue(); | |||||
| Matchday matchday = matchdayChangeEvent.getValue(); | |||||
| if (season != null && matchday != null) { | |||||
| String seasonParam = season.toString(); | |||||
| String matchdayParam = matchday.toString(); | |||||
| navigate(ui, seasonParam, matchdayParam); | |||||
| } | |||||
| }); | |||||
| } | |||||
| private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Season>, Season>> seasonSelectValueChangeListener() { | |||||
| return seasonChangeEvent -> getUI().ifPresent(ui -> { | |||||
| Season newSeason = seasonChangeEvent.getValue(); | |||||
| if (newSeason != null) { | |||||
| String seasonParam = newSeason.toString(); | |||||
| String matchdayParam = null; | |||||
| Matchday matchdayInNewSeason = null; | |||||
| Matchday matchdayInOldSeason = matchdaySelect.getValue(); | |||||
| if (matchdayInOldSeason != null) { | |||||
| matchdayParam = matchdayInOldSeason.toString(); | |||||
| matchdayInNewSeason = getMatchdayFromParam(matchdayParam, newSeason); | |||||
| } | |||||
| matchdayParam = matchdayInNewSeason == null ? "1" : matchdayParam; | |||||
| navigate(ui, seasonParam, matchdayParam); | |||||
| } | |||||
| }); | |||||
| } | |||||
| private void fillSeasonSelectWithData() { | |||||
| seasonList.clear(); | |||||
| seasonList.addAll(seasonService.getAllSeasonsSorted()); | |||||
| seasonSelect.setItems(seasonList); | |||||
| } | |||||
| private void fillMatchdaySelectWithData() { | |||||
| matchdayList.clear(); | |||||
| matchdayList.addAll(matchdayService.getMatchdaysForSeason(seasonSelect.getValue())); | |||||
| matchdaySelect.setItems(matchdayList); | |||||
| } | |||||
| private void configureMatchdayViewLayout() { | |||||
| outerMatchdaylayout.add(prevButton, innerMatchdayLayout, nextButton); | |||||
| matchdayViewHeader.addClassName("big_header"); | |||||
| innerMatchdayLayout.setPadding(false); | |||||
| innerMatchdayLayout.add(matchdayViewHeader, grid); | |||||
| innerMatchdayLayout.setAlignItems(FlexComponent.Alignment.CENTER); | |||||
| innerMatchdayLayout.addClassName("inner_matchday_layout"); | |||||
| Label headerPlayer1 = new Label("Player 1"); | |||||
| headerPlayer1.addClassName("column_header"); | |||||
| Label headerPlayer2 = new Label("Player 2"); | |||||
| headerPlayer2.addClassName("column_header"); | |||||
| Label headerResult = new Label("Result"); | |||||
| headerResult.addClassName("column_header"); | |||||
| grid.addColumn((ValueProvider<MatchForMatchdayView, Player>) MatchForMatchdayView::getPlayer1) | |||||
| .setHeader(headerPlayer1) | |||||
| .setTextAlign(ColumnTextAlign.CENTER) | |||||
| .setWidth("13em"); | |||||
| grid.addColumn((ValueProvider<MatchForMatchdayView, String>) match -> "vs.") | |||||
| .setHeader("vs.") | |||||
| .setTextAlign(ColumnTextAlign.CENTER) | |||||
| .setWidth("3em"); | |||||
| grid.addColumn((ValueProvider<MatchForMatchdayView, Player>) MatchForMatchdayView::getPlayer2) | |||||
| .setHeader(headerPlayer2) | |||||
| .setTextAlign(ColumnTextAlign.CENTER) | |||||
| .setWidth("13em"); | |||||
| grid.addColumn((ValueProvider<MatchForMatchdayView, String>) match -> { | |||||
| String result = match.getScore1().toString() + " : " + match.getScore2().toString(); | |||||
| return result.equals("0 : 0") ? "" : result; | |||||
| }) | |||||
| .setHeader(headerResult) | |||||
| .setTextAlign(ColumnTextAlign.CENTER) | |||||
| .setWidth("6em"); | |||||
| grid.setWidth("36em"); | |||||
| grid.setHeightByRows(true); | |||||
| grid.addClassName("matchday_grid"); | |||||
| } | |||||
| private String getPrevMatchdayParam() { | |||||
| return String.valueOf(Integer.parseInt(matchdayParam) - 1); | |||||
| } | |||||
| private String getNextMatchdayParam() { | |||||
| return String.valueOf(Integer.parseInt(matchdayParam) + 1); | |||||
| } | |||||
| private boolean isMatchDayParamValid(@NonNull String matchdayParam) { | |||||
| return matchdayList.stream().anyMatch(matchday -> matchdayParam.equals(matchday.toString())); | |||||
| } | |||||
| private ComponentEventListener<ClickEvent<Button>> getButtonClickListener(Button button, String matchdayParam) { | |||||
| return buttonClickEvent -> getUI().ifPresent(ui -> navigate(ui, seasonParam, matchdayParam)); | |||||
| } | |||||
| private void navigate(UI ui, String seasonParam, String matchdayParam) { | |||||
| ui.navigate(String.format("results/%s/%s/", seasonParam, matchdayParam)); | |||||
| } | |||||
| private void configureMatchdayView() { | |||||
| matchdayViewHeader.setText(String.format("Matchday %s", matchdaySelect.getValue().toString())); | |||||
| grid.setItems(matchService.getMatchesForMatchdayView(matchdaySelect.getValue())); | |||||
| } | |||||
| @Override | |||||
| public void setParameter(BeforeEvent beforeEvent, @WildcardParameter String param) { | |||||
| outer.removeAll(); | |||||
| if (!param.matches("^[0-9]*/[0-9]*/?$")) { | |||||
| invalidUrlLabel.setText("Invalid URL! Please provide params in the form season/matchday/"); | |||||
| outer.add(invalidUrlLabel); | |||||
| return; | |||||
| } | |||||
| String[] params = param.split("/"); | |||||
| seasonParam = params[0]; | |||||
| matchdayParam = params[1]; | |||||
| Season season = getSeasonFromParam(seasonParam); | |||||
| if (season == null) { | |||||
| invalidUrlLabel.setText(String.format("Invalid URL! Season \"%s\" does not exist in the database!", seasonParam)); | |||||
| outer.add(invalidUrlLabel); | |||||
| return; | |||||
| } | |||||
| seasonSelect.setValue(season); | |||||
| fillMatchdaySelectWithData(); | |||||
| Matchday matchday = getMatchdayFromParam(matchdayParam); | |||||
| if (matchday == null) { | |||||
| invalidUrlLabel.setText(String.format("Invalid URL! Matchday \"%s\" in Season \"%s\" does not exist in the database!", matchdayParam, seasonParam)); | |||||
| outer.add(invalidUrlLabel); | |||||
| return; | |||||
| } | |||||
| matchdaySelect.setValue(matchday); | |||||
| configureMatchdayView(); | |||||
| outer.add(selectionLayout); | |||||
| outer.add(outerMatchdaylayout); | |||||
| configureButtons(); | |||||
| } | |||||
| private void configureButtons() { | |||||
| prevButton.setEnabled(isMatchDayParamValid(getPrevMatchdayParam())); | |||||
| prevButton.addClickListener(getButtonClickListener(prevButton, getPrevMatchdayParam())); | |||||
| nextButton.setEnabled(isMatchDayParamValid(getNextMatchdayParam())); | |||||
| nextButton.addClickListener(getButtonClickListener(nextButton, getNextMatchdayParam())); | |||||
| } | |||||
| @Nullable | |||||
| private Season getSeasonFromParam(@NonNull String seasonParam) { | |||||
| for (Season season : seasonList) { | |||||
| if (seasonParam.equals(season.toString())) { | |||||
| return season; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| @Nullable | |||||
| private Matchday getMatchdayFromParam(@NonNull String matchdayParam) { | |||||
| return getMatchdayFromParam(matchdayParam, null); | |||||
| } | |||||
| @Nullable | |||||
| private Matchday getMatchdayFromParam(@NonNull String matchdayParam, @Nullable Season season) { | |||||
| List<Matchday> matchdayList = season == null ? this.matchdayList : matchdayService.getMatchdaysForSeason(season); | |||||
| for (Matchday matchday : matchdayList) { | |||||
| if (matchdayParam.equals(matchday.toString())) { | |||||
| return matchday; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| } | |||||