Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Gorse.NET.Tests/Gorse.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.5.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.11.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Gorse.NET\Gorse.NET.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion Gorse.NET.Tests/GorseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public partial class Tests
private const string ENDPOINT = "http://127.0.0.1:8088";
private const string API_KEY = "zhenghaoz";

private Gorse client = new Gorse(ENDPOINT, API_KEY);
private GorseClient client = new GorseClient(ENDPOINT, API_KEY);
}
14 changes: 7 additions & 7 deletions Gorse.NET.Tests/UnitTests/TestFeedbackAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ public void TestFeedback()
UserId = "2000",
ItemId = "1",
Value = 1.0,
Timestamp = DateTime.UtcNow.ToString("o"),
Timestamp = DateTime.UtcNow,
},
new Feedback
{
FeedbackType = "watch",
UserId = "2000",
ItemId = "1060",
Value = 2.0,
Timestamp = DateTime.UtcNow.ToString("o"),
Timestamp = DateTime.UtcNow,
},
new Feedback
{
FeedbackType = "watch",
UserId = "2000",
ItemId = "11",
Value = 3.0,
Timestamp = DateTime.UtcNow.ToString("o"),
Timestamp = DateTime.UtcNow,
},
};
foreach (var fb in feedbacks)
Expand All @@ -45,31 +45,31 @@ public void TestFeedback()
[Test]
public async Task TestFeedbackAsync()
{
var feedbacks = new Feedback[]
var feedbacks = new List<Feedback>
{
new Feedback
{
FeedbackType = "watch",
UserId = "2000",
ItemId = "1",
Value = 1.0,
Timestamp = DateTime.UtcNow.ToString("o"),
Timestamp = DateTime.UtcNow,
},
new Feedback
{
FeedbackType = "watch",
UserId = "2000",
ItemId = "1060",
Value = 2.0,
Timestamp = DateTime.UtcNow.ToString("o"),
Timestamp = DateTime.UtcNow,
},
new Feedback
{
FeedbackType = "watch",
UserId = "2000",
ItemId = "11",
Value = 3.0,
Timestamp = DateTime.UtcNow.ToString("o"),
Timestamp = DateTime.UtcNow,
},
};
foreach (var fb in feedbacks)
Expand Down
4 changes: 2 additions & 2 deletions Gorse.NET.Tests/UnitTests/TestItemsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void TestItems()
{ "embedding", new List<double> { 0.1, 0.2, 0.3 } }
},
Categories = new[] { "Comedy", "Animation" },
TimeStamp = DateTime.UtcNow,
Timestamp = DateTime.UtcNow,
Comment = "Minions (2015)",
};
var rowAffected = client.InsertItem(item);
Expand Down Expand Up @@ -54,7 +54,7 @@ public async Task TestItemsAsync()
{ "embedding", new List<double> { 0.1, 0.2, 0.3 } }
},
Categories = new[] { "Comedy", "Animation" },
TimeStamp = DateTime.UtcNow,
Timestamp = DateTime.UtcNow,
Comment = "Minions (2015)",
};
var rowAffected = await client.InsertItemAsync(item);
Expand Down
35 changes: 31 additions & 4 deletions Gorse.NET/API/FeedbackAPI.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@


using Gorse.NET.Models;
using RestSharp;

namespace Gorse.NET;

public partial class Gorse
{
public Result InsertFeedback(Feedback[] feedbacks)
/// <summary>
/// Insert feedback. Duplicate feedback will have their values summed.
/// Use <see cref="UpsertFeedback(IEnumerable{Feedback})"/> for overwrite semantics.
/// </summary>
Comment on lines +10 to +13
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These XML docs are on the synchronous InsertFeedback method but reference UpsertFeedbackAsync. This is misleading for callers; the docs should reference the synchronous alternative (UpsertFeedback) or mention both sync/async options consistently.

Copilot uses AI. Check for mistakes.
public Result InsertFeedback(IEnumerable<Feedback> feedbacks)
{
return _client.Request<Result, IEnumerable<Feedback>>(Method.Post, "api/feedback", feedbacks)!;
}

/// <summary>
/// Insert feedback. Duplicate feedback will have their values summed.
/// Use <see cref="UpsertFeedbackAsync(IEnumerable{Feedback})"/> for overwrite semantics.
/// </summary>
public Task<Result> InsertFeedbackAsync(IEnumerable<Feedback> feedbacks)
{
return _client.RequestAsync<Result, IEnumerable<Feedback>>(Method.Post, "api/feedback", feedbacks)!;
}

/// <summary>
/// Upsert feedback. Duplicate feedback will be overwritten (not summed).
/// Use <see cref="InsertFeedback(IEnumerable{Feedback})"/> for additive/sum semantics.
/// </summary>
Comment on lines +28 to +31
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These XML docs are on the synchronous UpsertFeedback method but reference InsertFeedbackAsync. Update the documentation to point to the synchronous InsertFeedback method (or mention both) so callers don’t have to infer the correct API.

Copilot uses AI. Check for mistakes.
public Result UpsertFeedback(IEnumerable<Feedback> feedbacks)
{
return _client.Request<Result, Feedback[]>(Method.Post, "api/feedback", feedbacks)!;
return _client.Request<Result, IEnumerable<Feedback>>(Method.Put, "api/feedback", feedbacks)!;
}

public Task<Result> InsertFeedbackAsync(Feedback[] feedbacks)
/// <summary>
/// Upsert feedback. Duplicate feedback will be overwritten (not summed).
/// Use <see cref="InsertFeedbackAsync(IEnumerable{Feedback})"/> for additive/sum semantics.
/// </summary>
public Task<Result> UpsertFeedbackAsync(IEnumerable<Feedback> feedbacks)
{
return _client.RequestAsync<Result, Feedback[]>(Method.Post, "api/feedback", feedbacks)!;
return _client.RequestAsync<Result, IEnumerable<Feedback>>(Method.Put, "api/feedback", feedbacks)!;
}

public FeedbacksResponse GetFeedbacks(int n = 10, string cursor = "")
Expand Down
8 changes: 4 additions & 4 deletions Gorse.NET/API/ItemsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public Task<Result> InsertItemAsync(Item item)
return _client.RequestAsync<Result, Item>(Method.Post, "api/item", item)!;
}

