Ejemplo n.º 1
0
// createProfile receives a hash and an optional username.
// If there is a username, it must be unique.
func createProfile(u *url.URL, h http.Header, r *Auth) (int, http.Header, Response, error) {
	var err error
	p := new(profile.Profile)
	a := profile.NewAuth(r.Hash, r.Username)
	// if Getting an Auth succeeds, there was an existing row
	err = a.Get()
	if err == nil {
		return error400("auth exists", "hash:", *r.Hash)
	}
	a.Name = r.Name

	err = p.Create()
	if err != nil {
		return error500("db failure: p56", err.Error())
	}
	a.Profile = p.Id

	err = a.Create()
	if err != nil {
		return error500("db failure: p62", err.Error())
	}

	// if all is well...
	oh := http.Header{}
	oh.Add(ChuteToken, *a.Token)
	response := Profile{Id: p.Id, Created: p.Created}
	return http.StatusCreated, oh, response, nil
}
Ejemplo n.º 2
0
func (p *Profile) convert(ip profile.Profile) error {
	p.Id = ip.Id
	p.RateTypeId = ip.RateTypeId
	p.DailyRate = ip.DailyRate
	p.HourlyRate = ip.HourlyRate
	p.RateUnits = ip.RateUnits
	p.Created = ip.Created
	p.Email = ip.Email
	p.Phone = ip.Phone
	p.Name = ip.Name
	p.Flags = ip.Flags
	p.Utypes = ip.Utypes

	dbPhotos, err := ip.Photos()
	if err != nil {
		return err
	}
	for _, photo := range dbPhotos {
		href := photo.GetExpiringUrl(ip.Folder)
		p.Photos = append(p.Photos, Photo{photo.Id, photo.Created, href, photo.Caption})
	}
	return nil
}