Skip to content

Commit

Permalink
Merge pull request #11 from isd-sgcu/JOH-27/user-endpoints
Browse files Browse the repository at this point in the history
[JOH-27] User endpoints and Admin middleware
  • Loading branch information
bookpanda authored Jan 10, 2024
2 parents e15cd3d + d0a1854 commit 9006fb2
Show file tree
Hide file tree
Showing 31 changed files with 1,155 additions and 288 deletions.
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Change made

- [ ]  New features
- [ ]  Bug fixes
- [ ]  Breaking changes
## Describe what you have done
-
### New Features
-
### Fix
-
### Others
-
4 changes: 2 additions & 2 deletions config/auth/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ app:
secret: <secret>

database:
host: localhost
host: local-db
port: 5432
name: johnjud_db
username: root
Expand All @@ -17,7 +17,7 @@ jwt:
issuer: <issuer>

redis:
host: localhost
host: local-cache
port: 6379
password: ""
dbnum: 0
10 changes: 7 additions & 3 deletions config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ app:
debug: true

service:
auth: auth:3002
backend: backend:3003
file: file:3004
auth: localhost:3002
backend: localhost:3003
file: localhost:3004
# Production, when gateway in a container in same network
# auth: auth:3002
# backend: backend:3003
# file: file:3004
6 changes: 0 additions & 6 deletions src/app/dto/common.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,3 @@ type ResponseGatewayTimeoutErr struct {
Message string `json:"message" example:"Connection timeout"`
Data interface{} `json:"data"`
}

type ResponseSuccess struct {
StatusCode int `json:"status_code" example:"200"`
Message string `json:"message" example:"success"`
Data interface{} `json:"data"`
}
4 changes: 2 additions & 2 deletions src/app/dto/pet.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ChangeViewPetRequest struct {
}

type ChangeViewPetResponse struct {
Success bool `json:"success" validate:"required"`
Success bool `json:"success"`
}

type AdoptByRequest struct {
Expand Down Expand Up @@ -90,5 +90,5 @@ type DeleteRequest struct {
Id string `json:"id" validate:"required"`
}
type DeleteResponse struct {
Success bool `json:"success" validate:"required"`
Success bool `json:"success"`
}
15 changes: 10 additions & 5 deletions src/app/dto/user.dto.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package dto

type UserDto struct {
type User struct {
Id string `json:"id"`
Email string `json:"email"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}

type UpdateUserRequest struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password" validate:"required,gte=6,lte=30"`
Firstname string `json:"firstname" validate:"required"`
Lastname string `json:"lastname" validate:"required"`
}

type UpdateUserDto struct {
Password string `json:"password" validate:"required,gte=6,lte=30"`
Firstname string `json:"firstname" validate:"required"`
Lastname string `json:"lastname" validate:"required"`
type DeleteUserResponse struct {
Success bool `json:"success"`
}
19 changes: 3 additions & 16 deletions src/app/handler/like/like.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/isd-sgcu/johnjud-gateway/src/app/dto"
"github.com/isd-sgcu/johnjud-gateway/src/app/router"
"github.com/isd-sgcu/johnjud-gateway/src/app/validator"
likeConst "github.com/isd-sgcu/johnjud-gateway/src/constant/like"
likeSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/like"
)

Expand Down Expand Up @@ -38,11 +37,7 @@ func (h *Handler) FindByUserId(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: likeConst.FindLikeSuccessMessage,
Data: response,
})
c.JSON(http.StatusOK, response)
return
}

Expand Down Expand Up @@ -77,11 +72,7 @@ func (h *Handler) Create(c router.IContext) {
return
}

c.JSON(http.StatusCreated, dto.ResponseSuccess{
StatusCode: http.StatusCreated,
Message: likeConst.CreateLikeSuccessMessage,
Data: response,
})
c.JSON(http.StatusCreated, response)
return
}

Expand All @@ -102,10 +93,6 @@ func (h *Handler) Delete(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: likeConst.DelteLikeSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}
19 changes: 3 additions & 16 deletions src/app/handler/like/like.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
errConst "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/like"
likeConst "github.com/isd-sgcu/johnjud-gateway/src/constant/like"
routerMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/router"
likeMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/service/like"
validatorMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/validator"
Expand Down Expand Up @@ -74,11 +73,7 @@ func (t *LikeHandlerTest) SetupTest() {

func (t *LikeHandlerTest) TestFindLikesSuccess() {
findLikeResponse := utils.ProtoToDtoList(t.Likes)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: likeConst.FindLikeSuccessMessage,
Data: findLikeResponse,
}
expectedResponse := findLikeResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -147,11 +142,7 @@ func (t *LikeHandlerTest) TestFindLikeInternalError() {

func (t *LikeHandlerTest) TestCreateSuccess() {
createLikeResponse := utils.ProtoToDto(t.Like)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusCreated,
Message: likeConst.CreateLikeSuccessMessage,
Data: createLikeResponse,
}
expectedResponse := createLikeResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -208,11 +199,7 @@ func (t *LikeHandlerTest) TestDeleteSuccess() {
deleteResponse := &dto.DeleteLikeResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: likeConst.DelteLikeSuccessMessage,
Data: deleteResponse,
}
expectedResponse := deleteResponse

controller := gomock.NewController(t.T())

Expand Down
43 changes: 7 additions & 36 deletions src/app/handler/pet/pet.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/isd-sgcu/johnjud-gateway/src/app/dto"
"github.com/isd-sgcu/johnjud-gateway/src/app/router"
"github.com/isd-sgcu/johnjud-gateway/src/app/validator"
petconst "github.com/isd-sgcu/johnjud-gateway/src/constant/pet"
imageSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/image"
petSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/pet"
)
Expand Down Expand Up @@ -40,11 +39,7 @@ func (h *Handler) FindAll(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.FindAllPetSuccessMessage,
Data: response,
})
c.JSON(http.StatusOK, response)
return
}

