muhammedikinci / scaleapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Scaleflix

Movie and Series API Project With Golang

Table of Contents
  1. Getting Started
  2. API Reference
  3. Test
  4. Contact

Getting Started

Prerequisites

  • Golang
  • Docker

Installation

  1. Clone the repo
    git clone https://github.com/muhammedikinci/scaleapi
    cd ./scaleapi
  2. Run docker compose file (with data)
    docker compose -p "scaleflix_with_data" -f .\docker-compose.crawler.yml up
  • API and Crawler can be restarted many times until database is ready to accept the connection

    restart: on-failure
  • Crawler project will terminate automatically after writing all movies and series that get from other APIs to the database

  • Crawler will add admin user to database, credentials: muhammed:1234

  • If you want to start the project without Crawler, you can use the base docker-compose file in the project

    docker compose -p "scaleflix_without_data" -f .\docker-compose.yml up

Installation Without Docker

This action needs the installation of PostgreSQL manually.

  1. Clone the repo

    git clone https://github.com/muhammedikinci/scaleapi
    cd ./scaleapi
  2. Install Go dependencies

    go mod download
  3. Start PostgreSQL Service and Create scaleflix database

  4. Start API without build

    go run ./cmd/server/.
  5. Start crawler without build

    go run ./cmd/crawler/.

API Reference

POST /register

curl --request POST \
  --url http://localhost:8080/register \
  --header 'Content-Type: application/json' \
  --data '{
	"username":"muhammed",
	"password":"1234"
    }'

POST /login

curl --request POST \
  --url http://localhost:8080/login \
  --header 'Content-Type: application/json' \
  --data '{
	"username":"muhammed",
	"password":"1234"
    }'

GET /movies

curl --request GET \
  --url http://localhost:8080/movies \
  --header 'Authorization: Bearer {{TOKEN}}' \
  --header 'Content-Type: application/json'
  • GET /movies/:id
  • GET /movies/filter?title={{title}}&genre={{genre}}

POST /movies (ADMIN REQUIRED)

curl --request POST \
  --url http://localhost:8080/movies \
  --header 'Authorization: Bearer {{TOKEN}}' \
  --header 'Content-Type: application/json' \
  --data '{
		"title": "Edge of Tomorrow",
		"image": "https://m.media-amazon.com/images/M/MV5BMTc5OTk4MTM3M15BMl5BanBnXkFtZTgwODcxNjg3MDE@._V1_SX300.jpg",
		"description": "A soldier fighting aliens gets to relive the same day over and over again, the day restarting every time he dies.",
		"rating": 7.9,
		"release_date": "06 Jun 2014",
		"director": "Doug Liman",
		"writer": "Christopher McQuarrie, Jez Butterworth, John-Henry Butterworth",
		"stars": "Tom Cruise, Emily Blunt, Bill Paxton",
		"duration": "113 min",
		"imdb_id": "tt1631867",
		"year": 2014,
		"genre": "Action, Adventure, Sci-Fi"
	}'

GET /series

curl --request GET \
  --url http://localhost:8080/series \
  --header 'Authorization: Bearer {{TOKEN}}' \
  --header 'Content-Type: application/json'
  • GET /series/:id
  • GET /series/:id/seasons
  • GET /series/:id/seasons/:season_id
  • GET /series/filter?title={{title}}&genre={{genre}}

POST /series (ADMIN REQUIRED)

curl --request POST \
  --url http://localhost:8080/series \
  --header 'Authorization: Bearer {{TOKEN}}' \
  --header 'Content-Type: application/json' \
  --data '{
	"title": "Under the Dome",
	"image": "https://static.tvmaze.com/uploads/images/original_untouched/81/202627.jpg",
	"description": "<p><b>Under the Dome</b> is the story of a small town that is suddenly and inexplicably sealed off from the rest of the world by an enormous transparent dome. The town'\''s inhabitants must deal with surviving the post-apocalyptic conditions while searching for answers about the dome, where it came from and if and when it will go away.</p>",
	"rating": 6.5,
	"release_date": "2013-06-24",
	"director": "",
	"writer": "",
	"stars": "",
	"imdb_id": "tt1553656",
	"year": 0,
	"genre": "Drama,Science-Fiction,Thriller"
    }'

POST /favorite_movie/:id

curl --request POST \
  --url http://localhost:8080/favorite_movie/{{movie_id}} \
  --header 'Authorization: Bearer {{TOKEN}}'

POST /favorite_serie/:id

curl --request POST \
  --url http://localhost:8080/favorite_serie/{{serie_id}} \
  --header 'Authorization: Bearer {{TOKEN}}'

GET /favorites

curl --request GET \
  --url http://localhost:8080/favorites \
  --header 'Authorization: Bearer {{TOKEN}}'

GET /favorites/filter?title={{}}&genre={{}}

curl --request GET \
  --url http://localhost:8080/favorite/filter?title={{}}&genre={{}} \
  --header 'Authorization: Bearer {{TOKEN}}'

Test

go test ./...

Contact

Muhammed İKİNCİ - muhammedikinci@outlook.com

About


Languages

Language:Go 99.5%Language:Dockerfile 0.5%