{"id":15162038,"url":"https://github.com/andres06-hub/loyalty-service","last_synced_at":"2026-01-21T02:02:49.104Z","repository":{"id":256891139,"uuid":"856734521","full_name":"andres06-hub/loyalty-service","owner":"andres06-hub","description":"service to accumulate points and redeem depending on a campaign","archived":false,"fork":false,"pushed_at":"2024-09-17T14:34:58.000Z","size":176,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T00:41:28.972Z","etag":null,"topics":["dokcer","golang","grpc","hexagonal-architecture","postgresql","rest-api","shell"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/andres06-hub.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-13T05:28:34.000Z","updated_at":"2024-09-17T23:24:08.000Z","dependencies_parsed_at":"2024-12-21T15:32:30.402Z","dependency_job_id":"18207817-754e-4cf4-ba69-5ce22b14cc1b","html_url":"https://github.com/andres06-hub/loyalty-service","commit_stats":{"total_commits":53,"total_committers":1,"mean_commits":53.0,"dds":0.0,"last_synced_commit":"03ee23421b28a44f47f94b1d3946b7c40caf358f"},"previous_names":["andres06-hub/loyalty-service"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andres06-hub/loyalty-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres06-hub%2Floyalty-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres06-hub%2Floyalty-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres06-hub%2Floyalty-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres06-hub%2Floyalty-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andres06-hub","download_url":"https://codeload.github.com/andres06-hub/loyalty-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres06-hub%2Floyalty-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28622472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T23:49:58.628Z","status":"online","status_checked_at":"2026-01-21T02:00:08.227Z","response_time":86,"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":["dokcer","golang","grpc","hexagonal-architecture","postgresql","rest-api","shell"],"created_at":"2024-09-27T01:04:10.011Z","updated_at":"2026-01-21T02:02:49.084Z","avatar_url":"https://github.com/andres06-hub.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loyalty-service\n\n## Levantar server\n\n1. Crear el archivo .env (colocar toas las envs que hay en el archivo **.env.example**)\n2. Primero se debe levantar el environment\n   - Aca corren migraciones y seeders si no hay nada en la DB (LA DB ya es una que esta en un cluster, se suminstrara la URI para observas los registros)\n   ```sh\n   ./start-environment.sh upb\n   ```\n   - Y para tumbar el ambiente ejecute\n   ```sh\n   ./start-environment.sh down\n   ```\n\n\u003e **Importante**: Los seeders tendran fechas en las campañas viejas, esto para primero validar y ver que se realiza la validaicon de ACTIVACION de campaña\n\u003e\n\u003e Si se quiere ya realizar el proceso, hay que actualizar la campaña, con fechas actuales\n\u003e\n\u003e Ejemplo: Datos actuales (ir al cURL de actualización)\n```sh\n{\n    \"startDate\": \"2024-09-15\",\n    \"endDate\": \"2024-09-30\",\n    \"bonusType\": \"double\",\n    \"bonusValue\": 2.00\n}\n```\n\n## Realizar peticiones en modo cURL\n\n### Rewards\n**Acumular puntos**\n\n- ***POST*** **/api/rewards**\n```sh\ncurl --location 'http://localhost:8888/api/rewards' \\\n--header 'Content-Type: application/json' \\\n--data '{\n  \"userId\": \"79f1ed5d-fb02-480f-8430-caabf42ce630\",\n  \"branchId\": \"51968d08-9018-4a5c-94e6-9c7181359ef7\",\n  \"purchaseAmount\": 20000\n}'\n```\n\n**Redimir puntos**\n- ***POST*** **/api/rewards/redeem**\n```sh\ncurl --location 'http://localhost:8888/api/rewards/redeem' \\\n--header 'Content-Type: application/json' \\\n--data '{\n  \"userId\": \"79f1ed5d-fb02-480f-8430-caabf42ce630\",\n  \"branchId\": \"51968d08-9018-4a5c-94e6-9c7181359ef7\",\n  \"rewardType\": \"points\",\n  \"rewardValue\": 10000\n}'\n```\n\n### Camapaigns\n#### Obtener campañas\n- ***GET*** **/api/campaigns**\n```sh\ncurl --location 'http://localhost:8888/api/campaigns'\n```\n\nObtener las campañas de una sucursal\n- ***GET*** **/api/campaigns?branchId={id}**\n```sh\ncurl --location 'http://localhost:8888/api/campaigns?branchId=51968d08-9018-4a5c-94e6-9c7181359ef7'\n```\n\n#### Actualizar campaña\n- ***PUT*** **/api/campaigns/:campaignId**\n```sh\ncurl --location --request PUT 'http://localhost:8888/api/campaigns/bdbc9716-217b-427e-80d0-a1e5f09bd3c4' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"startDate\": \"2024-09-15\",\n    \"endDate\": \"2024-09-30\",\n    \"bonusType\": \"double\",\n    \"bonusValue\": 2.00\n}'\n```\n\n\n## Unit Testing\n- Para correr las pruebas unitarias solo se debe ejecutar \n```sh\nmake test\n```\n\nEsto correra los test, y la covertura y generara una ruta local para ver las coverturas\n\n## Postman\nAca se encuentran los endpoints de loyalty\n\n[Postman](https://www.postman.com/interstellar-desert-612344/workspace/publicv2/collection/28382910-60d64557-1816-4328-9ea2-96fac161341b?action=share\u0026creator=28382910)\n\n## Technologies and tools\n\n- Framework: [go-zero](https://go-zero.dev/en/docs/tasks)\n- DB: [Postgres](https://www.postgresql.org/)\n- ORM: [Gorm](https://gorm.io/) \n- Docker\n- SH\n- Makefile\n- Github-Actions\n\n## Swagger\n\n## Diagramas\n### Acumulación de Recompensas - Diagrama de Secuencia\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant API\n    participant RewardsService\n    participant CampaignsRepository\n    participant RewardsRepository\n    participant PurchasesRepository\n    \n    User-\u003e\u003e+API: Request Accumulate Reward (userId, branchId, purchaseAmount)\n    API-\u003e\u003e+RewardsService: AccumulateReward(data)\n    RewardsService-\u003e\u003e+CampaignsRepository: FindOneByBranchId(branchId)\n    CampaignsRepository--\u003e\u003e-RewardsService: Return campaign details (if active)\n\n    alt Campaign Active\n        RewardsService-\u003e\u003eRewardsService: Calculate reward based on campaign\n    else No Campaign\n        RewardsService-\u003e\u003eRewardsService: Calculate reward based on default rule\n    end\n\n    RewardsService-\u003e\u003e+RewardsRepository: CreateRewards(newRewardData)\n    RewardsRepository--\u003e\u003e-RewardsService: Reward created\n\n    RewardsService-\u003e\u003e+PurchasesRepository: CreatePurchase(newPurchaseData)\n    PurchasesRepository--\u003e\u003e-RewardsService: Purchase created\n\n    RewardsService--\u003e\u003e-API: Return RewardsAccumulateResponse\n\n    API--\u003e\u003e-User: Send response (reward earned, campaign applied)\n```\n\n### Get campaigns\n```mermaid\nsequenceDiagram\n    participant User\n    participant API\n    participant CampaignService\n    participant CampaignRepository\n\n    User-\u003e\u003e+API: Request Get Campaigns (branchId: optional)\n    API-\u003e\u003e+CampaignService: GetCampaigns(branchId)\n\n    alt BranchId provided\n        CampaignService-\u003e\u003e+CampaignRepository: FindCampaignsByBranchId(branchId)\n        CampaignRepository--\u003e\u003e-CampaignService: Return campaigns for branchId\n    else No BranchId provided\n        CampaignService-\u003e\u003e+CampaignRepository: FindAllCampaigns()\n        CampaignRepository--\u003e\u003e-CampaignService: Return all campaigns\n    end\n\n    CampaignService--\u003e\u003e-API: Return campaigns (filtered by branchId or all)\n    API--\u003e\u003e-User: Send campaigns to user\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandres06-hub%2Floyalty-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandres06-hub%2Floyalty-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandres06-hub%2Floyalty-service/lists"}