feat(api): add client app service endpoints
This commit is contained in:
86
backend/api/internal/routers/client.go
Normal file
86
backend/api/internal/routers/client.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdkmiddleware "git.apinb.com/bsm-sdk/core/middleware"
|
||||
clientcommon "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/client/common"
|
||||
stafflogic "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/client/staff"
|
||||
userlogic "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/client/user"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// RegisterClient 注册用户 App 和工作人员 App 的隔离 API。
|
||||
func RegisterClient(serviceKey string, engine *gin.Engine) {
|
||||
registerUserClient(serviceKey, engine)
|
||||
registerStaffClient(serviceKey, engine)
|
||||
}
|
||||
|
||||
func registerUserClient(serviceKey string, engine *gin.Engine) {
|
||||
basePath := fmt.Sprintf("/%s/client/v1/user", serviceKey)
|
||||
anonymous := engine.Group(basePath)
|
||||
anonymous.POST("/auth/verification-code", clientcommon.SendVerificationCode("user_app"))
|
||||
anonymous.POST("/auth/register", userlogic.Register)
|
||||
anonymous.POST("/auth/login", userlogic.Login)
|
||||
anonymous.POST("/auth/reset-password", userlogic.ResetPassword)
|
||||
anonymous.GET("/public/gas-stations", userlogic.PublicGasStations)
|
||||
anonymous.GET("/public/delivery-points", userlogic.PublicDeliveryPoints)
|
||||
anonymous.GET("/public/contents", userlogic.PublicContents)
|
||||
anonymous.GET("/public/products", userlogic.PublicProducts)
|
||||
|
||||
protected := engine.Group(basePath)
|
||||
protected.Use(sdkmiddleware.JwtAuth(true), clientcommon.RequireClient("user_app"))
|
||||
protected.GET("/auth/profile", userlogic.Profile)
|
||||
protected.PUT("/auth/profile", userlogic.UpdateProfile)
|
||||
protected.PUT("/auth/password", userlogic.ChangePassword)
|
||||
protected.GET("/addresses", userlogic.ListAddresses)
|
||||
protected.POST("/addresses", userlogic.SaveAddress)
|
||||
protected.POST("/contents/read-confirmations", userlogic.ConfirmContentRead)
|
||||
protected.GET("/service-relation", userlogic.ServiceRelation)
|
||||
protected.GET("/gas/contracts", userlogic.ListGasContracts)
|
||||
protected.GET("/gas/orders", userlogic.ListGasOrders)
|
||||
protected.POST("/gas/orders/:identity/cancel", userlogic.CancelGasOrder)
|
||||
protected.GET("/tickets", userlogic.ListTickets)
|
||||
protected.POST("/tickets", userlogic.CreateTicket)
|
||||
protected.POST("/tickets/:identity/confirm", userlogic.ConfirmTicket)
|
||||
protected.POST("/tickets/:identity/cancel", userlogic.CancelTicket)
|
||||
protected.GET("/shop/orders", userlogic.ListShopOrders)
|
||||
protected.POST("/shop/orders", userlogic.CreateShopOrder)
|
||||
protected.POST("/shop/orders/:identity/cancel", userlogic.CancelShopOrder)
|
||||
protected.POST("/shop/orders/:identity/pay", userlogic.PayShopOrder)
|
||||
protected.POST("/shop/orders/:identity/confirm-receipt", userlogic.ConfirmShopReceipt)
|
||||
registerClientWalletRoutes(protected, "user_app")
|
||||
}
|
||||
|
||||
func registerStaffClient(serviceKey string, engine *gin.Engine) {
|
||||
basePath := fmt.Sprintf("/%s/client/v1/staff", serviceKey)
|
||||
anonymous := engine.Group(basePath)
|
||||
anonymous.POST("/auth/verification-code", clientcommon.SendVerificationCode("service_app"))
|
||||
anonymous.POST("/auth/login", stafflogic.Login)
|
||||
anonymous.POST("/auth/reset-password", stafflogic.ResetPassword)
|
||||
|
||||
protected := engine.Group(basePath)
|
||||
protected.Use(sdkmiddleware.JwtAuth(true), clientcommon.RequireClient("service_app"))
|
||||
protected.GET("/auth/profile", stafflogic.Profile)
|
||||
protected.PUT("/auth/password", stafflogic.ChangePassword)
|
||||
protected.POST("/attendance", stafflogic.Attendance)
|
||||
protected.GET("/tickets", stafflogic.ListTickets)
|
||||
protected.POST("/tickets/:identity/start", stafflogic.StartTicket)
|
||||
protected.POST("/tickets/:identity/exception", stafflogic.ExceptionTicket)
|
||||
protected.POST("/tickets/:identity/recover", stafflogic.RecoverTicket)
|
||||
protected.POST("/tickets/:identity/submit-result", stafflogic.SubmitTicketResult)
|
||||
registerClientWalletRoutes(protected, "service_app")
|
||||
}
|
||||
|
||||
func registerClientWalletRoutes(group *gin.RouterGroup, client string) {
|
||||
group.GET("/wallet", clientcommon.GetWallet(client))
|
||||
group.PUT("/wallet/payment-password", clientcommon.SetPaymentPassword(client))
|
||||
group.GET("/wallet/records", clientcommon.ListWalletRecords(client))
|
||||
group.POST("/wallet/recharges", clientcommon.CreateRecharge(client))
|
||||
group.POST("/wallet/recharges/:identity/mock-confirm", clientcommon.ConfirmMockRecharge(client))
|
||||
group.GET("/wallet/banks", clientcommon.ListBanks(client))
|
||||
group.POST("/wallet/banks", clientcommon.BindBank(client))
|
||||
group.DELETE("/wallet/banks/:identity", clientcommon.UnbindBank(client))
|
||||
group.GET("/wallet/withdrawals", clientcommon.ListWithdrawals(client))
|
||||
group.POST("/wallet/withdrawals", clientcommon.CreateWithdrawal(client))
|
||||
}
|
||||
34
backend/api/internal/routers/client_test.go
Normal file
34
backend/api/internal/routers/client_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestRegisterClientRoutes(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
engine := gin.New()
|
||||
RegisterClient("heqi", engine)
|
||||
|
||||
expected := map[string]bool{
|
||||
"POST /heqi/client/v1/user/auth/register": false,
|
||||
"POST /heqi/client/v1/user/auth/login": false,
|
||||
"POST /heqi/client/v1/user/wallet/recharges": false,
|
||||
"POST /heqi/client/v1/user/shop/orders/:identity/pay": false,
|
||||
"POST /heqi/client/v1/staff/auth/login": false,
|
||||
"POST /heqi/client/v1/staff/attendance": false,
|
||||
"POST /heqi/client/v1/staff/tickets/:identity/submit-result": false,
|
||||
}
|
||||
for _, route := range engine.Routes() {
|
||||
key := route.Method + " " + route.Path
|
||||
if _, ok := expected[key]; ok {
|
||||
expected[key] = true
|
||||
}
|
||||
}
|
||||
for route, found := range expected {
|
||||
if !found {
|
||||
t.Errorf("missing route %s", route)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,6 @@ func Register(serviceKey string, engine *gin.Engine) {
|
||||
RegisterPlatform(serviceKey, engine)
|
||||
RegisterGas(serviceKey, engine)
|
||||
RegisterDelivery(serviceKey, engine)
|
||||
RegisterClient(serviceKey, engine)
|
||||
registerUploadRoute(serviceKey, engine)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
sdkmiddleware "git.apinb.com/bsm-sdk/core/middleware"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/upload"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// registerUploadRoute 注册已认证的文件上传接口。
|
||||
func registerUploadRoute(serviceKey string, engine *gin.Engine) {
|
||||
engine.POST("/upload/file", upload.UploadFile)
|
||||
authorized := engine.Group("/upload")
|
||||
authorized.Use(sdkmiddleware.JwtAuth(true))
|
||||
authorized.POST("/file", upload.UploadFile)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user