コード例 #1
0
ファイル: response.go プロジェクト: RichardKnop/example-api
// NewUserResponse creates new UserResponse instance
func NewUserResponse(o *User) (*UserResponse, error) {
	response := &UserResponse{
		ID:        o.ID,
		Email:     o.OauthUser.Username,
		FirstName: o.FirstName.String,
		LastName:  o.LastName.String,
		Role:      o.OauthUser.RoleID.String,
		Confirmed: o.Confirmed,
		CreatedAt: util.FormatTime(&o.CreatedAt),
		UpdatedAt: util.FormatTime(&o.UpdatedAt),
	}

	// Set the self link
	response.SetLink(
		"self", // name
		fmt.Sprintf("/v1/users/%d", o.ID), // href
		"", // title
	)

	return response, nil
}
コード例 #2
0
ファイル: response.go プロジェクト: RichardKnop/example-api
// NewConfirmationResponse creates new ConfirmationResponse instance
func NewConfirmationResponse(o *Confirmation) (*ConfirmationResponse, error) {
	response := &ConfirmationResponse{
		EmailTokenResponse: EmailTokenResponse{
			ID:          o.ID,
			Reference:   o.Reference,
			EmailSent:   o.EmailSent,
			EmailSentAt: util.FormatTime(o.EmailSentAt),
			ExpiresAt:   util.FormatTime(&o.ExpiresAt),
			CreatedAt:   util.FormatTime(&o.CreatedAt),
			UpdatedAt:   util.FormatTime(&o.UpdatedAt),
		},
		UserID: o.User.ID,
	}

	// Set the self link
	response.SetLink(
		"self", // name
		fmt.Sprintf("/v1/confirmations/%d", o.ID), // href
		"", // title
	)

	return response, nil
}