2026-01-13 20:26:15 +00:00
|
|
|
package sync
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2026-01-30 18:21:27 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/html"
|
2026-03-03 17:08:58 +00:00
|
|
|
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
2026-03-04 18:29:52 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
2026-01-13 20:26:15 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-24 15:34:53 +00:00
|
|
|
type contentSource struct {
|
2026-03-12 23:49:16 +00:00
|
|
|
Inspections []platform.Inspection
|
|
|
|
|
Source *platform.BreedingSourceDetail
|
|
|
|
|
Traps []platform.TrapNearby
|
|
|
|
|
Treatments []platform.Treatment
|
2026-01-15 22:12:35 +00:00
|
|
|
//TreatmentCadence TreatmentCadence
|
2026-03-12 23:49:16 +00:00
|
|
|
TreatmentModels []platform.TreatmentModel
|
2026-03-04 18:29:52 +00:00
|
|
|
User platform.User
|
2026-01-15 22:12:35 +00:00
|
|
|
}
|
2026-02-24 15:34:53 +00:00
|
|
|
type contentTrap struct {
|
2026-03-12 23:49:16 +00:00
|
|
|
Trap platform.Trap
|
2026-03-04 18:29:52 +00:00
|
|
|
User platform.User
|
2026-01-15 22:12:35 +00:00
|
|
|
}
|
2026-02-24 15:34:53 +00:00
|
|
|
type contentLayoutTest struct {
|
2026-03-04 18:29:52 +00:00
|
|
|
User platform.User
|
2026-01-28 17:15:42 +00:00
|
|
|
}
|
2026-02-10 17:31:24 +00:00
|
|
|
type ContentDistrict struct {
|
2026-01-13 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDistrict(w http.ResponseWriter, r *http.Request) {
|
2026-03-09 18:02:22 +00:00
|
|
|
context := ContentDistrict{}
|
2026-02-07 05:51:21 +00:00
|
|
|
html.RenderOrError(w, "sync/district.html", &context)
|
2026-01-13 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 23:49:16 +00:00
|
|
|
func getLayoutTest(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentLayoutTest], *nhttp.ErrorWithStatus) {
|
2026-03-03 17:08:58 +00:00
|
|
|
return html.NewResponse("sync/layout-test.html", contentLayoutTest{}), nil
|
2026-01-28 17:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 06:08:55 -07:00
|
|
|
func getRoot(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
html.RenderOrError(w, "static/gen/main.html", struct{}{})
|
2026-01-13 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 23:49:16 +00:00
|
|
|
func getSource(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentSource], *nhttp.ErrorWithStatus) {
|
2026-01-13 20:26:15 +00:00
|
|
|
globalid_s := chi.URLParam(r, "globalid")
|
|
|
|
|
if globalid_s == "" {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("No globalid provided: %w", nil)
|
2026-01-13 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
globalid, err := uuid.Parse(globalid_s)
|
|
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("globalid is not a UUID: %w", nil)
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
s, err := platform.SourceByGlobalID(ctx, user.Organization, globalid)
|
2026-02-24 15:34:53 +00:00
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("Failed to get source: %w", err)
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
inspections, err := platform.InspectionsBySource(ctx, user.Organization, globalid)
|
2026-02-24 15:34:53 +00:00
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("Failed to get inspections: %w", err)
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
traps, err := platform.TrapsBySource(ctx, user.Organization, globalid)
|
2026-02-24 15:34:53 +00:00
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("Failed to get traps: %w", err)
|
2026-01-13 20:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 23:49:16 +00:00
|
|
|
treatments, err := platform.TreatmentsBySource(ctx, user.Organization, globalid)
|
2026-02-12 21:06:35 +00:00
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("Failed to get treatments: %w", err)
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
treatment_models := platform.ModelTreatment(treatments)
|
2026-02-24 15:34:53 +00:00
|
|
|
data := contentSource{
|
|
|
|
|
Inspections: inspections,
|
|
|
|
|
Source: s,
|
|
|
|
|
Traps: traps,
|
|
|
|
|
Treatments: treatments,
|
|
|
|
|
TreatmentModels: treatment_models,
|
2026-03-12 23:49:16 +00:00
|
|
|
User: user,
|
2026-02-12 21:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 17:08:58 +00:00
|
|
|
return html.NewResponse("sync/source.html", data), nil
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-07 05:51:21 +00:00
|
|
|
func getTemplateTest(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
html.RenderOrError(w, "sync/template-test.html", nil)
|
|
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
func getTrap(ctx context.Context, r *http.Request, user platform.User) (*html.Response[contentTrap], *nhttp.ErrorWithStatus) {
|
2026-01-15 22:12:35 +00:00
|
|
|
globalid_s := chi.URLParam(r, "globalid")
|
|
|
|
|
if globalid_s == "" {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("No globalid provided: %w", nil)
|
2026-01-15 22:12:35 +00:00
|
|
|
}
|
|
|
|
|
globalid, err := uuid.Parse(globalid_s)
|
|
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("globalid is not a UUID: %w", nil)
|
2026-01-15 22:12:35 +00:00
|
|
|
}
|
2026-03-12 23:49:16 +00:00
|
|
|
t, err := platform.TrapByGlobalId(ctx, user.Organization, globalid)
|
2026-02-24 15:34:53 +00:00
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("Failed to get trap: %w", err)
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
/*
|
2026-02-24 15:34:53 +00:00
|
|
|
latlng, err := t.H3Cell.LatLng()
|
|
|
|
|
if err != nil {
|
2026-03-03 17:08:58 +00:00
|
|
|
return nil, nhttp.NewError("Failed to get latlng: %w", err)
|
2026-01-13 20:26:15 +00:00
|
|
|
}
|
2026-03-27 06:08:55 -07:00
|
|
|
*/
|
2026-02-24 15:34:53 +00:00
|
|
|
data := contentTrap{
|
2026-03-12 23:49:16 +00:00
|
|
|
Trap: *t,
|
|
|
|
|
User: user,
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-03-03 17:08:58 +00:00
|
|
|
return html.NewResponse("sync/trap.html", data), nil
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 23:49:16 +00:00
|
|
|
func source(w http.ResponseWriter, r *http.Request, user platform.User, id uuid.UUID) {
|
2026-02-24 15:34:53 +00:00
|
|
|
}
|
2026-01-15 22:12:35 +00:00
|
|
|
|
2026-03-12 23:49:16 +00:00
|
|
|
func trap(w http.ResponseWriter, r *http.Request, user platform.User, id uuid.UUID) {
|
2026-01-15 22:12:35 +00:00
|
|
|
}
|