Start saving client ID on compliance reports

This commit is contained in:
Eli Ribble 2026-04-14 14:38:22 +00:00
parent 7545b2e4ef
commit a23866619d
No known key found for this signature in database
4 changed files with 35 additions and 1 deletions

30
platform/client.go Normal file
View file

@ -0,0 +1,30 @@
package platform
import (
"context"
"fmt"
"time"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/google/uuid"
)
func EnsureClient(ctx context.Context, client uuid.UUID, user_agent string) error {
_, err := models.PublicreportClients.Query(
models.SelectWhere.PublicreportClients.UUID.EQ(client),
).One(ctx, db.PGInstance.BobDB)
if err != nil {
if err.Error() == "sql: no rows in result set" {
return nil
}
return fmt.Errorf("failed existing client %s: %w", client.String(), err)
}
models.PublicreportClients.Insert(&models.PublicreportClientSetter{
Created: omit.From(time.Now()),
UserAgent: omit.From(user_agent),
UUID: omit.From(client),
}).One(ctx, db.PGInstance.BobDB)
return nil
}

View file

@ -13,6 +13,7 @@ import (
nhttp "github.com/Gleipnir-Technology/nidus-sync/http" nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform" "github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/platform/types" "github.com/Gleipnir-Technology/nidus-sync/platform/types"
"github.com/google/uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@ -47,10 +48,13 @@ func (res *complianceR) ByID(ctx context.Context, r *http.Request, query QueryPa
return report, nil return report, nil
} }
func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicreportComplianceForm) (*compliance, *nhttp.ErrorWithStatus) { func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicreportComplianceForm) (*compliance, *nhttp.ErrorWithStatus) {
user_agent := r.Header.Get("User-Agent")
platform.EnsureClient(ctx, n.ClientID, user_agent)
setter_report := models.PublicreportReportSetter{ setter_report := models.PublicreportReportSetter{
//AddressID: omitnull.From(latlng.Cell.String()), //AddressID: omitnull.From(latlng.Cell.String()),
AddressGid: omit.From(""), AddressGid: omit.From(""),
AddressRaw: omit.From(""), AddressRaw: omit.From(""),
ClientUUID: omitnull.From(n.ClientID),
Created: omit.From(time.Now()), Created: omit.From(time.Now()),
//H3cell: omitnull.From(latlng.Cell.String()), //H3cell: omitnull.From(latlng.Cell.String()),
LatlngAccuracyType: omit.From(enums.PublicreportAccuracytypeBrowser), LatlngAccuracyType: omit.From(enums.PublicreportAccuracytypeBrowser),
@ -100,7 +104,7 @@ type publicreportComplianceForm struct {
AccessInstructions omit.Val[string] `schema:"access_instructions" json:"access_instructions"` AccessInstructions omit.Val[string] `schema:"access_instructions" json:"access_instructions"`
Address omit.Val[types.Address] `schema:"address" json:"address"` Address omit.Val[types.Address] `schema:"address" json:"address"`
AvailabilityNotes omit.Val[string] `schema:"availability_notes" json:"availability_notes"` AvailabilityNotes omit.Val[string] `schema:"availability_notes" json:"availability_notes"`
ClientID string `schema:"client_id" json:"client_id"` ClientID uuid.UUID `schema:"client_id" json:"client_id"`
Comments omit.Val[string] `schema:"comments" json:"comments"` Comments omit.Val[string] `schema:"comments" json:"comments"`
GateCode omit.Val[string] `schema:"gate_code" json:"gate_code"` GateCode omit.Val[string] `schema:"gate_code" json:"gate_code"`
HasDog omitnull.Val[bool] `schema:"has_dog" json:"has_dog"` HasDog omitnull.Val[bool] `schema:"has_dog" json:"has_dog"`