From 52ce331f379abaeaeb4928b6873d1375ecbdb270 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 16 Sep 2025 22:33:43 +0300 Subject: [PATCH] =?UTF-8?q?v.0.2=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/server.go b/server.go index 40a2838..6dc5dc2 100644 --- a/server.go +++ b/server.go @@ -2,17 +2,18 @@ package main import ( "context" + "log" + "net" + "os" + "tailly_subscribers/proto" + "time" + "github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4/pgxpool" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/keepalive" "google.golang.org/grpc/status" - "log" - "net" - "os" - "tailly_subscribers/proto" - "time" ) type server struct { @@ -34,7 +35,6 @@ func (s *server) FollowUser(ctx context.Context, req *proto.FollowRequest) (*pro return nil, status.Error(codes.InvalidArgument, "cannot follow yourself") } - // ИСПРАВЛЕНИЕ: Используем QueryRow чтобы получить количество вставленных строк var subscriptionID int32 err := s.db.QueryRow(ctx, ` INSERT INTO subscriptions (follower_id, following_id) @@ -45,7 +45,6 @@ func (s *server) FollowUser(ctx context.Context, req *proto.FollowRequest) (*pro if err != nil { if err == pgx.ErrNoRows { - // Конфликт - подписка уже существует return &proto.FollowResponse{ Success: false, Message: "Already following this user", @@ -54,6 +53,19 @@ func (s *server) FollowUser(ctx context.Context, req *proto.FollowRequest) (*pro return nil, status.Errorf(codes.Internal, "failed to follow: %v", err) } + var notificationID int32 + err = s.db.QueryRow(ctx, ` + INSERT INTO subscription_notifications (subscription_id) + VALUES ($1) + RETURNING id`, + subscriptionID).Scan(¬ificationID) + + if err != nil { + s.logger.Printf("Warning: failed to create notification for subscription %d: %v", subscriptionID, err) + } else { + s.logger.Printf("Created notification %d for subscription %d", notificationID, subscriptionID) + } + return &proto.FollowResponse{ Success: true, Message: "Successfully followed user",