Files
honeyDueAPI/internal/services/user_service.go
Trey t 4976eafc6c Rebrand from Casera/MyCrib to honeyDue
Total rebrand across all Go API source files:
- Go module path: casera-api -> honeydue-api
- All imports updated (130+ files)
- Docker: containers, images, networks renamed
- Email templates: support email, noreply, icon URL
- Domains: casera.app/mycrib.treytartt.com -> honeyDue.treytartt.com
- Bundle IDs: com.tt.casera -> com.tt.honeyDue
- IAP product IDs updated
- Landing page, admin panel, config defaults
- Seeds, CI workflows, Makefile, docs
- Database table names preserved (no migration needed)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 06:33:38 -06:00

88 lines
2.4 KiB
Go

package services
import (
"errors"
"github.com/treytartt/honeydue-api/internal/apperrors"
"github.com/treytartt/honeydue-api/internal/dto/responses"
"github.com/treytartt/honeydue-api/internal/repositories"
)
var (
// Deprecated: Use apperrors.NotFound("error.user_not_found") instead
ErrUserNotFound = errors.New("user not found")
)
// UserService handles user-related business logic
type UserService struct {
userRepo *repositories.UserRepository
}
// NewUserService creates a new user service
func NewUserService(userRepo *repositories.UserRepository) *UserService {
return &UserService{
userRepo: userRepo,
}
}
// ListUsersInSharedResidences returns users that share residences with the given user
func (s *UserService) ListUsersInSharedResidences(userID uint) ([]responses.UserSummary, error) {
users, err := s.userRepo.FindUsersInSharedResidences(userID)
if err != nil {
return nil, apperrors.Internal(err)
}
var result []responses.UserSummary
for _, u := range users {
result = append(result, responses.UserSummary{
ID: u.ID,
Username: u.Username,
Email: u.Email,
FirstName: u.FirstName,
LastName: u.LastName,
})
}
return result, nil
}
// GetUserIfSharedResidence returns a user if they share a residence with the requesting user
func (s *UserService) GetUserIfSharedResidence(targetUserID, requestingUserID uint) (*responses.UserSummary, error) {
user, err := s.userRepo.FindUserIfSharedResidence(targetUserID, requestingUserID)
if err != nil {
return nil, apperrors.Internal(err)
}
if user == nil {
return nil, apperrors.NotFound("error.user_not_found")
}
return &responses.UserSummary{
ID: user.ID,
Username: user.Username,
Email: user.Email,
FirstName: user.FirstName,
LastName: user.LastName,
}, nil
}
// ListProfilesInSharedResidences returns user profiles for users in shared residences
func (s *UserService) ListProfilesInSharedResidences(userID uint) ([]responses.UserProfileSummary, error) {
profiles, err := s.userRepo.FindProfilesInSharedResidences(userID)
if err != nil {
return nil, apperrors.Internal(err)
}
var result []responses.UserProfileSummary
for _, p := range profiles {
result = append(result, responses.UserProfileSummary{
ID: p.ID,
UserID: p.UserID,
Bio: p.Bio,
ProfilePicture: p.ProfilePicture,
PhoneNumber: p.PhoneNumber,
})
}
return result, nil
}