{"id":15100951,"url":"https://github.com/theguptaji/bookstore_users-api","last_synced_at":"2026-01-06T17:14:46.347Z","repository":{"id":141468864,"uuid":"254803394","full_name":"theguptaji/bookstore_users-api","owner":"theguptaji","description":"Users API","archived":false,"fork":false,"pushed_at":"2020-04-27T18:14:38.000Z","size":42,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T18:16:12.814Z","etag":null,"topics":["go-gin","go-interface","golang","mvc-architecture","mysql-database","rest-api","uber-zap"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theguptaji.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-04-11T05:58:19.000Z","updated_at":"2020-04-27T18:14:40.000Z","dependencies_parsed_at":"2024-06-19T11:34:19.669Z","dependency_job_id":"c5b44846-4269-4301-a3c3-27c055fac454","html_url":"https://github.com/theguptaji/bookstore_users-api","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theguptaji%2Fbookstore_users-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theguptaji%2Fbookstore_users-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theguptaji%2Fbookstore_users-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theguptaji%2Fbookstore_users-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theguptaji","download_url":"https://codeload.github.com/theguptaji/bookstore_users-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858878,"owners_count":20684057,"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","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":["go-gin","go-interface","golang","mvc-architecture","mysql-database","rest-api","uber-zap"],"created_at":"2024-09-25T18:04:10.903Z","updated_at":"2026-01-06T17:14:46.293Z","avatar_url":"https://github.com/theguptaji.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bookstore_users-api\nRESTFUL API in golang. Developed with MVC architecture standards.\n\n## To Run \n* Setup a Mysql database.\n* Prepare a database named \"userDB\".\n* Create a table with following config\n```sql\nCREATE TABLE `users` (\n\t`id` BIGINT(64) NOT NULL AUTO_INCREMENT,\n\t`first_name` VARCHAR(45),\n\t`last_name` VARCHAR(45),\n\t`email` VARCHAR(45) NOT NULL,\n\t`data_created` VARCHAR(45) NOT NULL,\n\t`status` VARCHAR(30) NOT NULL,\n\t`password` VARCHAR(45),\n\tPRIMARY KEY (`id`)\n);\n```\n* We basically wants a schema like this\n```\n+--------------+-------------+------+-----+---------+----------------+\n| Field        | Type        | Null | Key | Default | Extra          |\n+--------------+-------------+------+-----+---------+----------------+\n| id           | bigint      | NO   | PRI | NULL    | auto_increment |\n| first_name   | varchar(45) | YES  |     | NULL    |                |\n| last_name    | varchar(45) | YES  |     | NULL    |                |\n| email        | varchar(45) | NO   | UNI | NULL    |                |\n| date_created | varchar(45) | NO   |     | NULL    |                |\n| status       | varchar(45) | NO   |     | NULL    |                |\n| password     | varchar(32) | NO   |     | NULL    |                |\n+--------------+-------------+------+-----+---------+----------------+\n```\n* Now set the following environment variables\n`mysql_users_username`, `mysql_users_password`, `mysql_users_host`, `mysql_users_schema`\n* At this point you can clone the repo and run the code\n```\ngit clone \u003crepo\u003e\ngo run main.go\n```\n* The application will be exposed at port 8080.\n\n## To Test\n* Prepare `curl` or http rest client like `postman` or `insomnia`.\n\n### Create a User by\n```\ncurl -x POST http://localhost:8080/users -d @data.json\n```\nwhere data.json could be:-\n```json\n{\n  \"id\": 1,\n  \"first_name\": \"aman\",\n  \"last_name\": \"gupta\",\n  \"email\": \"aman@email.com\"\n  \"password\": \"some-password\"\n}\n```\n* Make sure, your POST request data is following the standards of insert validation defined in `domain/users/user_dto.go`, you can also edit this function as per your needs :-\n```go\nfunc (user *User) Validate() *errors.RestErr {\n\tuser.FirstName = strings.TrimSpace(user.FirstName)\n\tuser.LastName = strings.TrimSpace(user.LastName)\n\n\t// TODO: Add validation for password\n\tuser.Email = strings.TrimSpace(strings.ToLower(user.Email))\n\tif user.Email == \"\" {\n\t\treturn errors.NewBadRequestError(\"invalid email address\")\n\t}\n\n\tuser.Password = strings.TrimSpace(user.Password)\n\tif user.Password == \"\" {\n\t\treturn errors.NewBadRequestError(\"invalid password\")\n\t}\n\treturn nil\n}\n```\n\n### Get a User by\n* This API offers two kinds of get user request, `PUBLIC` and `PRIVATE`\n* For public request set a header `X-public=true` and insert a user_id you want to get correspounding user to.\n* For private request no need to set header, but insert the user_id\n```\ncurl -x GET http://localhost:8080/users/\u003cid\u003e\n```\n* For private request you get following response:-\n```json\n{\n  \"id\": 1,\n  \"first_name\": \"aman\",\n  \"last_name\": \"gupta\",\n  \"email\": \"aman@email.com\",\n  \"date_created\": \"15046-04-15 14:15:52\",\n  \"status\": \"active\"\n}\n```\n* For public request you get following response:-\n```json\n{\n  \"id\": 1,\n  \"date_created\": \"15046-04-15 14:15:52\",\n  \"status\": \"active\"\n}\n```\n\n### Update a User by\n```\ncurl -x UPDATE http://localhost:8080/users/\u003cid\u003e -d @data.json\n```\nor\n```\ncurl -x PATCH http://localhost:8080/users/\u003cid\u003e -d @data.json\n```\n* Here patch will not update if an empty key is passed\n\n### Delete a User by\n```\ncurl -x DELETE http://localhost:8080/users/\u003cid\u003e \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheguptaji%2Fbookstore_users-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheguptaji%2Fbookstore_users-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheguptaji%2Fbookstore_users-api/lists"}