Example #1
0
func (s *ProjectService) list(req *restful.Request, resp *restful.Response) {
	// TODO (m0sth8): check  permissions

	query, err := fltr.FromRequest(req, manager.ProjectFltr{})
	if err != nil {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(err.Error()))
		return
	}

	u := filters.GetUser(req)
	admin := false
	// if user is not admin then show him only his projects or where he has membership
	if !admin {
		query = manager.Or(fltr.GetQuery(&manager.ProjectFltr{Owner: u.Id, Member: u.Id}))
	}
	mgr := s.Manager()
	defer mgr.Close()

	results, count, err := mgr.Projects.FilterByQuery(query)
	if err != nil {
		logrus.Error(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
		return
	}

	result := &project.ProjectList{
		Meta:    pagination.Meta{Count: count},
		Results: results,
	}
	resp.WriteEntity(result)
}
Example #2
0
func (s *UserService) list(req *restful.Request, resp *restful.Response) {
	// TODO (m0sth8): do not show emails and other fields for everyone
	// TODO (m0sth8): filter by email for admin only
	query, err := fltr.FromRequest(req, manager.UserFltr{})
	if err != nil {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(err.Error()))
		return
	}

	mgr := s.Manager()
	defer mgr.Close()

	results, count, err := mgr.Users.FilterByQuery(query)
	if err != nil {
		logrus.Error(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
		return
	}

	result := &user.UserList{
		Meta:    pagination.Meta{Count: count},
		Results: results,
	}
	resp.WriteEntity(result)
}
Example #3
0
func (s *FeedService) list(req *restful.Request, resp *restful.Response) {
	// TODO (m0sth8): check if this user has access to feed items
	mgr := s.Manager()
	defer mgr.Close()

	query, err := fltr.FromRequest(req, manager.FeedItemFltr{})
	if err != nil {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(err.Error()))
		return
	}
	skip := 0
	if p := req.QueryParameter("skip"); p != "" {
		if val, err := strconv.Atoi(p); err != nil {
			resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(fmt.Sprintf("skip: %s", err.Error())))
			return
		} else {
			skip = val
		}
	}
	limit := 20
	if p := req.QueryParameter("limit"); p != "" {
		if val, err := strconv.Atoi(p); err != nil {
			resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(fmt.Sprintf("limit: %s", err.Error())))
			return
		} else {
			limit = val
		}
	}
	sort := []string{"-updated"}
	results, count, err := mgr.Feed.FilterByQuery(query, mgr.Opts(skip, limit, sort))
	if err != nil {
		logrus.Error(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
		return
	}

	result := &feed.Feed{
		Meta:    pagination.Meta{Count: count},
		Results: results,
	}
	resp.WriteEntity(result)
}
Example #4
0
func (s *PlanService) list(req *restful.Request, resp *restful.Response) {
	query, err := fltr.FromRequest(req, manager.PlanFltr{})
	if err != nil {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq(err.Error()))
		return
	}

	mgr := s.Manager()
	defer mgr.Close()

	results, count, err := mgr.Plans.FilterByQuery(query)
	if err != nil {
		logrus.Error(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
		return
	}

	result := &plan.PlanList{
		Meta:    pagination.Meta{Count: count},
		Results: results,
	}
	resp.WriteEntity(result)
}