This commit is contained in:
parent
8b203908a0
commit
725945d95c
22 changed files with 381 additions and 135 deletions
|
|
@ -2,7 +2,6 @@ package platform
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
|
|
@ -10,34 +9,12 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
func MailerByID(ctx context.Context, user User, id int32) (*types.Mailer, error) {
|
||||
query := mailerQuery()
|
||||
query.Apply(
|
||||
sm.Where(models.ComplianceReportRequests.Columns.ID.EQ(psql.Arg(id))),
|
||||
sm.Where(
|
||||
models.Sites.Columns.OrganizationID.EQ(psql.Arg(user.Organization.ID)),
|
||||
),
|
||||
)
|
||||
mailers, err := mailerQueryToRows(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mailers[id], nil
|
||||
}
|
||||
func MailerList(ctx context.Context, user User, limit int) ([]*types.Mailer, error) {
|
||||
query := mailerQuery()
|
||||
query.Apply(
|
||||
sm.Where(
|
||||
models.Sites.Columns.OrganizationID.EQ(psql.Arg(user.Organization.ID)),
|
||||
),
|
||||
sm.OrderBy(models.ComplianceReportRequests.Columns.Created),
|
||||
sm.Limit(limit),
|
||||
)
|
||||
return mailerQueryToRows(ctx, query)
|
||||
func MailerList(ctx context.Context, user User, limit int) ([]types.Mailer, error) {
|
||||
return querypublic.MailersFromOrganizationID(ctx, db.PGInstance.PGXPool, int64(user.Organization.ID), int64(limit))
|
||||
}
|
||||
func mailerQuery() bob.BaseQuery[*dialect.SelectQuery] {
|
||||
return psql.Select(
|
||||
|
|
@ -78,11 +55,3 @@ func mailerQuery() bob.BaseQuery[*dialect.SelectQuery] {
|
|||
),
|
||||
)
|
||||
}
|
||||
func mailerQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQuery]) ([]*types.Mailer, error) {
|
||||
rows, err := bob.All(ctx, db.PGInstance.BobDB, query, scan.StructMapper[*types.Mailer]())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query mailers: %w", err)
|
||||
}
|
||||
|
||||
return rows, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue