Giter Club home page Giter Club logo

go-crud's Introduction

GoLang Movies Rest-API

API handles the following request

* Register user accepting email id, name, date of birth
* List all User and get a user by its email_id.
* Update User name and date of birth by email.
* Add movies in the movies table accepting Movies_title
* Get movie by ID.
* Add a list of movies the user has watched.
* Delete a movie from a list of movies of a user.
* List all the movies the user has watched.

Setup Environment Variables

  • Setup the your postgres database string in .env file.

  • Set the PORT variable.

Install Dependencies

  • go mod tidy

Start the Server

Use the follwing command to run the server.

  • go run migrate/migrate.go (Auto migrate feature of gorm to create user, movies and Many to Many relationship table user_movies)
  • CompileDaemon -command="./go-crud" (Start listening on the PORT)

Models

  • model/movieModel.go has following schema

type Movie struct {

Movie_id    int     `gorm:"primaryKey;autoIncrement;not null"`
Movie_title string  `gorm:"not null"`
Users       []*User `gorm:"many2many:user_movies;"`
}
  • model/userModel.go has following schema

type User struct {

Email       string `gorm:"primaryKey;not null"`
Name        string `gorm:"not null"`
DateOfBirth time.Time
Movies      []*Movie `gorm:"many2many:user_movies;"`
}

Authors

go-crud's People

Contributors

anuragpor 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.