add personal address
This commit is contained in:
1 parent
50d1ba630e
commit
d2a153536f
17 files changed
+239
-50
No files matched your search
@@ -45,3 +45,38 @@ func (s *Service) UpdateUser(updUser *domain.User, fromAdmin bool) (*domain.User
|
||||
return s.repo.UpdateUser(user)
|
||||
|
||||
}
|
||||
|
||||
func (s *Service) ListAdresses(userId string) ([]*domain.UserAddress, error) {
|
||||
return s.repo.ListUserAddresses(userId)
|
||||
}
|
||||
|
||||
func (s *Service) AddAddress(userId string, typ string, address string) (*domain.UserAddress, error) {
|
||||
addr := &domain.UserAddress{
|
||||
UserID: userId,
|
||||
Type: typ,
|
||||
Address: address,
|
||||
}
|
||||
return s.repo.CreateUserAddress(addr)
|
||||
}
|
||||
|
||||
func (s *Service) UpdateAddress(userId string, address *domain.UserAddress) (*domain.UserAddress, error) {
|
||||
old, err := s.repo.GetUserAddress(address.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if old.UserID != userId {
|
||||
return nil, fmt.Errorf("unauthorized")
|
||||
}
|
||||
return s.repo.UpdateUserAddress(address)
|
||||
}
|
||||
|
||||
func (s *Service) DeleteAddress(userId string, addressId string) error {
|
||||
old, err := s.repo.GetUserAddress(addressId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if old.UserID != userId {
|
||||
return fmt.Errorf("unauthorized")
|
||||
}
|
||||
return s.repo.DeleteUserAddress(addressId)
|
||||
}
|
||||
Reference in new issue
Block a user