Skip to content

Commit 48eb633

Browse files
committed
Update heartbeat monitors updated at time
1 parent a010009 commit 48eb633

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package entities
22

33
import (
4+
"time"
5+
46
"github.com/google/uuid"
57
)
68

79
// HeartbeatMonitor is used to monitor heartbeats of a phone
810
type HeartbeatMonitor struct {
9-
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
10-
PhoneID uuid.UUID `json:"phone_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
11-
UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
12-
QueueID string `json:"queue_id" example:"0360259236613675274"`
13-
Owner string `json:"owner" example:"+18005550199"`
11+
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
12+
PhoneID uuid.UUID `json:"phone_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
13+
UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
14+
QueueID string `json:"queue_id" example:"0360259236613675274"`
15+
Owner string `json:"owner" example:"+18005550199"`
16+
CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
17+
UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
1418
}

api/pkg/repositories/gorm_heartbeat_monitor_repository.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package repositories
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/google/uuid"
89

@@ -29,8 +30,10 @@ func (repository *gormHeartbeatMonitorRepository) UpdateQueueID(ctx context.Cont
2930
err := repository.db.
3031
Model(&entities.HeartbeatMonitor{}).
3132
Where("id = ?", monitorID).
32-
UpdateColumn("queue_id", queueID).
33-
Error
33+
Updates(map[string]any{
34+
"queue_id": queueID,
35+
"updated_at": time.Now().UTC(),
36+
}).Error
3437
if err != nil {
3538
msg := fmt.Sprintf("cannot update heartbeat monitor ID [%s]", monitorID)
3639
return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
@@ -73,11 +76,6 @@ func (repository *gormHeartbeatMonitorRepository) Index(ctx context.Context, use
7376
defer span.End()
7477

7578
query := repository.db.WithContext(ctx).Where("user_id = ?", userID).Where("owner = ?", owner)
76-
if len(params.Query) > 0 {
77-
queryPattern := "%" + params.Query + "%"
78-
query.Where("quantity ILIKE ?", queryPattern)
79-
}
80-
8179
heartbeats := new([]entities.Heartbeat)
8280
if err := query.Order("timestamp DESC").Limit(params.Limit).Offset(params.Skip).Find(&heartbeats).Error; err != nil {
8381
msg := fmt.Sprintf("cannot fetch heartbeats with owner [%s] and params [%+#v]", owner, params)

api/pkg/services/heartbeat_service.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ func (service *HeartbeatService) StoreMonitor(ctx context.Context, params *Heart
125125
}
126126

127127
heartbeatMonitor := &entities.HeartbeatMonitor{
128-
ID: uuid.New(),
129-
PhoneID: params.PhoneID,
130-
UserID: params.UserID,
131-
Owner: params.Owner,
128+
ID: uuid.New(),
129+
PhoneID: params.PhoneID,
130+
UserID: params.UserID,
131+
Owner: params.Owner,
132+
CreatedAt: time.Now().UTC(),
133+
UpdatedAt: time.Now().UTC(),
132134
}
133135

134136
if err = service.monitorRepository.Store(ctx, heartbeatMonitor); err != nil {

0 commit comments

Comments
 (0)