Skip to content

Commit

Permalink
feature: delete friend bill (without test)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielllllllllllllll committed Aug 4, 2024
1 parent 4af63e1 commit 1e90b85
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions services/api/controllers/friend_bill/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package friend_bill

import (
"context"
"database/sql"
"monify/lib"
monify "monify/protobuf/gen/go"

"github.com/google/uuid"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
)

func (s Service) DeleteFriendBill(ctx context.Context, req *monify.DeleteFriendBillRequest) (*emptypb.Empty, error) {
logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger)
_, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if !ok {
return nil, status.Error(codes.Unauthenticated, "Unauthorized.")
}
db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB)
_, err := db.ExecContext(ctx, `DELETE FROM friend_bill WHERE friend_bill_id = $1`, req.FriendBillId)
if err != nil {
logger.Error("Delete friend bill error.", zap.Error(err))
return nil, status.Error(codes.Internal, "")
}
return &emptypb.Empty{}, nil
}
6 changes: 6 additions & 0 deletions services/api/test/friend_bill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func TestFriendBill(t *testing.T) {
Title: "test1",
Description: "test1",
})
_, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{
RelationId: friendS_relationId[0],
Amount: 500,
Title: "test2",
Description: "test2",
})
assert.NoError(t, err)
_, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{
RelationId: friendS_relationId[0],
Expand Down

0 comments on commit 1e90b85

Please sign in to comment.