Skip to content

Commit

Permalink
fix: pet profile image ID can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
litsynp committed Mar 19, 2024
1 parent c473120 commit 8b348e9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/service/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"fmt"
pnd "github.com/pet-sitter/pets-next-door-api/api"
"github.com/pet-sitter/pets-next-door-api/internal/domain/media"
"github.com/pet-sitter/pets-next-door-api/internal/domain/pet"
Expand Down Expand Up @@ -273,9 +274,10 @@ func (service *UserService) AddPetsToOwner(ctx context.Context, uid string, addP

pets := make([]pet.PetWithProfileImage, len(addPetsRequest.Pets))
for i, item := range addPetsRequest.Pets {
media, err := mediaStore.FindMediaByID(ctx, *item.ProfileImageID)
if err != nil {
return err
if item.ProfileImageID != nil {
if _, err := mediaStore.FindMediaByID(ctx, *item.ProfileImageID); err != nil {
return pnd.ErrInvalidBody(fmt.Errorf("존재하지 않는 프로필 이미지 ID입니다. ID: %d", *item.ProfileImageID))
}
}

petToCreate := pet.Pet{
Expand All @@ -289,7 +291,7 @@ func (service *UserService) AddPetsToOwner(ctx context.Context, uid string, addP
BirthDate: item.BirthDate,
WeightInKg: item.WeightInKg,
},
ProfileImageID: &media.ID,
ProfileImageID: item.ProfileImageID,
}
createdPet, err := petStore.CreatePet(ctx, &petToCreate)
pets[i] = *createdPet
Expand Down

0 comments on commit 8b348e9

Please sign in to comment.