Compare commits

...

11 Commits

Author SHA1 Message Date
brian a5f9a887e0 got a JSON response from the database 2026-06-11 21:02:30 -06:00
brian 8d7584ef0b use env file 2026-06-11 19:45:57 -06:00
brian 1da9022cf5 got a basic route going 2026-06-11 19:39:26 -06:00
brian 94c35a9c72 renaming package line 2026-06-11 19:30:18 -06:00
brian 8bb021957f renaming model to be snake case 2026-06-11 19:30:01 -06:00
brian 7d53d3705b renaming model to be snake case 2026-06-11 19:29:55 -06:00
brian a37d8bdd94 stubbed out the models 2026-06-11 19:28:42 -06:00
brian e2745fc366 updated some go packages 2026-06-11 19:28:31 -06:00
brian c0db9a5673 building up the models for a movie 2026-06-03 11:56:07 -06:00
brian 9c5698b83d it listens and says hello 2026-06-03 11:55:56 -06:00
brian 1dbc0a42d9 seed the mongo data 2026-06-03 11:17:43 -06:00
14 changed files with 935 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
DATABASE_URI="mongodb://user:password@localhost:27017/?authSource=admin"
DATABASE_NAME=magic-stream-movies
@@ -0,0 +1,39 @@
package controllers
import (
"context"
"net/http"
"time"
"log"
"github.com/captbrogers/MagicStreamServer/database"
"github.com/captbrogers/MagicStreamServer/models"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
)
var movieCollection *mongo.Collection = database.OpenCollection("movies")
func GetMovies() gin.HandlerFunc {
return func(ginCtx *gin.Context) {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
defer cancel()
var movies []models.Movie
cursor, err := movieCollection.Find(ctx, bson.M{})
if err != nil {
ginCtx.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch movies"})
}
defer cursor.Close(ctx)
if err = cursor.All(ctx, &movies); err != nil {
log.Fatalf("Failed to decode: %v", err)
ginCtx.JSON(http.StatusInternalServerError, gin.H{"error": "failed to decode movies"})
}
ginCtx.JSON(http.StatusOK, movies)
}
}
@@ -0,0 +1,56 @@
package database
import (
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
func Connect() *mongo.Client {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Unable to find or read .env file in db Connect")
}
MongoDb := os.Getenv("DATABASE_URI")
if MongoDb == "" {
log.Fatal("DATABASE_URI not set")
}
fmt.Println("Database URI: ", MongoDb)
clientOptions := options.Client().ApplyURI(MongoDb)
client, err := mongo.Connect(clientOptions)
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
return client
}
var Client *mongo.Client = Connect()
func OpenCollection(collectionName string) *mongo.Collection {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Unable to find or read .env file in OpenCollection")
}
databaseName := os.Getenv("DATABASE_NAME")
if databaseName == "" {
log.Fatal("DATABASE_NAME not set")
}
fmt.Println("Database name: ", databaseName)
collection := Client.Database(databaseName).Collection(collectionName)
if collection == nil {
log.Fatal("Unable to OpenCollection")
return nil
}
return collection
}
+46
View File
@@ -0,0 +1,46 @@
module github.com/captbrogers/MagicStreamServer
go 1.26.4
require (
github.com/gin-gonic/gin v1.12.0
github.com/joho/godotenv v1.5.1
go.mongodb.org/mongo-driver/v2 v2.6.0
)
require (
github.com/bytedance/gopkg v0.1.4 // indirect
github.com/bytedance/sonic v1.15.1 // indirect
github.com/bytedance/sonic/loader v0.5.1 // indirect
github.com/cloudwego/base64x v0.1.7 // indirect
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
github.com/gin-contrib/sse v1.1.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.3 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.3.1 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.2.0 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
golang.org/x/arch v0.27.0 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)
+126
View File
@@ -0,0 +1,126 @@
github.com/bytedance/gopkg v0.1.4 h1:oZnQwnX82KAIWb7033bEwtxvTqXcYMxDBaQxo5JJHWM=
github.com/bytedance/gopkg v0.1.4/go.mod h1:v1zWfPm21Fb+OsyXN2VAHdL6TBb2L88anLQgdyje6R4=
github.com/bytedance/sonic v1.15.1 h1:nJD5PmM0vY7J8CT6MxoqbVAAMhkSmV2HgRAUrrpLoOw=
github.com/bytedance/sonic v1.15.1/go.mod h1:mT2NbXunuaEbnZ+mRIX/vYqKISmgEuHFDI4UzmKx2SA=
github.com/bytedance/sonic/loader v0.5.1 h1:Ygpfa9zwRCCKSlrp5bBP/b/Xzc3VxsAW+5NIYXrOOpI=
github.com/bytedance/sonic/loader v0.5.1/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
github.com/cloudwego/base64x v0.1.7 h1:NppS+Fgzg5ovhn4NkUXaDT3x9jldgH5ToMCqzBSi2zI=
github.com/cloudwego/base64x v0.1.7/go.mod h1:Cu1PV9zfrSf7ET2tIbWbbEy7jO7HHJ13q4X2SQ8aWYg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
github.com/gin-contrib/sse v1.1.1 h1:uGYpNwTacv5R68bSGMapo62iLTRa9l5zxGCps4hK6ko=
github.com/gin-contrib/sse v1.1.1/go.mod h1:QXzuVkA0YO7o/gun03UI1Q+FTI8ZV/n5t03kIQAI89s=
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.30.3 h1:4MU6YkEwx7GbcPJOZxrtbu+QfF3pJLJuaYTeAH0DYy8=
github.com/go-playground/validator/v10 v10.30.3/go.mod h1:4Axh7oCNGcoGkqLoE4YWt6n20mcEIsPRlB7vPk3lpyc=
github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.3.1 h1:MYEvvGnQjeNkRF1qUuGolNtNExTDwct51yp7olPtrEc=
github.com/pelletier/go-toml/v2 v2.3.1/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
github.com/quic-go/quic-go v0.59.1 h1:0Gmua0HW1Tv7ANR7hUYwRyD0MG5OJfgvYSZasGZzBic=
github.com/quic-go/quic-go v0.59.1/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.2.0 h1:bYKF2AEwG5rqd1BumT4gAnvwU/M9nBp2pTSxeZw7Wvs=
github.com/xdg-go/scram v1.2.0/go.mod h1:3dlrS0iBaWKYVt2ZfA4cj48umJZ+cAEbR6/SjLA88I8=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver/v2 v2.6.0 h1:b9sJOYrkmt4l8bY43ZenFBcPlhYIjaOfYHLtbB/5qi8=
go.mongodb.org/mongo-driver/v2 v2.6.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/arch v0.27.0 h1:0WNVcR8u9yFz8j5FvdHpgwNp3FS5U4guYdzHwEiGjoU=
golang.org/x/arch v0.27.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+26
View File
@@ -0,0 +1,26 @@
package main
import (
"fmt"
"log"
controller "github.com/captbrogers/MagicStreamServer/controllers"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.GET("/hello", func(ctx *gin.Context) {
ctx.String(200, "Ahoy matey!")
})
router.GET("/movies", controller.GetMovies())
if err := router.Run(":5180"); err != nil {
log.Fatal("failure to start the server")
}
fmt.Println("listening on port 5180...")
}
+26
View File
@@ -0,0 +1,26 @@
package models
import (
"go.mongodb.org/mongo-driver/v2/bson"
)
type Genre struct {
GenreID int `bson:"genre_id" json:"genre_id" validate:"required"`
GenreName string `bson:"genre_name" json:"genre_name" validate:"required,min=2,max=100"`
}
type Ranking struct {
RankingValue int `bson:"ranking_value" json:"ranking_value" validate:"required"`
RankingName string `bson:"ranking_name" json:"ranking_name" validate:"required"`
}
type Movie struct {
ID bson.ObjectID `bson:"_id" json:"_id"`
ImdbID string `bson:"imdb_id" json:"imdb_id" validate:"required"`
Title string `bson:"title" json:"title" validate:"required,min=2,max=500"`
PosterPath string `bson:"poster_path" json:"poster_path" validate:"required,url"`
YoutubeId string `bson:"youtube_id" json:"youtube_id" validate:"required"`
Genre []Genre `bson:"genre" json:"genre" validate:"required,dive"`
AdminReview string `bson:"admin_review" json:"admin_review" validate:"required"`
Ranking Ranking `bson:"ranking" json:"ranking" validate:"required"`
}
+38
View File
@@ -0,0 +1,38 @@
[
{
"genre_id": 1,
"genre_name": "Comedy"
},
{
"genre_id": 2,
"genre_name": "Drama"
},
{
"genre_id": 3,
"genre_name": "Western"
},
{
"genre_id": 4,
"genre_name": "Fantasy"
},
{
"genre_id": 5,
"genre_name": "Thriller"
},
{
"genre_id": 6,
"genre_name": "Sci-Fi"
},
{
"genre_id": 7,
"genre_name": "Action"
},
{
"genre_id": 8,
"genre_name": "Mystery"
},
{
"genre_id": 9,
"genre_name": "Crime"
}
]
+35
View File
@@ -0,0 +1,35 @@
const { MongoClient } = require('mongodb');
const fs = require('fs');
const url = 'mongodb://root:root@localhost:27017/?authSource=admin';
const dbName = 'magic-stream-movies';
async function importJson(collectionName, jsonFilePath) {
const client = new MongoClient(url);
try {
await client.connect();
console.log('Connected to MongoDB successfully.');
const db = client.db(dbName);
const collection = db.collection(collectionName);
const rawData = fs.readFileSync(jsonFilePath, 'utf-8');
const jsonData = JSON.parse(rawData);
const documents = Array.isArray(jsonData) ? jsonData : [jsonData];
const result = await collection.insertMany(documents);
console.log(`${result.insertedCount} documents successfully imported!`);
} catch (error) {
console.error('An error occurred during the import:', error);
} finally {
await client.close();
}
}
importJson('users', './users.json');
importJson('genres', './genres.json');
importJson('rankings', './rankings.json');
importJson('movies', './movies.json');
+297
View File
@@ -0,0 +1,297 @@
[
{
"imdb_id": "tt0111161",
"title": "The Shawshank Redemption",
"poster_path": "https://image.tmdb.org/t/p/w300/2GgerXCbCMgvt2kLwWEmJWCSG65.jpg",
"youtube_id": "PLl99DlL6b4",
"genre": [
{
"genre_id": 2,
"genre_name": "Drama"
}
],
"admin_review": "I loved the acting in this movie. It was absolutely sublime!",
"ranking": {
"ranking_value": 1,
"ranking_name": "Excellent"
}
},
{
"imdb_id": "tt7131622",
"title": "Once upon a time in Hollywood",
"poster_path": "https://image.tmdb.org/t/p/w300/wQKeS2JrsRF8XSfd9zqflrc5gad.jpg",
"youtube_id": "ELeMaP8EPAA",
"genre": [
{
"genre_id": 2,
"genre_name": "Drama"
},
{
"genre_id": 1,
"genre_name": "Comedy"
}
],
"admin_review": "This movie is awful.",
"ranking": {
"ranking_name": "Terrible",
"ranking_value": 5
}
},
{
"imdb_id": "tt0080339",
"title": "Airplane!",
"poster_path": "https://image.tmdb.org/t/p/w300/zOiB3p2WTTiwCFgTMnXuDGgzbTN.jpg",
"youtube_id": "07pPmCfKi3U",
"genre": [
{
"genre_id": 1,
"genre_name": "Comedy"
}
],
"admin_review": "I didn't love this movie but I didn't hate it either.",
"ranking": {
"ranking_value": 3,
"ranking_name": "Okay"
}
},
{
"imdb_id": "tt1119646",
"title": "The Hangover",
"poster_path": "https://image.tmdb.org/t/p/w300/c15rH9S5JN83UXqu9iM4TQsW6Rl.jpg",
"youtube_id": "jj6wcUes1no",
"genre": [
{
"genre_id": 1,
"genre_name": "Comedy"
}
],
"admin_review": "I didn't love this movie but I didn't hate it either.",
"ranking": {
"ranking_value": 3,
"ranking_name": "Okay"
}
},
{
"imdb_id": "tt0109040",
"title": "Ace Ventura: Pet Detective",
"poster_path": "https://image.tmdb.org/t/p/w300/dukxJWd72ffNWfqfFSVFFuym4RG.jpg",
"youtube_id": "qjBb1CKLpzE",
"genre": [
{
"genre_id": 1,
"genre_name": "Comedy"
}
],
"admin_review": "This is really not so great.",
"ranking": {
"ranking_value": 4,
"ranking_name": "Bad"
}
},
{
"imdb_id": "tt0105695",
"title": "Unforgiven",
"poster_path": "https://image.tmdb.org/t/p/w300/7W0CsZBe5fkX29DvHBi5Ct1WqLe.jpg",
"youtube_id": "6_UlfsdGiEc",
"genre": [
{
"genre_id": 2,
"genre_name": "Drama"
},
{
"genre_id": 3,
"genre_name": "Western"
}
],
"admin_review": "I hate this movie",
"ranking": {
"ranking_value": 5,
"ranking_name": "Terrible\n"
}
},
{
"imdb_id": "tt0060196",
"title": "The Good, The Bad, and the Ugly",
"poster_path": "https://image.tmdb.org/t/p/w300/e881nA7p982CHL5GjI1LICwHMd7.jpg",
"youtube_id": "WCN5JJY_wiA",
"genre": [
{
"genre_id": 3,
"genre_name": "Western"
}
],
"admin_review": "I did not like this!",
"ranking": {
"ranking_value": 4,
"ranking_name": "Bad"
}
},
{
"imdb_id": "tt0903624",
"title": "The Hobbit: An Unexpected Journey",
"poster_path": "https://image.tmdb.org/t/p/w300/vdAGcr1F6wJPRryeODVAcy2mU4z.jpg",
"youtube_id": "9PSXjr1gbjc",
"genre": [
{
"genre_id": 4,
"genre_name": "Fantasy"
}
],
"admin_review": "The movie was aweful! I really hated it.",
"ranking": {
"ranking_value": 5,
"ranking_name": "Terrible"
}
},
{
"imdb_id": "tt0241527",
"title": "Harry Potter and the Philosopher's Stone",
"poster_path": "https://image.tmdb.org/t/p/w300/e6JYlushXIXK85JGfDHEFHrrNYK.jpg",
"youtube_id": "VyHV0BRtdxo",
"genre": [
{
"genre_id": 4,
"genre_name": "Fantasy"
}
],
"admin_review": "This movie wasn't great but it wasn't bad either.",
"ranking": {
"ranking_value": 3,
"ranking_name": "Okay"
}
},
{
"imdb_id": "tt2267998",
"title": "Gone Girl",
"poster_path": "https://image.tmdb.org/t/p/w300/xpA0q0DJWKe7AY63pVPZbGLwuo5.jpg",
"youtube_id": "2-_-1nJf8Vg",
"genre": [
{
"genre_id": 2,
"genre_name": "Drama"
},
{
"genre_id": 4,
"genre_name": "Fantasy"
}
],
"admin_review": "An okay but dark movie.",
"ranking": {
"ranking_value": 3,
"ranking_name": "Okay"
}
},
{
"imdb_id": "tt8946378",
"title": "Knives Out",
"poster_path": "https://image.tmdb.org/t/p/w300/hVcCOlHU0HmGBBQNmS9RlalBXGz.jpg",
"youtube_id": "qGqiHJTsRkQ",
"genre": [
{
"genre_id": 2,
"genre_name": "Drama"
},
{
"genre_id": 5,
"genre_name": "Thriller"
},
{
"genre_id": 8,
"genre_name": "Mystery"
}
],
"admin_review": "The story was fantastic and the acting was sublime!",
"ranking": {
"ranking_value": 1,
"ranking_name": "Excellent"
}
},
{
"imdb_id": "tt0080684",
"title": "Star Wars: The Empire Strikes Back",
"poster_path": "https://image.tmdb.org/t/p/w300/1mh82R1qLKwdutQVGnpHItdwPCP.jpg",
"youtube_id": "JNwNXF9Y6kY",
"genre": [
{
"genre_id": 6,
"genre_name": "Sci-Fi"
},
{
"genre_id": 4,
"genre_name": "Fantasy"
}
],
"admin_review": "This is okay!",
"ranking": {
"ranking_name": "Okay",
"ranking_value": 3
}
},
{
"imdb_id": "tt0102975",
"title": "Star Trek: The Undiscovered Country",
"poster_path": "https://image.tmdb.org/t/p/w300/jukY1tFpuXgqrJLl1PvdOMarCvN.jpg",
"youtube_id": "RYA2q2Sm_Jo",
"genre": [
{
"genre_id": 6,
"genre_name": "Sci-Fi"
},
{
"genre_id": 7,
"genre_name": "Action"
}
],
"admin_review": "It wasn't good but it wasn't too bad either.",
"ranking": {
"ranking_value": 3,
"ranking_name": "Okay"
}
},
{
"imdb_id": "tt1297919",
"title": "Blitz",
"poster_path": "https://image.tmdb.org/t/p/w300/tI4fPu0LZ0FNdZdi6fvYGCRiuQs.jpg",
"youtube_id": "mhO2WJ3MNRI",
"genre": [
{
"genre_id": 9,
"genre_name": "Crime"
},
{
"genre_id": 7,
"genre_name": "Action"
},
{
"genre_id": 5,
"genre_name": "Thriller"
}
],
"admin_review": "This was a lovely movie!",
"ranking": {
"ranking_value": 1,
"ranking_name": "Excellent"
}
},
{
"imdb_id": "tt0790724",
"title": "Jack Reacher",
"poster_path": "https://image.tmdb.org/t/p/w300/8sih1uieUopA9zrEO1meNhmm7aO.jpg",
"youtube_id": "A7FiWkyevqY",
"genre": [
{
"genre_id": 7,
"genre_name": "Action"
},
{
"genre_id": 5,
"genre_name": "Thriller"
}
],
"admin_review": "This might be the worst movie that I have ever seen in my life!",
"ranking": {
"ranking_value": 5,
"ranking_name": "Terrible"
}
}
]
+5
View File
@@ -0,0 +1,5 @@
{
"dependencies": {
"mongodb": "^7.2.0"
}
}
+125
View File
@@ -0,0 +1,125 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
mongodb:
specifier: ^7.2.0
version: 7.2.0
packages:
'@mongodb-js/saslprep@1.4.11':
resolution: {integrity: sha512-o9rAHc0IpIjuPSxRutWpE1F62x7n+4mVS4rCNHkzhIUMQcc18bb6xEq5wd2NdN0WjepIyXIppRshYI2kQDOZVA==}
'@types/webidl-conversions@7.0.3':
resolution: {integrity: sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==}
'@types/whatwg-url@13.0.0':
resolution: {integrity: sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==}
bson@7.2.0:
resolution: {integrity: sha512-YCEo7KjMlbNlyHhz7zAZNDpIpQbd+wOEHJYezv0nMYTn4x31eIUM2yomNNubclAt63dObUzKHWsBLJ9QcZNSnQ==}
engines: {node: '>=20.19.0'}
memory-pager@1.5.0:
resolution: {integrity: sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==}
mongodb-connection-string-url@7.0.1:
resolution: {integrity: sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==}
engines: {node: '>=20.19.0'}
mongodb@7.2.0:
resolution: {integrity: sha512-F/2+BMZtLVhY30ioZp0dAmZ+IRZMBqI+nrv6t5+9/1AIwCa8sMRC3jBf81lpxMhnZgqq8CoUD503Z1oZWq1/sw==}
engines: {node: '>=20.19.0'}
peerDependencies:
'@aws-sdk/credential-providers': ^3.806.0
'@mongodb-js/zstd': ^7.0.0
gcp-metadata: ^7.0.1
kerberos: ^7.0.0
mongodb-client-encryption: '>=7.0.0 <7.1.0'
snappy: ^7.3.2
socks: ^2.8.6
peerDependenciesMeta:
'@aws-sdk/credential-providers':
optional: true
'@mongodb-js/zstd':
optional: true
gcp-metadata:
optional: true
kerberos:
optional: true
mongodb-client-encryption:
optional: true
snappy:
optional: true
socks:
optional: true
punycode@2.3.1:
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
engines: {node: '>=6'}
sparse-bitfield@3.0.3:
resolution: {integrity: sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==}
tr46@5.1.1:
resolution: {integrity: sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==}
engines: {node: '>=18'}
webidl-conversions@7.0.0:
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
engines: {node: '>=12'}
whatwg-url@14.2.0:
resolution: {integrity: sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==}
engines: {node: '>=18'}
snapshots:
'@mongodb-js/saslprep@1.4.11':
dependencies:
sparse-bitfield: 3.0.3
'@types/webidl-conversions@7.0.3': {}
'@types/whatwg-url@13.0.0':
dependencies:
'@types/webidl-conversions': 7.0.3
bson@7.2.0: {}
memory-pager@1.5.0: {}
mongodb-connection-string-url@7.0.1:
dependencies:
'@types/whatwg-url': 13.0.0
whatwg-url: 14.2.0
mongodb@7.2.0:
dependencies:
'@mongodb-js/saslprep': 1.4.11
bson: 7.2.0
mongodb-connection-string-url: 7.0.1
punycode@2.3.1: {}
sparse-bitfield@3.0.3:
dependencies:
memory-pager: 1.5.0
tr46@5.1.1:
dependencies:
punycode: 2.3.1
webidl-conversions@7.0.0: {}
whatwg-url@14.2.0:
dependencies:
tr46: 5.1.1
webidl-conversions: 7.0.0
+26
View File
@@ -0,0 +1,26 @@
[
{
"ranking_value": 999,
"ranking_name": "Not_Ranked"
},
{
"ranking_value": 1,
"ranking_name": "Excellent"
},
{
"ranking_value": 2,
"ranking_name": "Good"
},
{
"ranking_value": 3,
"ranking_name": "Okay"
},
{
"ranking_value": 4,
"ranking_name": "Bad"
},
{
"ranking_value": 5,
"ranking_name": "Terrible"
}
]
+88
View File
@@ -0,0 +1,88 @@
[
{
"user_id": "68385b9981097c6b4042dab4",
"first_name": "Bob",
"last_name": "Jones",
"email": "bobjones@hotmail.com",
"password": "$2a$10$FAd/ArLwxQ3WbNE3XKbyveRHidTpW9g84hX2CPr0tWdGGerrP6.3K",
"role": "ADMIN",
"created_at": {
"$date": "2025-05-29T13:05:29.000Z"
},
"updated_at": {
"$date": "2025-05-29T13:06:51.000Z"
},
"token": "",
"refresh_token": "",
"favourite_genres": [
{
"genre_id": 1,
"genre_name": "Comedy"
},
{
"genre_id": 4,
"genre_name": "Fantasy"
}
]
},
{
"user_id": "684535a8c3d7e6b4ac1c5203",
"first_name": "Sarah",
"last_name": "Smith",
"email": "sarahsmith@hotmail.com",
"password": "$2a$10$w0H8AI/xigWiq0hGsjyfqeWAR5d6oErWE4b7sz9uwCTKMwRIv49YW",
"role": "USER",
"created_at": {
"$date": "2025-06-08T07:03:04.865Z"
},
"updated_at": {
"$date": "2025-06-23T09:26:11.000Z"
},
"token": "",
"refresh_token": "",
"favourite_genres": [
{
"genre_id": 5,
"genre_name": "Thriller"
},
{
"genre_id": 6,
"genre_name": "Sci-fi"
},
{
"genre_id": 8,
"genre_name": "Mystery"
}
]
},
{
"user_id": "68512bc5a29d3bfe81637e3f",
"first_name": "Ben",
"last_name": "Madison",
"email": "benmadison@hotmail.com",
"password": "$2a$10$0rCBUYy4ZlTzuxcf20XV1.s7UVTbtkXkARQmzb3vstja4uDnp.NS.",
"role": "USER",
"created_at": {
"$date": "2025-06-17T08:48:05.649Z"
},
"updated_at": {
"$date": "2025-06-17T08:48:05.649Z"
},
"token": "",
"refresh_token": "",
"favourite_genres": [
{
"genre_id": 1,
"genre_name": "Comedy"
},
{
"genre_id": 5,
"genre_name": "Thriller"
},
{
"genre_id": 6,
"genre_name": "Sci-Fi"
}
]
}
]