feat(subscription): add Language parameter to GetSubscription request and update query logic
This commit is contained in:
parent
f632ea2c89
commit
10757612f5
@ -25,6 +25,9 @@ type (
|
|||||||
PortalPurchaseResponse {
|
PortalPurchaseResponse {
|
||||||
OrderNo string `json:"order_no"`
|
OrderNo string `json:"order_no"`
|
||||||
}
|
}
|
||||||
|
GetSubscriptionRequest {
|
||||||
|
Language string `form:"language"`
|
||||||
|
}
|
||||||
GetSubscriptionResponse {
|
GetSubscriptionResponse {
|
||||||
List []Subscribe `json:"list"`
|
List []Subscribe `json:"list"`
|
||||||
}
|
}
|
||||||
@ -75,7 +78,7 @@ service ppanel {
|
|||||||
|
|
||||||
@doc "Get Subscription"
|
@doc "Get Subscription"
|
||||||
@handler GetSubscription
|
@handler GetSubscription
|
||||||
get /subscribe returns (GetSubscriptionResponse)
|
get /subscribe (GetSubscriptionRequest) returns (GetSubscriptionResponse)
|
||||||
|
|
||||||
@doc "Pre Purchase Order"
|
@doc "Pre Purchase Order"
|
||||||
@handler PrePurchaseOrder
|
@handler PrePurchaseOrder
|
||||||
|
|||||||
@ -4,14 +4,23 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/public/portal"
|
"github.com/perfect-panel/server/internal/logic/public/portal"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get Subscription
|
// Get Subscription
|
||||||
func GetSubscriptionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func GetSubscriptionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
var req types.GetSubscriptionRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
l := portal.NewGetSubscriptionLogic(c.Request.Context(), svcCtx)
|
l := portal.NewGetSubscriptionLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetSubscription()
|
resp, err := l.GetSubscription(&req)
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,16 +27,25 @@ func NewGetSubscriptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetSubscriptionLogic) GetSubscription() (resp *types.GetSubscriptionResponse, err error) {
|
func (l *GetSubscriptionLogic) GetSubscription(req *types.GetSubscriptionRequest) (resp *types.GetSubscriptionResponse, err error) {
|
||||||
resp = &types.GetSubscriptionResponse{
|
resp = &types.GetSubscriptionResponse{
|
||||||
List: make([]types.Subscribe, 0),
|
List: make([]types.Subscribe, 0),
|
||||||
}
|
}
|
||||||
// Get the subscription list
|
// Get the subscription list
|
||||||
data, err := l.svcCtx.SubscribeModel.QuerySubscribeListByShow(l.ctx)
|
data, err := l.svcCtx.SubscribeModel.QuerySubscribeListByShow(l.ctx, req.Language)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorw("[Site GetSubscription]", logger.Field("err", err.Error()))
|
l.Errorw("[Site GetSubscription]", logger.Field("err", err.Error()))
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get subscription list error: %v", err.Error())
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get subscription list error: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
// If no data is found for the specified language, query default language data
|
||||||
|
if len(data) == 0 && req.Language != "" {
|
||||||
|
data, err = l.svcCtx.SubscribeModel.QuerySubscribeListByShow(l.ctx, "")
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[Site GetSubscription]", logger.Field("err", err.Error()))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get subscription list error: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
list := make([]types.Subscribe, len(data))
|
list := make([]types.Subscribe, len(data))
|
||||||
for i, item := range data {
|
for i, item := range data {
|
||||||
var sub types.Subscribe
|
var sub types.Subscribe
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
type customSubscribeLogicModel interface {
|
type customSubscribeLogicModel interface {
|
||||||
QuerySubscribeListByPage(ctx context.Context, page, size int, lang string, search string) (total int64, list []*Subscribe, err error)
|
QuerySubscribeListByPage(ctx context.Context, page, size int, lang string, search string) (total int64, list []*Subscribe, err error)
|
||||||
QuerySubscribeList(ctx context.Context) ([]*Subscribe, error)
|
QuerySubscribeList(ctx context.Context) ([]*Subscribe, error)
|
||||||
QuerySubscribeListByShow(ctx context.Context) ([]*Subscribe, error)
|
QuerySubscribeListByShow(ctx context.Context, lang string) ([]*Subscribe, error)
|
||||||
QuerySubscribeIdsByNodeIdAndNodeTag(ctx context.Context, node []int64, tags []string) ([]*Subscribe, error)
|
QuerySubscribeIdsByNodeIdAndNodeTag(ctx context.Context, node []int64, tags []string) ([]*Subscribe, error)
|
||||||
QuerySubscribeMinSortByIds(ctx context.Context, ids []int64) (int64, error)
|
QuerySubscribeMinSortByIds(ctx context.Context, ids []int64) (int64, error)
|
||||||
QuerySubscribeListByIds(ctx context.Context, ids []int64) ([]*Subscribe, error)
|
QuerySubscribeListByIds(ctx context.Context, ids []int64) ([]*Subscribe, error)
|
||||||
@ -78,11 +78,11 @@ func (m *customSubscribeModel) QuerySubscribeIdsByNodeIdAndNodeTag(ctx context.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QuerySubscribeListByShow Get Subscribe List By Show
|
// QuerySubscribeListByShow Get Subscribe List By Show
|
||||||
func (m *customSubscribeModel) QuerySubscribeListByShow(ctx context.Context) ([]*Subscribe, error) {
|
func (m *customSubscribeModel) QuerySubscribeListByShow(ctx context.Context, lang string) ([]*Subscribe, error) {
|
||||||
var list []*Subscribe
|
var list []*Subscribe
|
||||||
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
|
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
|
||||||
conn = conn.Model(&Subscribe{})
|
conn = conn.Model(&Subscribe{})
|
||||||
return conn.Where("`show` = true").Find(v).Error
|
return conn.Where("`show` = true AND `language` = ?", lang).Find(v).Error
|
||||||
})
|
})
|
||||||
return list, err
|
return list, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -965,6 +965,10 @@ type GetSubscribeLogResponse struct {
|
|||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetSubscriptionRequest struct {
|
||||||
|
Language string `form:"language"`
|
||||||
|
}
|
||||||
|
|
||||||
type GetSubscriptionResponse struct {
|
type GetSubscriptionResponse struct {
|
||||||
List []Subscribe `json:"list"`
|
List []Subscribe `json:"list"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user