Commit 50784c10 by CaIon

feat(api): change subscription product options and catalog endpoints to use GET method

parent b8f5ba4a
...@@ -103,11 +103,6 @@ func getWaffoPancakeBuyerEmail(user *model.User) string { ...@@ -103,11 +103,6 @@ func getWaffoPancakeBuyerEmail(user *model.User) string {
// the body and fall back to persisted creds when the body is blank (see // the body and fall back to persisted creds when the body is blank (see
// resolveWaffoPancakeAdminCreds). Only SaveWaffoPancake writes to OptionMap. // resolveWaffoPancakeAdminCreds). Only SaveWaffoPancake writes to OptionMap.
type waffoPancakeCredsRequest struct {
MerchantID string `json:"merchant_id"`
PrivateKey string `json:"private_key"`
}
type saveWaffoPancakeRequest struct { type saveWaffoPancakeRequest struct {
MerchantID string `json:"merchant_id"` MerchantID string `json:"merchant_id"`
PrivateKey string `json:"private_key"` PrivateKey string `json:"private_key"`
...@@ -221,15 +216,11 @@ func CreateWaffoPancakePair(c *gin.Context) { ...@@ -221,15 +216,11 @@ func CreateWaffoPancakePair(c *gin.Context) {
// Doubles as a credential probe (a successful 200 proves the resolved creds // Doubles as a credential probe (a successful 200 proves the resolved creds
// authenticate). See resolveWaffoPancakeAdminCreds for credential resolution. // authenticate). See resolveWaffoPancakeAdminCreds for credential resolution.
func ListWaffoPancakeCatalog(c *gin.Context) { func ListWaffoPancakeCatalog(c *gin.Context) {
var req waffoPancakeCredsRequest // Missing query creds mean "use persisted creds".
// An empty body means "use persisted creds"; only fail on malformed JSON. merchantID, privateKey := resolveWaffoPancakeAdminCreds(
if c.Request.ContentLength > 0 { strings.TrimSpace(c.Query("merchant_id")),
if err := c.ShouldBindJSON(&req); err != nil { strings.TrimSpace(c.Query("private_key")),
c.JSON(http.StatusOK, gin.H{"message": "error", "data": "参数错误"}) )
return
}
}
merchantID, privateKey := resolveWaffoPancakeAdminCreds(req.MerchantID, req.PrivateKey)
if merchantID == "" || privateKey == "" { if merchantID == "" || privateKey == "" {
c.JSON(http.StatusOK, gin.H{"message": "error", "data": "Waffo Pancake 凭证未配置"}) c.JSON(http.StatusOK, gin.H{"message": "error", "data": "Waffo Pancake 凭证未配置"})
return return
......
...@@ -191,11 +191,11 @@ func SetApiRouter(router *gin.Engine) { ...@@ -191,11 +191,11 @@ func SetApiRouter(router *gin.Engine) {
optionRoute.DELETE("/channel_affinity_cache", controller.ClearChannelAffinityCache) optionRoute.DELETE("/channel_affinity_cache", controller.ClearChannelAffinityCache)
optionRoute.POST("/rest_model_ratio", controller.ResetModelRatio) optionRoute.POST("/rest_model_ratio", controller.ResetModelRatio)
optionRoute.POST("/migrate_console_setting", controller.MigrateConsoleSetting) // 用于迁移检测的旧键,下个版本会删除 optionRoute.POST("/migrate_console_setting", controller.MigrateConsoleSetting) // 用于迁移检测的旧键,下个版本会删除
optionRoute.POST("/waffo-pancake/catalog", controller.ListWaffoPancakeCatalog) optionRoute.GET("/waffo-pancake/catalog", controller.ListWaffoPancakeCatalog)
optionRoute.POST("/waffo-pancake/pair", controller.CreateWaffoPancakePair) optionRoute.POST("/waffo-pancake/pair", controller.CreateWaffoPancakePair)
optionRoute.POST("/waffo-pancake/save", controller.SaveWaffoPancake) optionRoute.POST("/waffo-pancake/save", controller.SaveWaffoPancake)
optionRoute.POST("/waffo-pancake/subscription-product", controller.CreateWaffoPancakeSubscriptionProduct) optionRoute.POST("/waffo-pancake/subscription-product", controller.CreateWaffoPancakeSubscriptionProduct)
optionRoute.POST("/waffo-pancake/subscription-product-options", controller.ListWaffoPancakeSubscriptionProductOptions) optionRoute.GET("/waffo-pancake/subscription-product-options", controller.ListWaffoPancakeSubscriptionProductOptions)
} }
// Custom OAuth provider management (root only) // Custom OAuth provider management (root only)
......
...@@ -159,7 +159,7 @@ export async function listWaffoPancakeSubscriptionProductOptions(): Promise< ...@@ -159,7 +159,7 @@ export async function listWaffoPancakeSubscriptionProductOptions(): Promise<
products: { id: string; name: string; status: string }[] products: { id: string; name: string; status: string }[]
}> }>
> { > {
const res = await api.post( const res = await api.get(
'/api/option/waffo-pancake/subscription-product-options' '/api/option/waffo-pancake/subscription-product-options'
) )
return res.data return res.data
......
...@@ -64,9 +64,9 @@ export async function listWaffoPancakeCatalog( ...@@ -64,9 +64,9 @@ export async function listWaffoPancakeCatalog(
merchantID: string, merchantID: string,
privateKey: string privateKey: string
): Promise<CatalogResponse> { ): Promise<CatalogResponse> {
const res = await api.post<CatalogResponse>( const res = await api.get<CatalogResponse>(
'/api/option/waffo-pancake/catalog', '/api/option/waffo-pancake/catalog',
{ merchant_id: merchantID, private_key: privateKey } { params: { merchant_id: merchantID, private_key: privateKey } }
) )
return res.data return res.data
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment