add get me route

This commit is contained in:
2026-07-06 22:41:58 +07:00
parent b7219cfff9
commit 728fcc6fda
8 changed files with 313 additions and 37 deletions
+15 -12
View File
@@ -8,7 +8,6 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
)
type server struct {
@@ -93,19 +92,23 @@ func (s *server) GetUsers(ctx context.Context, req *proto.GetUsersReq) (*proto.G
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),
},
)
resUsers = append(resUsers, mapUser(user))
}
return &proto.GetUsersRsp{
Users: resUsers,
}, nil
}
func (s *server) GetMe(ctx context.Context, req *proto.GetMeReq) (*proto.GetMeRsp, error) {
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
user, err := s.usersService.GetUserByID(ctx, claims.UserID)
if err != nil {
return &proto.GetMeRsp{
Error: err.Error(),
}, nil
}
return &proto.GetMeRsp{
User: mapUser(user),
}, nil
}