diff --git a/users.go b/users.go index ed37a19..ab52195 100644 --- a/users.go +++ b/users.go @@ -88,6 +88,12 @@ func (s *UserService) IterBlockedUsers(ctx context.Context) iter.Seq2[types.Bloc return ListIter[types.BlockedUser](ctx, s.client, "/api/v1/user/list_blocked", nil) } +// Block blocks a user as the authenticated user. +func (s *UserService) Block(ctx context.Context, username string) error { + path := ResolvePath("/api/v1/user/block/{username}", pathParams("username", username)) + return s.client.Put(ctx, path, nil, nil) +} + // ListMySubscriptions returns all repositories watched by the authenticated user. func (s *UserService) ListMySubscriptions(ctx context.Context) ([]types.Repository, error) { return ListAll[types.Repository](ctx, s.client, "/api/v1/user/subscriptions", nil) diff --git a/users_test.go b/users_test.go index a0ebdc4..704e231 100644 --- a/users_test.go +++ b/users_test.go @@ -141,6 +141,24 @@ func TestUserService_ListBlockedUsers_Good(t *testing.T) { } } +func TestUserService_Block_Good(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPut { + t.Errorf("expected PUT, got %s", r.Method) + } + if r.URL.Path != "/api/v1/user/block/alice" { + t.Errorf("wrong path: %s", r.URL.Path) + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + if err := f.Users.Block(context.Background(), "alice"); err != nil { + t.Fatal(err) + } +} + func TestUserService_IterBlockedUsers_Good(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet {