-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe0eae7
commit f714c5f
Showing
31 changed files
with
940 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package entities | ||
|
||
type AclQueryParams struct { | ||
} | ||
|
||
type AclMeta struct { | ||
Roles []*Role | ||
Permissions []*Permission | ||
} | ||
|
||
type AclUserDto struct { | ||
UserId string | ||
Roles []string | ||
Permissions []string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package usecases | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" | ||
) | ||
|
||
type AclUsecase interface { | ||
GetAll(ctx context.Context) (*entities.AclMeta, *exceptions.CustomError) | ||
GetAllUser(ctx context.Context, userId string) (*entities.AclMeta, *exceptions.CustomError) | ||
UpdateUser(ctx context.Context, payload entities.AclUserDto) *exceptions.CustomError | ||
} |
30 changes: 30 additions & 0 deletions
30
services/auth/internal/delivery/http/delivery/acl/access.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package acl_handler | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" | ||
"github.com/febrihidayan/go-architecture-monorepo/pkg/utils" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response" | ||
) | ||
|
||
func (x *aclHttpHandler) Access(w http.ResponseWriter, r *http.Request) { | ||
var ( | ||
ctx = context.Background() | ||
) | ||
|
||
jwtToken, errJwt := utils.DecodeJwtToken(r.Header.Get("Authorization")) | ||
if errJwt != nil { | ||
utils.RespondWithError(w, http.StatusBadRequest, []error{errJwt}) | ||
return | ||
} | ||
|
||
results, err := x.aclUsecase.GetAllUser(ctx, jwtToken.Subject) | ||
if err != nil { | ||
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors) | ||
return | ||
} | ||
|
||
utils.RespondWithJSON(w, http.StatusOK, response.MapAclAccessListResponse(results)) | ||
} |
24 changes: 24 additions & 0 deletions
24
services/auth/internal/delivery/http/delivery/acl/get_all.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package acl_handler | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" | ||
"github.com/febrihidayan/go-architecture-monorepo/pkg/utils" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response" | ||
) | ||
|
||
func (x *aclHttpHandler) GetAll(w http.ResponseWriter, r *http.Request) { | ||
var ( | ||
ctx = context.Background() | ||
) | ||
|
||
results, err := x.aclUsecase.GetAll(ctx) | ||
if err != nil { | ||
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors) | ||
return | ||
} | ||
|
||
utils.RespondWithJSON(w, http.StatusOK, response.MapAclListResponse(results)) | ||
} |
39 changes: 39 additions & 0 deletions
39
services/auth/internal/delivery/http/delivery/acl/get_all_user.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package acl_handler | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" | ||
"github.com/febrihidayan/go-architecture-monorepo/pkg/utils" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
func (x *aclHttpHandler) GetAllUser(w http.ResponseWriter, r *http.Request) { | ||
var ( | ||
ctx = context.Background() | ||
vars = mux.Vars(r) | ||
id = vars["id"] | ||
) | ||
|
||
if id == "" { | ||
utils.RespondWithError(w, http.StatusBadRequest, []error{errors.New("param id required")}) | ||
return | ||
} | ||
|
||
_, errJwt := utils.DecodeJwtToken(r.Header.Get("Authorization")) | ||
if errJwt != nil { | ||
utils.RespondWithError(w, http.StatusBadRequest, []error{errJwt}) | ||
return | ||
} | ||
|
||
results, err := x.aclUsecase.GetAllUser(ctx, id) | ||
if err != nil { | ||
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors) | ||
return | ||
} | ||
|
||
utils.RespondWithJSON(w, http.StatusOK, response.MapAclListResponse(results)) | ||
} |
Oops, something went wrong.