public Result InsertItems(List<Item> items)
public Result InsertItems(IEnumerable<Item> items)
{
return _client.Request<Result, List<Item>>(Method.Post, "api/items", items)!;
return _client.Request<Result, IEnumerable<Item>>(Method.Post, "api/items", items)!;
}

public Task<Result> InsertItemsAsync(List<Item> items)
public Task<Result> InsertItemsAsync(IEnumerable<Item> items)
{
return _client.RequestAsync<Result, List<Item>>(Method.Post, "api/items", items)!;
return _client.RequestAsync<Result, IEnumerable<Item>>(Method.Post, "api/items", items)!;
}

public Item GetItem(string itemId)
Expand Down
62 changes: 36 additions & 26 deletions Gorse.NET/API/RecommendationAPI.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
using Gorse.NET.Models;
using RestSharp;

namespace Gorse.NET;

public partial class Gorse
{
public string[]? GetRecommend(string userId)
{
return _client.Request<string[], Object>(Method.Get, "api/recommend/" + userId, null);
}

public Task<string[]?> GetRecommendAsync(string userId)
{
return _client.RequestAsync<string[], Object>(Method.Get, "api/recommend/" + userId, null);
}

public List<UserScore> GetUserNeighbors(string userId, int n = 100, int offset = 0)
{
return _client.Request<List<UserScore>, object>(Method.Get, $"api/user/{userId}/neighbors?n={n}&offset={offset}", null)!;
}

public Task<List<UserScore>> GetUserNeighborsAsync(string userId, int n = 100, int offset = 0)
{
return _client.RequestAsync<List<UserScore>, object>(Method.Get, $"api/user/{userId}/neighbors?n={n}&offset={offset}", null)!;
}
using Gorse.NET.Models;
using RestSharp;

namespace Gorse.NET;

public partial class Gorse
{
public string[]? GetRecommend(string userId, int n = 10)
{
return _client.Request<string[], Object>(Method.Get, $"api/recommend/{userId}?n={n}", null);
}

public Task<string[]?> GetRecommendAsync(string userId, int n = 10)
{
return _client.RequestAsync<string[], Object>(Method.Get, $"api/recommend/{userId}?n={n}", null);
}

public List<UserScore> GetUserNeighbors(string userId, int n = 100, int offset = 0)
{
return _client.Request<List<UserScore>, object>(Method.Get, $"api/user/{userId}/neighbors?n={n}&offset={offset}", null)!;
}

public Task<List<UserScore>> GetUserNeighborsAsync(string userId, int n = 100, int offset = 0)
{
return _client.RequestAsync<List<UserScore>, object>(Method.Get, $"api/user/{userId}/neighbors?n={n}&offset={offset}", null)!;
}

public Task<List<UserScore>> GetItemNeighborsAsync(string itemId, int n = 12, int offset = 0, string recommender = "neighbors")
{
return _client.RequestAsync<List<UserScore>, object>(Method.Get, $"api/item-to-item/{recommender}/{itemId}?n={n}&offset={offset}", null)!;
}

public Task<List<UserScore>> GetRecommendLatestAsync(int n = 10)
{
return _client.RequestAsync<List<UserScore>, object>(Method.Get, $"api/latest?n={n}", null)!;
}
}
8 changes: 4 additions & 4 deletions Gorse.NET/API/UsersAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public Task<Result> InsertUserAsync(User user)
return _client.RequestAsync<Result, User>(Method.Post, "api/user", user)!;
}

public Result InsertUsers(List<User> users)
public Result InsertUsers(IEnumerable<User> users)
{
return _client.Request<Result, List<User>>(Method.Post, "api/users", users)!;
return _client.Request<Result, IEnumerable<User>>(Method.Post, "api/users", users)!;
}

public Task<Result> InsertUsersAsync(List<User> users)
public Task<Result> InsertUsersAsync(IEnumerable<User> users)
{
return _client.RequestAsync<Result, List<User>>(Method.Post, "api/users", users)!;
return _client.RequestAsync<Result, IEnumerable<User>>(Method.Post, "api/users", users)!;
}

public User GetUser(string userId)
Expand Down
36 changes: 18 additions & 18 deletions Gorse.NET/Gorse.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Gorse.NET</PackageId>
<Version>0.5.0</Version>
<Authors>zhenghaoz</Authors>
<Company>gorse.io</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Remove="RestSharp" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="RestSharp" Version="113.0.0" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Gorse.NET</PackageId>
<Version>0.5.3</Version>
<Authors>zhenghaoz</Authors>
<Company>gorse.io</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Remove="RestSharp" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="RestSharp" Version="113.1.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Gorse.NET/Models/Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public class Feedback
public string UserId { set; get; } = "";
public string ItemId { set; get; } = "";
public double Value { set; get; } = 0.0;
public string Timestamp { set; get; } = "";
public DateTime Timestamp { set; get; } = DateTime.UtcNow;
}
2 changes: 1 addition & 1 deletion Gorse.NET/Models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class Item
public string Comment { get; set; } = "";
public bool IsHidden { get; set; }
public object? Labels { set; get; }
public DateTime TimeStamp { get; set; } = DateTime.UtcNow;
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}