- use auto router for callback msg.
- first normal demo api FinishedPickup added.
This commit is contained in:
@@ -1,49 +1,32 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery/dada"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/legacy/dada/controller"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Operations about ELMOrder
|
||||
type DadaOrderController struct {
|
||||
type DadaDeliveryController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *DadaOrderController) URLMapping() {
|
||||
c.Mapping("OrderStatusChanged", c.OrderStatusChanged)
|
||||
}
|
||||
|
||||
// @Title all msg
|
||||
// @Description create object
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /msg [post]
|
||||
func (c *DadaOrderController) OrderStatusChanged() {
|
||||
obj, callbackResponse := api.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if callbackResponse == nil {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
cc := &controller.OrderController{}
|
||||
callbackResponse = cc.OrderStatusChanged(obj)
|
||||
func (c *DadaDeliveryController) Msg() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
obj, callbackResponse := api.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = dada.OnWaybillMsg(obj)
|
||||
}
|
||||
if globals.CallNewMsgHandler {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
utils.CallFuncAsync(func() {
|
||||
dada.OnWaybillMsg(obj)
|
||||
})
|
||||
} else {
|
||||
callbackResponse = dada.OnWaybillMsg(obj)
|
||||
}
|
||||
if callbackResponse != nil && callbackResponse.Code != 200 {
|
||||
c.CustomAbort(callbackResponse.Code, string(utils.MustMarshal(callbackResponse)))
|
||||
} else {
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
}
|
||||
if callbackResponse != nil && callbackResponse.Code != 200 {
|
||||
c.CustomAbort(callbackResponse.Code, string(utils.MustMarshal(callbackResponse)))
|
||||
} else {
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
c.Abort("404")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,32 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/elmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/elm"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/legacy/elm/controller"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Operations about ELMOrder
|
||||
type ELMOrderController struct {
|
||||
type ElemeController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *ELMOrderController) URLMapping() {
|
||||
c.Mapping("MsgPost", c.MsgPost)
|
||||
c.Mapping("MsgGet", c.MsgGet)
|
||||
}
|
||||
|
||||
// @Title all msg
|
||||
// @Description create object
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /msg [post]
|
||||
func (c *ELMOrderController) MsgPost() {
|
||||
obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if callbackResponse == nil {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
cc := &controller.OrderController{}
|
||||
callbackResponse = cc.OrderMessage(obj)
|
||||
}
|
||||
if globals.CallNewMsgHandler {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
utils.CallFuncAsync(func() {
|
||||
elm.OnCallbackMsg(obj)
|
||||
})
|
||||
} else {
|
||||
callbackResponse = elm.OnCallbackMsg(obj)
|
||||
}
|
||||
// https://open.shop.ele.me/openapi/documents/httppushmethod
|
||||
func (c *ElemeController) Msg() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = elm.OnCallbackMsg(obj)
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
} else if c.Ctx.Input.Method() == http.MethodGet { // 应用需要支持推送地址的GET访问,当GET请求访问时,请直接返回{“message”:“ok”},用于推送地址的可用性测试。
|
||||
c.Data["json"] = elmapi.SuccessResponse
|
||||
c.ServeJSON()
|
||||
} else {
|
||||
c.Abort("404")
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title all msg test
|
||||
// @Description create object
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @router /msg [get]
|
||||
func (c *ELMOrderController) MsgGet() {
|
||||
c.Data["json"] = elmapi.SuccessResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -1,183 +1,88 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/legacy/jd/controller"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Operations about JDOrder
|
||||
type JDOrderController struct {
|
||||
type DjswController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *JDOrderController) URLMapping() {
|
||||
c.Mapping("NewOrder", c.NewOrder)
|
||||
c.Mapping("OrderAdjust", c.OrderAdjust)
|
||||
c.Mapping("OrderWaitOutStore", c.OrderWaitOutStore)
|
||||
c.Mapping("PickFinishOrder", c.PickFinishOrder)
|
||||
c.Mapping("DeliveryOrder", c.DeliveryOrder)
|
||||
c.Mapping("LockOrder", c.LockOrder)
|
||||
c.Mapping("UserCancelOrder", c.UserCancelOrder)
|
||||
c.Mapping("ApplyCancelOrder", c.ApplyCancelOrder)
|
||||
c.Mapping("PushDeliveryStatus", c.PushDeliveryStatus)
|
||||
}
|
||||
func (c *DjswController) orderStatus(isCancelOrder bool) {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
var obj *jdapi.CallbackOrderMsg
|
||||
var callbackResponse *jdapi.CallbackResponse
|
||||
|
||||
func (c *JDOrderController) orderStatus(isCancelOrder bool) {
|
||||
var obj *jdapi.CallbackOrderMsg
|
||||
var callbackResponse *jdapi.CallbackResponse
|
||||
|
||||
if isCancelOrder {
|
||||
obj, callbackResponse = api.JdAPI.GetOrderApplyCancelCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if isCancelOrder {
|
||||
obj, callbackResponse = api.JdAPI.GetOrderApplyCancelCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
} else {
|
||||
obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
}
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = jd.OnOrderMsg(obj)
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
} else {
|
||||
obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
c.Abort("404")
|
||||
}
|
||||
if callbackResponse == nil {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
cc := controller.OrderController{}
|
||||
callbackResponse = cc.OrderStatus(obj)
|
||||
}
|
||||
if globals.CallNewMsgHandler {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
utils.CallFuncAsync(func() {
|
||||
jd.OnOrderMsg(obj)
|
||||
})
|
||||
} else {
|
||||
callbackResponse = jd.OnOrderMsg(obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title newOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /newOrder [post]
|
||||
func (c *JDOrderController) NewOrder() {
|
||||
func (c *DjswController) NewOrder() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title AdjustOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /orderAdjust [post]
|
||||
func (c *JDOrderController) OrderAdjust() {
|
||||
func (c *DjswController) OrderAdjust() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title orderWaitOutStore
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /orderWaitOutStore [post]
|
||||
func (c *JDOrderController) OrderWaitOutStore() {
|
||||
func (c *DjswController) OrderWaitOutStore() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title pickFinishOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /pickFinishOrder [post]
|
||||
func (c *JDOrderController) PickFinishOrder() {
|
||||
func (c *DjswController) PickFinishOrder() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title deliveryOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /deliveryOrder [post]
|
||||
func (c *JDOrderController) DeliveryOrder() {
|
||||
func (c *DjswController) DeliveryOrder() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title finishOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /finishOrder [post]
|
||||
func (c *JDOrderController) FinishOrder() {
|
||||
func (c *DjswController) FinishOrder() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title lockOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /lockOrder [post]
|
||||
func (c *JDOrderController) LockOrder() {
|
||||
func (c *DjswController) LockOrder() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title userCancelOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /userCancelOrder [post]
|
||||
func (c *JDOrderController) UserCancelOrder() {
|
||||
func (c *DjswController) UserCancelOrder() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
// @Title applyCancelOrder
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /applyCancelOrder [post]
|
||||
func (c *JDOrderController) ApplyCancelOrder() {
|
||||
func (c *DjswController) ApplyCancelOrder() {
|
||||
c.orderStatus(true)
|
||||
}
|
||||
|
||||
// @Title pushDeliveryStatus
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /pushDeliveryStatus [post]
|
||||
func (c *JDOrderController) PushDeliveryStatus() {
|
||||
obj, callbackResponse := api.JdAPI.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if callbackResponse == nil {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
cc := controller.OrderController{}
|
||||
callbackResponse = cc.OrderDeliveryStatus(obj)
|
||||
}
|
||||
if globals.CallNewMsgHandler {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
utils.CallFuncAsync(func() {
|
||||
jd.OnWaybillMsg(obj)
|
||||
})
|
||||
} else {
|
||||
callbackResponse = jd.OnWaybillMsg(obj)
|
||||
}
|
||||
func (c *DjswController) PushDeliveryStatus() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
obj, callbackResponse := api.JdAPI.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = jd.OnWaybillMsg(obj)
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
} else {
|
||||
c.Abort("404")
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title pushDeliveryStatus
|
||||
// @Description create object
|
||||
// @Param jd_param_json formData string true "应用级别输入参数"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /orderCommentPush [post]
|
||||
func (c *JDOrderController) OrderComment() {
|
||||
func (c *DjswController) OrderCommentPush() {
|
||||
c.orderStatus(false)
|
||||
}
|
||||
|
||||
28
controllers/jx_order.go
Normal file
28
controllers/jx_order.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type OrderController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *OrderController) URLMapping() {
|
||||
c.Mapping("FinishedPickup", c.FinishedPickup)
|
||||
}
|
||||
|
||||
// @Title 完成拣货
|
||||
// @Description 完成拣货,如果是购物平台负责配送,则自动召唤相应配送
|
||||
// @Param orderid path string true "订单ID"
|
||||
// @Success 200 {object} business.model.CallResult
|
||||
// @Failure 200 {object} business.model.CallResult
|
||||
// @router /finishedpickup/:orderid [post]
|
||||
func (c *OrderController) FinishedPickup() {
|
||||
c.Data["json"] = &model.CallResult{
|
||||
Code: 0,
|
||||
Result: c.Ctx.Input.Param(":orderid"),
|
||||
}
|
||||
c.ServeJSON()
|
||||
}
|
||||
@@ -1,72 +1,40 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery/mtps"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/legacy/mtps/controller"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Operations about ELMOrder
|
||||
type MTPSOrderController struct {
|
||||
type MtpsController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *MTPSOrderController) URLMapping() {
|
||||
c.Mapping("Status", c.Status)
|
||||
c.Mapping("Except", c.Except)
|
||||
func (c *MtpsController) Status() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
obj, callbackResponse := api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = mtps.OnWaybillMsg(obj)
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
} else {
|
||||
c.Abort("404")
|
||||
}
|
||||
}
|
||||
|
||||
// @Title all msg
|
||||
// @Description create object
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /status [post]
|
||||
func (c *MTPSOrderController) Status() {
|
||||
obj, callbackResponse := api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request)
|
||||
if callbackResponse == nil {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
cc := &controller.OrderController{}
|
||||
callbackResponse = cc.OrderStatusChanged(obj)
|
||||
}
|
||||
if globals.CallNewMsgHandler {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
utils.CallFuncAsync(func() {
|
||||
mtps.OnWaybillMsg(obj)
|
||||
})
|
||||
} else {
|
||||
callbackResponse = mtps.OnWaybillMsg(obj)
|
||||
}
|
||||
func (c *MtpsController) Except() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
obj, callbackResponse := api.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = mtps.OnWaybillExcept(obj)
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
} else {
|
||||
c.Abort("404")
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title all msg test
|
||||
// @Description create object
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router /except [Post]
|
||||
func (c *MTPSOrderController) Except() {
|
||||
obj, callbackResponse := api.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request)
|
||||
if callbackResponse == nil {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
cc := &controller.OrderController{}
|
||||
callbackResponse = cc.OrderException(obj)
|
||||
}
|
||||
if globals.CallNewMsgHandler {
|
||||
if globals.CallLegacyMsgHandler {
|
||||
utils.CallFuncAsync(func() {
|
||||
mtps.OnWaybillExcept(obj)
|
||||
})
|
||||
} else {
|
||||
callbackResponse = mtps.OnWaybillExcept(obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/models"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Operations about object
|
||||
type ObjectController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create object
|
||||
// @Param body body models.Object true "The object content"
|
||||
// @Success 200 {string} models.Object.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router / [post]
|
||||
func (o *ObjectController) Post() {
|
||||
var ob models.Object
|
||||
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
|
||||
objectid := models.AddOne(ob)
|
||||
o.Data["json"] = map[string]string{"ObjectId": objectid}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find object by objectid
|
||||
// @Param objectId path string true "the objectid you want to get"
|
||||
// @Success 200 {object} models.Object
|
||||
// @Failure 403 :objectId is empty
|
||||
// @router /:objectId [get]
|
||||
func (o *ObjectController) Get() {
|
||||
objectId := o.Ctx.Input.Param(":objectId")
|
||||
if objectId != "" {
|
||||
ob, err := models.GetOne(objectId)
|
||||
if err != nil {
|
||||
o.Data["json"] = err.Error()
|
||||
} else {
|
||||
o.Data["json"] = ob
|
||||
}
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description get all objects
|
||||
// @Success 200 {object} models.Object
|
||||
// @Failure 403 :objectId is empty
|
||||
// @router / [get]
|
||||
func (o *ObjectController) GetAll() {
|
||||
obs := models.GetAll()
|
||||
o.Data["json"] = obs
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// @Description update the object
|
||||
// @Param objectId path string true "The objectid you want to update"
|
||||
// @Param body body models.Object true "The body"
|
||||
// @Success 200 {object} models.Object
|
||||
// @Failure 403 :objectId is empty
|
||||
// @router /:objectId [put]
|
||||
func (o *ObjectController) Put() {
|
||||
objectId := o.Ctx.Input.Param(":objectId")
|
||||
var ob models.Object
|
||||
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
|
||||
|
||||
err := models.Update(objectId, ob.Score)
|
||||
if err != nil {
|
||||
o.Data["json"] = err.Error()
|
||||
} else {
|
||||
o.Data["json"] = "update success!"
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the object
|
||||
// @Param objectId path string true "The objectId you want to delete"
|
||||
// @Success 200 {string} delete success!
|
||||
// @Failure 403 objectId is empty
|
||||
// @router /:objectId [delete]
|
||||
func (o *ObjectController) Delete() {
|
||||
objectId := o.Ctx.Input.Param(":objectId")
|
||||
models.Delete(objectId)
|
||||
o.Data["json"] = "delete success!"
|
||||
o.ServeJSON()
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/models"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Operations about Users
|
||||
type UserController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title CreateUser
|
||||
// @Description create users
|
||||
// @Param body body models.User true "body for user content"
|
||||
// @Success 200 {int} models.User.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router / [post]
|
||||
func (u *UserController) Post() {
|
||||
var user models.User
|
||||
json.Unmarshal(u.Ctx.Input.RequestBody, &user)
|
||||
uid := models.AddUser(user)
|
||||
u.Data["json"] = map[string]string{"uid": uid}
|
||||
u.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description get all Users
|
||||
// @Success 200 {object} models.User
|
||||
// @router / [get]
|
||||
func (u *UserController) GetAll() {
|
||||
users := models.GetAllUsers()
|
||||
u.Data["json"] = users
|
||||
u.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description get user by uid
|
||||
// @Param uid path string true "The key for staticblock"
|
||||
// @Success 200 {object} models.User
|
||||
// @Failure 403 :uid is empty
|
||||
// @router /:uid [get]
|
||||
func (u *UserController) Get() {
|
||||
uid := u.GetString(":uid")
|
||||
if uid != "" {
|
||||
user, err := models.GetUser(uid)
|
||||
if err != nil {
|
||||
u.Data["json"] = err.Error()
|
||||
} else {
|
||||
u.Data["json"] = user
|
||||
}
|
||||
}
|
||||
u.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// @Description update the user
|
||||
// @Param uid path string true "The uid you want to update"
|
||||
// @Param body body models.User true "body for user content"
|
||||
// @Success 200 {object} models.User
|
||||
// @Failure 403 :uid is not int
|
||||
// @router /:uid [put]
|
||||
func (u *UserController) Put() {
|
||||
uid := u.GetString(":uid")
|
||||
if uid != "" {
|
||||
var user models.User
|
||||
json.Unmarshal(u.Ctx.Input.RequestBody, &user)
|
||||
uu, err := models.UpdateUser(uid, &user)
|
||||
if err != nil {
|
||||
u.Data["json"] = err.Error()
|
||||
} else {
|
||||
u.Data["json"] = uu
|
||||
}
|
||||
}
|
||||
u.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the user
|
||||
// @Param uid path string true "The uid you want to delete"
|
||||
// @Success 200 {string} delete success!
|
||||
// @Failure 403 uid is empty
|
||||
// @router /:uid [delete]
|
||||
func (u *UserController) Delete() {
|
||||
uid := u.GetString(":uid")
|
||||
models.DeleteUser(uid)
|
||||
u.Data["json"] = "delete success!"
|
||||
u.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Login
|
||||
// @Description Logs user into the system
|
||||
// @Param username query string true "The username for login"
|
||||
// @Param password query string true "The password for login"
|
||||
// @Success 200 {string} login success
|
||||
// @Failure 403 user not exist
|
||||
// @router /login [get]
|
||||
func (u *UserController) Login() {
|
||||
username := u.GetString("username")
|
||||
password := u.GetString("password")
|
||||
if models.Login(username, password) {
|
||||
u.Data["json"] = "login success"
|
||||
} else {
|
||||
u.Data["json"] = "user not exist"
|
||||
}
|
||||
u.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title logout
|
||||
// @Description Logs out current logged in user session
|
||||
// @Success 200 {string} logout success
|
||||
// @router /logout [get]
|
||||
func (u *UserController) Logout() {
|
||||
u.Data["json"] = "logout success"
|
||||
u.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user