當前位置: 首頁>>代碼示例>>Golang>>正文


Golang model.Company類代碼示例

本文整理匯總了Golang中github.com/coduno/api/model.Company的典型用法代碼示例。如果您正苦於以下問題:Golang Company類的具體用法?Golang Company怎麽用?Golang Company使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Company類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetCompanyByUser

func GetCompanyByUser(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
	if r.Method != "GET" {
		return http.StatusMethodNotAllowed, nil
	}

	p, ok := passenger.FromContext(ctx)
	if !ok {
		return http.StatusUnauthorized, nil
	}

	var u model.User
	if err := datastore.Get(ctx, p.User, &u); err != nil {
		return http.StatusInternalServerError, nil
	}

	if u.Company == nil {
		return http.StatusUnauthorized, nil
	}

	// The account is associated with a company, so we return it.
	var company model.Company
	if err := datastore.Get(ctx, u.Company, &company); err != nil {
		return http.StatusInternalServerError, err
	}

	json.NewEncoder(w).Encode(company.Key(u.Company))
	return http.StatusOK, nil
}
開發者ID:pbochis,項目名稱:api,代碼行數:28,代碼來源:user.go

示例2: PostCompany

// PostCompany creates a new company after validating by key.
func PostCompany(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	if r.Method != "POST" {
		return http.StatusMethodNotAllowed, nil
	}

	var company model.Company
	if err = json.NewDecoder(r.Body).Decode(&company); err != nil {
		return http.StatusBadRequest, err
	}

	var companies model.Companys
	_, err = model.NewQueryForCompany().
		Filter("Address =", company.Address.Address).
		Limit(1).
		GetAll(ctx, &companies)

	if err != nil {
		return http.StatusInternalServerError, err
	}

	if len(companies) > 0 {
		return http.StatusConflict, errors.New("already registered")
	}

	var key *datastore.Key
	if key, err = company.Put(ctx, nil); err != nil {
		return http.StatusInternalServerError, err
	}

	// TODO(flowlo): Respond with HTTP 201 and include a
	// location header and caching information.

	json.NewEncoder(w).Encode(company.Key(key))
	return http.StatusOK, nil
}
開發者ID:pbochis,項目名稱:api,代碼行數:36,代碼來源:company.go

示例3: GetCompanyByUser

func GetCompanyByUser(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
	if !util.CheckMethod(r, "GET") {
		return http.StatusMethodNotAllowed, nil
	}
	p, ok := passenger.FromContext(ctx)

	if !ok {
		return http.StatusUnauthorized, nil
	}
	key := p.UserKey.Parent()
	if key == nil {
		return http.StatusUnauthorized, nil
	}
	// The account is associated with a company, so we return it.
	var company model.Company
	if err := datastore.Get(ctx, key, &company); err != nil {
		return http.StatusInternalServerError, err
	}
	json.NewEncoder(w).Encode(company.Key(key))
	return http.StatusOK, nil
}
開發者ID:tudorgergely,項目名稱:api,代碼行數:21,代碼來源:user.go

示例4: CreateAndSaveCompany

// CreateAndSaveCompany creates a new Company and saves it to datastore using the provided context
func CreateAndSaveCompany(t *testing.T, ctx context.Context, name, email string) (model.Company, *datastore.Key) {
	if name == "" {
		name = "Example Company"
	}
	if email == "" {
		email = "[email protected]"
	}
	company := model.Company{
		Address: mail.Address{
			Name:    name,
			Address: email,
		},
	}
	var err error
	var key *datastore.Key

	key, err = company.Put(ctx, nil)
	if err != nil {
		t.Fatal(err)
	}
	return company, key
}
開發者ID:flowlo,項目名稱:coduno-api,代碼行數:23,代碼來源:controllers_test.go


注:本文中的github.com/coduno/api/model.Company類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。