Add a resource for getting service requests

This commit is contained in:
Eli Ribble 2026-04-14 19:59:32 +00:00
parent 28ec1c3d67
commit 4a440e3022
No known key found for this signature in database
18 changed files with 387 additions and 51 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
"github.com/gorilla/mux"
"net/http"
//"github.com/rs/zerolog/log"
@ -21,8 +22,8 @@ func Lead(r *mux.Router) *leadR {
}
type createLead struct {
PoolLocations map[int]platform.Location `json:"pool_locations"`
SignalIDs []int `json:"signal_ids"`
PoolLocations map[int]types.Location `json:"pool_locations"`
SignalIDs []int `json:"signal_ids"`
}
type contentListLead struct {
Leads []lead `json:"leads"`
@ -44,7 +45,7 @@ func (res *leadR) Create(ctx context.Context, r *http.Request, user platform.Use
return "", nhttp.NewErrorStatus(http.StatusBadRequest, "can't make a lead with multiple signals yet")
}
signal_id := req.SignalIDs[0]
var pool_location *platform.Location
var pool_location *types.Location
l, ok := req.PoolLocations[signal_id]
if ok {
pool_location = &l

View file

@ -0,0 +1,34 @@
package resource
import (
"context"
"net/http"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
//"github.com/aarondl/opt/null"
//"github.com/gorilla/mux"
)
type serviceRequestR struct {
router *router
}
func ServiceRequest(r *router) *serviceRequestR {
return &serviceRequestR{
router: r,
}
}
func (res *serviceRequestR) List(ctx context.Context, r *http.Request, user platform.User, query QueryParams) ([]*types.ServiceRequest, *nhttp.ErrorWithStatus) {
limit := 20
if query.Limit != nil {
limit = *query.Limit
}
serviceRequests, err := platform.ServiceRequestList(ctx, user, limit)
if err != nil {
return nil, nhttp.NewError("list signals: %w", err)
}
return serviceRequests, nil
}

View file

@ -51,6 +51,7 @@ type sessionURLAPI struct {
Impersonation string `json:"impersonation"`
PublicreportMessage string `json:"publicreport_message"`
ReviewTask string `json:"review_task"`
ServiceRequest string `json:"service_request"`
Signal string `json:"signal"`
Sync string `json:"sync"`
Upload string `json:"upload"`
@ -96,6 +97,7 @@ func (res *sessionR) Get(ctx context.Context, r *http.Request, user platform.Use
Impersonation: config.MakeURLNidus("/api/impersonation"),
PublicreportMessage: urls.API.Publicreport.Message,
ReviewTask: config.MakeURLNidus("/api/review-task"),
ServiceRequest: config.MakeURLNidus("/api/service-request"),
Signal: config.MakeURLNidus("/api/signal"),
Sync: config.MakeURLNidus("/api/sync"),
Upload: config.MakeURLNidus("/api/upload"),

34
resource/sync.go Normal file
View file

@ -0,0 +1,34 @@
package resource
import (
"context"
"net/http"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
//"github.com/aarondl/opt/null"
"github.com/gorilla/mux"
)
type syncR struct {
router *mux.Router
}
func Sync(r *mux.Router) *syncR {
return &syncR{
router: r,
}
}
func (res *syncR) List(ctx context.Context, r *http.Request, user platform.User, query QueryParams) ([]*types.Sync, *nhttp.ErrorWithStatus) {
limit := 20
if query.Limit != nil {
limit = *query.Limit
}
syncs, err := platform.SyncList(ctx, user, limit)
if err != nil {
return nil, nhttp.NewError("list signals: %w", err)
}
return syncs, nil
}