3.3 KiB
3.3 KiB
This is the API for my 2023-2024 FBLA Coding & Programming App
Installation
- Install Dart SDK
- Install PostgreSQL and set it up
- Clone the repo
git clone https://git.marinodev.com/MarinoDev/FBLA24.git
cd FBLA24/api/
- Run
dart pub installto install dart packages
Usage
- Create
fbladatabase in postgres
CREATE DATABASE fbla
WITH
OWNER = [username]
ENCODING = 'UTF8'
CONNECTION LIMIT = -1
IS_TEMPLATE = False;
Make sure to change [username] to the actual username of your postgres instance
2. Create businesses table
-- Table: public.businesses
-- DROP TABLE IF EXISTS public.businesses;
CREATE TABLE IF NOT EXISTS public.businesses
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 MAXVALUE 2147483647 CACHE 1 ),
name text COLLATE pg_catalog."default" NOT NULL,
description text COLLATE pg_catalog."default" NOT NULL,
type text COLLATE pg_catalog."default" NOT NULL,
website text COLLATE pg_catalog."default" NOT NULL,
"contactName" text COLLATE pg_catalog."default" NOT NULL,
"contactEmail" text COLLATE pg_catalog."default" NOT NULL,
"contactPhone" text COLLATE pg_catalog."default" NOT NULL,
notes text COLLATE pg_catalog."default" NOT NULL,
"locationName" text COLLATE pg_catalog."default" NOT NULL,
"locationAddress" text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT businesses_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.businesses
OWNER to [username];
Make sure to change [username] to the actual username of your postgres instance
3. Create users table
-- Table: public.users
-- DROP TABLE IF EXISTS public.users;
CREATE TABLE IF NOT EXISTS public.users
(
username text COLLATE pg_catalog."default" NOT NULL,
password_hash text COLLATE pg_catalog."default" NOT NULL,
salt text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT users_pkey PRIMARY KEY (username),
CONSTRAINT username UNIQUE (username)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.users
OWNER to postgres;
- Set environment variables
POSTGRES_ADDRESS(IP address),POSTGRES_PORT(default 5432),POSTGRES_USERNAME, andPOSTGRES_PASSWORDto appropriate information for your postgres database. Also setSECRET_KEYto anything you want to genera te JSON Web Tokens. - Set lib/create_first_user.dart username and password variables at top of file and run with
dart run lib/create_first_user.dartNote: the username and password you use here will be what you use to log into the app as an admin - Your database should be all set up! Start the API with
dart run lib/fbla_api.dartor alternatively, run it in a docker container with Docker Build and Docker Compose using the included Dockerfile and docker-compose.yml files. If usingDocker Compose, change the first portion of the volumes path on line 9 to any desired storage location. Note the address it is serving at, you will need this to connect it to the UI, and to run tests. - Test your api with
dart run test/fbla_api_test.dart, settingapiAddresson line 8 to your api address.