Push update to public report event when reporter is saved
This commit is contained in:
parent
1075e35bca
commit
148454d392
3 changed files with 69 additions and 17 deletions
|
|
@ -71,34 +71,53 @@ func EventTypeFromString(s string) EventType {
|
|||
type ResourceType int
|
||||
|
||||
const (
|
||||
TypeRMONuisance = iota
|
||||
TypeUnknown = iota
|
||||
TypeRMONuisance
|
||||
TypeRMOWater
|
||||
)
|
||||
|
||||
func Created(type_ ResourceType, organization_id int32, uri_id string) {
|
||||
var resource string
|
||||
var uri string
|
||||
switch type_ {
|
||||
case TypeRMONuisance:
|
||||
resource = "rmo:nuisance"
|
||||
uri = config.MakeURLReport("/report/%s", uri_id)
|
||||
case TypeRMOWater:
|
||||
resource = "rmo:water"
|
||||
uri = config.MakeURLReport("/report/%s", uri_id)
|
||||
default:
|
||||
|
||||
}
|
||||
func Created(t ResourceType, organization_id int32, uri_id string) {
|
||||
go Send(Envelope{
|
||||
Event: Event{
|
||||
Resource: resource,
|
||||
Resource: resourceString(t),
|
||||
Time: time.Now(),
|
||||
Type: EventTypeCreated,
|
||||
URI: uri,
|
||||
URI: makeURI(t, uri_id),
|
||||
},
|
||||
OrganizationID: organization_id,
|
||||
})
|
||||
}
|
||||
func Updated(t ResourceType, organization_id int32, uri_id string) {
|
||||
go Send(Envelope{
|
||||
Event: Event{
|
||||
Resource: resourceString(t),
|
||||
Time: time.Now(),
|
||||
Type: EventTypeUpdated,
|
||||
URI: makeURI(t, uri_id),
|
||||
},
|
||||
OrganizationID: organization_id,
|
||||
})
|
||||
}
|
||||
func Send(env Envelope) {
|
||||
chanEvents <- env
|
||||
|
||||
}
|
||||
func resourceString(t ResourceType) string {
|
||||
switch t {
|
||||
case TypeRMONuisance:
|
||||
return "rmo:nuisance"
|
||||
case TypeRMOWater:
|
||||
return "rmo:water"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
func makeURI(t ResourceType, id string) string {
|
||||
switch t {
|
||||
case TypeRMONuisance:
|
||||
return config.MakeURLReport("/report/%s", id)
|
||||
case TypeRMOWater:
|
||||
return config.MakeURLReport("/report/%s", id)
|
||||
default:
|
||||
return config.MakeURLReport("/unknown")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
|
@ -36,5 +37,22 @@ func PublicreportInvalid(ctx context.Context, user User, report_id string) error
|
|||
}
|
||||
|
||||
log.Info().Str("report-id", report_id).Str("tablename", tablename).Msg("Marked as invalid")
|
||||
resource := resourceTypeFromTablename(tablename)
|
||||
event.Updated(resource, user.Organization.ID(), report_id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id string, tablename string) {
|
||||
resource := resourceTypeFromTablename(tablename)
|
||||
event.Updated(resource, org_id, report_id)
|
||||
}
|
||||
func resourceTypeFromTablename(tablename string) event.ResourceType {
|
||||
switch tablename {
|
||||
case "nuisance":
|
||||
return event.TypeRMONuisance
|
||||
case "water":
|
||||
return event.TypeRMOWater
|
||||
default:
|
||||
return event.TypeUnknown
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue