Skip to content

Commit

Permalink
include UploadProfile message
Browse files Browse the repository at this point in the history
  • Loading branch information
AssassinRobot committed Sep 3, 2024
1 parent f46e129 commit abc2259
Show file tree
Hide file tree
Showing 16 changed files with 1,318 additions and 1,737 deletions.
48 changes: 48 additions & 0 deletions delivery/grpc/handlers/user_handler.go
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
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ require (
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/grpc v1.66.0
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
Loading

0 comments on commit abc2259

Please sign in to comment.