diff --git a/authz/authz.go b/authz/authz.go index 4a7e83db..6aaa0166 100644 --- a/authz/authz.go +++ b/authz/authz.go @@ -88,6 +88,8 @@ p, *, *, GET, /api/get-application, *, * p, *, *, GET, /api/get-user, *, * p, *, *, GET, /api/get-user-application, *, * p, *, *, GET, /api/get-resources, *, * +p, *, *, GET, /api/get-product, *, * +p, *, *, GET, /api/get-providers, *, * p, *, *, POST, /api/unlink, *, * p, *, *, POST, /api/set-password, *, * p, *, *, POST, /api/send-verification-code, *, * diff --git a/controllers/payment.go b/controllers/payment.go index 2a6ad5ba..d9fb585e 100644 --- a/controllers/payment.go +++ b/controllers/payment.go @@ -50,6 +50,24 @@ func (c *ApiController) GetPayments() { } } +// GetUserPayments +// @Title GetUserPayments +// @Tag Payment API +// @Description get payments for a user +// @Param owner query string true "The owner of payments" +// @Param organization query string true "The organization of the user" +// @Param user query string true "The username of the user" +// @Success 200 {array} object.Payment The Response object +// @router /get-user-payments [get] +func (c *ApiController) GetUserPayments() { + owner := c.Input().Get("owner") + organization := c.Input().Get("organization") + user := c.Input().Get("user") + + payments := object.GetUserPayments(owner, organization, user) + c.ResponseOk(payments) +} + // @Title GetPayment // @Tag Payment API // @Description get payment diff --git a/object/payment.go b/object/payment.go index 784f721e..881f3e66 100644 --- a/object/payment.go +++ b/object/payment.go @@ -29,14 +29,17 @@ type Payment struct { CreatedTime string `xorm:"varchar(100)" json:"createdTime"` DisplayName string `xorm:"varchar(100)" json:"displayName"` - Provider string `xorm:"varchar(100)" json:"provider"` - Type string `xorm:"varchar(100)" json:"type"` - Organization string `xorm:"varchar(100)" json:"organization"` - User string `xorm:"varchar(100)" json:"user"` - ProductId string `xorm:"varchar(100)" json:"productId"` - ProductName string `xorm:"varchar(100)" json:"productName"` - Price float64 `json:"price"` - Currency string `xorm:"varchar(100)" json:"currency"` + Provider string `xorm:"varchar(100)" json:"provider"` + Type string `xorm:"varchar(100)" json:"type"` + Organization string `xorm:"varchar(100)" json:"organization"` + User string `xorm:"varchar(100)" json:"user"` + ProductId string `xorm:"varchar(100)" json:"productId"` + ProductName string `xorm:"varchar(100)" json:"productName"` + + Detail string `xorm:"varchar(100)" json:"detail"` + Tag string `xorm:"varchar(100)" json:"tag"` + Currency string `xorm:"varchar(100)" json:"currency"` + Price float64 `json:"price"` PayUrl string `xorm:"varchar(2000)" json:"payUrl"` State string `xorm:"varchar(100)" json:"state"` @@ -62,6 +65,16 @@ func GetPayments(owner string) []*Payment { return payments } +func GetUserPayments(owner string, organization string, user string) []*Payment { + payments := []*Payment{} + err := adapter.Engine.Desc("created_time").Find(&payments, &Payment{Owner: owner, Organization: organization, User: user}) + if err != nil { + panic(err) + } + + return payments +} + func GetPaginationPayments(owner string, offset, limit int, field, value, sortField, sortOrder string) []*Payment { payments := []*Payment{} session := GetSession(owner, offset, limit, field, value, sortField, sortOrder) diff --git a/object/product.go b/object/product.go index 8890f20e..e76ab246 100644 --- a/object/product.go +++ b/object/product.go @@ -197,8 +197,10 @@ func BuyProduct(id string, providerId string, user *User, host string) (string, User: user.Name, ProductId: productId, ProductName: productName, - Price: product.Price, + Detail: product.Detail, + Tag: product.Tag, Currency: product.Currency, + Price: product.Price, PayUrl: payUrl, State: "Created", } diff --git a/routers/router.go b/routers/router.go index 0615d787..5f75ff32 100644 --- a/routers/router.go +++ b/routers/router.go @@ -159,6 +159,7 @@ func initAPI() { beego.Router("/api/buy-product", &controllers.ApiController{}, "POST:BuyProduct") beego.Router("/api/get-payments", &controllers.ApiController{}, "GET:GetPayments") + beego.Router("/api/get-user-payments", &controllers.ApiController{}, "GET:GetUserPayments") beego.Router("/api/get-payment", &controllers.ApiController{}, "GET:GetPayment") beego.Router("/api/update-payment", &controllers.ApiController{}, "POST:UpdatePayment") beego.Router("/api/add-payment", &controllers.ApiController{}, "POST:AddPayment")