Get latest syncs from the API
This commit is contained in:
parent
347e8dcb86
commit
28ec1c3d67
6 changed files with 89 additions and 30 deletions
|
|
@ -1,27 +0,0 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
)
|
||||
|
||||
type Location = types.Location
|
||||
|
||||
type ClientSync struct {
|
||||
Fieldseeker FieldseekerRecordsSync
|
||||
Since time.Time
|
||||
}
|
||||
|
||||
type FieldseekerRecordsSync struct {
|
||||
MosquitoSources []MosquitoSource
|
||||
ServiceRequests models.FieldseekerServicerequestSlice
|
||||
TrapData models.FieldseekerTraplocationSlice
|
||||
}
|
||||
|
||||
type MosquitoSource struct {
|
||||
PointLocation models.FieldseekerPointlocation
|
||||
Inspections models.FieldseekerMosquitoinspectionSlice
|
||||
Treatments models.FieldseekerTreatmentSlice
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/rs/zerolog/log"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Address struct {
|
||||
|
|
@ -25,7 +25,7 @@ func (a Address) String() string {
|
|||
return fmt.Sprintf("%s %s, %s, %s, %s, %s", a.Number, a.Street, a.Locality, a.Region, a.PostalCode, a.Country)
|
||||
}
|
||||
func AddressFromModel(m *models.Address) Address {
|
||||
log.Debug().Int32("id", m.ID).Float64("lat", m.LocationLatitude.GetOr(0.0)).Float64("lng", m.LocationLongitude.GetOr(0.0)).Msg("converting address")
|
||||
//log.Debug().Int32("id", m.ID).Float64("lat", m.LocationLatitude.GetOr(0.0)).Float64("lng", m.LocationLongitude.GetOr(0.0)).Msg("converting address")
|
||||
return Address{
|
||||
Country: m.Country,
|
||||
GID: m.Gid,
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ type sessionURLAPI struct {
|
|||
PublicreportMessage string `json:"publicreport_message"`
|
||||
ReviewTask string `json:"review_task"`
|
||||
Signal string `json:"signal"`
|
||||
Sync string `json:"sync"`
|
||||
Upload string `json:"upload"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
|
@ -96,6 +97,7 @@ func (res *sessionR) Get(ctx context.Context, r *http.Request, user platform.Use
|
|||
PublicreportMessage: urls.API.Publicreport.Message,
|
||||
ReviewTask: config.MakeURLNidus("/api/review-task"),
|
||||
Signal: config.MakeURLNidus("/api/signal"),
|
||||
Sync: config.MakeURLNidus("/api/sync"),
|
||||
Upload: config.MakeURLNidus("/api/upload"),
|
||||
User: config.MakeURLNidus("/api/user"),
|
||||
},
|
||||
|
|
|
|||
50
ts/store/sync.ts
Normal file
50
ts/store/sync.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { Sync } from "@/type/api";
|
||||
import { SSEManager, SSEMessage } from "@/SSEManager";
|
||||
import { useSessionStore } from "@/store/session";
|
||||
|
||||
export const useStoreSync = defineStore("sync", () => {
|
||||
// State
|
||||
const all = ref<Sync[] | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
|
||||
// Subscription
|
||||
SSEManager.subscribe((msg: SSEMessage) => {
|
||||
if (msg.resource.startsWith("sync:sync")) {
|
||||
fetchAll();
|
||||
}
|
||||
});
|
||||
// Actions
|
||||
async function fetchAll(): Promise<Sync[]> {
|
||||
const session = useSessionStore();
|
||||
if (session.urls == null) {
|
||||
throw new Error("can't fetch without user URL data");
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
const response = await fetch(`${session.urls.api.sync}?${params}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = (await response.json()) as Sync[];
|
||||
all.value = data;
|
||||
return data;
|
||||
} catch (err) {
|
||||
console.error("Error loading communications:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return {
|
||||
// State
|
||||
all,
|
||||
// Actions
|
||||
fetchAll,
|
||||
};
|
||||
});
|
||||
|
|
@ -637,6 +637,34 @@ export interface Session {
|
|||
self: User;
|
||||
urls: URLs;
|
||||
}
|
||||
export interface SyncDTO {
|
||||
created: Date;
|
||||
id: string;
|
||||
organization: string;
|
||||
records_created: number;
|
||||
records_unchanged: number;
|
||||
records_updated: number;
|
||||
}
|
||||
export class Sync {
|
||||
constructor(
|
||||
public created: Date,
|
||||
public id: string,
|
||||
public organization: string,
|
||||
public records_created: number,
|
||||
public records_unchanged: number,
|
||||
public records_updated: number,
|
||||
) {}
|
||||
static fromJSON(json: SyncDTO): Sync {
|
||||
return new Sync(
|
||||
new Date(json.created),
|
||||
json.id,
|
||||
json.organization,
|
||||
json.records_created,
|
||||
json.records_unchanged,
|
||||
json.records_updated,
|
||||
);
|
||||
}
|
||||
}
|
||||
export interface URLs {
|
||||
api: URLsAPI;
|
||||
tegola: string;
|
||||
|
|
@ -650,6 +678,7 @@ interface URLsAPI {
|
|||
publicreport_message: string;
|
||||
review_task: string;
|
||||
signal: string;
|
||||
sync: string;
|
||||
upload: string;
|
||||
user: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ import { onMounted, reactive } from "vue";
|
|||
import MapAggregate from "@/components/MapAggregate.vue";
|
||||
import { formatBigNumber, formatTimeRelative } from "@/format";
|
||||
import { useSessionStore } from "@/store/session";
|
||||
import { useStoreSync } from "@/store/sync";
|
||||
import type { Bounds } from "@/type/api";
|
||||
|
||||
const dashboard = reactive({
|
||||
|
|
@ -180,8 +181,12 @@ const dashboard = reactive({
|
|||
},
|
||||
recentRequests: [],
|
||||
});
|
||||
const storeSync = useStoreSync();
|
||||
const session = useSessionStore();
|
||||
onMounted(async () => {});
|
||||
onMounted(async () => {
|
||||
const syncs = await storeSync.fetchAll();
|
||||
console.log("syncs", syncs);
|
||||
});
|
||||
function mapBounds(): Bounds | undefined {
|
||||
if (session.organization?.service_area) {
|
||||
return session.organization?.service_area;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue