One a simple crud app in local environment for the administrator that allows you to manage users in the database. The administrator uses OAuth2 with Password (and hashing), Bearer with JWT tokens authentication and authorisation. User data is saved in the postgres database in the docker. Users also can login to app via OAuth2. This is subapi for users.
- FastApi
- Uvicorn
- Docker
- Python 3.9
- Postgres 14
- Swagger
$ mkdir /home/memories/database
$ docker run -d \
--name memories -p 127.0.0.1:5432:5432 \
-e POSTGRES_PASSWORD=memories \
-e POSTGRES_DB=memories -v /home/memories/database:/var/lib/postgresql/data postgres
$ docker exec -it memories bash
$ su - postgres
$ psql
CREATE USER memories WITH password 'memories';
ALTER DATABASE memories OWNER TO memories;
\c memories memories
CREATE TABLE public."role" (
id_role serial NOT NULL,
role_name varchar(50) NOT NULL,
CONSTRAINT role_pkey PRIMARY KEY (id_role),
CONSTRAINT role_role_name_key UNIQUE (role_name)
);
CREATE TABLE public.users (
id serial NOT NULL,
name varchar(20) NOT NULL,
surname varchar(30) NOT NULL,
email varchar(100) NOT NULL,
created_on timestamp NOT NULL,
role_id int4 NOT NULL,
"password" varchar(100) NOT NULL,
CONSTRAINT users_email_key UNIQUE (email),
CONSTRAINT users_pkey PRIMARY KEY (id),
CONSTRAINT role_users FOREIGN KEY (role_id) REFERENCES public."role"(id_role)
);
CREATE TABLE public.tags (
id serial NOT NULL,
tag varchar(20) NOT NULL,
user_id int4 NOT NULL,
CONSTRAINT tag_unique UNIQUE (tag, user_id),
CONSTRAINT tags_pkey PRIMARY KEY (id)
);
CREATE TABLE public.posts (
id serial NOT NULL,
post varchar(500) NOT NULL,
created_on timestamp NOT NULL,
tag_id int4 NOT NULL,
user_id int4 NOT NULL,
CONSTRAINT posts_pkey PRIMARY KEY (id),
CONSTRAINT post_user_id FOREIGN KEY (user_id) REFERENCES public.users(id),
CONSTRAINT tag_posts FOREIGN KEY (tag_id) REFERENCES public.tags(id)
);
$ uvicorn main:app --port 8000 --reload
127.0.0.1:8000/users/docs
127.0.0.1:8000/admin/docs
- improve the structure of the login files
- improve the structure of the schemas files
- add the ability to add posts for users
- better containerization - dockerfile
- ...
- ...