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

[JOH-27] User endpoints and Admin middleware #11

Merged
merged 38 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cd3b103
feat: usersvc findone
bookpanda Jan 5, 2024
ce0e52f
fix: typo
bookpanda Jan 5, 2024
dc54903
feat: usersvc update
bookpanda Jan 5, 2024
59baa48
fix: remove validation in resp
bookpanda Jan 5, 2024
3ac9671
feat: user svc delete
bookpanda Jan 5, 2024
3059615
fix: pet svc delete return nil
bookpanda Jan 5, 2024
ba9a37e
fix: auth config
bookpanda Jan 6, 2024
24856ea
Merge branch 'dev' into JOH-27/user-endpoints
bookpanda Jan 7, 2024
0c1b397
feat: pr template
bookpanda Jan 7, 2024
5876f32
feat: pr template
bookpanda Jan 7, 2024
6bead97
fix: remove user old svc mock
bookpanda Jan 7, 2024
898a26c
fix: update user add password, email
bookpanda Jan 7, 2024
97a2beb
chore: gen mock
bookpanda Jan 7, 2024
5714a97
feat: user client mock
bookpanda Jan 7, 2024
ba8edcc
feat: user delete add unavailable
bookpanda Jan 7, 2024
fd4c0cf
feat: user svc test
bookpanda Jan 7, 2024
2cae2d9
feat: findone swagger
bookpanda Jan 7, 2024
6e11f07
fix: merge update, findone dto -> dto.User
bookpanda Jan 7, 2024
d2d291c
feat: user handler update
bookpanda Jan 8, 2024
746e744
feat: add context Role()
bookpanda Jan 8, 2024
915c17b
chore: gen mock
bookpanda Jan 8, 2024
8f8f8bd
feat: role const
bookpanda Jan 8, 2024
35e2242
feat: add admin path
bookpanda Jan 8, 2024
e31bf92
feat: user handler delete
bookpanda Jan 8, 2024
81b3501
fix: handler pass by ref
bookpanda Jan 9, 2024
fb02398
feat: user handler test
bookpanda Jan 9, 2024
0c82d9b
fix: remove validate in resp
bookpanda Jan 9, 2024
974c192
fix: user handler lighter sucess respo
bookpanda Jan 9, 2024
71c3175
fix: pet handler lighter sucess resp
bookpanda Jan 9, 2024
797e5a4
fix: like handler use lighter success resp
bookpanda Jan 9, 2024
88d4f6d
fix: pet create url
bookpanda Jan 9, 2024
b625e8d
feat: add admin paths
bookpanda Jan 9, 2024
4e497d0
fix: auth config
bookpanda Jan 9, 2024
4de877f
fix: url endpoints not ending in /
bookpanda Jan 9, 2024
44cd89f
fix: auth middleware detect :id
bookpanda Jan 9, 2024
6fb9623
fix: paths
bookpanda Jan 9, 2024
46f26d8
fix: auth cache
bookpanda Jan 9, 2024
d0a1854
fix: admin paths
bookpanda Jan 9, 2024
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
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
Nitiwat-owen marked this conversation as resolved.
Show resolved Hide resolved
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 UpdatePetRequest struct {
Expand All @@ -81,5 +81,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 @@ -354,10 +329,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
Loading