From 6064ef8fdef2d2c3a7144f107aae7fee1017168d Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 10 May 2026 14:52:02 +0700 Subject: [PATCH] Update QR token generation --- internal/processor/table_processor.go | 10 ++++++++++ internal/repository/table_repository.go | 7 +++++++ internal/repository/table_repository_interface.go | 1 + 3 files changed, 18 insertions(+) diff --git a/internal/processor/table_processor.go b/internal/processor/table_processor.go index 0adf23c..1dcea07 100644 --- a/internal/processor/table_processor.go +++ b/internal/processor/table_processor.go @@ -4,6 +4,7 @@ import ( "apskel-pos-be/internal/constants" "apskel-pos-be/internal/entities" "apskel-pos-be/internal/models" + "apskel-pos-be/internal/pkg/tabletoken" "apskel-pos-be/internal/repository" "context" "errors" @@ -212,6 +213,15 @@ func (p *TableProcessor) GetTokenByID(ctx context.Context, id uuid.UUID) (string if err != nil { return "", err } + + if _, _, _, err := tabletoken.Decode(table.Token); err != nil { + newToken := tabletoken.Encode(table.ID, table.OrganizationID, table.OutletID) + if updateErr := p.tableRepo.UpdateToken(ctx, table.ID, newToken); updateErr != nil { + return "", updateErr + } + return newToken, nil + } + return table.Token, nil } diff --git a/internal/repository/table_repository.go b/internal/repository/table_repository.go index add78c8..c040187 100644 --- a/internal/repository/table_repository.go +++ b/internal/repository/table_repository.go @@ -171,6 +171,13 @@ func (r *TableRepository) ReleaseTable(ctx context.Context, tableID uuid.UUID, p }).Error } +func (r *TableRepository) UpdateToken(ctx context.Context, tableID uuid.UUID, token string) error { + return r.db.WithContext(ctx). + Model(&entities.Table{}). + Where("id = ?", tableID). + Update("token", token).Error +} + func (r *TableRepository) GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error) { var table entities.Table err := r.db.WithContext(ctx). diff --git a/internal/repository/table_repository_interface.go b/internal/repository/table_repository_interface.go index 33f1367..5e3accf 100644 --- a/internal/repository/table_repository_interface.go +++ b/internal/repository/table_repository_interface.go @@ -24,4 +24,5 @@ type TableRepositoryInterface interface { OccupyTable(ctx context.Context, tableID, orderID uuid.UUID, startTime *time.Time) error ReleaseTable(ctx context.Context, tableID uuid.UUID, paymentAmount float64) error GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error) + UpdateToken(ctx context.Context, tableID uuid.UUID, token string) error }