Code Monkey home page Code Monkey logo

movie-crud-apis's Introduction

Movie CRUD API in Golang

This Go application implements a simple CRUD (Create, Read, Update, Delete) API for managing a movie watchlist using MongoDB. The API provides endpoints for retrieving all movies, adding a new movie, marking a movie as watched, deleting a specific movie, and deleting all movies.

How to Run

  1. Ensure you have Go installed on your machine.
  2. Clone this repository.
  3. Replace the MongoDB connection string in the code with your actual connection string.
  4. Run the application using the go run main.go command.

Routes and Functions

  1. GET /api/movies

    • Function: GetMyAllMovies
    • Description: Retrieve all movies from the watchlist.
    • Usage: GET /api/movies
  2. POST /api/movie

    • Function: CreateMovie
    • Description: Add a new movie to the watchlist.
    • Usage: POST /api/movie
    • Request Body Format: JSON with movie details.
  3. PUT /api/movies/{id}

    • Function: MarkAsWatched
    • Description: Mark a specific movie as watched.
    • Usage: PUT /api/movies/{id}
    • Path Parameter: id (MongoDB ObjectID of the movie)
  4. DELETE /api/movies/{id}

    • Function: DeleteAMovie
    • Description: Delete a specific movie from the watchlist.
    • Usage: DELETE /api/movies/{id}
    • Path Parameter: id (MongoDB ObjectID of the movie)
  5. DELETE /api/deleteallmovies

    • Function: DeleteAllMovies
    • Description: Delete all movies from the watchlist.
    • Usage: DELETE /api/deleteallmovies

MongoDB Setup

The application uses MongoDB as the database for storing movie records.

  • Connection String: Replace "xyz" in the connectionString constant with your MongoDB connection string.
  • Database Name: The database name is set to "netflix".
  • Collection Name: The collection name is set to "watchlist".

MongoDB Helper Functions

  • insertOneMovie(movie model.Netflix)

    • Inserts a single movie record into the MongoDB collection.
  • getAllMovies() []primitive.M

    • Retrieves all movies from the MongoDB collection.
  • updateOneMovie(movieId string)

    • Marks a specific movie as watched in the MongoDB collection.
  • deleteOneMovie(movieId string)

    • Deletes a specific movie from the MongoDB collection.
  • deleteAll() int64

    • Deletes all movies from the MongoDB collection.

movie-crud-apis's People

Contributors

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