Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proyecto Final Backend 2 Backend para Panaderia.

Warning

Profe lea el chat de plataforma para las variables de entorno

Important

Levantar el proyecto usando este esquema de variables de entorno:

.env.dev

PORT=8080

URI_MONGODB=mongodb://localhost:27017/"colocar un nombre a la base de datos"

FRONTEND_DEV_URL=http://localhost:3000

COOKIE_SIGN=

JWT_PRIVATE_KEY=

JWT_EXPIRES_IN=

MAIL_SERVICE=gmail

MAIL_PORT=587

MAIL_FROM=

MAIL_PASS=

MAIL_HOST=smtp.gmail.com

.env.prod

PORT=8080

URI_MONGODB="la url de mongo atlas"

FRONTEND_DEV_URL=http://localhost:3000

COOKIE_SIGN=

JWT_PRIVATE_KEY=

JWT_EXPIRES_IN=

MAIL_SERVICE=gmail

MAIL_PORT=587

MAIL_FROM=

MAIL_PASS=

MAIL_HOST=smtp.gmail.com

User Routes

Register a new user

  • POST /auth/register
    • Role: PUBLIC
    • Request Body:
      {
        "first_name": "John",
        "last_name": "Doe",
        "email": "john@example.com", //Profe porfa coloque un mail valido para que compruebe que le llegue el email.
        "age": 25,
        "password": "password123",
        "role": "USER" // Optional, defaults to "USER"
      }

Login

  • POST /auth/login
    • Role: PUBLIC
    • Request Body:
      {
        "email": "john@example.com",
        "password": "password123"
      }

Logout

  • POST /auth/logout
    • Role: USER, ADMIN
    • Clears the authentication token

Product Routes

Get all products (paginated)

  • GET /products/
    • Role: PUBLIC
    • Query Parameters:
      • limit: Number of items per page (default: 10)
      • page: Page number (default: 1)
      • sort: Sort order ('asc' or 'desc')
      • query: Search query string

Get product by slug

  • GET /products/detail/:slug
    • Role: PUBLIC
    • Example: /products/detail/example-product

Create product

  • POST /products/createProduct
    • Role: ADMIN
    • Request Body:
      {
        "title": "New Product",
        "description": "Product description",
        "price": 99.99,
        "stock": 100,
        "category": "electronics",
        "imageUrl": "[http://example.com/image.jpg"](http://example.com/image.jpg")
      }

Update product

  • PUT /products/detail/:slug
    • Role: ADMIN
    • Request Body: (include only fields to update)
      {
        "price": 89.99,
        "stock": 90
      }

Delete product

  • DELETE /products/detail/:slug
    • Role: ADMIN

Cart Routes

Get current user's cart

  • GET /cart/:cid
    • Role: USER, ADMIN
    • Returns the cart with all products

Add product to cart

  • POST /cart/:cid/products/:pid
    • Role: USER, ADMIN
    • Request Body:
      {
        "quantity": 1
      }

Update product quantity in cart

  • PUT /cart/:cid/products/:pid
    • Role: USER, ADMIN
    • Request Body:
      {
        "quantity": 3
      }

Remove product from cart

  • DELETE /cart/:cid/products/:pid
    • Role: USER, ADMIN

Clear cart

  • DELETE /cart/:cid
    • Role: USER, ADMIN

Purchase cart

  • POST /cart/:cid/purchase
    • Role: USER, ADMIN
    • The logic is in the services but basically you need to send in the request body the email and then the service update the stock if it's enough. The validation sends only the products that had stock and the outOfStock items remain on the cart.
    • Returns order details and send the email to the user with the order.

User Profile

Get current user profile

  • GET /user/current
    • Role: USER, ADMIN
    • Returns the currently authenticated user's profile

General

Health check

  • GET /user/
    • Role: PUBLIC
    • Returns a welcome message and API status

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages