コード例 #1
0
ファイル: me.go プロジェクト: nerdzeu/nerdz-api
// NewProjectFollowing handles the request and creates and adds target to the following list of the current user
func NewProjectFollowing() echo.HandlerFunc {

	// swagger:route POST /me/following/projects/{target} project following NewProjectFollowing
	//
	// Adds target project to the following list of the current user
	//
	//  Produces:
	//  - application/json
	//
	//  Security:
	//      oauth: following:write
	//
	//  Responses:
	//      default: apiResponse

	return func(c echo.Context) error {
		if !rest.IsGranted("following:write", c) {
			return rest.InvalidScopeResponse("following:write", c)
		}

		var target *nerdz.Project
		var err error
		if target, err = rest.Project("target", c); err != nil {
			return err
		}
		me := c.Get("me").(*nerdz.User)
		if err = me.Follow(target); err != nil {
			errstr := err.Error()
			c.JSON(http.StatusBadRequest, &rest.Response{
				Data:         nil,
				HumanMessage: errstr,
				Message:      errstr,
				Status:       http.StatusBadRequest,
				Success:      false,
			})
			return errors.New(errstr)
		}
		// Return selected field from the followed Project
		return rest.SelectFields(target.GetTO(me), c)
	}
}
コード例 #2
0
ファイル: rest.go プロジェクト: nerdzeu/nerdz-api
// GetProjectInfo returns the *ProjectInfo of the project
func GetProjectInfo(project *nerdz.Project) *ProjectInfo {
	var info ProjectInfo
	info.Info = *project.Info().GetTO()
	return &info
}