Skip to content

Commit

Permalink
refactor: fix processor
Browse files Browse the repository at this point in the history
  • Loading branch information
KunLee76 committed May 12, 2024
1 parent fc815f9 commit ede7148
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
3 changes: 1 addition & 2 deletions internal/sbi/api_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"github.com/gin-gonic/gin"

"github.com/free5gc/nrf/internal/logger"
"github.com/free5gc/nrf/internal/sbi/processor"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/httpwrapper"
Expand Down Expand Up @@ -48,7 +47,7 @@

req := httpwrapper.NewRequest(c.Request, nil)
req.Query = c.Request.URL.Query()
httpResponse := processor.HandleNFDiscoveryRequest(req)
httpResponse := s.processor.HandleNFDiscoveryRequest(req)

responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions internal/sbi/api_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/free5gc/util/mongoapi"
"github.com/free5gc/openapi"
"github.com/free5gc/util/httpwrapper"
"github.com/free5gc/nrf/internal/sbi/processor"
)

func (s *Server) getNFManagementRoutes() []Route {
Expand Down Expand Up @@ -85,7 +84,7 @@ func (s *Server) getDeregisterNFInstance(c *gin.Context) {
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["nfInstanceID"] = c.Params.ByName("nfInstanceID")

httpResponse := processor.HandleNFDeregisterRequest(req)
httpResponse := s.processor.HandleNFDeregisterRequest(req)

responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
Expand All @@ -112,7 +111,7 @@ func (s *Server) getNFInstance(c *gin.Context) {
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["nfInstanceID"] = c.Params.ByName("nfInstanceID")

httpResponse := processor.HandleGetNFInstanceRequest(req)
httpResponse := s.processor.HandleGetNFInstanceRequest(req)

responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
Expand Down Expand Up @@ -170,7 +169,7 @@ func (s *Server) getRegisterNFInstance(c *gin.Context) {
req := httpwrapper.NewRequest(c.Request, nfprofile)

// step 4: call producer
httpResponse := processor.HandleNFRegisterRequest(req)
httpResponse := s.processor.HandleNFRegisterRequest(req)

for key, val := range httpResponse.Header {
c.Header(key, val[0])
Expand Down Expand Up @@ -216,7 +215,7 @@ func (s *Server) getUpdateNFInstance(c *gin.Context) {
req.Params["nfInstanceID"] = c.Params.ByName("nfInstanceID")
req.Body = requestBody

httpResponse := processor.HandleUpdateNFInstanceRequest(req)
httpResponse := s.processor.HandleUpdateNFInstanceRequest(req)

responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
Expand All @@ -243,7 +242,7 @@ func (s *Server) getNFInstances(c *gin.Context) {
req := httpwrapper.NewRequest(c.Request, nil)
req.Query = c.Request.URL.Query()

httpResponse := processor.HandleGetNFInstancesRequest(req)
httpResponse := s.processor.HandleGetNFInstancesRequest(req)

responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
Expand All @@ -270,7 +269,7 @@ func (s *Server) getRemoveSubscription(c *gin.Context) {
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["subscriptionID"] = c.Params.ByName("subscriptionID")

httpResponse := processor.HandleRemoveSubscriptionRequest(req)
httpResponse := s.processor.HandleRemoveSubscriptionRequest(req)

responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
Expand Down Expand Up @@ -311,7 +310,7 @@ func (s *Server) getUpdateSubscription(c *gin.Context) {
req.Params["subscriptionID"] = c.Params.ByName("subscriptionID")
req.Body = requestBody

httpResponse := processor.HandleUpdateSubscriptionRequest(req)
httpResponse := s.processor.HandleUpdateSubscriptionRequest(req)
responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
logger.NfmLog.Warnln(err)
Expand Down Expand Up @@ -368,7 +367,7 @@ func (s *Server) getCreateSubscription(c *gin.Context) {

req := httpwrapper.NewRequest(c.Request, subscription)

httpResponse := processor.HandleCreateSubscriptionRequest(req)
httpResponse := s.processor.HandleCreateSubscriptionRequest(req)
responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
logger.NfmLog.Errorln(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/processor/nfdiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/free5gc/util/mongoapi"
)

func HandleNFDiscoveryRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleNFDiscoveryRequest(request *httpwrapper.Request) *httpwrapper.Response {
// Get all query parameters
logger.DiscLog.Infoln("Handle NFDiscoveryRequest")

Expand Down
16 changes: 8 additions & 8 deletions internal/sbi/processor/nfmanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/free5gc/util/mongoapi"
)

func HandleNFDeregisterRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleNFDeregisterRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle NFDeregisterRequest")
nfInstanceId := request.Params["nfInstanceID"]

Expand All @@ -37,7 +37,7 @@ func HandleNFDeregisterRequest(request *httpwrapper.Request) *httpwrapper.Respon
}
}

func HandleGetNFInstanceRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleGetNFInstanceRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle GetNFInstanceRequest")
nfInstanceId := request.Params["nfInstanceID"]

Expand All @@ -54,7 +54,7 @@ func HandleGetNFInstanceRequest(request *httpwrapper.Request) *httpwrapper.Respo
}
}

func HandleNFRegisterRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleNFRegisterRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle NFRegisterRequest")
nfProfile := request.Body.(models.NfProfile)

Expand All @@ -79,7 +79,7 @@ func HandleNFRegisterRequest(request *httpwrapper.Request) *httpwrapper.Response
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

func HandleUpdateNFInstanceRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleUpdateNFInstanceRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle UpdateNFInstanceRequest")
nfInstanceID := request.Params["nfInstanceID"]
patchJSON := request.Body.([]byte)
Expand All @@ -92,7 +92,7 @@ func HandleUpdateNFInstanceRequest(request *httpwrapper.Request) *httpwrapper.Re
}
}

func HandleGetNFInstancesRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleGetNFInstancesRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle GetNFInstancesRequest")
nfType := request.Query.Get("nf-type")
limit_param := request.Query.Get("limit")
Expand Down Expand Up @@ -136,7 +136,7 @@ func HandleGetNFInstancesRequest(request *httpwrapper.Request) *httpwrapper.Resp
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

func HandleRemoveSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleRemoveSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle RemoveSubscription")
subscriptionID := request.Params["subscriptionID"]

Expand All @@ -145,7 +145,7 @@ func HandleRemoveSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.
return httpwrapper.NewResponse(http.StatusNoContent, nil, nil)
}

func HandleUpdateSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleUpdateSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle UpdateSubscription")
subscriptionID := request.Params["subscriptionID"]
patchJSON := request.Body.([]byte)
Expand All @@ -159,7 +159,7 @@ func HandleUpdateSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.
}
}

func HandleCreateSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.Response {
func (p *Processor) HandleCreateSubscriptionRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.NfmLog.Infoln("Handle CreateSubscriptionRequest")
subscription := request.Body.(models.NrfSubscriptionData)

Expand Down

0 comments on commit ede7148

Please sign in to comment.