Skip to content

Fix #371 #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
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
60 changes: 58 additions & 2 deletions src/redmine-net-api/Net/RedmineApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ public string CreateEntityFragment<T>(string ownerId = null)
{
var type = typeof(T);

return CreateEntityFragment(type, ownerId);
}
public string CreateEntityFragment<T>(RequestOptions requestOptions)
{
var type = typeof(T);

return CreateEntityFragment(type, requestOptions);
}
internal string CreateEntityFragment(Type type, RequestOptions requestOptions)
{
string ownerId = null;
if (requestOptions is { QueryString: not null })
{
ownerId = requestOptions.QueryString.Get(RedmineKeys.PROJECT_ID) ??
requestOptions.QueryString.Get(RedmineKeys.ISSUE_ID);
}

return CreateEntityFragment(type, ownerId);
}
internal string CreateEntityFragment(Type type, string ownerId = null)
{
if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
{
return ProjectParentFragment(ownerId, TypeUrlFragments[type]);
Expand All @@ -129,7 +150,7 @@ public string CreateEntityFragment<T>(string ownerId = null)

if (type == typeof(Upload))
{
return RedmineKeys.UPLOADS;
return $"{RedmineKeys.UPLOADS}.{Format}";
}

if (type == typeof(Attachment) || type == typeof(Attachments))
Expand All @@ -144,13 +165,21 @@ public string CreateEntityFragment<T>(string ownerId = null)
{
var type = typeof(T);

return GetFragment(type, id);
}
internal string GetFragment(Type type, string id)
{
return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}";
}

public string PatchFragment<T>(string ownerId)
{
var type = typeof(T);

return PatchFragment(type, ownerId);
}
internal string PatchFragment(Type type, string ownerId)
{
if (type == typeof(Attachment) || type == typeof(Attachments))
{
return IssueAttachmentFragment(ownerId);
Expand All @@ -163,13 +192,21 @@ public string DeleteFragment<T>(string id)
{
var type = typeof(T);

return DeleteFragment(type, id);
}
internal string DeleteFragment(Type type,string id)
{
return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}";
}

public string UpdateFragment<T>(string id)
{
var type = typeof(T);

return UpdateFragment(type, id);
}
internal string UpdateFragment(Type type, string id)
{
return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}";
}

Expand All @@ -179,8 +216,27 @@ public string UpdateFragment<T>(string id)

return GetListFragment(type, ownerId);
}

public string GetListFragment<T>(RequestOptions requestOptions) where T : class, new()
{
var type = typeof(T);

return GetListFragment(type, requestOptions);
}

internal string GetListFragment(Type type, RequestOptions requestOptions)
{
string ownerId = null;
if (requestOptions is { QueryString: not null })
{
ownerId = requestOptions.QueryString.Get(RedmineKeys.PROJECT_ID) ??
requestOptions.QueryString.Get(RedmineKeys.ISSUE_ID);
}

return GetListFragment(type, ownerId);
}

public string GetListFragment(Type type, string ownerId = null)
internal string GetListFragment(Type type, string ownerId = null)
{
if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
{
Expand Down
30 changes: 30 additions & 0 deletions tests/redmine-net-api.Tests/Bugs/RedmineApi-371.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Specialized;
using Padi.DotNet.RedmineAPI.Tests.Infrastructure;
using Redmine.Net.Api.Extensions;
using Redmine.Net.Api.Net;
using Redmine.Net.Api.Types;
using Xunit;

namespace Padi.DotNet.RedmineAPI.Tests.Bugs;

public sealed class RedmineApi371 : IClassFixture<RedmineFixture>
{
private readonly RedmineFixture _fixture;

public RedmineApi371(RedmineFixture fixture)
{
_fixture = fixture;
}

[Fact]
public void Should_Return_IssueCategories()
{
var result = _fixture.RedmineManager.Get<IssueCategory>(new RequestOptions()
{
QueryString = new NameValueCollection()
{
{ "project_id", 1.ToInvariantString() }
}
});
}
}
Loading