YourPets-backend Documentation
Welcome to YourPets repository
Here is an example of the best use of this API
YourPets is a web application that helps people find loving families for their pets. It allows users to create notices for their pets, which can be either for sale, lost/found, or offered for free. Users can also search for pets that are available for adoption.
-
Clone the repository to your local machine:
- git clone https://github.com/Mamont777/YourPet-backend.git
- Install the required dependencies:
- cd YourPet-backend
- npm install
- Set up the MongoDB database:
- Ensure you have MongoDB installed and running on your machine.
- Update the database configuration in the `config.js` file.
- Start the development server:
-npm start
The website will be accessible at `http://localhost:3000` in your browser.
The backend provides the following API endpoints for the YourPets website:
- "POST /users/register": Register a new user
- "POST /api/users/login": Log in an existing user
- "PATCH /users/info/update": Update user's information
- "GET /users/current": Return information of current user
- "POST /users/logout": Log out user
- "GET /notices": Return object with array of all notices and sum of them
- "POST /notices": Add new notice
- "GET /notices/:id": Return notice by id
- "GET /notices/user/added": Return object with array of added notices by current user and sum of them
- "DELETE /notices/user/added/:id": Delete notice
- "GET /notices/user/favorite": Return object with array of user's favorite notices and sum of them
- "PATCH /notices/user/favorite/:id": Add notice to the array of user's favorite notices
- "DELETE /notices/user/favorite/:id": Delete notice from array of user's favorite notices
- "GET /notices/users/search": Return object with array of notices chooses by category or title and sum of them
- "GET /notices/users/filter": Return object with array of notices chooses by age or sex and sum of them
- "GET /pets": Return object with array of all user's pets
- "POST /pets": Add new pet
- "DELETE /pets/:id": Delete pet
- "GET /friends": Return object with array of all friends
- "GET /news": Return object with array of all news and sum of them
User authentication is handled using JWT (JSON Web Tokens). Upon successful login, a token will be provided, which should be included in the `Authorization` header of subsequent requests to access protected routes.
- "User": Represents a registered user with fields like "email", "password", "name", "birthday", "phone", "city", "avatarURL", "token", "favorites" and fields with date of create and update.
- "Notice": Represents a pet notice with fields like "title", "name", "date", "category", "type", "sex", "location", "price", "comments", "owner", "ownerEmail", "ownerPhone", "fileURL", "createdAt", and "updatedAt".
- "Pet": Represents a pets with fields like "name", "date", "type", "comments", "owner", "fileURL", "createdAt", and "updatedAt"
- "New": Represents a news notice with fields like "imgURL", "title", "text", "date", "url" and "id"
- "Friend": Represents a friends notice with fields like "imageURL", "title", "addressURL", "address", "workDays", "url", "phone" and "email"
The backend handles errors using custom middleware. If an error occurs, the server will respond with an appropriate error message and status code.