Skip to content

Commit

Permalink
Merge pull request #20 from isd-sgcu/JOH-48/update-pet-type
Browse files Browse the repository at this point in the history
[JOH-48] Update pet type
  • Loading branch information
bookpanda authored Jan 10, 2024
2 parents 9006fb2 + 73d4a04 commit b36ef41
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 46 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/gofiber/fiber/v2 v2.52.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.5.0
github.com/isd-sgcu/johnjud-go-proto v0.2.2
github.com/isd-sgcu/johnjud-go-proto v0.3.1
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.18.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/isd-sgcu/johnjud-go-proto v0.2.2 h1:TOAmbwy/I+8/J5LPZH0ZN7lSLczBiZe1fs88gH8XrhY=
github.com/isd-sgcu/johnjud-go-proto v0.2.2/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4=
github.com/isd-sgcu/johnjud-go-proto v0.3.1 h1:WyWfzl+5nWOw3AmINtcTfojg4CJh8ZRNbZC6qA//OXU=
github.com/isd-sgcu/johnjud-go-proto v0.3.1/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
Expand Down
16 changes: 11 additions & 5 deletions src/app/dto/pet.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ type PetResponse struct {
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"`
IsClubPet *bool `json:"is_club_pet"`
Background string `json:"background"`
Origin string `json:"origin"`
Address string `json:"address"`
Contact string `json:"contact"`
AdoptBy string `json:"adopt_by"`
Expand All @@ -35,15 +37,17 @@ type CreatePetRequest struct {
Species string `json:"species" validate:"required"`
Name string `json:"name" validate:"required"`
Birthdate string `json:"birthdate" validate:"required"`
Gender pet.Gender `json:"gender" validate:"required" example:"1"`
Gender pet.Gender `json:"gender" validate:"required" example:"male"`
Color string `json:"color" validate:"required"`
Pattern string `json:"pattern" validate:"required"`
Habit string `json:"habit" validate:"required"`
Caption string `json:"caption"`
Status pet.Status `json:"status" validate:"required" example:"1"`
Status pet.Status `json:"status" validate:"required" example:"findhome"`
IsSterile *bool `json:"is_sterile" validate:"required"`
IsVaccinated *bool `json:"is_vaccinated" validate:"required"`
IsVisible *bool `json:"is_visible" validate:"required"`
IsClubPet *bool `json:"is_club_pet" validate:"required"`
Background string `json:"background"`
Origin string `json:"origin" validate:"required"`
Address string `json:"address"`
Contact string `json:"contact"`
AdoptBy string `json:"adopt_by"`
Expand Down Expand Up @@ -73,14 +77,16 @@ type UpdatePetRequest struct {
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"`
IsClubPet *bool `json:"is_club_pet"`
Background string `json:"background"`
Origin string `json:"origin"`
Address string `json:"address"`
Contact string `json:"contact"`
AdoptBy string `json:"adopt_by"`
Expand Down
15 changes: 11 additions & 4 deletions src/app/handler/pet/pet.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,28 @@ func (t *PetHandlerTest) SetupTest() {
t.ImagesList = imagesList
t.Images = imagesList[0]
var pets []*petProto.Pet
genders := []petConst.Gender{petConst.MALE, petConst.FEMALE}
statuses := []petConst.Status{petConst.ADOPTED, petConst.FINDHOME}

for i := 0; i <= 3; i++ {
pet := &petProto.Pet{
Id: faker.UUIDDigit(),
Type: faker.Word(),
Species: faker.Word(),
Name: faker.Name(),
Birthdate: faker.Word(),
Gender: petProto.Gender(rand.Intn(1) + 1),
Gender: string(genders[rand.Intn(2)]),
Color: faker.Word(),
Pattern: faker.Word(),
Habit: faker.Paragraph(),
Caption: faker.Paragraph(),
Images: []*imgProto.Image{},
Status: petProto.PetStatus(rand.Intn(1) + 1),
Status: string(statuses[rand.Intn(2)]),
IsSterile: true,
IsVaccinated: true,
IsVisible: true,
IsClubPet: true,
Background: faker.Paragraph(),
Origin: faker.Paragraph(),
Address: faker.Paragraph(),
Contact: faker.Paragraph(),
AdoptBy: "",
Expand All @@ -83,14 +88,16 @@ func (t *PetHandlerTest) SetupTest() {
Name: t.Pet.Name,
Birthdate: t.Pet.Birthdate,
Gender: pet.Gender(t.Pet.Gender),
Color: t.Pet.Color,
Pattern: t.Pet.Pattern,
Habit: t.Pet.Habit,
Caption: t.Pet.Caption,
Status: pet.Status(t.Pet.Status),
IsSterile: &t.Pet.IsSterile,
IsVaccinated: &t.Pet.IsVaccinated,
IsVisible: &t.Pet.IsVisible,
IsClubPet: &t.Pet.IsClubPet,
Background: t.Pet.Background,
Origin: t.Pet.Origin,
Address: t.Pet.Address,
Contact: t.Pet.Contact,
AdoptBy: t.Pet.AdoptBy,
Expand Down
22 changes: 16 additions & 6 deletions src/app/service/pet/pet.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (t *PetServiceTest) SetupTest() {
imagesList := utils.MockImageList(3)
t.ImagesList = imagesList
t.Images = imagesList[0]
genders := []pet.Gender{pet.MALE, pet.FEMALE}
statuses := []pet.Status{pet.ADOPTED, pet.FINDHOME}

var pets []*petproto.Pet
for i := 0; i <= 3; i++ {
Expand All @@ -60,16 +62,18 @@ func (t *PetServiceTest) SetupTest() {
Species: faker.Word(),
Name: faker.Name(),
Birthdate: faker.Word(),
Gender: petproto.Gender(rand.Intn(1) + 1),
Gender: string(genders[rand.Intn(2)]),
Color: faker.Word(),
Pattern: faker.Word(),
Habit: faker.Paragraph(),
Caption: faker.Paragraph(),
Images: imagesList[i],
Status: petproto.PetStatus(rand.Intn(1) + 1),
Status: string(statuses[rand.Intn(2)]),
IsSterile: true,
IsVaccinated: true,
IsVisible: true,
IsClubPet: true,
Background: faker.Paragraph(),
Origin: faker.Paragraph(),
Address: faker.Paragraph(),
Contact: faker.Paragraph(),
AdoptBy: faker.UUIDDigit(),
Expand All @@ -88,6 +92,8 @@ func (t *PetServiceTest) SetupTest() {
Name: t.Pet.Name,
Birthdate: t.Pet.Birthdate,
Gender: t.Pet.Gender,
Color: t.Pet.Color,
Pattern: t.Pet.Pattern,
Habit: t.Pet.Habit,
Caption: t.Pet.Caption,
Images: t.Pet.Images,
Expand All @@ -96,7 +102,7 @@ func (t *PetServiceTest) SetupTest() {
IsVaccinated: t.Pet.IsVaccinated,
IsVisible: false,
IsClubPet: t.Pet.IsClubPet,
Background: t.Pet.Background,
Origin: t.Pet.Origin,
Address: t.Pet.Address,
Contact: t.Pet.Contact,
AdoptBy: t.Pet.AdoptBy,
Expand All @@ -110,6 +116,8 @@ func (t *PetServiceTest) SetupTest() {
Name: t.Pet.Name,
Birthdate: t.Pet.Birthdate,
Gender: pet.Gender(t.Pet.Gender),
Color: t.Pet.Color,
Pattern: t.Pet.Pattern,
Habit: t.Pet.Habit,
Caption: t.Pet.Caption,
Images: []string{},
Expand All @@ -118,7 +126,7 @@ func (t *PetServiceTest) SetupTest() {
IsVaccinated: &t.Pet.IsVaccinated,
IsVisible: &t.Pet.IsVisible,
IsClubPet: &t.Pet.IsClubPet,
Background: t.Pet.Background,
Origin: t.Pet.Origin,
Address: t.Pet.Address,
Contact: t.Pet.Contact,
AdoptBy: t.Pet.AdoptBy,
Expand All @@ -130,6 +138,8 @@ func (t *PetServiceTest) SetupTest() {
Name: t.Pet.Name,
Birthdate: t.Pet.Birthdate,
Gender: pet.Gender(t.Pet.Gender),
Color: t.Pet.Color,
Pattern: t.Pet.Pattern,
Habit: t.Pet.Habit,
Caption: t.Pet.Caption,
Images: []string{},
Expand All @@ -138,7 +148,7 @@ func (t *PetServiceTest) SetupTest() {
IsVaccinated: &t.Pet.IsVaccinated,
IsVisible: &t.Pet.IsVisible,
IsClubPet: &t.Pet.IsClubPet,
Background: t.Pet.Background,
Origin: t.Pet.Origin,
Address: t.Pet.Address,
Contact: t.Pet.Contact,
AdoptBy: t.Pet.AdoptBy,
Expand Down
46 changes: 27 additions & 19 deletions src/app/utils/pet/pet.utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ func ProtoToDto(in *petproto.Pet, images []*imgproto.Image) *dto.PetResponse {
Name: in.Name,
Birthdate: in.Birthdate,
Gender: pet.Gender(in.Gender),
Color: in.Color,
Pattern: in.Pattern,
Habit: in.Habit,
Caption: in.Caption,
Status: pet.Status(in.Status),
IsSterile: &in.IsSterile,
IsVaccinated: &in.IsVaccinated,
IsVisible: &in.IsVisible,
IsClubPet: &in.IsClubPet,
Background: in.Background,
Origin: in.Origin,
Address: in.Address,
Contact: in.Contact,
AdoptBy: in.AdoptBy,
Expand All @@ -58,16 +60,18 @@ func CreateDtoToProto(in *dto.CreatePetRequest) *petproto.CreatePetRequest {
Species: in.Species,
Name: in.Name,
Birthdate: in.Birthdate,
Gender: petproto.Gender(in.Gender),
Gender: string(in.Gender),
Color: in.Color,
Pattern: in.Pattern,
Habit: in.Habit,
Caption: in.Caption,
Images: []*imgproto.Image{},
Status: petproto.PetStatus(in.Status),
Status: string(in.Status),
IsSterile: *in.IsSterile,
IsVaccinated: *in.IsVaccinated,
IsVisible: *in.IsVisible,
IsClubPet: *in.IsClubPet,
Background: in.Background,
Origin: in.Origin,
Address: in.Address,
Contact: in.Contact,
AdoptBy: in.AdoptBy,
Expand All @@ -78,20 +82,22 @@ func CreateDtoToProto(in *dto.CreatePetRequest) *petproto.CreatePetRequest {
func UpdateDtoToProto(id string, in *dto.UpdatePetRequest) *petproto.UpdatePetRequest {
req := &petproto.UpdatePetRequest{
Pet: &petproto.Pet{
Id: id,
Type: in.Type,
Species: in.Species,
Name: in.Name,
Birthdate: in.Birthdate,
Gender: petproto.Gender(in.Gender),
Habit: in.Habit,
Caption: in.Caption,
Images: []*imgproto.Image{},
Status: petproto.PetStatus(in.Status),
Background: in.Background,
Address: in.Address,
Contact: in.Contact,
AdoptBy: in.AdoptBy,
Id: id,
Type: in.Type,
Species: in.Species,
Name: in.Name,
Birthdate: in.Birthdate,
Gender: string(in.Gender),
Color: in.Color,
Pattern: in.Pattern,
Habit: in.Habit,
Caption: in.Caption,
Images: []*imgproto.Image{},
Status: string(in.Status),
Origin: in.Origin,
Address: in.Address,
Contact: in.Contact,
AdoptBy: in.AdoptBy,
},
}

Expand Down Expand Up @@ -132,14 +138,16 @@ func ProtoToDtoList(in []*petproto.Pet, imagesList [][]*imgproto.Image) []*dto.P
Name: p.Name,
Birthdate: p.Birthdate,
Gender: pet.Gender(p.Gender),
Color: p.Color,
Pattern: p.Pattern,
Habit: p.Habit,
Caption: p.Caption,
Status: pet.Status(p.Status),
IsSterile: &p.IsSterile,
IsVaccinated: &p.IsVaccinated,
IsVisible: &p.IsVisible,
IsClubPet: &p.IsClubPet,
Background: p.Background,
Origin: p.Origin,
Address: p.Address,
Contact: p.Contact,
AdoptBy: p.AdoptBy,
Expand Down
22 changes: 11 additions & 11 deletions src/constant/pet/pet.constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"strings"
)

type Gender int
type Gender string

const (
MALE = 1
FEMALE = 2
MALE Gender = "male"
FEMALE Gender = "female"
)

type Status int
type Status string

const (
ADOPTED = 1
FINDHOME = 2
ADOPTED Status = "adopted"
FINDHOME Status = "findhome"
)

func (g *Gender) UnmarshalJSON(data []byte) error {
Expand All @@ -28,10 +28,10 @@ func (g *Gender) UnmarshalJSON(data []byte) error {
s = strings.ToUpper(s)
switch s {
case "MALE":
*g = Gender(1)
*g = MALE
return nil
case "FEMALE":
*g = Gender(2)
*g = FEMALE
return nil

default:
Expand All @@ -47,14 +47,14 @@ func (st *Status) UnmarshalJSON(data []byte) error {
s = strings.ToUpper(s)
switch s {
case "ADOPTED":
*st = Status(1)
*st = ADOPTED
return nil
case "FINDHOME":
*st = Status(2)
*st = FINDHOME
return nil

default:
return errors.New("invalid gender")
return errors.New("invalid status")
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/mocks/client/auth/auth.mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"context"

authProto "github.com/isd-sgcu/johnjud-go-proto/johnjud/auth/auth/v1"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc"
Expand Down Expand Up @@ -45,3 +46,17 @@ func (m *AuthClientMock) SignOut(_ context.Context, in *authProto.SignOutRequest
err, _ := args.Get(1).(error)
return resp, err
}

func (m *AuthClientMock) ForgotPassword(_ context.Context, in *authProto.ForgotPasswordRequest, _ ...grpc.CallOption) (*authProto.ForgotPasswordResponse, error) {
args := m.Called(in)
resp, _ := args.Get(0).(*authProto.ForgotPasswordResponse)
err, _ := args.Get(1).(error)
return resp, err
}

func (m *AuthClientMock) ResetPassword(_ context.Context, in *authProto.ResetPasswordRequest, _ ...grpc.CallOption) (*authProto.ResetPasswordResponse, error) {
args := m.Called(in)
resp, _ := args.Get(0).(*authProto.ResetPasswordResponse)
err, _ := args.Get(1).(error)
return resp, err
}

0 comments on commit b36ef41

Please sign in to comment.