mygram-api

module
v0.0.0-...-d702761 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2023 License: MIT

README

MyGram REST API

Hacktiv8 Scalable Web Service with Go - Final Project

Techs:

  • Gin Framework
  • JWT Authentication & Authorization
  • PostgreSQL & GORM
  • govalidation
  • Swagger docs
  • Cloudinary file upload
  • testing & httptest & testify

Swagger

Swagger docs

Endpoints

Category Method Endpoint Middleware Description
User POST /api/v1/users/register - User registration
User POST /api/v1/users/login - User login
Photo GET /api/v1/photos Authentication Get all photos
Photo GET /api/v1/photos/:id Authentication Get photo by ID
Photo POST /api/v1/photos Authentication Create new photo
Photo PUT /api/v1/photos/:id Authentication & Authorization Update photo by ID
Photo DELETE /api/v1/photos/:id Authentication & Authorization Delete photo by ID
Comment GET /api/v1/photos/:photoId/comments Authentication Get all comments
Comment GET /api/v1/photos/:photoId/comments/:id Authentication Get comment by ID
Comment POST /api/v1/photos/:photoId/comments Authentication Create new comment
Comment PUT /api/v1/photos/:photoId/comments/:id Authentication & Authorization Update comment by ID
Comment DELETE /api/v1/photos/:photoId/comments/:id Authentication & Authorization Delete comment by ID
Social Media GET /api/v1/social-medias Authentication Get all social medias
Social Media GET /api/v1/social-medias/:id Authentication Get social media by ID
Social Media POST /api/v1/social-medias Authentication Create new social media
Social Media PUT /api/v1/social-medias/:id Authentication & Authorization Update social media by ID
Social Media DELETE /api/v1/social-medias/:id Authentication & Authorization Delete social media by ID

Dependencies

  • go get github.com/asaskevich/govalidator
  • go get github.com/golang-jwt/jwt/v5
  • go get github.com/gin-gonic/gin
  • go get golang.org/x/crypto
  • go get gorm.io/driver/postgres
  • go get gorm.io/gorm
  • go get github.com/joho/godotenv
  • go get github.com/swaggo/swag/cmd/swag
  • go get github.com/swaggo/gin-swagger
  • go get github.com/swaggo/files
  • go get github.com/google/uuid
  • go get github.com/cloudinary/cloudinary-go/v2
  • go get github.com/cloudinary/cloudinary-go/v2/api/uploader
  • go get github.com/stretchr/testify

Setup DB (Postgres)

  • Login psql: psql -U postgres
  • Show databases: \list or \l
  • Create database: CREATE DATABASE db_mygram_api; & CREATE DATABASE db_mygram_api_test;
  • Select database: \c db_mygram_api
  • Show tables: dt

Setup env

  • Copy cp .env.example .env
  • Setup environment variables

Init swagger docs

  • using Makefile: make swagger

During local development, swagger docs available at: http://localhost:8080/swagger/index.html

Run test

  • using Makefile: make test

Run app

  • local development: make start or air for live reload
  • or using Docker: docker compose up

Build app

  • using Makefile: make build

Build result at /bin/mygram-api.exe

Create random string

openssl rand -base64 32

DB Schema

DB schema

Directories

Path Synopsis
cmd
Code generated by swaggo/swag.
Code generated by swaggo/swag.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL