You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
3.8 KiB
153 lines
3.8 KiB
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"laic-backend/common"
|
|
"laic-backend/service"
|
|
"laic-backend/vo"
|
|
)
|
|
|
|
func GetProfile(c *gin.Context) {
|
|
data, e := service.DefaultAccountService.GetProfile(common.GetUserId(c))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func UpdateProfile(c *gin.Context) {
|
|
var req vo.ProfileUpdateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
data, e := service.DefaultAccountService.UpdateProfile(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func GetTrafficBalance(c *gin.Context) {
|
|
data, e := service.DefaultAccountService.GetTrafficBalance(common.GetUserId(c))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func GetResourceSummary(c *gin.Context) {
|
|
data, e := service.DefaultAccountService.GetResourceSummary(common.GetUserId(c))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func GetUsagePage(c *gin.Context) {
|
|
var req vo.UsagePageReq
|
|
bindPage(c, &req.Pagination)
|
|
_ = c.ShouldBindQuery(&req)
|
|
data, e := service.DefaultAccountService.GetUsagePage(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func GetDownloadPage(c *gin.Context) {
|
|
var req vo.UsagePageReq
|
|
bindPage(c, &req.Pagination)
|
|
data, e := service.DefaultAccountService.GetDownloadPage(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func GetOrderPage(c *gin.Context) {
|
|
var req vo.OrderPageReq
|
|
bindPage(c, &req.Pagination)
|
|
_ = c.ShouldBindQuery(&req)
|
|
data, e := service.DefaultAccountService.GetOrderPage(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func CreateTrafficOrder(c *gin.Context) {
|
|
var req vo.TrafficOrderCreateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
data, e := service.DefaultAccountService.CreateTrafficOrder(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func PayTrafficOrder(c *gin.Context) {
|
|
id, e := parseID(c)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
data, e := service.DefaultAccountService.PayTrafficOrder(id, common.GetUserId(c), c.GetHeader("Idempotency-Key"))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func ListSimCards(c *gin.Context) {
|
|
var req vo.SimCardPageReq
|
|
bindPage(c, &req.Pagination)
|
|
_ = c.ShouldBindQuery(&req)
|
|
data, e := service.DefaultAccountService.ListSimCards(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func GetSimRechargeLogPage(c *gin.Context) {
|
|
var req vo.SimRechargeLogPageReq
|
|
bindPage(c, &req.Pagination)
|
|
_ = c.ShouldBindQuery(&req)
|
|
data, e := service.DefaultAccountService.GetSimRechargeLogPage(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func RechargeSimCard(c *gin.Context) {
|
|
id, e := parseID(c)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
var req vo.SimRechargeReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
data, e := service.DefaultAccountService.RechargeSimCard(common.GetUserId(c), id, &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func bindPage(c *gin.Context, p *common.Pagination) {
|
|
_ = c.ShouldBindQuery(p)
|
|
if p.PageNum <= 0 {
|
|
p.PageNum = 1
|
|
}
|
|
if p.PageSize <= 0 {
|
|
p.PageSize = 10
|
|
}
|
|
}
|
|
|