コード例 #1
0
func (a *Address) GetAllAddress(r *http.Request) ([]AddressReturn, error) {
	addressModel := model.Address{}
	addressModel.UserId = a.UserId
	addressData, err := addressModel.GetAllAddress(r)

	if err != nil {
		return []AddressReturn{}, err
	}

	//return address data slices
	results := make([]AddressReturn, 0, 10)

	for _, r := range addressData {
		y := AddressReturn{
			Id:       r.Id,
			Street1:  r.Street1,
			Street2:  r.Street2,
			City:     r.City,
			State:    r.State,
			PostCode: r.PostCode,
			Country:  r.Country,
		}

		results = append(results, y)
	}

	return results, nil
}
コード例 #2
0
func (a *Address) GetAddress(r *http.Request) (AddressReturn, error) {
	addressModel := model.Address{}

	addressData, err := addressModel.GetAddress(r)

	if err != nil {
		return AddressReturn{}, err
	}

	address := AddressReturn{
		Id:       addressData.Id,
		Street1:  addressData.Street1,
		Street2:  addressData.Street2,
		City:     addressData.City,
		State:    addressData.State,
		PostCode: addressData.PostCode,
		Country:  addressData.Country,
	}

	return address, nil
}
コード例 #3
0
func (a *Address) UpdateAddress(r *http.Request) (bool, error) {
	addressModel := model.Address{}

	//grab json data from request
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&a)

	//populate model
	addressModel.UserId = a.UserId
	addressModel.Street1 = a.Street1
	addressModel.Street2 = a.Street2
	addressModel.City = a.City
	addressModel.State = a.State
	addressModel.PostCode = a.PostCode
	addressModel.Country = a.Country

	err = addressModel.UpdateAddress(r, a.Id)

	if err != nil {
		return false, err
	}

	return true, nil
}