From 9263ab8b43283ad27ba0cda1e5dfea93803e1157 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Tue, 23 Jan 2024 11:21:45 +0700 Subject: [PATCH 1/3] chore: update proto --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 806be65..27865cd 100644 --- a/go.mod +++ b/go.mod @@ -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.5.0 + github.com/isd-sgcu/johnjud-go-proto v0.5.2 github.com/rs/zerolog v1.31.0 github.com/spf13/viper v1.18.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 8f1963c..62603e0 100644 --- a/go.sum +++ b/go.sum @@ -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.5.0 h1:GgqRzWjya5p1yhfU/kpX8i4WL42+qT2TkyXZmssH6B4= github.com/isd-sgcu/johnjud-go-proto v0.5.0/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4= +github.com/isd-sgcu/johnjud-go-proto v0.5.2 h1:LWhi7zaEeEOJ60nyCxxMeAr7Bvl9stWvQbaw0RWz/Cs= +github.com/isd-sgcu/johnjud-go-proto v0.5.2/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= From 18d52eb15635de8191e6daf4d5c84d8c6731ce33 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Tue, 23 Jan 2024 11:21:51 +0700 Subject: [PATCH 2/3] fix: pet dto --- src/app/dto/pet.dto.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/dto/pet.dto.go b/src/app/dto/pet.dto.go index 6455129..970b38a 100644 --- a/src/app/dto/pet.dto.go +++ b/src/app/dto/pet.dto.go @@ -32,6 +32,8 @@ type FindAllPetRequest struct { Color string `json:"color"` Pattern string `json:"pattern"` Age string `json:"age"` + MinAge int `json:"min_age"` + MaxAge int `json:"max_age"` Origin string `json:"origin"` PageSize int `json:"page_size"` Page int `json:"page"` From 77e122536f0b06afd275b008e53361c7749d2689 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Tue, 23 Jan 2024 11:32:48 +0700 Subject: [PATCH 3/3] fix: pet utils --- src/app/utils/pet/pet.utils.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app/utils/pet/pet.utils.go b/src/app/utils/pet/pet.utils.go index c768f29..55c0ff1 100644 --- a/src/app/utils/pet/pet.utils.go +++ b/src/app/utils/pet/pet.utils.go @@ -147,10 +147,11 @@ func FindAllDtoToProto(in *dto.FindAllPetRequest) *petproto.FindAllPetRequest { Gender: in.Gender, Color: in.Color, Pattern: in.Pattern, - Age: in.Age, Origin: in.Origin, PageSize: int32(in.PageSize), Page: int32(in.Page), + MaxAge: int32(in.MaxAge), + MinAge: int32(in.MinAge), } } @@ -170,7 +171,8 @@ func QueriesToFindAllDto(queries map[string]string) (*dto.FindAllPetRequest, err Gender: "", Color: "", Pattern: "", - Age: "", + MinAge: 0, + MaxAge: 0, Origin: "", PageSize: 0, Page: 0, @@ -188,8 +190,18 @@ func QueriesToFindAllDto(queries map[string]string) (*dto.FindAllPetRequest, err request.Color = v case "pattern": request.Pattern = v - case "age": - request.Age = v + case "minAge": + minAge, err := strconv.Atoi(v) + if err != nil { + return nil, errors.New("error parsing minAge") + } + request.MinAge = minAge + case "maxAge": + maxAge, err := strconv.Atoi(v) + if err != nil { + return nil, errors.New("error parsing maxAge") + } + request.MaxAge = maxAge case "origin": request.Origin = v case "pageSize":