-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_subscription_id_document.go
77 lines (67 loc) · 2.13 KB
/
api_subscription_id_document.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
/*
* NRF NFManagement Service
*
* NRF NFManagement Service
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package management
import (
"github.com/nycu-ucr/gonet/http"
"github.com/nycu-ucr/gin"
"github.com/nycu-ucr/http_wrapper"
"github.com/nycu-ucr/nrf/logger"
"github.com/nycu-ucr/nrf/producer"
"github.com/nycu-ucr/openapi"
"github.com/nycu-ucr/openapi/models"
)
// RemoveSubscription - Deletes a subscription
func HTTPRemoveSubscription(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req.Params["subscriptionID"] = c.Params.ByName("subscriptionID")
httpResponse := producer.HandleRemoveSubscriptionRequest(req)
responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
logger.ManagementLog.Warnln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(httpResponse.Status, "application/json", responseBody)
}
}
// UpdateSubscription - Updates a subscription
func HTTPUpdateSubscription(c *gin.Context) {
requestBody, err := c.GetRawData()
if err != nil {
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
logger.ManagementLog.Errorf("Get Request Body error: %+v", err)
c.JSON(http.StatusInternalServerError, problemDetail)
return
}
req := http_wrapper.NewRequest(c.Request, nil)
req.Params["subscriptionID"] = c.Params.ByName("subscriptionID")
req.Body = requestBody
httpResponse := producer.HandleUpdateSubscriptionRequest(req)
responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
logger.ManagementLog.Warnln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(httpResponse.Status, "application/json", responseBody)
}
}