package service import ( "context" "log" pb "lunar-tear/server/gen/proto" "lunar-tear/server/internal/store" "lunar-tear/server/internal/userdata" emptypb "google.golang.org/protobuf/types/known/emptypb" ) type NotificationServiceServer struct { pb.UnimplementedNotificationServiceServer users store.UserRepository sessions store.SessionRepository } func NewNotificationServiceServer(users store.UserRepository, sessions store.SessionRepository) *NotificationServiceServer { return &NotificationServiceServer{users: users, sessions: sessions} } func (s *NotificationServiceServer) GetHeaderNotification(ctx context.Context, req *emptypb.Empty) (*pb.GetHeaderNotificationResponse, error) { log.Printf("[NotificationService] GetHeaderNotification") userId := currentUserId(ctx, s.users, s.sessions) user, err := s.users.LoadUser(userId) if err != nil { return &pb.GetHeaderNotificationResponse{ GiftNotReceiveCount: 0, FriendRequestReceiveCount: 0, IsExistUnreadInformation: false, DiffUserData: userdata.EmptyDiff(), }, nil } return &pb.GetHeaderNotificationResponse{ GiftNotReceiveCount: int32(len(user.Gifts.NotReceived)), FriendRequestReceiveCount: user.Notifications.FriendRequestReceiveCount, IsExistUnreadInformation: user.Notifications.IsExistUnreadInformation, DiffUserData: userdata.EmptyDiff(), }, nil }