Skip to content

Commit

Permalink
fix: remove tmp logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Feb 22, 2024
1 parent ccdee26 commit a7ea5f8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
24 changes: 0 additions & 24 deletions src/app/service/pet/pet.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,9 @@ func (s *Service) FindAll(_ context.Context, req *proto.FindAllPetRequest) (res
log.Error().Err(err).Str("service", "event").Str("module", "find all").Msg("Error while querying all events")
return nil, status.Error(codes.Unavailable, "Internal error")
}
log.Info().
Str("service", "pet").
Str("module", "repo.FindAll").Interface("pets", pets).Msg("")
log.Info().
Str("service", "pet").
Str("module", "repo.FindAll").Msgf("number: %d", len(pets))

petUtils.FilterPet(&pets, req)
log.Info().
Str("service", "pet").
Str("module", "filtered pets").Interface("filteredPets", pets).Msg("")
log.Info().
Str("service", "pet").
Str("module", "filtered pets").Msgf("number: %d", len(pets))
petUtils.PaginatePets(&pets, req.Page, req.PageSize, &metaData)
log.Info().
Str("service", "pet").
Str("module", "paginated pets").Interface("paginatedPets", pets).Msg("")
log.Info().
Str("service", "pet").
Str("module", "paginated pets").Msgf("number: %d", len(pets))

for _, pet := range pets {
images, err := s.imageService.FindByPetId(pet.ID.String())
Expand All @@ -128,12 +110,6 @@ func (s *Service) FindAll(_ context.Context, req *proto.FindAllPetRequest) (res
imagesList[pet.ID.String()] = images
}
petWithImages, err := petUtils.RawToDtoList(&pets, imagesList, req)
log.Info().
Str("service", "pet").
Str("module", "pet with images").Interface("petWithImages", petWithImages).Msg("")
log.Info().
Str("service", "pet").
Str("module", "pet with images").Msgf("number: %d", len(pets))

if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("error converting raw to dto list: %v", err))
Expand Down
29 changes: 2 additions & 27 deletions src/app/utils/pet/pet.utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,32 @@ func FilterPet(in *[]*pet.Pet, query *proto.FindAllPetRequest) error {
if query.MaxAge == 0 {
query.MaxAge = math.MaxInt32
}
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet").Msgf("minAge: %d, maxAge: %d", query.MinAge, query.MaxAge)
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet").Interface("query", query).Msgf("query")

var results []*pet.Pet
for _, p := range *in {
res, err := filterAge(p, query.MinAge, query.MaxAge)
if err != nil {
return err
}
if !res {
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet reject").Msgf("pet id = %s age not in range", p.ID.String())
continue
}
if query.Search != "" && !strings.Contains(p.Name, query.Search) {
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet reject").Msg("not in search")
continue
}
if query.Type != "" && p.Type != query.Type {
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet reject").Msg("not the type")
continue
}
if query.Gender != "" && p.Gender != petConst.Gender(query.Gender) {
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet reject").Msg("not the gender")
continue
}
if query.Color != "" && p.Color != query.Color {
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet reject").Msg("not the color")
continue
}
if query.Origin != "" && p.Origin != query.Origin {
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet reject").Msg("not the origin")
continue
}
log.Info().
Str("service", "filter pet").
Str("module", "FilterPet accept").Interface("pet", p).Msgf("pet accepted")

results = append(results, p)
}
*in = results
Expand Down

0 comments on commit a7ea5f8

Please sign in to comment.