Skip to content

Commit 22dd35f

Browse files
authored
Separate API endpoint for getting announcements, sort announcements by newest (#1070)
2 parents 3c72a79 + 6c1b5ca commit 22dd35f

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

Refresh.Database/GameDatabaseContext.Notifications.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void DeleteNotification(GameNotification notification)
8181
});
8282
}
8383

84-
public IEnumerable<GameAnnouncement> GetAnnouncements() => this.GameAnnouncements;
84+
public IEnumerable<GameAnnouncement> GetAnnouncements() => this.GameAnnouncements.OrderByDescending(a => a.CreatedAt);
8585

8686
public GameAnnouncement? GetAnnouncementById(ObjectId id) => this.GameAnnouncements.FirstOrDefault(a => a.AnnouncementId == id);
8787

Refresh.Interfaces.APIv3/Endpoints/InstanceApiEndpoints.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public ApiResponse<ApiStatisticsResponse> GetStatistics(RequestContext context,
4141
};
4242
}
4343

44+
[ApiV3Endpoint("announcements"), Authentication(false), AllowDuringMaintenance]
45+
[DocSummary("Retrieves all current announcements.")]
46+
[RateLimitSettings(300, 60, 240, "announcements-api")]
47+
public ApiResponse<List<ApiGameAnnouncementResponse>> GetAllAnnouncements(RequestContext context, DataContext dataContext)
48+
=> ApiGameAnnouncementResponse.FromOldList(dataContext.Database.GetAnnouncements().ToArray(), dataContext).ToList();
49+
4450
[ApiV3Endpoint("instance"), Authentication(false), AllowDuringMaintenance]
4551
[ClientCacheResponse(3600)] // One hour
4652
[DocSummary("Retrieves various information and metadata about the Refresh instance.")]

Refresh.Interfaces.Game/Endpoints/AnnouncementEndpoints.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static bool AnnounceGetAnnouncements(StringBuilder output, GameDatabaseC
4747
{
4848
IEnumerable<GameAnnouncement> announcements = database.GetAnnouncements().ToList();
4949
foreach (GameAnnouncement announcement in announcements)
50-
output.Append($"{announcement.Title}: {announcement.Text}\n");
50+
output.Append($"{announcement.Title}: {announcement.Text}\n\n");
5151

5252
return announcements.Any();
5353
}

0 commit comments

Comments
 (0)