Initial work marking communications
And a bunch of lint fixes
This commit is contained in:
parent
67c99436d1
commit
3153e8bf13
36 changed files with 1958 additions and 487 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
|
|
@ -12,7 +13,7 @@ import (
|
|||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/google/uuid"
|
||||
//"github.com/gorilla/mux"
|
||||
"github.com/gorilla/mux"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ type communication struct {
|
|||
Response string `json:"response"`
|
||||
Source string `json:"source"`
|
||||
Type string `json:"type"`
|
||||
URI string `json:"uri"`
|
||||
}
|
||||
|
||||
func toImageURLs(m map[string][]uuid.UUID, id string) []string {
|
||||
|
|
@ -49,7 +51,10 @@ func toImageURLs(m map[string][]uuid.UUID, id string) []string {
|
|||
}
|
||||
return urls
|
||||
}
|
||||
func (res *communicationR) List(ctx context.Context, r *http.Request, user platform.User, query QueryParams) ([]*communication, *nhttp.ErrorWithStatus) {
|
||||
func (res *communicationR) Get(ctx context.Context, r *http.Request, user platform.User, query QueryParams) (*communication, *nhttp.ErrorWithStatus) {
|
||||
return nil, nil
|
||||
}
|
||||
func (res *communicationR) List(ctx context.Context, r *http.Request, user platform.User, query QueryParams) ([]communication, *nhttp.ErrorWithStatus) {
|
||||
comms, err := platform.CommunicationsForOrganization(ctx, int64(user.Organization.ID))
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("nuisance report query: %w", err)
|
||||
|
|
@ -68,58 +73,19 @@ func (res *communicationR) List(ctx context.Context, r *http.Request, user platf
|
|||
for _, pr := range public_reports {
|
||||
public_report_id_to_report[pr.ID] = pr
|
||||
}
|
||||
result := make([]*communication, len(comms))
|
||||
result := make([]communication, len(comms))
|
||||
for i, comm := range comms {
|
||||
source_uri := "unknown"
|
||||
type_ := "unknown"
|
||||
if comm.SourceReportID != nil {
|
||||
public_report, ok := public_report_id_to_report[*comm.SourceReportID]
|
||||
if !ok {
|
||||
return nil, nhttp.NewError("lookup report id %d failed", comm.SourceReportID)
|
||||
}
|
||||
source_uri, err = reportURI(res.router, "", public_report.PublicID)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("gen report URI: %w", err)
|
||||
}
|
||||
type_ = "publicreport." + public_report.ReportType.String()
|
||||
} else if comm.SourceEmailLogID != nil {
|
||||
source_uri, err = emailURI(res.router, *comm.SourceEmailLogID)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("gen email URI: %w", err)
|
||||
}
|
||||
type_ = "email"
|
||||
} else if comm.SourceTextLogID != nil {
|
||||
source_uri, err = textURI(res.router, *comm.SourceTextLogID)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("gen email URI: %w", err)
|
||||
}
|
||||
source_uri = "text"
|
||||
public_report, ok := public_report_id_to_report[*comm.SourceReportID]
|
||||
if !ok {
|
||||
return nil, nhttp.NewError("lookup report id %d failed", comm.SourceReportID)
|
||||
}
|
||||
closed_by, err := userURI(res.router, comm.ClosedBy)
|
||||
c, err := res.hydrateCommunication(*comm, public_report)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("gen closed_by URI: %w", err)
|
||||
}
|
||||
opened_by, err := userURI(res.router, comm.OpenedBy)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("gen opened_by URI: %w", err)
|
||||
}
|
||||
response, err := responseURI(res.router, comm)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("gen response URI: %w", err)
|
||||
}
|
||||
result[i] = &communication{
|
||||
Closed: comm.Closed,
|
||||
ClosedBy: closed_by,
|
||||
Created: comm.Created,
|
||||
ID: comm.ID,
|
||||
Opened: comm.Opened,
|
||||
OpenedBy: opened_by,
|
||||
Response: response,
|
||||
Source: source_uri,
|
||||
Type: type_,
|
||||
return nil, err
|
||||
}
|
||||
result[i] = c
|
||||
}
|
||||
_by_created := func(a, b *communication) int {
|
||||
_by_created := func(a, b communication) int {
|
||||
if a.Created.Equal(b.Created) {
|
||||
return 0
|
||||
} else if a.Created.Before(b.Created) {
|
||||
|
|
@ -132,10 +98,93 @@ func (res *communicationR) List(ctx context.Context, r *http.Request, user platf
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func emailURI(r *router, id int32) (string, error) {
|
||||
return "fake email uri", nil
|
||||
type communicationMarkRequest struct{}
|
||||
|
||||
func (res *communicationR) MarkInvalid(ctx context.Context, r *http.Request, user platform.User, cmr communicationMarkRequest) (communication, *nhttp.ErrorWithStatus) {
|
||||
return res.markReport(ctx, r, user, platform.CommunicationMarkInvalid)
|
||||
}
|
||||
func responseURI(r *router, comm *modelpublic.Communication) (string, error) {
|
||||
func (res *communicationR) MarkPendingResponse(ctx context.Context, r *http.Request, user platform.User, cmr communicationMarkRequest) (communication, *nhttp.ErrorWithStatus) {
|
||||
return res.markReport(ctx, r, user, platform.CommunicationMarkPendingResponse)
|
||||
}
|
||||
func (res *communicationR) MarkPossibleIssue(ctx context.Context, r *http.Request, user platform.User, cmr communicationMarkRequest) (communication, *nhttp.ErrorWithStatus) {
|
||||
return res.markReport(ctx, r, user, platform.CommunicationMarkPossibleIssue)
|
||||
}
|
||||
func (res *communicationR) MarkPossibleResolved(ctx context.Context, r *http.Request, user platform.User, cmr communicationMarkRequest) (communication, *nhttp.ErrorWithStatus) {
|
||||
return res.markReport(ctx, r, user, platform.CommunicationMarkPossibleResolved)
|
||||
}
|
||||
func (res *communicationR) hydrateCommunication(comm modelpublic.Communication, public_report *modelpublicreport.Report) (communication, *nhttp.ErrorWithStatus) {
|
||||
var err error
|
||||
source_uri := "unknown"
|
||||
type_ := "unknown"
|
||||
if comm.SourceReportID != nil {
|
||||
source_uri, err = reportURI(res.router, "", public_report.PublicID)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen report URI: %w", err)
|
||||
}
|
||||
type_ = "publicreport." + public_report.ReportType.String()
|
||||
} else if comm.SourceEmailLogID != nil {
|
||||
source_uri, err = emailURI(*res.router, *comm.SourceEmailLogID)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen email URI: %w", err)
|
||||
}
|
||||
type_ = "email"
|
||||
} else if comm.SourceTextLogID != nil {
|
||||
source_uri, err = textURI(*res.router, *comm.SourceTextLogID)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen email URI: %w", err)
|
||||
}
|
||||
source_uri = "text"
|
||||
}
|
||||
closed_by, err := userURI(res.router, comm.ClosedBy)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen closed_by URI: %w", err)
|
||||
}
|
||||
opened_by, err := userURI(res.router, comm.OpenedBy)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen opened_by URI: %w", err)
|
||||
}
|
||||
response, err := responseURI(*res.router, comm)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen response URI: %w", err)
|
||||
}
|
||||
uri, err := res.router.IDToURI("communication.ByIDGet", int(comm.ID))
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewError("gen comm uri: %w", err)
|
||||
}
|
||||
return communication{
|
||||
Closed: comm.Closed,
|
||||
ClosedBy: closed_by,
|
||||
Created: comm.Created,
|
||||
ID: comm.ID,
|
||||
Opened: comm.Opened,
|
||||
OpenedBy: opened_by,
|
||||
Response: response,
|
||||
Source: source_uri,
|
||||
Type: type_,
|
||||
URI: uri,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type markFunc = func(context.Context, platform.User, int64) error
|
||||
|
||||
func (res *communicationR) markReport(ctx context.Context, r *http.Request, user platform.User, m markFunc) (communication, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
report_id_str := vars["id"]
|
||||
if report_id_str == "" {
|
||||
return communication{}, nhttp.NewBadRequest("no id provided")
|
||||
}
|
||||
report_id, err := strconv.Atoi(report_id_str)
|
||||
if err != nil {
|
||||
return communication{}, nhttp.NewBadRequest("can't turn report ID into an int: %w", err)
|
||||
}
|
||||
m(ctx, user, int64(report_id))
|
||||
result, err := platform.CommunicationFromID(ctx, user, int64(report_id))
|
||||
if result == nil {
|
||||
return communication{}, nhttp.NewUnauthorized("you are not authorized to modify communication %d", report_id)
|
||||
}
|
||||
return res.hydrateCommunication(*result, nil)
|
||||
}
|
||||
func responseURI(r router, comm modelpublic.Communication) (string, error) {
|
||||
if comm.ResponseEmailLogID != nil {
|
||||
return emailURI(r, *comm.ResponseEmailLogID)
|
||||
} else if comm.ResponseTextLogID != nil {
|
||||
|
|
@ -144,7 +193,11 @@ func responseURI(r *router, comm *modelpublic.Communication) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
}
|
||||
func textURI(r *router, id int32) (string, error) {
|
||||
func emailURI(r router, id int32) (string, error) {
|
||||
return "fake email uri", nil
|
||||
}
|
||||
|
||||
func textURI(r router, id int32) (string, error) {
|
||||
return "fake text uri", nil
|
||||
}
|
||||
func userURI(r *router, id *int32) (string, error) {
|
||||
|
|
|
|||
|
|
@ -29,21 +29,21 @@ type complianceR struct {
|
|||
}
|
||||
|
||||
type publicReportComplianceForm struct {
|
||||
AccessInstructions omit.Val[string] `schema:"access_instructions" json:"access_instructions"`
|
||||
Address omit.Val[types.Address] `schema:"address" json:"address"`
|
||||
AvailabilityNotes omit.Val[string] `schema:"availability_notes" json:"availability_notes"`
|
||||
ClientID uuid.UUID `schema:"client_id" json:"client_id"`
|
||||
Comments omit.Val[string] `schema:"comments" json:"comments"`
|
||||
District omit.Val[string] `schema:"district" json:"district"`
|
||||
GateCode omit.Val[string] `schema:"gate_code" json:"gate_code"`
|
||||
HasDog omitnull.Val[bool] `schema:"has_dog" json:"has_dog"`
|
||||
Location omit.Val[types.Location] `schema:"location" json:"location"`
|
||||
MailerID omit.Val[string] `schema:"mailer_id" json:"mailer_id"`
|
||||
PermissionType omit.Val[enums.Permissionaccesstype] `schema:"permission_type" json:"permission_type"`
|
||||
Reporter omit.Val[types.Contact] `schema:"reporter" json:"reporter"`
|
||||
ReportPhoneCanSMS omitnull.Val[bool] `schema:"report_phone_can_text" json:"report_phone_can_text"`
|
||||
Submitted omitnull.Val[time.Time] `schema:"submitted" json:"submitted"`
|
||||
WantsScheduled omitnull.Val[bool] `schema:"wants_scheduled" json:"wants_scheduled"`
|
||||
AccessInstructions omit.Val[string] `schema:"access_instructions" json:"access_instructions"`
|
||||
Address omit.Val[types.Address] `schema:"address" json:"address"`
|
||||
AvailabilityNotes omit.Val[string] `schema:"availability_notes" json:"availability_notes"`
|
||||
ClientID uuid.UUID `schema:"client_id" json:"client_id"`
|
||||
Comments omit.Val[string] `schema:"comments" json:"comments"`
|
||||
District omit.Val[string] `schema:"district" json:"district"`
|
||||
GateCode omit.Val[string] `schema:"gate_code" json:"gate_code"`
|
||||
HasDog omitnull.Val[bool] `schema:"has_dog" json:"has_dog"`
|
||||
Location omit.Val[types.Location] `schema:"location" json:"location"`
|
||||
MailerID omit.Val[string] `schema:"mailer_id" json:"mailer_id"`
|
||||
PermissionType omit.Val[enums.PublicreportPermissionaccesstype] `schema:"permission_type" json:"permission_type"`
|
||||
Reporter omit.Val[types.Contact] `schema:"reporter" json:"reporter"`
|
||||
ReportPhoneCanSMS omitnull.Val[bool] `schema:"report_phone_can_text" json:"report_phone_can_text"`
|
||||
Submitted omitnull.Val[time.Time] `schema:"submitted" json:"submitted"`
|
||||
WantsScheduled omitnull.Val[bool] `schema:"wants_scheduled" json:"wants_scheduled"`
|
||||
}
|
||||
|
||||
func (res *complianceR) ByID(ctx context.Context, r *http.Request, u platform.User, query QueryParams) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
|
|
@ -88,7 +88,7 @@ func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicRep
|
|||
Comments: omit.From(""),
|
||||
GateCode: omit.From(""),
|
||||
HasDog: omitnull.FromPtr[bool](nil),
|
||||
PermissionType: omit.From(enums.PermissionaccesstypeUnselected),
|
||||
PermissionType: omit.From(enums.PublicreportPermissionaccesstypeUnselected),
|
||||
//ReportID omit.Val[int32]
|
||||
WantsScheduled: omitnull.FromPtr[bool](nil),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue