This project encompasses both the backend and a minimal frontend for an application intended for veterinarians, providing the ability to share information about various animal conditions, including explanatory texts and relevant images. This platform not only enables knowledge sharing but also supports the continuous learning of veterinary professionals.
- Guest
- Guest only has access to see posts and comments.
- Guest can also filter post by tag or sort them by creation date.
- User
- User can create/edit/delete his own posts.
- User can add comments to posts.
- User can edit his own comments.
- User can edit his own profile.
- User can delete his own account.
- Admin
- Admin has full access to create/edit/delete posts and comments.
- Admin has access to delete users.
-
prisma
- dbml
- schema.dbml (dbml file to visualise the Entity-Relationship Diagram with
dbdiagram.io)
- schema.dbml (dbml file to visualise the Entity-Relationship Diagram with
- schema.prisma
- dbml
-
src
- controllers
- middlewares
- routes
- services
- utils
- validations
-
static
- views (nunjucks templates for frontend)
- Clone project
- Create a .env file
- Add variables
DB_LINK<- for your database connection stringGOOGLE_CLIENT_ID<- for Google OauthGOOGLE_CLIENT_SECRET<- for Google OauthCLOUD_NAME<- for image upload (cloudinary)CLOUDINARY_API_KEY<- for image upload (cloudinary)CLOUDINARY_API_SECRET<- for image upload (cloudinary)JWTSECRET<- secret for jwt authentication
- Run
npm installfor installing necessary packages - Run
npm startfor run app
┌───────┐
│ start │
└───┬───┘ ┌─────────────────┐
│ ┌───►│filter/sort posts│
│ │ └─────────────────┘
▼ │
┌─────┐ │ ┌────────────────────┐
┌─────────────────────────────────────►│guest├──────┴───►│view posts/comments │
│ └──┬──┘ └────────────────────┘
│ │
│ │
│ │
│ ▼
│ ┌────────────────┐
│ │ signup / login │
│ └────┬─────┬─────┘
│ │ │
│ ┌────┐ │ │ ┌─────┐
│ ┌───────────────────┤user│◄──┘ └───►│admin├─────┐
│ │ └──┬─┘ └─┬───┘ │
│ │ │ │ │
│ │ ┌──────────────────▼───────┐ │ ┌──────▼───────────────────┐
│ │ │edit own pots and comments│ │ │edit all pots and comments│
│ │ └──────────────────────────┘ │ └──────────────────────────┘
│ │ │
│ │ │ ┌───────────────────────────┐
│ │ ┌─────────────────────────────┐ ├─►│delete users posts/comments│
│ ├──────►│delete his own posts/comments│ │ └───────────────────────────┘
│ │ └─────────────────────────────┘ │
│ │ │ ┌────────────┐
│ │ ├─►│delete users│
│ │ ┌──────────────────┐ │ └────────────┘
│ ├──────►│delete his account│ │
│ │ └───────────┬──────┘ │
│ │ │ │ ┌──────────────────┐
│ │ ┌──────┐ │ ├─►│delete his account├─────┐
│ └──────►│logout├────┤ │ └──────────────────┘ │
│ └──────┘ │ │ │
│ │ │ ┌──────┐ │
│ │ └─►│logout├─────────────────┤
└───────────────────────────┬┘ └──────┘ │
│ │
└──────────────────────────────────────────────────┘
Available for all.
Used for creating an account. Renders a form to be filled in order to create an account and gives the alternative to log in if you have already an account.
POST : http://localhost:3000/signup
Used for creating an account.
Request body:
{
"email": <String>,
"password": <String>,
"name": <String>
}It will check if already exists a user with given email. If there is, an error message will be displayed in the console and it will be redirected to sign form.
Available for all.
Used for log into an account. Renders a form to be filled in order to log in and gives the alternative to sign in or to log in with Google account.
POST : http://localhost:3000/login
Available for all.
Request body:
{
"email": <String>,
"password": <String>
}It verifies if user exist and password provided is correct the generates a JWT token that is stored in the current session. If login fails, it redirects to log in form otherwise it redirects to main page.
Available only for users and admins.
Destroy the current session. If it fails, it will respond with the code status 500 otherwise it will redirect to login.
Initiates the Google OAuth 2.0 authentication flow
Callback URL for handling the OAuth 2.0 response
GET : http://localhost:3000/
Available for all.
Displays posts and options to sort by date and to filter by tag name.
If guest is log as a user it displays buttons for creating a post , edit /delete his own posts ,add comment, edit his comments or view/edit profile.
If guest logs as an admin it displays buttons for creat/edit/delete all posts , add/edit/delete comments, manage users or view/edit profile.
Available only for users and admins.
Renders a form to be filled in order to create a new post
POST : http://localhost:3000/post
Available only for users and admins.
Request body:
{
"title": <String>,
"content": <String>,
"tags": <String>,
"type": <String>,
"imagePath": <String>,
"userId": <Integer>,
}Available only for users and admins.
Renders a form to be filled in order to modify a post
Available only for users and admins.
Request body:
{
"title": <String>,
"content": <String>,
"tags": <String>,
"type": <String>,
"imagePath": <String>,
"userId": <Integer>,
}DELETE: http://localhost:3000/post/:id
Available only for users and admins.
Used for deleting a specific post.
Available only for users and admins.
Renders the user's profile and displays buttons for edit or delete account.
DELETE: http://localhost:3000/user/:id
Available only for users and admins.
Available only for users and admins.
Renders a form to be filled in order to edit profile information.
Available only for users and admins.
Request body:
{
"name": <String>,
"email": <String>,
"bio": <String>
}Only for admins.
Renders all users in order to delete accounts
Available for all.
Available only for users and admins.
Available only for users and admins.
Request body:
{
"content": <String>
}Available only for users and admins.
Available only for users and admins.
Request body:
{
"content": <String>
}Available only for users and admins.