-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
520 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
/* | ||
* Nchf_ConvergedCharging | ||
* | ||
* ConvergedCharging Service © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved. | ||
* | ||
* API version: 3.0.3 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package sbi | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/free5gc/chf/internal/sbi/producer" | ||
"github.com/free5gc/openapi" | ||
"github.com/free5gc/openapi/models" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/free5gc/chf/internal/logger" | ||
"github.com/free5gc/util/httpwrapper" | ||
) | ||
|
||
// Index is the index handler. | ||
func Index(c *gin.Context) { | ||
c.String(http.StatusOK, "Hello World!") | ||
} | ||
|
||
func (s *Server) getConvergenChargingEndpoints() []Endpoint { | ||
return []Endpoint{ | ||
{ | ||
Method: http.MethodGet, | ||
Pattern: "/", | ||
APIFunc: Index, | ||
}, | ||
{ | ||
Method: http.MethodPost, | ||
Pattern: "/chargingdata/:ChargingDataRef/release", | ||
APIFunc: s.ChargingdataChargingDataRefReleasePost, | ||
}, | ||
{ | ||
Method: http.MethodPost, | ||
Pattern: "/chargingdata/:ChargingDataRef/update", | ||
APIFunc: s.ChargingdataChargingDataRefUpdatePost, | ||
}, | ||
{ | ||
Method: http.MethodPost, | ||
Pattern: "/chargingdata", | ||
APIFunc: s.ChargingdataPost, | ||
}, | ||
{ | ||
Method: http.MethodGet, | ||
Pattern: "/recharging", | ||
APIFunc: s.RechargeGet, | ||
}, | ||
{ | ||
Method: http.MethodPut, | ||
Pattern: "/recharging/:rechargingInfo", | ||
APIFunc: s.RechargePut, | ||
}, | ||
} | ||
} | ||
|
||
// ChargingdataChargingDataRefReleasePost - | ||
func (s *Server) ChargingdataChargingDataRefReleasePost(c *gin.Context) { | ||
var chargingDataReq models.ChargingDataRequest | ||
|
||
requestBody, err := c.GetRawData() | ||
if err != nil { | ||
problemDetail := models.ProblemDetails{ | ||
Title: "System failure", | ||
Status: http.StatusInternalServerError, | ||
Detail: err.Error(), | ||
Cause: "SYSTEM_FAILURE", | ||
} | ||
logger.ChargingdataPostLog.Errorf("Get Request Body error: %+v", err) | ||
c.JSON(http.StatusInternalServerError, problemDetail) | ||
return | ||
} | ||
|
||
err = openapi.Deserialize(&chargingDataReq, requestBody, "application/json") | ||
if err != nil { | ||
problemDetail := "[Request Body] " + err.Error() | ||
rsp := models.ProblemDetails{ | ||
Title: "Malformed request syntax", | ||
Status: http.StatusBadRequest, | ||
Detail: problemDetail, | ||
} | ||
logger.ChargingdataPostLog.Errorln(problemDetail) | ||
c.JSON(http.StatusBadRequest, rsp) | ||
return | ||
} | ||
|
||
req := httpwrapper.NewRequest(c.Request, chargingDataReq) | ||
req.Params["ChargingDataRef"] = c.Param("ChargingDataRef") | ||
|
||
rsp := producer.HandleChargingdataRelease(req) | ||
|
||
for key, value := range rsp.Header { | ||
c.Header(key, value[0]) | ||
} | ||
responseBody, err := openapi.Serialize(rsp.Body, "application/json") | ||
if err != nil { | ||
logger.ChargingdataPostLog.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) | ||
} | ||
} | ||
|
||
// ChargingdataChargingDataRefUpdatePost | ||
func (s *Server) ChargingdataChargingDataRefUpdatePost(c *gin.Context) { | ||
var chargingDataReq models.ChargingDataRequest | ||
|
||
requestBody, err := c.GetRawData() | ||
if err != nil { | ||
problemDetail := models.ProblemDetails{ | ||
Title: "System failure", | ||
Status: http.StatusInternalServerError, | ||
Detail: err.Error(), | ||
Cause: "SYSTEM_FAILURE", | ||
} | ||
logger.ChargingdataPostLog.Errorf("Get Request Body error: %+v", err) | ||
c.JSON(http.StatusInternalServerError, problemDetail) | ||
return | ||
} | ||
|
||
err = openapi.Deserialize(&chargingDataReq, requestBody, "application/json") | ||
if err != nil { | ||
problemDetail := "[Request Body] " + err.Error() | ||
rsp := models.ProblemDetails{ | ||
Title: "Malformed request syntax", | ||
Status: http.StatusBadRequest, | ||
Detail: problemDetail, | ||
} | ||
logger.ChargingdataPostLog.Errorln(problemDetail) | ||
c.JSON(http.StatusBadRequest, rsp) | ||
return | ||
} | ||
|
||
req := httpwrapper.NewRequest(c.Request, chargingDataReq) | ||
req.Params["ChargingDataRef"] = c.Param("ChargingDataRef") | ||
|
||
rsp := producer.HandleChargingdataUpdate(req) | ||
|
||
for key, value := range rsp.Header { | ||
c.Header(key, value[0]) | ||
} | ||
responseBody, err := openapi.Serialize(rsp.Body, "application/json") | ||
if err != nil { | ||
logger.ChargingdataPostLog.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) | ||
} | ||
} | ||
|
||
// ChargingdataPost | ||
func (s *Server) ChargingdataPost(c *gin.Context) { | ||
var chargingDataReq models.ChargingDataRequest | ||
|
||
requestBody, err := c.GetRawData() | ||
if err != nil { | ||
problemDetail := models.ProblemDetails{ | ||
Title: "System failure", | ||
Status: http.StatusInternalServerError, | ||
Detail: err.Error(), | ||
Cause: "SYSTEM_FAILURE", | ||
} | ||
logger.ChargingdataPostLog.Errorf("Get Request Body error: %+v", err) | ||
c.JSON(http.StatusInternalServerError, problemDetail) | ||
return | ||
} | ||
|
||
err = openapi.Deserialize(&chargingDataReq, requestBody, "application/json") | ||
if err != nil { | ||
problemDetail := "[Request Body] " + err.Error() | ||
rsp := models.ProblemDetails{ | ||
Title: "Malformed request syntax", | ||
Status: http.StatusBadRequest, | ||
Detail: problemDetail, | ||
} | ||
logger.ChargingdataPostLog.Errorln(problemDetail) | ||
c.JSON(http.StatusBadRequest, rsp) | ||
return | ||
} | ||
|
||
req := httpwrapper.NewRequest(c.Request, chargingDataReq) | ||
|
||
rsp := producer.HandleChargingdataInitial(req) | ||
|
||
for key, value := range rsp.Header { | ||
c.Header(key, value[0]) | ||
} | ||
responseBody, err := openapi.Serialize(rsp.Body, "application/json") | ||
if err != nil { | ||
logger.ChargingdataPostLog.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) | ||
} | ||
} | ||
|
||
func (s *Server) RechargeGet(c *gin.Context) { | ||
c.String(http.StatusOK, "recharge") | ||
} | ||
|
||
func (s *Server) RechargePut(c *gin.Context) { | ||
rechargingInfo := c.Param("rechargingInfo") | ||
ueIdRatingGroup := strings.Split(rechargingInfo, "_") | ||
ueId := ueIdRatingGroup[0] | ||
rgStr := ueIdRatingGroup[1] | ||
rg, err := strconv.Atoi(rgStr) | ||
if err != nil { | ||
logger.RechargingLog.Errorf("UE[%s] fail to recharge for rating group %s", ueId, rgStr) | ||
} | ||
|
||
logger.RechargingLog.Warnf("UE[%s] Recharg for rating group %d", ueId, rg) | ||
|
||
producer.NotifyRecharge(ueId, int32(rg)) | ||
|
||
c.JSON(http.StatusNoContent, gin.H{}) | ||
} |
Oops, something went wrong.