Expand Down Expand Up @@ -77,11 +72,7 @@ func (h *Handler) FindOne(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.FindOnePetSuccessMessage,
Data: response,
})
c.JSON(http.StatusOK, response)
return
}

Expand Down Expand Up @@ -128,11 +119,7 @@ func (h *Handler) Create(c router.IContext) {
return
}

c.JSON(http.StatusCreated, dto.ResponseSuccess{
StatusCode: http.StatusCreated,
Message: petconst.CreatePetSuccessMessage,
Data: response,
})
c.JSON(http.StatusCreated, response)
return
}

Expand Down Expand Up @@ -191,11 +178,7 @@ func (h *Handler) Update(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.UpdatePetSuccessMessage,
Data: pet,
})
c.JSON(http.StatusOK, pet)
return
}

Expand Down Expand Up @@ -254,11 +237,7 @@ func (h *Handler) ChangeView(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.ChangeViewPetSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}

Expand Down Expand Up @@ -291,11 +270,7 @@ func (h *Handler) Delete(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.DeletePetSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}

Expand Down Expand Up @@ -353,10 +328,6 @@ func (h *Handler) Adopt(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.AdoptPetSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}
43 changes: 7 additions & 36 deletions src/app/handler/pet/pet.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

errConst "github.com/isd-sgcu/johnjud-gateway/src/app/constant"
utils "github.com/isd-sgcu/johnjud-gateway/src/app/utils/pet"
petConst "github.com/isd-sgcu/johnjud-gateway/src/constant/pet"
petProto "github.com/isd-sgcu/johnjud-go-proto/johnjud/backend/pet/v1"
imgProto "github.com/isd-sgcu/johnjud-go-proto/johnjud/file/image/v1"

Expand Down Expand Up @@ -131,11 +130,7 @@ func (t *PetHandlerTest) SetupTest() {

func (t *PetHandlerTest) TestFindAllSuccess() {
findAllResponse := utils.ProtoToDtoList(t.Pets, t.ImagesList)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.FindAllPetSuccessMessage,
Data: findAllResponse,
}
expectedResponse := findAllResponse

controller := gomock.NewController(t.T())

Expand All @@ -153,11 +148,7 @@ func (t *PetHandlerTest) TestFindAllSuccess() {

func (t *PetHandlerTest) TestFindOneSuccess() {
findOneResponse := utils.ProtoToDto(t.Pet, t.Images)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.FindOnePetSuccessMessage,
Data: findOneResponse,
}
expectedResponse := findOneResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -212,11 +203,7 @@ func (t *PetHandlerTest) TestFindOneGrpcErr() {

func (t *PetHandlerTest) TestCreateSuccess() {
createResponse := utils.ProtoToDto(t.Pet, t.Images)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusCreated,
Message: petConst.CreatePetSuccessMessage,
Data: createResponse,
}
expectedResponse := createResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -255,11 +242,7 @@ func (t *PetHandlerTest) TestCreateGrpcErr() {

func (t *PetHandlerTest) TestUpdateSuccess() {
updateResponse := utils.ProtoToDto(t.Pet, t.Images)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.UpdatePetSuccessMessage,
Data: updateResponse,
}
expectedResponse := updateResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -322,11 +305,7 @@ func (t *PetHandlerTest) TestDeleteSuccess() {
deleteResponse := &dto.DeleteResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.DeletePetSuccessMessage,
Data: deleteResponse,
}
expectedResponse := deleteResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -386,11 +365,7 @@ func (t *PetHandlerTest) TestChangeViewSuccess() {
changeViewResponse := &dto.ChangeViewPetResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.ChangeViewPetSuccessMessage,
Data: changeViewResponse,
}
expectedResponse := changeViewResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -457,11 +432,7 @@ func (t *PetHandlerTest) TestAdoptSuccess() {
adoptByResponse := &dto.AdoptByResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.AdoptPetSuccessMessage,
Data: adoptByResponse,
}
expectedResponse := adoptByResponse

controller := gomock.NewController(t.T())

Expand Down
Loading

0 comments on commit 9006fb2

Please sign in to comment.