{"id":30797072,"url":"https://github.com/gharib-uk/movie-database","last_synced_at":"2025-09-05T17:13:06.489Z","repository":{"id":144486787,"uuid":"388120785","full_name":"gharib-uk/movie-database","owner":"gharib-uk","description":"A Rest-API with Go and React for managing and showing movies","archived":false,"fork":false,"pushed_at":"2021-08-22T08:52:13.000Z","size":418,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T16:46:32.068Z","etag":null,"topics":["database","golang-application","golang-examples","movie-database"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gharib-uk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-21T13:10:30.000Z","updated_at":"2024-11-13T14:51:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"2698b41f-c45c-4f2a-ad62-66cc33f39e07","html_url":"https://github.com/gharib-uk/movie-database","commit_stats":null,"previous_names":["gharib-uk/movie-database"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gharib-uk/movie-database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gharib-uk%2Fmovie-database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gharib-uk%2Fmovie-database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gharib-uk%2Fmovie-database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gharib-uk%2Fmovie-database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gharib-uk","download_url":"https://codeload.github.com/gharib-uk/movie-database/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gharib-uk%2Fmovie-database/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273790385,"owners_count":25168669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","golang-application","golang-examples","movie-database"],"created_at":"2025-09-05T17:12:58.103Z","updated_at":"2025-09-05T17:13:06.481Z","avatar_url":"https://github.com/gharib-uk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# movie-database\nA Rest-API for managing a website for showing their associated information.\nActually, Everything is same as my Booking Management System except for GraphQL and bcrypt pkg for hashing passwords.\n\n## GraphQL in Golang\n- First I implement my GraphQL schema definition.\n- Second I define movieType.\n- Third with ``` moviesGraphQL ``` function take the response to the user.\n\u003cbr\u003e\n\n```go\n// GraphQL Schema Definition\nvar fields = graphql.Fields{\n\t\"movie\": \u0026graphql.Field{\n\t\tType:        movieType,\n\t\tDescription: \"Get movie by id\",\n\t\tArgs: graphql.FieldConfigArgument{\n\t\t\t\"id\": \u0026graphql.ArgumentConfig{\n\t\t\t\tType: graphql.Int,\n\t\t\t},\n\t\t},\n\t\tResolve: func(p graphql.ResolveParams) (interface{}, error) {\n\t\t\tid, ok := p.Args[\"id\"].(int)\n\t\t\tif ok {\n\t\t\t\tfor _, movie := range movies {\n\t\t\t\t\tif movie.ID == id {\n\t\t\t\t\t\treturn movie, nil\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil, nil\n\t\t},\n\t},\n\t\"list\": \u0026graphql.Field{\n\t\tType:        graphql.NewList(movieType),\n\t\tDescription: \"Get all movies\",\n\t\tResolve: func(params graphql.ResolveParams) (interface{}, error) {\n\t\t\treturn movies, nil\n\t\t},\n\t},\n\t\"search\": \u0026graphql.Field{\n\t\tType:        graphql.NewList(movieType),\n\t\tDescription: \"Search movies by title\",\n\t\tArgs: graphql.FieldConfigArgument{\n\t\t\t\"titleContains\": \u0026graphql.ArgumentConfig{\n\t\t\t\tType: graphql.String,\n\t\t\t},\n\t\t},\n\t\tResolve: func(params graphql.ResolveParams) (interface{}, error) {\n\t\t\tvar theList []*models.Movie\n\t\t\tsearch, ok := params.Args[\"titleContains\"].(string)\n\t\t\tif ok {\n\t\t\t\tfor _, currentMovie := range movies {\n\t\t\t\t\tif strings.Contains(currentMovie.Title, search) {\n\t\t\t\t\t\tlog.Println(\"Found one\")\n\t\t\t\t\t\ttheList = append(theList, currentMovie)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn theList, nil\n\t\t},\n\t},\n}\n\n```\n\u003cbr\u003e\n\n```go\n// GraphQL object definition\nvar movieType = graphql.NewObject(\n\tgraphql.ObjectConfig{\n\t\tName: \"Movie\",\n\t\tFields: graphql.Fields{\n\t\t\t\"id\": \u0026graphql.Field{\n\t\t\t\tType: graphql.Int,\n\t\t\t},\n\t\t\t\"title\": \u0026graphql.Field{\n\t\t\t\tType: graphql.String,\n\t\t\t},\n\t\t\t\"description\": \u0026graphql.Field{\n\t\t\t\tType: graphql.String,\n\t\t\t},\n\t\t\t\"year\": \u0026graphql.Field{\n\t\t\t\tType: graphql.Int,\n\t\t\t},\n\t\t\t\"release_date\": \u0026graphql.Field{\n\t\t\t\tType: graphql.DateTime,\n\t\t\t},\n\t\t\t\"runtime\": \u0026graphql.Field{\n\t\t\t\tType: graphql.Int,\n\t\t\t},\n\t\t\t\"rating\": \u0026graphql.Field{\n\t\t\t\tType: graphql.Int,\n\t\t\t},\n\t\t\t\"mpaa_rating\": \u0026graphql.Field{\n\t\t\t\tType: graphql.String,\n\t\t\t},\n\t\t\t\"created_at\": \u0026graphql.Field{\n\t\t\t\tType: graphql.DateTime,\n\t\t\t},\n\t\t\t\"updated_at\": \u0026graphql.Field{\n\t\t\t\tType: graphql.DateTime,\n\t\t\t},\n\t\t},\n\t},\n)\n```\n\u003cbr\u003e\n\n```go\nfunc (app *Application) moviesGraphQL(w http.ResponseWriter, r *http.Request) {\n\tmovies, _ = app.models.DB.GetAll()\n\n\tq, err := io.ReadAll(r.Body)\n\tif err != nil {\n\t\tzerolog.Error().Msg(err.Error())\n\t\tw.Write([]byte(err.Error()))\n\t\treturn\n\t}\n\tquery := string(q)\n\n\tlog.Println(query)\n\n\trootQuery := graphql.ObjectConfig{Name: \"RootQuery\", Fields: fields}\n\tschemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}\n\tschema, err := graphql.NewSchema(schemaConfig)\n\tif err != nil {\n\t\thttp.Error(w, \"Failed to create graphql schema\", http.StatusInternalServerError)\n\t\tzerolog.Error().Msg(err.Error())\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\n\tparams := graphql.Params{Schema: schema, RequestString: query}\n\tresp := graphql.Do(params)\n\tif len(resp.Errors) \u003e 0 {\n\t\thttp.Error(w, fmt.Sprintf(\"failed: %+v\", resp.Errors), http.StatusInternalServerError)\n\t\tzerolog.Error().Msg(fmt.Sprintf(\"failed: %+v\", resp.Errors))\n\t\treturn\n\t}\n\n\tj, _ := json.MarshalIndent(resp, \"\", \"  \")\n\tw.Header().Set(\"Content-Type\", \"application/json\")\n\tw.WriteHeader(http.StatusOK)\n\tw.Write(j)\n\n\treturn\n}\n```\n\u003cbr\u003e\n\n***\n\n## Hashing Passwords\nUse bcrypt ``` golang.org/x/crypto/bcrypt ``` pkg for hashing passwords alternatively you can use scrypt pkg for using more strong ``` golang.org/x/crypto/scrypt ``` hashing algorithms.\n\n- First I use ``` createHashPassword ``` for hashing passwords.\n- Second I use this function for comparing hash and password ``` compareHashAndPass ```.\n- Third we have minCost, DefaultCost, MaxCost for specify the cost for hashing use them for your purposes.\n\n```go\nfunc createHashPassword(pass string) (string, error) {\n\thashPass, err := bcrypt.GenerateFromPassword([]byte(pass), 12)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn string(hashPass), err\n}\n\nfunc compareHashAndPass(hashPass string, pass string) error {\n\terr := bcrypt.CompareHashAndPassword([]byte(hashPass), []byte(pass))\n\tif err != nil {\n\t\treturn bcrypt.ErrMismatchedHashAndPassword\n\t}\n\n\treturn nil\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgharib-uk%2Fmovie-database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgharib-uk%2Fmovie-database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgharib-uk%2Fmovie-database/lists"}