movieginmongoapi

command module
v0.0.0-...-48705a9 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 12 Imported by: 0

README

Movie Theater Backend API

This repository contains the backend API for a movie theater application.

The application manages movie schedules and movie details, and also offers the ability to make online reservations for tickets.

The backend is developed using the Go programming language (version go1.22.4) with the Gin framework and MongoDB as the database.

Features

  • Manage movie schedules and details
  • Online ticket reservations
  • User authentication and authorization
  • Secure API endpoints with JWT and PASETO access tokens
  • Configuration management using Viper
  • Robust unit tests with Testify
  • Mocking database interactions for testing

Technology Stack

  • using go1.22
  • using gin-gonic v1.10.0 web framework
  • using viper as a configuration solution
  • using mongo-db as NoSQL DB
  • using jwt-go to provide an implementation of JWT
  • using x/crypto, Go Cryptography package
  • using testify, for write robust unit tests
  • using Gomock for mocking database

Getting Started

Prerequisites
  • Go (version go1.22.4 or higher)
  • MongoDB
  • Git
Installation
  1. Clone the repository:
git clone https://github.com/yourusername/movietheater-backend.git
cd movietheater-backend
  1. Install dependencies:
go mod download
  1. Install MongoDB

Instructions for installation are https://www.mongodb.com/docs/manual/installation/

  1. Set up environment variables

Create a .env file in the root directory of the project and add the necessary configuration variables.

TOKEN_SYMMETRIC_KEY=your_jwt_secret
ACCESS_TOKEN_DURATION=15m
REFRESH_TOKEN_DURATION=24h
HTTP_SERVER_ADDRESS=0.0.0.0:8080
MONGO_URL=mongodb://localhost:27017
USERNAME=db_username
PASSWORD=db_password
DATABASE=db_name
JWT_SECRET=your_jwt_secret
  1. Start local MongoDB with replica sets:

Create folder data and 3 subfolders: rs0-0, rs0-1, rs0-2. Inside the mongosh shell, run the following command:

rs.initiate({
  _id: "rs0",
  members: [
    { _id: 0, host: "localhost:27017" }
  ]
});

After initiating the replica set, add the other members:

rs.add("localhost:27018");
rs.add("localhost:27019");
rs.status();

Running the Application

  1. Start MongoDB:

Open separate command prompt windows (or other shells) and run the following commands to start each replica set:

mongod --port 27017 --dbpath folder_path\data\rs0-0 --replSet rs0
mongod --port 27018 --dbpath folder_path\data\rs0-1 --replSet rs0
mongod --port 27019 --dbpath folder_path\data\rs0-2 --replSet rs0

In another command prompt, connect to the first MongoDB instance and initiate the replica set:

mongosh --port 27017
  1. Run the server:
go run main.go
  1. Access the API:

The API will be available at http://localhost:8080

Running Tests

To run tests, use the following command:

go test ./...

This will run all the tests in the project, including unit tests with mocked database interactions.

API Documentation

Detailed documentation and descriptions of the API endpoints are available at:

http://localhost:8080/swagger/index.html

QR Code for GitHub Repository

QR Code

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
api
db
mock
Package mockdb is a generated GoMock package.
Package mockdb is a generated GoMock package.
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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