self-order+notification #5
@ -4,6 +4,7 @@ import (
|
|||||||
"apskel-pos-be/internal/constants"
|
"apskel-pos-be/internal/constants"
|
||||||
"apskel-pos-be/internal/entities"
|
"apskel-pos-be/internal/entities"
|
||||||
"apskel-pos-be/internal/models"
|
"apskel-pos-be/internal/models"
|
||||||
|
"apskel-pos-be/internal/pkg/tabletoken"
|
||||||
"apskel-pos-be/internal/repository"
|
"apskel-pos-be/internal/repository"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
@ -212,6 +213,15 @@ func (p *TableProcessor) GetTokenByID(ctx context.Context, id uuid.UUID) (string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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
|
return table.Token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -171,6 +171,13 @@ func (r *TableRepository) ReleaseTable(ctx context.Context, tableID uuid.UUID, p
|
|||||||
}).Error
|
}).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) {
|
func (r *TableRepository) GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error) {
|
||||||
var table entities.Table
|
var table entities.Table
|
||||||
err := r.db.WithContext(ctx).
|
err := r.db.WithContext(ctx).
|
||||||
|
|||||||
@ -24,4 +24,5 @@ type TableRepositoryInterface interface {
|
|||||||
OccupyTable(ctx context.Context, tableID, orderID uuid.UUID, startTime *time.Time) error
|
OccupyTable(ctx context.Context, tableID, orderID uuid.UUID, startTime *time.Time) error
|
||||||
ReleaseTable(ctx context.Context, tableID uuid.UUID, paymentAmount float64) error
|
ReleaseTable(ctx context.Context, tableID uuid.UUID, paymentAmount float64) error
|
||||||
GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error)
|
GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error)
|
||||||
|
UpdateToken(ctx context.Context, tableID uuid.UUID, token string) error
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user