Skip to content

MyFanss/MyFanss_Backend

Repository files navigation

My Fans Backend

A NestJS-based RESTful API , using TypeORM with PostgreSQL. This README provides instructions for contributors to set up the project and details the available API endpoints.

API Documentation

Method Endpoint Description Request Body Response
POST /users Create a new user CreateUserDto (name, email, password) UserResponseDto (name, email, message)
GET /users/:id Get a user by ID None UserResponseDto (name, email, message)
GET /users Get all users None UserResponseDto[]
PUT /users/:id Update a user by ID UpdateUserDto (name?, email?, password?) UserResponseDto (name, email, message)
DELETE /users/:id Delete a user by ID None string (success message)

Example Requests

Create User

curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d '{ "name": "Oladele20", "email": "samuel@mailto.com","password": "password3" }'

Response:

{
	"name": "Oladele20",
	"email": "samuel@mailto.com",
	"message": "user created successfully..."
}

Get User by ID

curl http://localhost:3000/users/1

Response:

{
  "name": "Oladele20",
	"email": "samuel@mailto.com",
}

Get All Users

curl http://localhost:3000/users

Response:

[
	{
		"name": "Oladele1",
		"email": "stringing20@mail.com"
	},
	{
		"name": "Oladele20",
		"email": "samuel@mailto.com"
	}
]

Update User

curl -X PUT http://localhost:3000/users/1 -H "Content-Type: application/json" -d '{"name":"blurbeast"}'

Response:

{
	"name": "blurbeast",
	"email": "samuel@mailto.com",
	"message": "user updated successfully"
}

Delete User

curl -X DELETE http://localhost:3000/users/1

Response:

"User deleted successfully"

Local Setup for Contributors

Prerequisites

  • Node.js: v20.x (install via nvm):
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
    nvm install 20
    nvm use 20
  • PostgreSQL: Install and ensure it’s running:
    sudo apt update
    sudo apt install postgresql postgresql-contrib
    sudo service postgresql start
  • Git: Installed for cloning the repository.

Setup Steps

  1. Clone the Repository:

    git clone https://github.com/your-username/my-fans-backend.git
    cd my-fans-backend
  2. Install Dependencies:

    npm install
  3. Configure Environment: Create a .env file in the root directory with the following:

    DB_HOST=localhost
    DB_PORT=5432
    DB_NAME=my_fans_db
    DB_USERNAME=postgres
    DB_PASSWORD=password
  4. Start the Application:

    npm run start:dev
  5. Test APIs: Use the curl commands in the API Documentation section to verify endpoints.

Contributing

  1. Fork the repository.
  2. Clone your fork locally:
    git clone https://github.com/your-username/my-fans-backend.git
  3. Create a feature branch:
    git checkout -b feature/your-feature
  4. Make changes and commit:
    git commit -m "Add your feature or fix"
    If Husky linting blocks the commit, bypass temporarily:
    git commit -m "Add your feature or fix" --no-verify
  5. Push to your fork:
    git push origin feature/your-feature
  6. Open a Pull Request on the main repository.

Troubleshooting

  • Not-Null Constraint Errors:
    • Ensure CreateUserDto has valid data for name, email, and password.
    • Check migrations for correct User table schema (NOT NULL constraints).
  • Database Connection Issues:
    • Verify .env variables (DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD).
    • Check PostgreSQL status:
      sudo service postgresql status

License

MIT License# MyFanss_Backend

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •