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-26] Sign out #5

Merged
merged 10 commits into from
Jan 4, 2024
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-playground/validator/v10 v10.16.0
github.com/gofiber/fiber/v2 v2.51.0
github.com/google/uuid v1.5.0
github.com/isd-sgcu/johnjud-go-proto v0.0.8
github.com/isd-sgcu/johnjud-go-proto v0.2.2
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.18.2
Expand Down Expand Up @@ -68,7 +68,7 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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.0.8 h1:nIQBZgK2OFVrLjVtpeDgwows8poA7LhsIVE4hlbBC1o=
github.com/isd-sgcu/johnjud-go-proto v0.0.8/go.mod h1:HP0w9gC30b5WNnqeFBM9JJZud+pvyikz0+pGFSI/Wjw=
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/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 Expand Up @@ -250,6 +252,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
Expand Down
4 changes: 4 additions & 0 deletions src/app/dto/auth.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ type SignInRequest struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password" validate:"required,gte=6,lte=30"`
}

type SignOutResponse struct {
IsSuccess bool `json:"is_success"`
}
35 changes: 0 additions & 35 deletions src/app/handler/adopt/adopt.handler.go

This file was deleted.

20 changes: 19 additions & 1 deletion src/app/handler/auth/auth.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ func (h *Handler) SignIn(c router.IContext) {
c.JSON(http.StatusOK, response)
}

func (h *Handler) Signout(c router.IContext) {
// SignOut is a function that remove token and auth session of user
// @Summary Sign out user
// @Description Return the bool value of success
// @Tags auth
// @Accept json
// @Produce json
// @Success 200 {object} dto.SignOutResponse
// @Failure 500 {object} dto.ResponseInternalErr "Internal service error"
// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down"
// @Router /v1/auth/signout [post]
func (h *Handler) SignOut(c router.IContext) {
token := c.Token()

response, respErr := h.service.SignOut(token)
if respErr != nil {
c.JSON(respErr.StatusCode, respErr)
return
}

c.JSON(http.StatusOK, response)
}
46 changes: 46 additions & 0 deletions src/app/handler/auth/auth.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,49 @@ func (t *AuthHandlerTest) TestSignInServiceError() {

handler.SignIn(context)
}

func (t *AuthHandlerTest) TestSignOutSuccess() {
token := faker.Word()
signOutResponse := &dto.SignOutResponse{
IsSuccess: true,
}

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

authSvc := mock_auth.NewMockService(controller)
userSvc := mock_user.NewMockService(controller)
validator := mock_validator.NewMockIDtoValidator(controller)
context := mock_router.NewMockIContext(controller)

context.EXPECT().Token().Return(token)
authSvc.EXPECT().SignOut(token).Return(signOutResponse, nil)
context.EXPECT().JSON(http.StatusOK, signOutResponse)

handler := NewHandler(authSvc, userSvc, validator)

handler.SignOut(context)
}

func (t *AuthHandlerTest) TestSignOutServiceError() {
token := faker.Word()
errResponse := &dto.ResponseErr{
StatusCode: http.StatusInternalServerError,
Message: constant.InternalErrorMessage,
Data: nil,
}

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

authSvc := mock_auth.NewMockService(controller)
userSvc := mock_user.NewMockService(controller)
validator := mock_validator.NewMockIDtoValidator(controller)
context := mock_router.NewMockIContext(controller)

handler := NewHandler(authSvc, userSvc, validator)

context.EXPECT().Token().Return(token)
authSvc.EXPECT().SignOut(token).Return(nil, errResponse)
context.EXPECT().JSON(http.StatusInternalServerError, errResponse)

handler.SignOut(context)
}
24 changes: 0 additions & 24 deletions src/app/router/adopt.router.go

This file was deleted.

4 changes: 1 addition & 3 deletions src/app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type FiberRouter struct {
pet fiber.Router
image fiber.Router
like fiber.Router
adopt fiber.Router
}

type IGuard interface {
Expand Down Expand Up @@ -53,9 +52,8 @@ func NewFiberRouter(authGuard IGuard, conf config.App) *FiberRouter {
pet := GroupWithAuthMiddleware(r, "/pet", authGuard.Use)
image := GroupWithAuthMiddleware(r, "/image", authGuard.Use)
like := GroupWithAuthMiddleware(r, "/like", authGuard.Use)
adopt := GroupWithAuthMiddleware(r, "/adopt", authGuard.Use)

return &FiberRouter{r, auth, user, pet, image, adopt, like}
return &FiberRouter{r, auth, user, pet, image, like}
}

func GroupWithAuthMiddleware(r *fiber.App, path string, middleware func(ctx IContext) error) fiber.Router {
Expand Down
28 changes: 0 additions & 28 deletions src/app/service/adopt/adopt.service.go

This file was deleted.

Loading
Loading