/
api_ue_id_crud.go
87 lines (74 loc) · 2.29 KB
/
api_ue_id_crud.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Ndscf_DataRepository
*
* Ndscf Data Repository Service. © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package datarepository
import (
"encoding/json"
"net/http"
"strings"
"github.com/gorilla/mux"
)
// UeIdCRUDApiController binds http requests to an api service and writes the service results to the http response
type UeIdCRUDApiController struct {
service UeIdCRUDApiServicer
errorHandler ErrorHandler
}
// UeIdCRUDApiOption for how the controller is set up.
type UeIdCRUDApiOption func(*UeIdCRUDApiController)
// WithUeIdCRUDApiErrorHandler inject ErrorHandler into controller
func WithUeIdCRUDApiErrorHandler(h ErrorHandler) UeIdCRUDApiOption {
return func(c *UeIdCRUDApiController) {
c.errorHandler = h
}
}
// NewUeIdCRUDApiController creates a default api controller
func NewUeIdCRUDApiController(s UeIdCRUDApiServicer, opts ...UeIdCRUDApiOption) Router {
controller := &UeIdCRUDApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all of the api route for the UeIdCRUDApiController
func (c *UeIdCRUDApiController) Routes() Routes {
return Routes{
{
"CreateOrModifyCorrelation",
strings.ToUpper("Put"),
"/ndscf/v1/correlation/{ueId}",
c.CreateOrModifyCorrelation,
},
}
}
// CreateOrModifyCorrelation - Create/Modify correlation between ueId and subIDs
func (c *UeIdCRUDApiController) CreateOrModifyCorrelation(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
ueIdParam := params["ueId"]
subIdsParam := SubIds{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&subIdsParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertSubIdsRequired(subIdsParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.CreateOrModifyCorrelation(r.Context(), ueIdParam, subIdsParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}