[backend/masto-client] Add rules endpoint and include rules in InstanceV1 and Instance2
This commit is contained in:
parent
76bb3f1c95
commit
464008b2e1
4 changed files with 32 additions and 2 deletions
|
@ -46,7 +46,8 @@ public class InstanceController(
|
||||||
return new InstanceInfoV1Response(config.Value, instanceName, instanceDescription, adminContact)
|
return new InstanceInfoV1Response(config.Value, instanceName, instanceDescription, adminContact)
|
||||||
{
|
{
|
||||||
Stats = new InstanceStats(userCount, noteCount, instanceCount),
|
Stats = new InstanceStats(userCount, noteCount, instanceCount),
|
||||||
Pleroma = new PleromaInstanceExtensions { VapidPublicKey = vapidKey, Metadata = new InstanceMetadata() }
|
Pleroma = new PleromaInstanceExtensions { VapidPublicKey = vapidKey, Metadata = new InstanceMetadata() },
|
||||||
|
Rules = await GetRules()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +67,8 @@ public class InstanceController(
|
||||||
|
|
||||||
return new InstanceInfoV2Response(config.Value, instanceName, instanceDescription, adminContact)
|
return new InstanceInfoV2Response(config.Value, instanceName, instanceDescription, adminContact)
|
||||||
{
|
{
|
||||||
Usage = new InstanceUsage { Users = new InstanceUsersUsage { ActiveMonth = activeMonth } }
|
Usage = new InstanceUsage { Users = new InstanceUsersUsage { ActiveMonth = activeMonth } },
|
||||||
|
Rules = await GetRules()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +89,17 @@ public class InstanceController(
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("/api/v1/instance/rules")]
|
||||||
|
[ProducesResults(HttpStatusCode.OK)]
|
||||||
|
public async Task<List<RuleEntity>> GetRules()
|
||||||
|
{
|
||||||
|
return await db.Rules
|
||||||
|
.OrderBy(p => p.Order)
|
||||||
|
.ThenBy(p => p.Id)
|
||||||
|
.Select(p => new RuleEntity { Id = p.Id, Text = p.Text, Hint = p.Description })
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("/api/v1/instance/translation_languages")]
|
[HttpGet("/api/v1/instance/translation_languages")]
|
||||||
[ProducesResults(HttpStatusCode.OK)]
|
[ProducesResults(HttpStatusCode.OK)]
|
||||||
public Dictionary<string, IEnumerable<string>> GetTranslationLanguages() => new();
|
public Dictionary<string, IEnumerable<string>> GetTranslationLanguages() => new();
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
using Iceshrimp.Backend.Core.Database;
|
||||||
|
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||||
|
|
||||||
|
namespace Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
||||||
|
|
||||||
|
public class RuleEntity : IEntity
|
||||||
|
{
|
||||||
|
[J("id")] public required string Id { get; set; }
|
||||||
|
[J("text")] public required string Text { get; set; }
|
||||||
|
[J("hint")] public required string? Hint { get; set; }
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
||||||
using Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
using Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Extensions;
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
|
@ -37,6 +38,8 @@ public class InstanceInfoV1Response(
|
||||||
|
|
||||||
[J("pleroma")] public required PleromaInstanceExtensions Pleroma { get; set; }
|
[J("pleroma")] public required PleromaInstanceExtensions Pleroma { get; set; }
|
||||||
|
|
||||||
|
[J("rules")] public required List<RuleEntity> Rules { get; set; }
|
||||||
|
|
||||||
//TODO: add the rest
|
//TODO: add the rest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Extensions;
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||||
|
@ -26,6 +27,8 @@ public class InstanceInfoV2Response(
|
||||||
|
|
||||||
[J("usage")] public required InstanceUsage Usage { get; set; }
|
[J("usage")] public required InstanceUsage Usage { get; set; }
|
||||||
|
|
||||||
|
[J("rules")] public required List<RuleEntity> Rules { get; set; }
|
||||||
|
|
||||||
//TODO: add the rest
|
//TODO: add the rest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue