-
Notifications
You must be signed in to change notification settings - Fork 5
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
f46e129
commit abc2259
Showing
16 changed files
with
1,318 additions
and
1,737 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package grpc_handlers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/kavkaco/Kavka-Core/delivery/grpc/interceptor" | ||
"github.com/kavkaco/Kavka-Core/internal/service/user" | ||
"github.com/kavkaco/Kavka-Core/log" | ||
userv1 "github.com/kavkaco/Kavka-Core/protobuf/gen/go/protobuf/user/v1" | ||
"github.com/kavkaco/Kavka-Core/protobuf/gen/go/protobuf/user/v1/userv1connect" | ||
) | ||
|
||
type userGrpcServer struct { | ||
logger *log.SubLogger | ||
userService user.UserService | ||
} | ||
|
||
func NewUserGrpcServer(logger *log.SubLogger, userService user.UserService) userv1connect.UserServiceHandler { | ||
return &userGrpcServer{logger, userService} | ||
} | ||
|
||
func (h *userGrpcServer) UploadProfile(ctx context.Context, stream *connect.ClientStream[userv1.UploadProfileRequest]) (*connect.Response[userv1.UploadProfileResponse], error) { | ||
headers := stream.RequestHeader() | ||
|
||
filename := headers.Get("filename") | ||
if filename == "" { | ||
return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("missing filename")) | ||
} | ||
userID := ctx.Value(interceptor.UserID{}).(string) | ||
if userID == "" { | ||
return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("missing userID")) | ||
} | ||
|
||
for stream.Receive() { | ||
bytes := stream.Msg().Bytes | ||
|
||
err := h.userService.UpdateProfilePicture(ctx, userID, filename, bytes) | ||
if err != nil { | ||
return nil, connect.NewError(connect.CodeInternal, err.Error) | ||
} | ||
} | ||
|
||
res := connect.NewResponse(&userv1.UploadProfileResponse{}) | ||
|
||
return res, nil | ||
} |
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
Oops, something went wrong.