{"id":21538958,"url":"https://github.com/edigar/socialnets-api","last_synced_at":"2025-03-17T21:39:17.706Z","repository":{"id":199338764,"uuid":"702585366","full_name":"edigar/socialnets-api","owner":"edigar","description":"Social network API ","archived":false,"fork":false,"pushed_at":"2025-01-23T00:43:45.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-23T01:27:51.597Z","etag":null,"topics":["api","socialnetwork"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edigar.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-09T15:38:10.000Z","updated_at":"2025-01-23T00:43:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"122f60a7-fa91-4874-848c-47706a606eea","html_url":"https://github.com/edigar/socialnets-api","commit_stats":null,"previous_names":["edigar/socialnets-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edigar%2Fsocialnets-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edigar%2Fsocialnets-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edigar%2Fsocialnets-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edigar%2Fsocialnets-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edigar","download_url":"https://codeload.github.com/edigar/socialnets-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244114929,"owners_count":20400468,"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":["api","socialnetwork"],"created_at":"2024-11-24T04:13:47.882Z","updated_at":"2025-03-17T21:39:17.680Z","avatar_url":"https://github.com/edigar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Socialnets-API\n\nA social network API with the functionalities (so far) of user registration, following users, search, posting, and liking posts.\n\n## Requirements\n\n- [PostgreSQL](https://www.postgresql.org/) 16.0\n- [Golang](https://go.dev/) 1.21.1\n\nIf you use [docker](https://www.docker.com/), here you will find a complete environment container.\n\n## Installation\n\nClone or download this repository.\n\nCopy `.env.example` to `.env`.\n\n\u003e [!IMPORTANT]\n\u003e You must set `SECRET_KEY` in this file, which can literally be any string.\n\nHowever, you can generate a `SECRET_KEY` with the following Go code, which will print it in the prompt. After that, simply copy the generated hash to the `.env` file.\n\n```Go\npackage main\n\nimport (\n\t\"crypto/rand\"\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"log\"\n)\n\nfunc main() {\n\tkey := make([]byte, 64)\n\tif _, err := rand.Read(key); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tsecret := base64.StdEncoding.EncodeToString(key)\n\tfmt.Println(secret)\n}\n```\n\nAfter that, choose one of the following options (Docker or Local).\n\n### Docker\n\nAt the root of the project there is a Dockerfile and docker-compose.yml files with requirements to run the project.\nYou can run with docker by building the image and running it.\n\nExecute:\n\n```bash\ndocker-compose up\n```\n\nYou'll have API running on http://localhost\n\n### Local\n\nSet database configuration on `.env` file and create the database. In docker folder, you will found a SQL script that will create database and tables.\n\n```bash\n# Install dependencies\ngo mod tidy\n\n# Start application\ngo run ./cmd/api/main.go\n```\n\nIf you want to generate the executable, use:\n```bash\n# Install dependencies\ngo mod tidy\n\n# Generate executable\ngo build ./cmd/api\n\n# Start application\n./api\n```\n\nYou'll have API running on http://localhost:8000 (if you don't change `API_PORT` on `.env`).\n\n## Migrations\n\nThis project uses [pressly/goose](https://github.com/pressly/goose) to manage migrations, which are located in the build/migrations folder. To execute them, install Goose:\n\n```bash\ngo install github.com/pressly/goose/v3/cmd/goose@latest\n```\n\nChange variables and run:\n```bash\ngoose -dir build/migrations postgres \"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:5432/{DATABASE_NAME}?sslmode=disable\" up\n```\n\nFor convenience, you can set the database driver and connection string as environment variables:\n\n```bash\nexport GOOSE_DRIVER=postgres\nexport GOOSE_DBSTRING=postgresql://db_user:your_password@db_host:5432/socialnets?sslmode=disable\n```\n\nAnd then, you can run the migration using a short command:\n\n```bash\ngoose -dir build/migrations up\n```\n\n## Usage\n\nAfter starting application, you'll have access to following routes:\n\n| Method | URI                                | Authentication | Description                             |\n|:------:|------------------------------------|:--------------:|-----------------------------------------|\n|  GET   | /health                            |       No       | Application status health check         |\n|  POST  | /api/login                         |       No       | User login                              |\n|  POST  | /api/user                          |       No       | Create an user                          |\n|  GET   | /api/user                          |      Yes       | Search for users                        |\n|  GET   | /api/user/{userId}                 |      Yes       | Get an user data                        |\n|  PUT   | /api/user/{userId}                 |      Yes       | Update an user data                     |\n| DELETE | /api/user/{userId}                 |      Yes       | Delete an user                          |\n|  POST  | /api/user/{userId}/follow          |      Yes       | Logged user follows an user             |\n|  POST  | /api/user/{userId}/unfollow        |      Yes       | Logged user unfollows an user           |\n|  GET   | /api/user/{userId}/followers       |      Yes       | Get all followers by an user            |\n|  GET   | /api/user/{userId}/following       |      Yes       | Gets all users who are following a user |\n|  POST  | /api/user/{userId}/update-password |      Yes       | Update password user                    |\n|  POST  | /api/post                          |      Yes       | Create a post                           |\n|  GET   | /api/post                          |      Yes       | Get all post for a logged user          |\n|  GET   | /api/post/{postId}                 |      Yes       | Get a post                              |\n|  PUT   | /api/post/{postId}                 |      Yes       | Update a post                           |\n| DELETE | /api/post/{postId}                 |      Yes       | Delete a post                           |\n|  GET   | /api/user/{userId}/posts           |      Yes       | Gets all posts from a user              |\n|  POST  | /api/post/{postId}/like            |      Yes       | Like a user post                        |\n|  POST  | /api/post/{postId}/unlike          |      Yes       | Unlike a user post                      |\n\nAuthentication, once performed with login (email) and password on `/api/login`, is maintained via a JWT Bearer Token.\n\nYou can find more information, like payload and responses in the application swagger (coming soon).\n\nSo API is already to use.\n\n## Tests\n\nTo run tests run on root of the project:\n\n```bash\ngo test ./...\n```\n\n### Coverage\n\nRun at the root of the project to see tests coverage:\n```bash\ngo test ./... --cover\n```\n\n## API documentation\n\n:construction:\n\nSoon a [swagger](https://swagger.io/docs/specification/2-0/what-is-swagger/) doc will be added.\n\n## TODO\n\n- [ ] ~~Add [GORM](https://gorm.io) to the project~~\n- [ ] Improve tests\n- [ ] Add [Swagger](https://swagger.io) documentation\n- [x] Implements UUID for user's Id\n- [ ] Register who liked a post, so that each user can only like each post once, in addition to having information on who liked each post. \n    + [ ] Add likes table\n    + [ ] Control who like or unlike a post.\n- [x] Implements migrations\n- [ ] Password recovery\n\n## License\n\n[MIT](./LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedigar%2Fsocialnets-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedigar%2Fsocialnets-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedigar%2Fsocialnets-api/lists"}