-
Notifications
You must be signed in to change notification settings - Fork 0
/
opsTrackingReading.go
57 lines (47 loc) · 1.69 KB
/
opsTrackingReading.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package wildlifenl
import (
"context"
"net/http"
"github.com/UtrechtUniversity/wildlifenl/models"
"github.com/UtrechtUniversity/wildlifenl/stores"
"github.com/danielgtaylor/huma/v2"
)
type NewTrackingReadingInput struct {
Input
Body *models.TrackingReadingRecord `json:"trackingReading"`
}
type TrackingReadingHolder struct {
Body *models.TrackingReading `json:"trackingReading"`
}
type TrackingReadingsHolder struct {
Body []models.TrackingReading `json:"trackingReadings"`
}
type trackingReadingOperations Operations
func newTrackingReadingOperations() *trackingReadingOperations {
o := trackingReadingOperations{
Endpoint: "tracking-reading",
}
return &o
}
func (o *trackingReadingOperations) RegisterAdd(api huma.API) {
name := "Add TrackingReading"
description := "Submit a new tracking reading."
path := "/" + o.Endpoint + "/"
scopes := []string{}
method := http.MethodPost
huma.Register(api, huma.Operation{
OperationID: name, Summary: name, Path: path, Method: method, Tags: []string{o.Endpoint}, Description: generateDescription(description, scopes), Security: []map[string][]string{{"auth": scopes}},
}, func(ctx context.Context, input *NewTrackingReadingInput) (*TrackingReadingHolder, error) {
trackingReading, err := stores.NewTrackingReadingStore(relationalDB, timeseriesDB).Add(input.credential.UserID, input.Body)
if err != nil {
return nil, handleError(err)
}
// Add Tracking-Reading -> Create Conveyance.
conveyance, err := stores.NewConveyanceStore(relationalDB).AddForTrackingReading(trackingReading)
if err != nil {
return nil, handleError(err)
}
trackingReading.Conveyance = conveyance
return &TrackingReadingHolder{Body: trackingReading}, nil
})
}