Skip to content

Commit

Permalink
Replace MongoDBLibrary with util/mongoapi
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Jan 18, 2024
1 parent adb4a68 commit 492e0dd
Show file tree
Hide file tree
Showing 29 changed files with 2,544 additions and 2,154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package datarepository

import (
"github.com/omec-project/util/mongoapi"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -27,23 +28,25 @@ import (
)

// HTTPQueryAmData - Retrieves the access and mobility subscription data of a UE
func HTTPQueryAmData(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")
req.Params["servingPlmnId"] = c.Params.ByName("servingPlmnId")

rsp := producer.HandleQueryAmData(req)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
func HTTPQueryAmData(m mongoapi.MongoClient) gin.HandlerFunc {
return func(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")
req.Params["servingPlmnId"] = c.Params.ByName("servingPlmnId")

rsp := producer.HandleQueryAmData(req, m)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
}
199 changes: 103 additions & 96 deletions datarepository/api_amf3_gpp_access_registration_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package datarepository

import (
"github.com/omec-project/util/mongoapi"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -27,120 +28,126 @@ import (
)

// HTTPAmfContext3gpp - To modify the AMF context data of a UE using 3gpp access in the UDR
func HTTPAmfContext3gpp(c *gin.Context) {
var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
if err != nil {
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
func HTTPAmfContext3gpp(m mongoapi.MongoClient) gin.HandlerFunc {
return func(c *gin.Context) {
var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
if err != nil {
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
logger.DataRepoLog.Errorf("Get Request Body error: %+v", err)
c.JSON(http.StatusInternalServerError, problemDetail)
return
}
logger.DataRepoLog.Errorf("Get Request Body error: %+v", err)
c.JSON(http.StatusInternalServerError, problemDetail)
return
}

err = openapi.Deserialize(&patchItemArray, requestBody, "application/json")
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
err = openapi.Deserialize(&patchItemArray, requestBody, "application/json")
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.DataRepoLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}
logger.DataRepoLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}

req := http_wrapper.NewRequest(c.Request, patchItemArray)
req.Params["ueId"] = c.Params.ByName("ueId")

rsp := producer.HandleAmfContext3gpp(req)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
req := http_wrapper.NewRequest(c.Request, patchItemArray)
req.Params["ueId"] = c.Params.ByName("ueId")

rsp := producer.HandleAmfContext3gpp(req, m)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
}

// HTTPCreateAmfContext3gpp - To store the AMF context data of a UE using 3gpp access in the UDR
func HTTPCreateAmfContext3gpp(c *gin.Context) {
var amf3GppAccessRegistration models.Amf3GppAccessRegistration

requestBody, err := c.GetRawData()
if err != nil {
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
func HTTPCreateAmfContext3gpp(m mongoapi.MongoClient) gin.HandlerFunc {
return func(c *gin.Context) {
var amf3GppAccessRegistration models.Amf3GppAccessRegistration

requestBody, err := c.GetRawData()
if err != nil {
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
logger.DataRepoLog.Errorf("Get Request Body error: %+v", err)
c.JSON(http.StatusInternalServerError, problemDetail)
return
}
logger.DataRepoLog.Errorf("Get Request Body error: %+v", err)
c.JSON(http.StatusInternalServerError, problemDetail)
return
}

err = openapi.Deserialize(&amf3GppAccessRegistration, requestBody, "application/json")
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
err = openapi.Deserialize(&amf3GppAccessRegistration, requestBody, "application/json")
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.DataRepoLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}
logger.DataRepoLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}

req := http_wrapper.NewRequest(c.Request, amf3GppAccessRegistration)
req.Params["ueId"] = c.Params.ByName("ueId")

rsp := producer.HandleCreateAmfContext3gpp(req)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
req := http_wrapper.NewRequest(c.Request, amf3GppAccessRegistration)
req.Params["ueId"] = c.Params.ByName("ueId")

rsp := producer.HandleCreateAmfContext3gpp(req, m)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
}

// HTTPQueryAmfContext3gpp - Retrieves the AMF context data of a UE using 3gpp access
func HTTPQueryAmfContext3gpp(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

rsp := producer.HandleQueryAmfContext3gpp(req)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
func HTTPQueryAmfContext3gpp(m mongoapi.MongoClient) gin.HandlerFunc {
return func(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

rsp := producer.HandleQueryAmfContext3gpp(req, m)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.DataRepoLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
}
Loading

0 comments on commit 492e0dd

Please sign in to comment.