Don't error out on missing report
This commit is contained in:
parent
7e79308868
commit
c6cb645453
2 changed files with 30 additions and 33 deletions
|
|
@ -53,9 +53,6 @@ func GenerateReportID() (string, error) {
|
|||
return builder.String(), nil
|
||||
}
|
||||
|
||||
func PublicReportByID(ctx context.Context, report_id string, is_public bool) (*types.PublicReport, error) {
|
||||
return publicreport.ByID(ctx, report_id, is_public)
|
||||
}
|
||||
func PublicReportByIDCompliance(ctx context.Context, report_id string, is_public bool) (*types.PublicReportCompliance, error) {
|
||||
result, err := publicreport.ByIDCompliance(ctx, report_id, is_public)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,36 @@ import (
|
|||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
func ByID(ctx context.Context, public_id string, is_public bool) (*types.PublicReport, error) {
|
||||
func ByIDCompliance(ctx context.Context, public_id string, is_public bool) (*types.PublicReportCompliance, error) {
|
||||
report, err := byID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
return compliance(ctx, public_id, report)
|
||||
}
|
||||
func ByIDNuisance(ctx context.Context, public_id string, is_public bool) (*types.PublicReportNuisance, error) {
|
||||
report, err := byID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
return nuisance(ctx, public_id, report)
|
||||
}
|
||||
func ByIDWater(ctx context.Context, public_id string, is_public bool) (*types.PublicReportWater, error) {
|
||||
report, err := byID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
return water(ctx, public_id, report)
|
||||
}
|
||||
func ReportsForOrganization(ctx context.Context, org_id int32, is_public bool) ([]*types.PublicReport, error) {
|
||||
query := reportQuery()
|
||||
query.Apply(
|
||||
sm.Where(psql.Quote("r", "organization_id").EQ(psql.Arg(org_id))),
|
||||
sm.Where(psql.Quote("r", "reviewed").IsNull()),
|
||||
)
|
||||
return reportQueryToRows(ctx, query, is_public)
|
||||
}
|
||||
func byID(ctx context.Context, public_id string, is_public bool) (*types.PublicReport, error) {
|
||||
query := reportQuery()
|
||||
query.Apply(
|
||||
sm.Where(psql.Quote("r", "public_id").EQ(psql.Arg(public_id))),
|
||||
|
|
@ -30,35 +59,6 @@ func ByID(ctx context.Context, public_id string, is_public bool) (*types.PublicR
|
|||
}
|
||||
return reports[0], nil
|
||||
}
|
||||
func ByIDCompliance(ctx context.Context, public_id string, is_public bool) (*types.PublicReportCompliance, error) {
|
||||
report, err := ByID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
return compliance(ctx, public_id, report)
|
||||
}
|
||||
func ByIDNuisance(ctx context.Context, public_id string, is_public bool) (*types.PublicReportNuisance, error) {
|
||||
report, err := ByID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
return nuisance(ctx, public_id, report)
|
||||
}
|
||||
func ByIDWater(ctx context.Context, public_id string, is_public bool) (*types.PublicReportWater, error) {
|
||||
report, err := ByID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
return water(ctx, public_id, report)
|
||||
}
|
||||
func ReportsForOrganization(ctx context.Context, org_id int32, is_public bool) ([]*types.PublicReport, error) {
|
||||
query := reportQuery()
|
||||
query.Apply(
|
||||
sm.Where(psql.Quote("r", "organization_id").EQ(psql.Arg(org_id))),
|
||||
sm.Where(psql.Quote("r", "reviewed").IsNull()),
|
||||
)
|
||||
return reportQueryToRows(ctx, query, is_public)
|
||||
}
|
||||
func reportQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQuery], is_public bool) ([]*types.PublicReport, error) {
|
||||
rows, err := bob.All(ctx, db.PGInstance.BobDB, query, scan.StructMapper[types.PublicReport]())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue