back-end code for chess website
- have Go installed
- have a PostgreSQL database running
- have within your profile (.zshrc for example) a exported variable
CHESS_DB_DSN
with your Postgres connection string - have go-migrate installed
- set up database, tables, user and extensions with:
make setup-dev
-
if you are using a different database, you will need to change the
CHESS_DB_DSN
variable in theMakefile
to match your database connection string -
For any errors create a new issue in the repository and I will try to help you out and update README
TODO: add more setup instructions for Linux and Windows
- especially for the migrate cli tool and other dependencies
NOTE this is currently changing frequently as the project is in development
TODO
Column | Type | Collation | Nullable | Default
--------------+-----------------------------+-----------+----------+----------------------------------------
club_id | bigint | | not null | nextval('clubs_club_id_seq'::regclass)
is_active | boolean | | not null | true
is_verified | boolean | | not null | false
created_at | timestamp(0) with time zone | | not null | now()
updated_at | timestamp(0) with time zone | | not null | now()
deleted_at | timestamp(0) with time zone | | |
code | text | | not null |
name | text | | not null |
address | text | | not null |
observations | text | | |
city | text | | not null |
country | text | | not null | 'Spain'::text
Indexes:
"clubs_pkey" PRIMARY KEY, btree (club_id)
Referenced by:
TABLE "users" CONSTRAINT "fk_admin_of" FOREIGN KEY (club_admin_of) REFERENCES clubs(club_id) ON DELETE CASCADE
TABLE "users" CONSTRAINT "fk_user_club" FOREIGN KEY (club_id) REFERENCES clubs(club_id) ON DELETE CASCADE
club_id
- primary keyis_active
- boolean to determine if club is activecreated_at
- date club was createdupdated_at
- date club was last updateddeleted_at
- date club was deletedname
- club's namedescription
- club's descriptionavatar
- club's profile picture URLorganizer_id
- foreign key tousers
tableemail
- club's emailphone
- club's phone numberwebsite
- club's websitecountry
- club's country of residence (SPAIN, USA, etc.) DEFAULT: SPAINprovince
- club's province of residence (MADRID, BARCELONA, etc.)city
- club's city of residence (ALCOBENDAS, SANT CUGAT, etc.)address
- club's addressmembers
- foreign keys[] tousers
table
CREATE TABLE IF NOT EXISTS clubs (
id bigserial PRIMARY KEY,
is_active boolean NOT NULL DEFAULT TRUE,
is_verified boolean NOT NULL DEFAULT FALSE,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
deleted_at timestamp(0) with time zone,
code text NOT NULL,
name text NOT NULL,
address text NOT NULL,
observations text,
city text NOT NULL
);
Table "public.users"
Column | Type | Collation | Nullable | Default
-----------------------+-----------------------------+-----------+----------+----------------------------------------
user_id | bigint | | not null | nextval('users_user_id_seq'::regclass)
is_active | boolean | | not null | false
is_verified | boolean | | not null | false
is_admin_of_club | boolean | | not null | false
club_admin_of | bigint | | |
created_at | timestamp(0) with time zone | | not null | now()
updated_at | timestamp(0) with time zone | | not null | now()
deleted_at | timestamp(0) with time zone | | |
first_name | text | | not null |
last_name | text | | not null |
dob | date | | |
sex | text | | |
username | text | | |
email | text | | |
password | text | | |
password_reset_token | text | | |
avatar | text | | |
club_id | bigint | | |
club_role_id | bigint | | |
about_me | text | | |
is_arbiter | boolean | | not null | false
is_coach | boolean | | not null | false
price_per_hour | integer | | not null | 0
chess_com_username | text | | not null | ''::text
lichess_username | text | | not null | ''::text
chess24_username | text | | not null | ''::text
country | text | | not null | 'SPAIN'::text
province | text | | not null | ''::text
city | text | | not null | ''::text
neighborhood | text | | not null | ''::text
elo_fide_standard | integer | | |
elo_fide_rapid | integer | | |
elo_national_standard | integer | | |
elo_national_rapid | integer | | |
elo_regional_standard | integer | | |
club_user_code | text | | |
chess_age_category | text | | |
elo_regional_rapid | integer | | |
Indexes:
"users_pkey" PRIMARY KEY, btree (user_id)
"users_club_user_code_unique" UNIQUE CONSTRAINT, btree (club_user_code)
Foreign-key constraints:
"fk_admin_of" FOREIGN KEY (club_admin_of) REFERENCES clubs(club_id) ON DELETE CASCADE
"fk_user_club" FOREIGN KEY (club_id) REFERENCES clubs(club_id) ON DELETE CASCADE
user_id
- primary keyis_active
- boolean to determine if user is activeis_verified
- boolean to determine if user is verifiedis_admin
- boolean to determine if user is adminclub_admin
- foreign key toclubs
table (what club the user is admin of)created_at
- date user was createdupdated_at
- date user was last updateddeleted_at
- date user was deletedfirst_name
- user's first namelast_name
- user's last namedob
- user's date of birth- this is for tournament search purposes
sex
- user's personal identity(male or female)- this is for tournament search purposes
username
- unique usernameemail
- unique emailpassword
- hashed passwordavatar
- user's profile picture URLclub_id
- foreign key toclubs
tableclub_role_id
- foreign key toclub_roles
tableabout_me
- user's personal biois_arbiter
- boolean to determine if user is an arbiteris_coach
- boolean to determine if user is a coachtitle
- user's title (GM, IM, FM, etc.)chess_com_username
- user's chess.com usernamelichess_username
- user's lichess usernamechess24_username
- user's chess24 usernamecountry
- user's country of residence (SPAIN, USA, etc.) DEFAULT: SPAINprovince
- user's province of residence (MADRID, BARCELONA, etc.)city
- user's city of residence (ALCOBENDAS, SANT CUGAT, etc.)neighborhood
- user's neighborhood of residence (LA MORALEJA, VALLVIDRERA, etc.)elo_fide_standard
- user's FIDE standard ratingelo_fide_rapid
- user's FIDE rapid ratingelo_national_standard
- user's national standard ratingelo_national_rapid
- user's national rapid ratingelo_regional_standard
- user's regional standard ratingelo_regional_rapid
- user's regional rapid rating
CREATE TABLE IF NOT EXISTS users (
user_id bigserial PRIMARY KEY,
is_active boolean NOT NULL DEFAULT FALSE,
is_verified boolean NOT NULL DEFAULT FALSE,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
soft_deleted bool NOT NULL DEFAULT FALSE,
user_code text NOT NULL DEFAULT uuid_generate_v1(),
first_name text NOT NULL DEFAULT '',
last_name text NOT NULL DEFAULT '',
username text NOT NULL DEFAULT '',
password text NOT NULL DEFAULT '',
password_reset_token text NOT NULL DEFAULT '',
email text NOT NULL DEFAULT '',
avatar text NOT NULL DEFAULT '',
dob date NOT NULL DEFAULT '1900-01-01',
about_me text NOT NULL DEFAULT '',
sex text NOT NULL DEFAULT '',
club_id bigint NOT NULL DEFAULT 0, -- fk to club table
chess_age_category text NOT NULL DEFAULT '',
elo_fide_standard integer NOT NULL DEFAULT 1200,
elo_fide_rapid integer NOT NULL DEFAULT 1200,
elo_fide_blitz integer NOT NULL DEFAULT 1200,
elo_fide_bullet integer NOT NULL DEFAULT 1200,
elo_national_standard integer NOT NULL DEFAULT 1200,
elo_national_rapid integer NOT NULL DEFAULT 1200,
elo_national_blitz integer NOT NULL DEFAULT 1200,
elo_national_bullet integer NOT NULL DEFAULT 1200,
elo_regional_standard integer NOT NULL DEFAULT 1200,
elo_regional_rapid integer NOT NULL DEFAULT 1200,
elo_regional_blitz integer NOT NULL DEFAULT 1200,
elo_regional_bullet integer NOT NULL DEFAULT 1200,
is_arbiter boolean NOT NULL DEFAULT FALSE,
is_coach boolean NOT NULL DEFAULT FALSE,
price_per_hour float NOT NULL DEFAULT 0,
currency text NOT NULL DEFAULT '',
chess_com_username text NOT NULL DEFAULT '',
lichess_username text NOT NULL DEFAULT '',
chess24_username text NOT NULL DEFAULT '',
country text NOT NULL DEFAULT '',
province text NOT NULL DEFAULT '',
city text NOT NULL DEFAULT '',
neighborhood text NOT NULL DEFAULT '',
version integer NOT NULL DEFAULT 0
);
In order for the person to be able to have an active account, they need to sign up for the website.
Tournaments represent the parent of the games
table and will define the rules
and regulations of the subsequent games of the child games.
tournament_id
- primary keyis_active
- boolean to determine if tournament is activecreated_at
- date tournament was createdupdated_at
- date tournament was last updateddeleted_at
- date tournament was deletedstart_at
- date tournament was startedend_at
- date tournament was endedno_of_rounds
- number of rounds in tournamenttime_control
- time control of tournament (Standard, Rapid, Blitz)clock_type
- clock type of tournament (Analog, Digital)clock_rythm
- clock increment of tournament(50+10, 25+5, etc.)arbiters
- foreign keys[] tousers
tablelocation
- tournament's locationfide_valid
- boolean to determine if tournament is FIDE validnational_valid
- boolean to determine if tournament is national validregional_valid
- boolean to determine if tournament is regional validorganizer_id
- foreign key tousers
table
CREATE TABLE IF NOT EXISTS tournaments (
tournament_id bigserial PRIMARY KEY,
is_active boolean NOT NULL DEFAULT TRUE,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
deleted_at timestamp(0) with time zone,
name text NOT NULL,
description text,
start_date timestamp(0) with time zone NOT NULL,
end_date timestamp(0) with time zone NOT NULL,
no_of_rounds integer NOT NULL DEFAULT 0,
time_control text NOT NULL, -- create fk to time_control table
clock_type text NOT NULL,
clock_rhythm text NOT NULL,
aribiters bigint[] NOT NULL DEFAULT '{}', -- create fk
location text,
organizer_id bigint,
);
A game is also considered a round or a match. For example a tournament can be composed
of 9 rounds. Those 9 rounds can be considered 9 games and will thus be stored in the
games
table.
game_id
- primary keyis_active
- boolean to determine if game is activecreated_at
- date game was createdupdated_at
- date game was last updateddeleted_at
- date game was deletedstart_at
- date game was startedend_at
- date game was endedlocation
- game's locationfide_valid
- boolean to determine if game is FIDE validnational_valid
- boolean to determine if game is national validregional_valid
- boolean to determine if game is regional validorganizer_id
- foreign key tousers
tableorganizer_email
- organizer's emailorganizer_phone
- organizer's phone numberplayers_attending
- foreign keys[] tousers
table of members that are registered to the websiteclub_members_price
- price for club membersclub_non_members_price
- price for non-club membersqr_code
- URL to QR code for gamedescription
- game's descriptionadditional_info
- game's additional infotournament_id
- foreign key totournaments
table
CREATE TABLE IF NOT EXISTS games (
game_id bigserial PRIMARY KEY,
is_active boolean NOT NULL DEFAULT TRUE,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
deleted_at timestamp(0) with time zone,
start_at timestamp(0) with time zone NOT NULL,
end_at timestamp(0) with time zone,
location text,
fide_valid boolean NOT NULL DEFAULT FALSE,
national_valid boolean NOT NULL DEFAULT FALSE,
regional_valid boolean NOT NULL DEFAULT FALSE,
organizer_id bigint,
organizer_email text NOT NULL,
organizer_phone text NOT NULL,
players_attending integer[] NOT NULL DEFAULT '{}',
club_member_price integer NOT NULL DEFAULT 0,
club_non_member_price integer NOT NULL DEFAULT 0,
qr_code text,
description text,
additional_info text,
tournament_id bigint,
);
TODO
TODO
POST /user/create
- create user
{
"code":398409,
"first_name":" Christian",
"last_name":"Francia",
"sex":"M",
"title":"",
"chess_age_category":"Senior",
"club_id":65,
"country":"Spain",
"elo_fide_standard":0,
"elo_fide_rapid":0,
"elo_national_standard":0,
"elo_national_rapid":0,
"elo_regional_standard":1028,
"elo_regional_rapid":1154
}
POST /user/login
- login user