Skip to content

Backend application - Time capsule to collect memorable moments from your journey, developed during NLW Spacetime

Notifications You must be signed in to change notification settings

kevinCubas/spacetime-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLW - Spacetime SERVER

Back-end Time capsule designed to help you collect your most memorable moments. This README document provides an overview of the features, used technologies, and functionalities of the application, as well as instructions on how to set it up and use it effectively.

You may find the frontend application in the following repo: FrontendApp

Technologies Used:

Features:

  • Authentication: The application retrieves the access token and user information from GitHub and creates a user in the database if they are not already registered. A JWT (JSON Web Token) is generated and returned to the frontend for subsequent API requests.

  • GET memories: This action retrieves all the memories created by the user. The backend fetches the memories associated with the user ID from the database and returns them as a list.

  • GET memory details(get by id):The backend fetches the memory from the database based on the provided memoryId. If the memory is public, it can be accessed by other users as well. The details of the memory, including its description, media, visibility, and creation timestamp, are returned to the frontend.

  • Create(POST) new memory: The user provides the necessary details such as description, media (image or video), and visibility (public or personal). Associates the memory with the user, and saves it in the database.

  • Edit(PUT) Memory: verifies that the memory belongs to the authenticated user, and updates the corresponding record in the database.

  • Delete(DELETE) Memory: verifies that the memory belongs to the authenticated user and deletes the corresponding record from the database. This action is irreversible, and once a memory is deleted, it cannot be recovered.

Routes

  • /auth: Handles authentication with GitHub, retrieves access tokens, and creates users in the database.
  • /memories: CRUD operations for memories with JWT verification.
  • /uploads: Handles media local uploads, validates the format and file size, and return the URL to the front.

Prisma Schema

The databe of the application is the SQLite. It consists of two models:

  • User: Represents a user in the system and stores their GitHub information.
  • Memory: Represents a memory created by a user, including the associated user ID, cover URL, content, visibility status, and creation timestamp.

Installation and Setup:

Requirements

  • Node: 17 or latest version
  • NPM: 9 or latest version (NPM is included with Node)
  • GIT

GITHUB OAuth token AND .env set up

  1. Go to the GitHub Developer Settings page: https://github.com/settings/developers.

  2. Click on "New OAuth App" to create a new OAuth App.

  3. Fill in the following information for your OAuth App:

  • Application Name: Choose a name for your application.
  • Homepage URL: http://localhost:3000. - change port if necessary.
  • Authorization callback URL: Enter the callback URL where GitHub will redirect users after authentication. For local development, we are using http://localhost:3000/api/auth/callback in the frontend
  1. Click on "Register Application" to create the OAuth App.

After creating the OAuth App, you will see the "Client ID" and "Client Secret" on the OAuth App page. These credentials will be used to authenticate your application with GitHub.

  1. In your project, create a .env file in the root directory if it doesn't already exist.

  2. Set the DATABASE_URL environment variable

DATABASE_URL="file:./dev.db"
  1. Set the GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET environment variables, replacing <CLIENT_ID> and <client_secret> with your actual credentials obtained from the GitHub OAuth App page:
GITHUB_CLIENT_ID=<client_id>
GITHUB_CLIENT_SECRET=<client_secret>

Remember to keep your GitHub Client ID and Client Secret secure and never expose them publicly.

Steps to install and run:

  1. Clone the repository
  git clone https://github.com/kevinCubas/spacetime-server.git
  1. Change into the project directory:
cd spacetime-server
  1. Install dependencies using npm:
  npm install
  1. Run the application locally: port 3333
  npm run dev

Contributing

To contribute to this project, please follow these guidelines:

  1. Fork the repository
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Make your changes and commit them using Conventional Commits
  4. Push to the branch: git push origin feature/your-feature-name
  5. Submit a pull request

Contributors:

KevinCubas

About

Backend application - Time capsule to collect memorable moments from your journey, developed during NLW Spacetime

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages