feat(ui): add message cache management page and dashboard enhancements
- Introduced MessageCachePage for browsing and managing cached webhook events. - Enhanced DashboardPage to display runtime stats and message cache information. - Added new API types for message cache events and system stats. - Integrated SwaggerPage for API documentation and live request testing.
This commit is contained in:
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.warky.dev/wdevs/whatshooked/pkg/models"
|
||||
@@ -202,29 +203,63 @@ func (r *WhatsAppAccountRepository) GetByPhoneNumber(ctx context.Context, phoneN
|
||||
|
||||
// UpdateConfig updates the config JSON column and phone number for a WhatsApp account
|
||||
func (r *WhatsAppAccountRepository) UpdateConfig(ctx context.Context, id string, phoneNumber string, cfgJSON string, active bool) error {
|
||||
_, err := r.db.NewUpdate().Model((*models.ModelPublicWhatsappAccount)(nil)).
|
||||
Set("config = ?", cfgJSON).
|
||||
Set("phone_number = ?", phoneNumber).
|
||||
Set("active = ?", active).
|
||||
Set("updated_at = ?", time.Now()).
|
||||
Where("id = ?", id).
|
||||
Exec(ctx)
|
||||
return err
|
||||
now := time.Now()
|
||||
updated, err := r.updateAccountTable(ctx, id, map[string]any{
|
||||
"config": cfgJSON,
|
||||
"phone_number": phoneNumber,
|
||||
"active": active,
|
||||
"updated_at": now,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updated {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("no whatsapp account row found for id=%s", id)
|
||||
}
|
||||
|
||||
// UpdateStatus updates the status of a WhatsApp account
|
||||
func (r *WhatsAppAccountRepository) UpdateStatus(ctx context.Context, id string, status string) error {
|
||||
query := r.db.NewUpdate().Model((*models.ModelPublicWhatsappAccount)(nil)).
|
||||
Set("status = ?", status).
|
||||
Where("id = ?", id)
|
||||
|
||||
now := time.Now()
|
||||
fields := map[string]any{
|
||||
"status": status,
|
||||
"updated_at": now,
|
||||
}
|
||||
if status == "connected" {
|
||||
now := time.Now()
|
||||
query = query.Set("last_connected_at = ?", now)
|
||||
fields["last_connected_at"] = now
|
||||
}
|
||||
|
||||
_, err := query.Exec(ctx)
|
||||
return err
|
||||
updated, err := r.updateAccountTable(ctx, id, fields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updated {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("no whatsapp account row found for id=%s", id)
|
||||
}
|
||||
|
||||
func (r *WhatsAppAccountRepository) updateAccountTable(ctx context.Context, id string, fields map[string]any) (bool, error) {
|
||||
query := r.db.NewUpdate().Table("whatsapp_account").Where("id = ?", id)
|
||||
for column, value := range fields {
|
||||
query = query.Set(column+" = ?", value)
|
||||
}
|
||||
|
||||
result, err := query.Exec(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if result == nil {
|
||||
return false, nil
|
||||
}
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return rowsAffected > 0, nil
|
||||
}
|
||||
|
||||
// SessionRepository provides session-specific operations
|
||||
|
||||
Reference in New Issue
Block a user