mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-09-18 17:28:27 +03:00
refactor: sync
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type AgentRequest struct {
|
||||
Name string
|
||||
Args map[string]string
|
||||
TimeOut int
|
||||
}
|
||||
|
||||
type AgentResponse struct {
|
||||
Success bool
|
||||
Output string
|
||||
Error string
|
||||
ExecTimeMS int
|
||||
}
|
||||
|
||||
type AgentAlert struct {
|
||||
Timestamp int
|
||||
Level string
|
||||
Title string
|
||||
Description string
|
||||
}
|
||||
|
||||
type SystemMetrics struct {
|
||||
CPUUsage float64
|
||||
MemoryUsage float64
|
||||
DiskUsage float64
|
||||
}
|
||||
|
||||
type HeartbeatModel struct {
|
||||
ID int
|
||||
AgentID string
|
||||
Timestamp time.Time
|
||||
Metrics SystemMetrics
|
||||
}
|
||||
|
||||
type CreateHeartbeatModel struct {
|
||||
AgentID string
|
||||
Timestamp time.Time
|
||||
Metrics SystemMetrics
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
"github.com/rs/zerolog"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
)
|
||||
|
||||
type StreamConn interface {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
)
|
||||
|
||||
func toCreateHeartbeatModel(agentID string, heartbeat *pb.AgentEvent_Heartbeat) domainHub.CreateHeartbeatModel {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
)
|
||||
|
||||
type streamMock struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package connection_manager
|
||||
import (
|
||||
"sync"
|
||||
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
)
|
||||
|
||||
type AgentConnStore struct {
|
||||
|
||||
@@ -77,7 +77,7 @@ func toDomainCapabilities(caps []byte) []domain.Capability {
|
||||
return capabilities
|
||||
}
|
||||
|
||||
func toDBHeartbeat(heartbeat domainHub.CreateHeartbeatModel) gen2.InsertHeartbeatParams {
|
||||
func toDBHeartbeat(heartbeat domain.CreateHeartbeatModel) gen2.InsertHeartbeatParams {
|
||||
|
||||
return gen2.InsertHeartbeatParams{
|
||||
AgentID: heartbeat.AgentID,
|
||||
@@ -88,12 +88,12 @@ func toDBHeartbeat(heartbeat domainHub.CreateHeartbeatModel) gen2.InsertHeartbea
|
||||
}
|
||||
}
|
||||
|
||||
func toHeartBeatModel(heartbeat gen2.Heartbeat) domainHub.HeartbeatModel {
|
||||
return domainHub.HeartbeatModel{
|
||||
func toHeartBeatModel(heartbeat gen2.Heartbeat) domain.HeartbeatModel {
|
||||
return domain.HeartbeatModel{
|
||||
Timestamp: heartbeat.HeartbeatTimestamp,
|
||||
AgentID: heartbeat.AgentID,
|
||||
ID: int(heartbeat.ID),
|
||||
Metrics: domainHub.SystemMetrics{
|
||||
Metrics: domain.SystemMetrics{
|
||||
CPUUsage: heartbeat.CpuUsage,
|
||||
DiskUsage: heartbeat.DiskUsage,
|
||||
MemoryUsage: heartbeat.MemoryUsage,
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
"github.com/lorsanstand/HomeOps-Hub/hub/internal/store/sqlc/gen"
|
||||
"github.com/lorsanstand/HomeOps-Hub/shared/domain"
|
||||
)
|
||||
|
||||
type HubStore struct {
|
||||
@@ -36,19 +37,19 @@ func (h *HubStore) UpdateAgentByID(ctx context.Context, ID int, updateAgent doma
|
||||
return h.queries.UpdateAgentByID(ctx, data)
|
||||
}
|
||||
|
||||
func (h *HubStore) CreateHeartbeat(ctx context.Context, heartbeat domainHub.CreateHeartbeatModel) error {
|
||||
func (h *HubStore) CreateHeartbeat(ctx context.Context, heartbeat domain.CreateHeartbeatModel) error {
|
||||
data := toDBHeartbeat(heartbeat)
|
||||
return h.queries.InsertHeartbeat(ctx, data)
|
||||
}
|
||||
|
||||
func (h *HubStore) GetHeartbeatsByIDAfter(ctx context.Context, agentID string, timestamp time.Time) ([]domainHub.HeartbeatModel, error) {
|
||||
func (h *HubStore) GetHeartbeatsByIDAfter(ctx context.Context, agentID string, timestamp time.Time) ([]domain.HeartbeatModel, error) {
|
||||
data := gen.SelectHeartbeatsAfterParams{AgentID: agentID, Timestamp: timestamp}
|
||||
heartbeats, err := h.queries.SelectHeartbeatsAfter(ctx, data)
|
||||
if err != nil {
|
||||
return []domainHub.HeartbeatModel{}, err
|
||||
return []domain.HeartbeatModel{}, err
|
||||
}
|
||||
|
||||
heartbeatsModel := make([]domainHub.HeartbeatModel, len(heartbeats))
|
||||
heartbeatsModel := make([]domain.HeartbeatModel, len(heartbeats))
|
||||
|
||||
for i, heartbeat := range heartbeats {
|
||||
heartbeatsModel[i] = toHeartBeatModel(heartbeat)
|
||||
|
||||
Reference in New Issue
Block a user