Skip to content

Commit

Permalink
add testing http auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
febrihidayan committed Jan 23, 2024
1 parent 050599d commit 0895858
Show file tree
Hide file tree
Showing 55 changed files with 2,076 additions and 74 deletions.
8 changes: 4 additions & 4 deletions services/auth/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func initHandler(

grpcClientFactory := factories.NewGrpcFactory(grpcClient)

auth_handler.AuthHttpHandler(router, cfg, mongoFactory, grpcClientFactory)
permision_handler.PermissionHttpHandler(router, cfg, mongoFactory)
role_handler.RoleHttpHandler(router, cfg, mongoFactory)
acl_handler.AclHttpHandler(router, cfg, mongoFactory)
auth_handler.NewAuthHttpHandler(router, cfg, mongoFactory, grpcClientFactory)
permision_handler.NewPermissionHttpHandler(router, cfg, mongoFactory)
role_handler.NewRoleHttpHandler(router, cfg, mongoFactory)
acl_handler.NewAclHttpHandler(router, cfg, mongoFactory)
}
4 changes: 2 additions & 2 deletions services/auth/internal/delivery/http/delivery/acl/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *aclHttpHandler) Access(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) Access(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
)
Expand All @@ -20,7 +20,7 @@ func (x *aclHttpHandler) Access(w http.ResponseWriter, r *http.Request) {
return
}

results, err := x.aclUsecase.GetAllUser(ctx, jwtToken.Subject)
results, err := x.AclUsecase.GetAllUser(ctx, jwtToken.Subject)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *aclHttpHandler) GetAllPermission(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) GetAllPermission(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
)

results, err := x.aclUsecase.GetAllPermission(ctx)
results, err := x.AclUsecase.GetAllPermission(ctx)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gorilla/mux"
)

func (x *aclHttpHandler) GetAllPermissionByRole(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) GetAllPermissionByRole(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
vars = mux.Vars(r)
Expand All @@ -23,7 +23,7 @@ func (x *aclHttpHandler) GetAllPermissionByRole(w http.ResponseWriter, r *http.R
return
}

results, err := x.aclUsecase.GetAllPermissionByRole(ctx, id)
results, err := x.AclUsecase.GetAllPermissionByRole(ctx, id)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *aclHttpHandler) GetAllRole(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) GetAllRole(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
)

results, err := x.aclUsecase.GetAllRole(ctx)
results, err := x.AclUsecase.GetAllRole(ctx)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gorilla/mux"
)

func (x *aclHttpHandler) GetAllUser(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) GetAllUser(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
vars = mux.Vars(r)
Expand All @@ -29,7 +29,7 @@ func (x *aclHttpHandler) GetAllUser(w http.ResponseWriter, r *http.Request) {
return
}

results, err := x.aclUsecase.GetAllUser(ctx, id)
results, err := x.AclUsecase.GetAllUser(ctx, id)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
14 changes: 7 additions & 7 deletions services/auth/internal/delivery/http/delivery/acl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
"github.com/gorilla/mux"
)

