diff --git a/platform/publicreport.go b/platform/publicreport.go index aacbfd15..d335bf0c 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -265,11 +265,13 @@ func publicReportCreate(ctx context.Context, setter_report models.PublicreportRe } defer txn.Rollback(ctx) - public_id, err := GenerateReportID() - if err != nil { - return nil, fmt.Errorf("create public ID: %w", err) + if setter_report.PublicID.IsUnset() { + public_id, err := GenerateReportID() + if err != nil { + return nil, fmt.Errorf("create public ID: %w", err) + } + setter_report.PublicID = omit.From(public_id) } - setter_report.PublicID = omit.From(public_id) var addr *models.Address if address != nil && address.GID != "" { @@ -305,7 +307,7 @@ func publicReportCreate(ctx context.Context, setter_report models.PublicreportRe publicReportUpdateLocation(ctx, txn, result.ID, l) } } - log.Info().Str("public_id", public_id).Int32("id", result.ID).Msg("Created base report") + log.Info().Str("public_id", setter_report.PublicID.GetOr("")).Int32("id", result.ID).Msg("Created base report") if len(saved_images) > 0 { setters := make([]*models.PublicreportReportImageSetter, 0) diff --git a/resource/publicreport_compliance.go b/resource/publicreport_compliance.go index 51b70a34..b40830c3 100644 --- a/resource/publicreport_compliance.go +++ b/resource/publicreport_compliance.go @@ -43,6 +43,7 @@ type publicreportComplianceForm struct { 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"` @@ -89,7 +90,7 @@ func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicrep Location: omitnull.FromPtr[string](nil), MapZoom: omit.From(float32(0.0)), //OrganizationID: omit.From[int32](int32(*district_id)), - //PublicID: omit.From(public_id), + PublicID: n.MailerID, ReporterEmail: omit.From(""), ReporterName: omit.From(""), ReporterPhone: omit.From(""), diff --git a/ts/rmo/router.ts b/ts/rmo/router.ts index 82fcb57b..f5ccb2e5 100644 --- a/ts/rmo/router.ts +++ b/ts/rmo/router.ts @@ -5,6 +5,7 @@ import ComplianceAddress from "@/rmo/content/compliance/Address.vue"; import ComplianceComplete from "@/rmo/content/compliance/Complete.vue"; import ComplianceConcern from "@/rmo/content/compliance/Concern.vue"; import ComplianceContact from "@/rmo/content/compliance/Contact.vue"; +import ComplianceDistrict from "@/rmo/view/ComplianceDistrict.vue"; import ComplianceEvidence from "@/rmo/content/compliance/Evidence.vue"; import ComplianceIntro from "@/rmo/content/compliance/Intro.vue"; import ComplianceMailer from "@/rmo/view/ComplianceMailer.vue"; @@ -87,10 +88,16 @@ const routes: RouteRecordRaw[] = [ }, ], component: Compliance, - path: "/district/:slug/compliance", + path: "/compliance/:public_id", name: "Compliance", props: true, }, + { + component: ComplianceDistrict, + path: "/district/:slug/compliance", + name: "ComplianceDistrict", + props: true, + }, { path: "/district/:slug/nuisance", name: "NuisanceDistrict", @@ -110,53 +117,6 @@ const routes: RouteRecordRaw[] = [ props: true, }, { - children: [ - { - component: ComplianceIntro, - name: "ComplianceIntro", - path: "", - }, - { - component: ComplianceAddress, - name: "ComplianceAddress", - path: "address", - }, - { - component: ComplianceComplete, - name: "ComplianceComplete", - path: "complete", - }, - { - component: ComplianceConcern, - name: "ComplianceConcern", - path: "concern", - }, - { - component: ComplianceContact, - name: "ComplianceContact", - path: "contact", - }, - { - component: ComplianceEvidence, - name: "ComplianceEvidence", - path: "evidence", - }, - { - component: CompliancePermission, - name: "CompliancePermission", - path: "permission", - }, - { - component: ComplianceProcess, - name: "ComplianceProcess", - path: "process", - }, - { - component: ComplianceSubmit, - name: "ComplianceSubmit", - path: "submit", - }, - ], path: "/mailer/:public_id", name: "ComplianceMailer", component: ComplianceMailer, diff --git a/ts/rmo/view/ComplianceDistrict.vue b/ts/rmo/view/ComplianceDistrict.vue new file mode 100644 index 00000000..dc81a424 --- /dev/null +++ b/ts/rmo/view/ComplianceDistrict.vue @@ -0,0 +1,72 @@ + + + + + + Loading... + + Loading report details... + + + + + + diff --git a/ts/rmo/view/ComplianceMailer.vue b/ts/rmo/view/ComplianceMailer.vue index a5413e74..50097d29 100644 --- a/ts/rmo/view/ComplianceMailer.vue +++ b/ts/rmo/view/ComplianceMailer.vue @@ -1,54 +1,19 @@ - - - - - - - - - - - - Reference number: {{ report.public_id }} - + + + + + Loading... + + Loading report details... + + diff --git a/ts/store/publicreport.ts b/ts/store/publicreport.ts index 77bb4c24..9dc09280 100644 --- a/ts/store/publicreport.ts +++ b/ts/store/publicreport.ts @@ -1,11 +1,16 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import { PublicReport, type PublicReportDTO } from "@/type/api"; + +import { apiClient } from "@/client"; +import { + PublicReport, + type PublicReportCreateRequest, + type PublicReportDTO, +} from "@/type/api"; export const useStorePublicReport = defineStore("publicreport", () => { // State const _byID = ref>(new Map()); - const error = ref(null); const loading = ref(false); //const ongoingFetch = ref | null>(null); @@ -15,7 +20,6 @@ export const useStorePublicReport = defineStore("publicreport", () => { // Actions async function byID(id: string): Promise { loading.value = true; - error.value = null; try { const url = `/api/publicreport/${id}`; const response = await fetch(url); @@ -32,10 +36,29 @@ export const useStorePublicReport = defineStore("publicreport", () => { throw err; } } - + async function byURI(uri: string): Promise { + const id = uri.split("/").pop() || ""; + if (!id) { + throw new Error(`${uri} is not a recognized public report URI`); + } + return byID(id); + } + async function create( + data: PublicReportCreateRequest, + ): Promise { + const resp = (await apiClient.JSONPost( + "/api/rmo/compliance", + data, + )) as PublicReportDTO; + const result = PublicReport.fromJSON(resp); + _byID.value.set(result.public_id, result); + return result; + } return { // Actions add, byID, + byURI, + create, }; }); diff --git a/ts/type/api.ts b/ts/type/api.ts index 4c5cff49..c3c0ac5d 100644 --- a/ts/type/api.ts +++ b/ts/type/api.ts @@ -174,6 +174,11 @@ export interface PublicReportDTO { //water?: Water; uri: string; } +export interface PublicReportCreateRequest { + client_id: string; + district?: string; + mailer_id?: string; +} export interface PublicReportOptions { address: Address; created: Date;
Loading report details...