From ed68d7145d759476b0ae20b9973c024c78192cae Mon Sep 17 00:00:00 2001 From: Arvindh Date: Thu, 31 Oct 2024 12:42:39 +0530 Subject: [PATCH] add publish subscribe Signed-off-by: Arvindh --- channels/postgres/channels.go | 13 +++++++------ things/postgres/clients.go | 14 ++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/channels/postgres/channels.go b/channels/postgres/channels.go index f8d4d0cc83..05f493c885 100644 --- a/channels/postgres/channels.go +++ b/channels/postgres/channels.go @@ -15,6 +15,7 @@ import ( "github.com/absmach/magistrala/internal/api" "github.com/absmach/magistrala/pkg/apiutil" "github.com/absmach/magistrala/pkg/clients" + "github.com/absmach/magistrala/pkg/connections" "github.com/absmach/magistrala/pkg/errors" repoerr "github.com/absmach/magistrala/pkg/errors/repository" "github.com/absmach/magistrala/pkg/postgres" @@ -249,7 +250,7 @@ func (cr *channelRepository) AddConnections(ctx context.Context, conns []channel dbConns := toDBConnections(conns) q := `INSERT INTO connections (channel_id, domain_id, thing_id, type) - VALUES (:channel_id, :domain_id, :thing_id :type);` + VALUES (:channel_id, :domain_id, :thing_id, :type );` if _, err := cr.db.NamedExecContext(ctx, q, dbConns); err != nil { return postgres.HandleError(repoerr.ErrCreateEntity, err) @@ -613,10 +614,10 @@ type dbChannelsPage struct { } type dbConnection struct { - ChannelID string `db:"channel_id"` - DomainID string `db:"domain_id"` - ThingID string `db:"thing_id"` - Type uint8 `db:"type"` + ChannelID string `db:"channel_id"` + DomainID string `db:"domain_id"` + ThingID string `db:"thing_id"` + Type connections.Type `db:"type"` } func toDBConnections(conns []channels.Connection) []dbConnection { @@ -632,6 +633,6 @@ func toDBConnection(conn channels.Connection) dbConnection { ThingID: conn.ThingID, ChannelID: conn.ChannelID, DomainID: conn.DomainID, - Type: uint8(conn.Type), + Type: conn.Type, } } diff --git a/things/postgres/clients.go b/things/postgres/clients.go index 411024d85e..f2a2d97b87 100644 --- a/things/postgres/clients.go +++ b/things/postgres/clients.go @@ -11,6 +11,7 @@ import ( "github.com/absmach/magistrala/pkg/clients" mgclients "github.com/absmach/magistrala/pkg/clients" pgclients "github.com/absmach/magistrala/pkg/clients/postgres" + "github.com/absmach/magistrala/pkg/connections" "github.com/absmach/magistrala/pkg/errors" repoerr "github.com/absmach/magistrala/pkg/errors/repository" "github.com/absmach/magistrala/pkg/postgres" @@ -199,8 +200,9 @@ func (repo *clientsRepo) AddConnections(ctx context.Context, conns []things.Conn dbConns := toDBConnections(conns) + fmt.Printf("%+v\n", dbConns) q := `INSERT INTO connections (channel_id, domain_id, thing_id, type) - VALUES (:channel_id, :domain_id, :thing_id :type);` + VALUES (:channel_id, :domain_id, :thing_id, :type);` if _, err := repo.DB.NamedExecContext(ctx, q, dbConns); err != nil { return postgres.HandleError(repoerr.ErrCreateEntity, err) @@ -363,10 +365,10 @@ func (repo *clientsRepo) UnsetParentGroupFromThings(ctx context.Context, parentG } type dbConnection struct { - ThingID string `db:"thing_id"` - ChannelID string `db:"channel_id"` - DomainID string `db:"domain_id"` - Type uint8 `db:"type"` + ThingID string `db:"thing_id"` + ChannelID string `db:"channel_id"` + DomainID string `db:"domain_id"` + Type connections.Type `db:"type"` } func toDBConnections(conns []things.Connection) []dbConnection { @@ -382,6 +384,6 @@ func toDBConnection(conn things.Connection) dbConnection { ThingID: conn.ThingID, ChannelID: conn.ChannelID, DomainID: conn.DomainID, - Type: uint8(conn.Type), + Type: conn.Type, } }