From 7db81c0e68f3f187e19c99981bb482061742d275 Mon Sep 17 00:00:00 2001 From: abhishek Date: Thu, 23 Jul 2026 11:08:57 +0530 Subject: [PATCH] Return the created location from CreateTenantLocation so its locationid is available immediately The store/branch QR code the app scans is just {tenantid, locationid} JSON, but the onboarding response previously discarded the DB-assigned locationid, so the frontend had no way to render a store's QR right after onboarding without a separate lookup. Co-Authored-By: Claude Sonnet 5 --- repositories/tenantRepository.go | 16 +++++++++------- services/tenantService.go | 6 +++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/repositories/tenantRepository.go b/repositories/tenantRepository.go index 5cf9cf0..fa32615 100644 --- a/repositories/tenantRepository.go +++ b/repositories/tenantRepository.go @@ -25,7 +25,7 @@ type TenantRepository interface { GetStaffs(tid int) ([]models.StaffInfo, error) CreateStaff(user models.User) error UpdateStaff(user models.User) error - CreateTenantLocation(data models.Tenantlocations) error + CreateTenantLocation(data models.Tenantlocations) (models.Tenantlocations, error) UpdateTenantLocation(data models.Tenantlocations) error CheckTenantByNo(cno string) int CreateTenantUser(data models.Tenants) (bool, error) @@ -346,7 +346,7 @@ func (r *tenantRepository) UpdateStaff(user models.User) error { return nil } -func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) error { +func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) (models.Tenantlocations, error) { var user models.Tenantuser tx := r.db.Begin() @@ -360,10 +360,12 @@ func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) err data.Status = "Active" } - // Step 1: Insert into tenantlocations + // Step 1: Insert into tenantlocations. GORM writes the DB-assigned + // locationid back onto data, which callers need to build the store's + // QR code (payload is just {tenantid, locationid}) right after onboarding. if err := tx.Create(&data).Error; err != nil { tx.Rollback() - return err + return models.Tenantlocations{}, err } // Step 2: Insert into app_users @@ -389,15 +391,15 @@ func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) err if err := tx.Table("app_users").Create(&user).Error; err != nil { tx.Rollback() - return err + return models.Tenantlocations{}, err } // Commit if err := tx.Commit().Error; err != nil { - return err + return models.Tenantlocations{}, err } - return nil + return data, nil } func (r *tenantRepository) UpdateTenantLocation(input models.Tenantlocations) error { diff --git a/services/tenantService.go b/services/tenantService.go index a92ef10..800a99f 100644 --- a/services/tenantService.go +++ b/services/tenantService.go @@ -107,7 +107,7 @@ func (s *tenantService) UpdateStaff(user models.User) error { } func (s *tenantService) CreateTenantLocation(data models.Tenantlocations) map[string]interface{} { - err := s.repo.CreateTenantLocation(data) + created, err := s.repo.CreateTenantLocation(data) if err != nil { return map[string]interface{}{ "code": http.StatusConflict, @@ -116,10 +116,14 @@ func (s *tenantService) CreateTenantLocation(data models.Tenantlocations) map[st } } + // "details" carries back the DB-assigned locationid so the frontend can + // build the store's QR code (tenantid+locationid) immediately after + // onboarding, instead of having to look the new location up separately. return map[string]interface{}{ "code": http.StatusCreated, "message": "Tenant Location Successfully Created", "status": true, + "details": created, } }