Skip to content

Commit

Permalink
feat: image service
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Dec 22, 2023
1 parent ebc7b2a commit d5b99e8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/app/service/image/image.service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package image

import (
"context"
"time"

proto "github.com/isd-sgcu/johnjud-go-proto/johnjud/file/image/v1"
"github.com/rs/zerolog/log"
)

type Service struct {
client proto.ImageServiceClient
}

func NewService(client proto.ImageServiceClient) *Service {
return &Service{client: client}
}

func (s *Service) FindByPetId(petId string) ([]*proto.Image, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

res, err := s.client.FindByPetId(ctx, &proto.FindImageByPetIdRequest{PetId: petId})
if err != nil {
log.Error().
Err(err).
Str("service", "image").
Str("module", "find by petId").
Msg("Error while connecting to service")
return nil, err
}
return res.Images, nil

}

0 comments on commit d5b99e8

Please sign in to comment.