type aclHttpHandler struct {
cfg *config.AuthConfig
aclUsecase usecases.AclUsecase
type AclHttpHandler struct {
Cfg *config.AuthConfig
AclUsecase usecases.AclUsecase
}

func AclHttpHandler(
func NewAclHttpHandler(
r *mux.Router,
config *config.AuthConfig,
mongoFactory *factories.MongoFactory,
) {
handler := &aclHttpHandler{
cfg: config,
aclUsecase: acl.NewAclInteractor(
handler := &AclHttpHandler{
Cfg: config,
AclUsecase: acl.NewAclInteractor(
config,
mongoFactory,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/gorilla/mux"
)

func (x *aclHttpHandler) UpdatePermissionByRole(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) UpdatePermissionByRole(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
vars = mux.Vars(r)
Expand Down Expand Up @@ -43,7 +43,7 @@ func (x *aclHttpHandler) UpdatePermissionByRole(w http.ResponseWriter, r *http.R
Permissions: payload.Permissions,
}

if err := x.aclUsecase.UpdatePermissionByRole(ctx, data); err != nil {
if err := x.AclUsecase.UpdatePermissionByRole(ctx, data); err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/gorilla/mux"
)

func (x *aclHttpHandler) UpdateUser(w http.ResponseWriter, r *http.Request) {
func (x *AclHttpHandler) UpdateUser(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
vars = mux.Vars(r)
Expand Down Expand Up @@ -44,7 +44,7 @@ func (x *aclHttpHandler) UpdateUser(w http.ResponseWriter, r *http.Request) {
Roles: payload.Roles,
}

if err := x.aclUsecase.UpdateUser(ctx, data); err != nil {
if err := x.AclUsecase.UpdateUser(ctx, data); err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gorilla/mux"
)

func (x *authHttpHandler) EmailVerified(w http.ResponseWriter, r *http.Request) {
func (x *AuthHttpHandler) EmailVerified(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
vars = mux.Vars(r)
Expand All @@ -22,7 +22,7 @@ func (x *authHttpHandler) EmailVerified(w http.ResponseWriter, r *http.Request)
return
}

if err := x.authUsecase.EmailVerified(ctx, token); err != nil {
if err := x.AuthUsecase.EmailVerified(ctx, token); err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}
Expand Down
14 changes: 7 additions & 7 deletions services/auth/internal/delivery/http/delivery/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (
"github.com/gorilla/mux"
)

type authHttpHandler struct {
cfg *config.AuthConfig
authUsecase usecases.AuthUsecase
type AuthHttpHandler struct {
Cfg *config.AuthConfig
AuthUsecase usecases.AuthUsecase
}

func AuthHttpHandler(
func NewAuthHttpHandler(
r *mux.Router,
config *config.AuthConfig,
mongoFactory *factories.MongoFactory,
grpcClientFactory *factories.GrpcClientFactory,
) {
handler := &authHttpHandler{
cfg: config,
authUsecase: auth.NewAuthInteractor(
handler := &AuthHttpHandler{
Cfg: config,
AuthUsecase: auth.NewAuthInteractor(
config,
mongoFactory,
grpcClientFactory,
Expand Down
4 changes: 2 additions & 2 deletions services/auth/internal/delivery/http/delivery/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *authHttpHandler) Login(w http.ResponseWriter, r *http.Request) {
func (x *AuthHttpHandler) Login(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.AuthLoginRequest
Expand All @@ -35,7 +35,7 @@ func (x *authHttpHandler) Login(w http.ResponseWriter, r *http.Request) {
Password: payload.Password,
}

login, err := x.authUsecase.Login(ctx, data)
login, err := x.AuthUsecase.Login(ctx, data)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/request"
)

func (x *authHttpHandler) PasswordEmail(w http.ResponseWriter, r *http.Request) {
func (x *AuthHttpHandler) PasswordEmail(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.AuthEmailRequest
Expand All @@ -28,7 +28,7 @@ func (x *authHttpHandler) PasswordEmail(w http.ResponseWriter, r *http.Request)
return
}

if err := x.authUsecase.PasswordEmail(ctx, payload.Email); err != nil {
if err := x.AuthUsecase.PasswordEmail(ctx, payload.Email); err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/request"
)

func (x *authHttpHandler) PasswordReset(w http.ResponseWriter, r *http.Request) {
func (x *AuthHttpHandler) PasswordReset(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.AuthPasswordResetRequest
Expand All @@ -34,7 +34,7 @@ func (x *authHttpHandler) PasswordReset(w http.ResponseWriter, r *http.Request)
Password: payload.Password,
}

if err := x.authUsecase.PasswordReset(ctx, data); err != nil {
if err := x.AuthUsecase.PasswordReset(ctx, data); err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/request"
)

func (x *authHttpHandler) Register(w http.ResponseWriter, r *http.Request) {
func (x *AuthHttpHandler) Register(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.AuthRegisterRequest
Expand All @@ -36,7 +36,7 @@ func (x *authHttpHandler) Register(w http.ResponseWriter, r *http.Request) {
ConfirmPassword: payload.ConfirmPassword,
}

_, err := x.authUsecase.Register(ctx, data)
_, err := x.AuthUsecase.Register(ctx, data)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/request"
)

func (x *authHttpHandler) SendEmailVerified(w http.ResponseWriter, r *http.Request) {
func (x *AuthHttpHandler) SendEmailVerified(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.AuthEmailRequest
Expand All @@ -28,7 +28,7 @@ func (x *authHttpHandler) SendEmailVerified(w http.ResponseWriter, r *http.Reque
return
}

if err := x.authUsecase.SendEmailVerified(ctx, payload.Email); err != nil {
if err := x.AuthUsecase.SendEmailVerified(ctx, payload.Email); err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/request"
)

func (x *permissionHttpHandler) Create(w http.ResponseWriter, r *http.Request) {
func (x *PermissionHttpHandler) Create(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.PermissionCreateRequest
Expand All @@ -35,7 +35,7 @@ func (x *permissionHttpHandler) Create(w http.ResponseWriter, r *http.Request) {
Description: payload.Description,
}

_, err := x.permissionUsecase.Create(ctx, data)
_, err := x.PermissionUsecase.Create(ctx, data)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gorilla/mux"
)

func (x *permissionHttpHandler) Find(w http.ResponseWriter, r *http.Request) {
func (x *PermissionHttpHandler) Find(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
vars = mux.Vars(r)
Expand All @@ -23,7 +23,7 @@ func (x *permissionHttpHandler) Find(w http.ResponseWriter, r *http.Request) {
return
}

result, err := x.permissionUsecase.Find(ctx, id)
result, err := x.PermissionUsecase.Find(ctx, id)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *permissionHttpHandler) GetAll(w http.ResponseWriter, r *http.Request) {
func (x *PermissionHttpHandler) GetAll(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
query request.PermissionQueryParams
Expand All @@ -28,7 +28,7 @@ func (x *permissionHttpHandler) GetAll(w http.ResponseWriter, r *http.Request) {
PerPage: query.PerPage,
}

results, err := x.permissionUsecase.GetAll(ctx, params)
results, err := x.PermissionUsecase.GetAll(ctx, params)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
"github.com/gorilla/mux"
)

type permissionHttpHandler struct {
cfg *config.AuthConfig
permissionUsecase usecases.PermissionUsecase
type PermissionHttpHandler struct {
Cfg *config.AuthConfig
PermissionUsecase usecases.PermissionUsecase
}

func PermissionHttpHandler(
func NewPermissionHttpHandler(
r *mux.Router,
config *config.AuthConfig,
mongoFactory *factories.MongoFactory,
) {
handler := &permissionHttpHandler{
cfg: config,
permissionUsecase: permission.NewPermissionInteractor(
handler := &PermissionHttpHandler{
Cfg: config,
PermissionUsecase: permission.NewPermissionInteractor(
config,
mongoFactory,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/gorilla/mux"
)

func (x *permissionHttpHandler) Update(w http.ResponseWriter, r *http.Request) {
func (x *PermissionHttpHandler) Update(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
payload request.PermissionUpdateRequest
Expand All @@ -42,7 +42,7 @@ func (x *permissionHttpHandler) Update(w http.ResponseWriter, r *http.Request) {
Description: payload.Description,
}

result, err := x.permissionUsecase.Update(ctx, data)
result, err := x.PermissionUsecase.Update(ctx, data)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
Expand Down
Loading

0 comments on commit 0895858

Please sign in to comment.