Skip to content

Commit

Permalink
add publish subscribe
Browse files Browse the repository at this point in the history
Signed-off-by: Arvindh <[email protected]>
  • Loading branch information
arvindh123 committed Oct 31, 2024
1 parent b47d3f6 commit ed68d71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 7 additions & 6 deletions channels/postgres/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
14 changes: 8 additions & 6 deletions things/postgres/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}

0 comments on commit ed68d71

Please sign in to comment.