本文整理汇总了Golang中github.com/solher/zest/interfaces.GetQueryFilter函数的典型用法代码示例。如果您正苦于以下问题:Golang GetQueryFilter函数的具体用法?Golang GetQueryFilter怎么用?Golang GetQueryFilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetQueryFilter函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindByID
func (c *AclCtrl) FindByID(w http.ResponseWriter, r *http.Request, params map[string]string) {
id, err := strconv.Atoi(params["id"])
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
return
}
filter, err := interfaces.GetQueryFilter(r)
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.FilterDecodingError, err)
return
}
filter = interfaces.FilterIfOwnerRelations(r, filter)
relations := interfaces.GetOwnerRelations(r)
acl, err := c.interactor.FindByID(id, usecases.QueryContext{Filter: filter, OwnerRelations: relations})
if err != nil {
switch err {
case internalerrors.NotFound:
c.render.JSONError(w, http.StatusUnauthorized, apierrors.Unauthorized, err)
default:
c.render.JSONError(w, http.StatusInternalServerError, apierrors.InternalServerError, err)
}
return
}
acl.BeforeRender()
c.render.JSON(w, http.StatusOK, acl)
}
示例2: FindByID
func (c *AccountCtrl) FindByID(w http.ResponseWriter, r *http.Request, params map[string]string) {
var (
id int
err error
)
if params["id"] == "me" {
sessionCtx := context.Get(r, "currentSession")
if sessionCtx == nil {
c.render.JSONError(w, http.StatusUnauthorized, apierrors.SessionNotFound, nil)
return
}
id = sessionCtx.(domain.Session).AccountID
} else {
id, err = strconv.Atoi(params["id"])
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
return
}
}
filter, err := interfaces.GetQueryFilter(r)
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.FilterDecodingError, err)
return
}
filter = interfaces.FilterIfOwnerRelations(r, filter)
relations := interfaces.GetOwnerRelations(r)
account, err := c.interactor.FindByID(id, usecases.QueryContext{Filter: filter, OwnerRelations: relations})
if err != nil {
switch err {
case internalerrors.NotFound:
c.render.JSONError(w, http.StatusUnauthorized, apierrors.Unauthorized, err)
default:
c.render.JSONError(w, http.StatusInternalServerError, apierrors.InternalServerError, err)
}
return
}
account.BeforeRender()
c.render.JSON(w, http.StatusOK, account)
}
示例3: DeleteAll
func (c *AclCtrl) DeleteAll(w http.ResponseWriter, r *http.Request, _ map[string]string) {
filter, err := interfaces.GetQueryFilter(r)
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.FilterDecodingError, err)
return
}
filter = interfaces.FilterIfLastRessource(r, filter)
filter = interfaces.FilterIfOwnerRelations(r, filter)
relations := interfaces.GetOwnerRelations(r)
err = c.interactor.DeleteAll(usecases.QueryContext{Filter: filter, OwnerRelations: relations})
if err != nil {
c.render.JSONError(w, http.StatusInternalServerError, apierrors.InternalServerError, err)
return
}
c.render.JSON(w, http.StatusNoContent, nil)
}
示例4: Find
func (c *AclCtrl) Find(w http.ResponseWriter, r *http.Request, _ map[string]string) {
filter, err := interfaces.GetQueryFilter(r)
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.FilterDecodingError, err)
return
}
filter = interfaces.FilterIfLastRessource(r, filter)
filter = interfaces.FilterIfOwnerRelations(r, filter)
relations := interfaces.GetOwnerRelations(r)
acls, err := c.interactor.Find(usecases.QueryContext{Filter: filter, OwnerRelations: relations})
if err != nil {
c.render.JSONError(w, http.StatusInternalServerError, apierrors.InternalServerError, err)
return
}
for i := range acls {
(&acls[i]).BeforeRender()
}
c.render.JSON(w, http.StatusOK, acls)
}