GithubHelp home page GithubHelp logo

diazlp / golang-phone-review-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 384 KB

A Golang-based API for managing phone reviews, comments, and likes.

Go 100.00%
gin-gonic godotenv gorm jwt-authentication mysql swaggo

golang-phone-review-api's Introduction

Phone Review API

This API provides endpoints to manage phone reviews, comments, and likes. It includes user authentication and role-based access control.

Overview

1. Database Schema:

SchemaERD

2. Project Dependencies:

  • Gin HTTP Framework
  • GORM Library
  • Swaggo Documentation Framework
  • MySQL
  • JWT Authentication
  • godotenv

Getting Started

To run this application locally:

  1. Clone the repository:
    git clone https://github.com/diazlp/golang-phone-review-api.git
  2. Install dependencies
    go mod tidy
  3. Create a .env file with neccessary environment variables
    API_SECRET=<your_secret>
    TOKEN_HOUR_LIFESPAN=<token_lifespan>
  4. Change database configuration on /configs/database.go
    username := <your_db_username>
    password := <your_db_password>
    host   	 := <your_db_host>
    database := <project_db_name>
  5. Run the application:
    go run main.go

Note: Kindly run swag init after you make codebase changes to update swagger API documentation

API Endpoints

Authentication

  • POST /register: Register a new user.
  • POST /login: Log in with existing credentials.
  • POST /change-password: Change user password.

Phone Endpoints

  • GET /phones: Get all phones.
  • GET /phones/:phone_id: Get details of a specific phone.
  • GET /phones/:phone_id/reviews: Get reviews for a specific phone.
  • POST /phones/:phone_id/reviews: Create a review for a phone.
  • POST /phones: Create a new phone.

Review Endpoints

  • GET /reviews: Get all reviews.
  • GET /reviews/:review_id/comments: Get comments for a review.
  • GET /reviews/:review_id/likes: Get likes for a review.
  • PUT /reviews/:review_id: Update a review.
  • DELETE /reviews/:review_id: Delete a review.
  • POST /reviews/:review_id/comments: Create a comment for a review.
  • POST /reviews/:review_id/likes: Like a review.

Comment Endpoints

  • GET /comments: Get all comments.
  • GET /comments/:comment_id/likes: Get likes for a comment.
  • PUT /comments/:comment_id: Update a comment.
  • DELETE /comments/:comment_id: Delete a comment.
  • POST /comments/:comment_id/likes: Like a comment.

Like Endpoints

  • GET /likes: Get all likes.
  • DELETE /likes/:like_id: Delete a like.

Authentication & Authorization

  • User registration is open to everyone.
  • User authentication is required for some endpoints.
  • All user can use GET endpoints.
  • Role-based access control is implemented:
    • "Guest" role: Can like reviews and comments.
    • "Writer" role: Can create and edit reviews and comments.
    • "Admin" role: Can create phone, create review and delete review.

golang-phone-review-api's People

Contributors

diazlp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.