add full auth

This commit is contained in:
2026-07-06 15:56:10 +07:00
parent 434627d61a
commit 6be4142487
14 changed files with 1512 additions and 50 deletions
+36
View File
@@ -2,8 +2,13 @@ package app
import (
"context"
"evening_detective_server/internal/modules/processor_jwt"
"evening_detective_server/internal/services/users_service"
proto "evening_detective_server/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
)
type server struct {
@@ -73,3 +78,34 @@ func (s *server) Refresh(ctx context.Context, req *proto.RefreshReq) (*proto.Ref
RefreshToken: refreshToken,
}, nil
}
func (s *server) GetUsers(ctx context.Context, req *proto.GetUsersReq) (*proto.GetUsersRsp, error) {
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
if !claims.HasRole("admin") {
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
users, err := s.usersService.GetUsers(ctx)
if err != nil {
return &proto.GetUsersRsp{
Error: err.Error(),
}, nil
}
resUsers := make([]*proto.User, 0, len(users))
for _, user := range users {
resUsers = append(
resUsers,
&proto.User{
Id: int32(user.ID),
Username: user.Username,
Email: user.Email,
Roles: user.Roles,
IsActive: user.IsActive,
CreatedAt: timestamppb.New(user.CreatedAt),
},
)
}
return &proto.GetUsersRsp{
Users: resUsers,
}, nil
}