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) }
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) }
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) }
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) }