Compare commits
9
Commits
61330f8036
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c98e7c526
|
||
|
|
a3e56ba3ad
|
||
|
|
7a04bdb2aa
|
||
|
|
808c416471
|
||
|
|
351affe570
|
||
|
|
111c107474
|
||
|
|
4501133b5c
|
||
|
|
d4b46c93e0
|
||
|
|
d5167fae21
|
@@ -9,12 +9,15 @@ import (
|
|||||||
"github.com/captbrogers/MagicStreamServer/models"
|
"github.com/captbrogers/MagicStreamServer/models"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var movieCollection *mongo.Collection = database.OpenCollection("movies")
|
var movieCollection *mongo.Collection = database.OpenCollection("movies")
|
||||||
|
|
||||||
|
var validate = validator.New()
|
||||||
|
|
||||||
func GetMovies() gin.HandlerFunc {
|
func GetMovies() gin.HandlerFunc {
|
||||||
return func(ginCtx *gin.Context) {
|
return func(ginCtx *gin.Context) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
@@ -61,7 +64,7 @@ func GetMovie() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddMovie() gin.HandlersChain {
|
func AddMovie() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -72,5 +75,18 @@ func AddMovie() gin.HandlersChain {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := validate.Struct(movie); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Validation failed when binding struct", "details": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := movieCollection.InsertOne(ctx, movie)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to insert the movie"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusCreated, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
module github.com/captbrogers/MagicStreamServer
|
module github.com/captbrogers/MagicStreamServer
|
||||||
|
|
||||||
go 1.26.4
|
go 1.26.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.12.0
|
github.com/gin-gonic/gin v1.12.0
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ func main() {
|
|||||||
|
|
||||||
router.GET("/movie/:imdb_id", controller.GetMovie())
|
router.GET("/movie/:imdb_id", controller.GetMovie())
|
||||||
|
|
||||||
|
router.POST("/movie", controller.AddMovie())
|
||||||
|
|
||||||
if err := router.Run(":5180"); err != nil {
|
if err := router.Run(":5180"); err != nil {
|
||||||
log.Fatal("failure to start the server")
|
log.Fatal("failure to start the server")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ type Ranking struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Movie struct {
|
type Movie struct {
|
||||||
ID bson.ObjectID `bson:"_id" json:"_id"`
|
ID bson.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
|
||||||
ImdbID string `bson:"imdb_id" json:"imdb_id" validate:"required"`
|
ImdbID string `bson:"imdb_id" json:"imdb_id" validate:"required"`
|
||||||
|
ReleaseYear int `bson:"release_year" json:"release_year" validate:"required"` // how to get this to be a numeric value that is four digits starting with 19?
|
||||||
Title string `bson:"title" json:"title" validate:"required,min=2,max=500"`
|
Title string `bson:"title" json:"title" validate:"required,min=2,max=500"`
|
||||||
PosterPath string `bson:"poster_path" json:"poster_path" validate:"required,url"`
|
PosterPath string `bson:"poster_path" json:"poster_path" validate:"required,url"`
|
||||||
YoutubeId string `bson:"youtube_id" json:"youtube_id" validate:"required"`
|
YoutubeId string `bson:"youtube_id" json:"youtube_id" validate:"required"`
|
||||||
Genre []Genre `bson:"genre" json:"genre" validate:"required,dive"`
|
Genre []Genre `bson:"genre" json:"genre" validate:"required,dive"`
|
||||||
AdminReview string `bson:"admin_review" json:"admin_review" validate:"required"`
|
AdminReview string `bson:"admin_review" json:"admin_review"`
|
||||||
Ranking Ranking `bson:"ranking" json:"ranking" validate:"required"`
|
Ranking Ranking `bson:"ranking" json:"ranking" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0111161",
|
"imdb_id": "tt0111161",
|
||||||
"title": "The Shawshank Redemption",
|
"title": "The Shawshank Redemption",
|
||||||
|
"release_year": 1994,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/2GgerXCbCMgvt2kLwWEmJWCSG65.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/2GgerXCbCMgvt2kLwWEmJWCSG65.jpg",
|
||||||
"youtube_id": "PLl99DlL6b4",
|
"youtube_id": "PLl99DlL6b4",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt7131622",
|
"imdb_id": "tt7131622",
|
||||||
"title": "Once upon a time in Hollywood",
|
"title": "Once upon a time in Hollywood",
|
||||||
|
"release_year": 2019,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/wQKeS2JrsRF8XSfd9zqflrc5gad.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/wQKeS2JrsRF8XSfd9zqflrc5gad.jpg",
|
||||||
"youtube_id": "ELeMaP8EPAA",
|
"youtube_id": "ELeMaP8EPAA",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -40,6 +42,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0080339",
|
"imdb_id": "tt0080339",
|
||||||
"title": "Airplane!",
|
"title": "Airplane!",
|
||||||
|
"release_year": 1980,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/zOiB3p2WTTiwCFgTMnXuDGgzbTN.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/zOiB3p2WTTiwCFgTMnXuDGgzbTN.jpg",
|
||||||
"youtube_id": "07pPmCfKi3U",
|
"youtube_id": "07pPmCfKi3U",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -57,6 +60,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt1119646",
|
"imdb_id": "tt1119646",
|
||||||
"title": "The Hangover",
|
"title": "The Hangover",
|
||||||
|
"release_year": 2009,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/c15rH9S5JN83UXqu9iM4TQsW6Rl.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/c15rH9S5JN83UXqu9iM4TQsW6Rl.jpg",
|
||||||
"youtube_id": "jj6wcUes1no",
|
"youtube_id": "jj6wcUes1no",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -74,6 +78,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0109040",
|
"imdb_id": "tt0109040",
|
||||||
"title": "Ace Ventura: Pet Detective",
|
"title": "Ace Ventura: Pet Detective",
|
||||||
|
"release_year": 1994,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/dukxJWd72ffNWfqfFSVFFuym4RG.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/dukxJWd72ffNWfqfFSVFFuym4RG.jpg",
|
||||||
"youtube_id": "qjBb1CKLpzE",
|
"youtube_id": "qjBb1CKLpzE",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -91,6 +96,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0105695",
|
"imdb_id": "tt0105695",
|
||||||
"title": "Unforgiven",
|
"title": "Unforgiven",
|
||||||
|
"release_year": 1992,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/7W0CsZBe5fkX29DvHBi5Ct1WqLe.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/7W0CsZBe5fkX29DvHBi5Ct1WqLe.jpg",
|
||||||
"youtube_id": "6_UlfsdGiEc",
|
"youtube_id": "6_UlfsdGiEc",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -112,6 +118,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0060196",
|
"imdb_id": "tt0060196",
|
||||||
"title": "The Good, The Bad, and the Ugly",
|
"title": "The Good, The Bad, and the Ugly",
|
||||||
|
"release_year": 1966,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/e881nA7p982CHL5GjI1LICwHMd7.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/e881nA7p982CHL5GjI1LICwHMd7.jpg",
|
||||||
"youtube_id": "WCN5JJY_wiA",
|
"youtube_id": "WCN5JJY_wiA",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -129,6 +136,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0903624",
|
"imdb_id": "tt0903624",
|
||||||
"title": "The Hobbit: An Unexpected Journey",
|
"title": "The Hobbit: An Unexpected Journey",
|
||||||
|
"release_year": 2012,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/vdAGcr1F6wJPRryeODVAcy2mU4z.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/vdAGcr1F6wJPRryeODVAcy2mU4z.jpg",
|
||||||
"youtube_id": "9PSXjr1gbjc",
|
"youtube_id": "9PSXjr1gbjc",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -146,6 +154,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0241527",
|
"imdb_id": "tt0241527",
|
||||||
"title": "Harry Potter and the Philosopher's Stone",
|
"title": "Harry Potter and the Philosopher's Stone",
|
||||||
|
"release_year": 2001,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/e6JYlushXIXK85JGfDHEFHrrNYK.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/e6JYlushXIXK85JGfDHEFHrrNYK.jpg",
|
||||||
"youtube_id": "VyHV0BRtdxo",
|
"youtube_id": "VyHV0BRtdxo",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -163,6 +172,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt2267998",
|
"imdb_id": "tt2267998",
|
||||||
"title": "Gone Girl",
|
"title": "Gone Girl",
|
||||||
|
"release_year": 2014,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/xpA0q0DJWKe7AY63pVPZbGLwuo5.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/xpA0q0DJWKe7AY63pVPZbGLwuo5.jpg",
|
||||||
"youtube_id": "2-_-1nJf8Vg",
|
"youtube_id": "2-_-1nJf8Vg",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -184,6 +194,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt8946378",
|
"imdb_id": "tt8946378",
|
||||||
"title": "Knives Out",
|
"title": "Knives Out",
|
||||||
|
"release_year": 2019,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/hVcCOlHU0HmGBBQNmS9RlalBXGz.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/hVcCOlHU0HmGBBQNmS9RlalBXGz.jpg",
|
||||||
"youtube_id": "qGqiHJTsRkQ",
|
"youtube_id": "qGqiHJTsRkQ",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -209,6 +220,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0080684",
|
"imdb_id": "tt0080684",
|
||||||
"title": "Star Wars: The Empire Strikes Back",
|
"title": "Star Wars: The Empire Strikes Back",
|
||||||
|
"release_year": 1980,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/1mh82R1qLKwdutQVGnpHItdwPCP.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/1mh82R1qLKwdutQVGnpHItdwPCP.jpg",
|
||||||
"youtube_id": "JNwNXF9Y6kY",
|
"youtube_id": "JNwNXF9Y6kY",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -230,6 +242,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0102975",
|
"imdb_id": "tt0102975",
|
||||||
"title": "Star Trek: The Undiscovered Country",
|
"title": "Star Trek: The Undiscovered Country",
|
||||||
|
"release_year": 1991,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/jukY1tFpuXgqrJLl1PvdOMarCvN.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/jukY1tFpuXgqrJLl1PvdOMarCvN.jpg",
|
||||||
"youtube_id": "RYA2q2Sm_Jo",
|
"youtube_id": "RYA2q2Sm_Jo",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -251,6 +264,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt1297919",
|
"imdb_id": "tt1297919",
|
||||||
"title": "Blitz",
|
"title": "Blitz",
|
||||||
|
"release_year": 2011,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/tI4fPu0LZ0FNdZdi6fvYGCRiuQs.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/tI4fPu0LZ0FNdZdi6fvYGCRiuQs.jpg",
|
||||||
"youtube_id": "mhO2WJ3MNRI",
|
"youtube_id": "mhO2WJ3MNRI",
|
||||||
"genre": [
|
"genre": [
|
||||||
@@ -276,6 +290,7 @@
|
|||||||
{
|
{
|
||||||
"imdb_id": "tt0790724",
|
"imdb_id": "tt0790724",
|
||||||
"title": "Jack Reacher",
|
"title": "Jack Reacher",
|
||||||
|
"release_year": 2012,
|
||||||
"poster_path": "https://image.tmdb.org/t/p/w300/8sih1uieUopA9zrEO1meNhmm7aO.jpg",
|
"poster_path": "https://image.tmdb.org/t/p/w300/8sih1uieUopA9zrEO1meNhmm7aO.jpg",
|
||||||
"youtube_id": "A7FiWkyevqY",
|
"youtube_id": "A7FiWkyevqY",
|
||||||
"genre": [
|
"genre": [
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"imdb_id": "tt0240468",
|
||||||
|
"title": "Kung Pow! Enter the Fist",
|
||||||
|
"release_year": 2002,
|
||||||
|
"poster_path": "https://www.themoviedb.org/t/p/w600_and_h900_face/gVsZ1hsJ9g11oCCav4N8ccp9bRw.jpg",
|
||||||
|
"youtube_id": "yieQoIEPenM",
|
||||||
|
"admin_review": "An amazing movie!",
|
||||||
|
"genre": [
|
||||||
|
{
|
||||||
|
"genre_id": 1,
|
||||||
|
"genre_name": "Comedy"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"genre_id": 7,
|
||||||
|
"genre_name": "Action"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ranking": {
|
||||||
|
"ranking_value": 1,
|
||||||
|
"ranking_name": "Excellent"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user