Skip to content

Commit

Permalink
Merge pull request #32 from isd-sgcu/gear/joh-49-johnjud-gateway-comb…
Browse files Browse the repository at this point in the history
…ine-image-service-in-to-pet-service

Gear/joh 49 johnjud gateway combine image service in to pet service
  • Loading branch information
macgeargear authored Feb 3, 2024
2 parents e14e0fe + d21e7ac commit e028125
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 58 deletions.
36 changes: 18 additions & 18 deletions src/app/dto/pet.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import (
)

type PetResponse struct {
Id string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Birthdate string `json:"birthdate"`
Gender pet.Gender `json:"gender"`
Color string `json:"color"`
Pattern string `json:"pattern"`
Habit string `json:"habit"`
Caption string `json:"caption"`
Status pet.Status `json:"status"`
IsSterile *bool `json:"is_sterile"`
IsVaccinated *bool `json:"is_vaccinated"`
IsVisible *bool `json:"is_visible"`
Origin string `json:"origin"`
Address string `json:"address"`
Contact string `json:"contact"`
AdoptBy string `json:"adopt_by"`
Images []ImageResponse `json:"images"`
Id string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Birthdate string `json:"birthdate"`
Gender pet.Gender `json:"gender"`
Color string `json:"color"`
Pattern string `json:"pattern"`
Habit string `json:"habit"`
Caption string `json:"caption"`
Status pet.Status `json:"status"`
IsSterile *bool `json:"is_sterile"`
IsVaccinated *bool `json:"is_vaccinated"`
IsVisible *bool `json:"is_visible"`
Origin string `json:"origin"`
Address string `json:"address"`
Contact string `json:"contact"`
AdoptBy string `json:"adopt_by"`
Images []*ImageResponse `json:"images"`
}

type FindAllPetRequest struct {
Expand Down
6 changes: 3 additions & 3 deletions src/app/handler/pet/pet.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (t *PetHandlerTest) TestFindAllSuccess() {
}

func (t *PetHandlerTest) TestFindOneSuccess() {
findOneResponse := utils.ProtoToDto(t.Pet, t.Images)
findOneResponse := utils.ProtoToDto(t.Pet, utils.ImageProtoToDto(t.Images))
expectedResponse := findOneResponse

controller := gomock.NewController(t.T())
Expand Down Expand Up @@ -235,7 +235,7 @@ func (t *PetHandlerTest) TestFindOneGrpcErr() {
}

func (t *PetHandlerTest) TestCreateSuccess() {
createResponse := utils.ProtoToDto(t.Pet, t.Images)
createResponse := utils.ProtoToDto(t.Pet, utils.ImageProtoToDto(t.Images))
expectedResponse := createResponse

controller := gomock.NewController(t.T())
Expand Down Expand Up @@ -274,7 +274,7 @@ func (t *PetHandlerTest) TestCreateGrpcErr() {
}

func (t *PetHandlerTest) TestUpdateSuccess() {
updateResponse := utils.ProtoToDto(t.Pet, t.Images)
updateResponse := utils.ProtoToDto(t.Pet, utils.ImageProtoToDto(t.Images))
expectedResponse := updateResponse

controller := gomock.NewController(t.T())
Expand Down
38 changes: 30 additions & 8 deletions src/app/service/pet/pet.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import (

"github.com/isd-sgcu/johnjud-gateway/src/app/constant"
"github.com/isd-sgcu/johnjud-gateway/src/app/dto"

utils "github.com/isd-sgcu/johnjud-gateway/src/app/utils/pet"
imageSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/image"
petproto "github.com/isd-sgcu/johnjud-go-proto/johnjud/backend/pet/v1"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type Service struct {
petClient petproto.PetServiceClient
petClient petproto.PetServiceClient
imageService imageSvc.Service
}

func NewService(petClient petproto.PetServiceClient) *Service {
func NewService(petClient petproto.PetServiceClient, imageService imageSvc.Service) *Service {
return &Service{
petClient: petClient,
petClient: petClient,
imageService: imageService,
}
}

Expand Down Expand Up @@ -94,8 +98,13 @@ func (s *Service) FindOne(id string) (result *dto.PetResponse, err *dto.Response
}
}
}
images := utils.MockImageList(1)[0]
findOneResponse := utils.ProtoToDto(res.Pet, images)

imgRes, imgErrRes := s.imageService.FindByPetId(res.Pet.Id)
if imgErrRes != nil {
return nil, imgErrRes
}

findOneResponse := utils.ProtoToDto(res.Pet, imgRes)
return findOneResponse, nil
}

Expand Down Expand Up @@ -134,8 +143,21 @@ func (s *Service) Create(in *dto.CreatePetRequest) (result *dto.PetResponse, err
}
}
}
images := utils.MockImageList(1)[0]
createPetResponse := utils.ProtoToDto(res.Pet, images)

_, assignErr := s.imageService.AssignPet(&dto.AssignPetRequest{
Ids: in.Images,
PetId: res.Pet.Id,
})
if assignErr != nil {
return nil, assignErr
}

imgRes, imgErrRes := s.imageService.FindByPetId(res.Pet.Id)
if imgErrRes != nil {
return nil, imgErrRes
}

createPetResponse := utils.ProtoToDto(res.Pet, imgRes)
return createPetResponse, nil
}

Expand Down Expand Up @@ -181,7 +203,7 @@ func (s *Service) Update(id string, in *dto.UpdatePetRequest) (result *dto.PetRe
}
}
images := utils.MockImageList(1)[0]
updatePetResponse := utils.ProtoToDto(res.Pet, images)
updatePetResponse := utils.ProtoToDto(res.Pet, utils.ImageProtoToDto(images))
return updatePetResponse, nil
}

Expand Down
Loading

0 comments on commit e028125

Please sign in to comment.