Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gear/joh 49 johnjud gateway combine image service in to pet service #32

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading