Skip to content

Commit

Permalink
AdminOptions.TenantId
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Aug 14, 2024
1 parent 8ef5968 commit e6414a3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
13 changes: 10 additions & 3 deletions OneShelf.Admin/OneShelf.Admin.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using OneShelf.Admin.Web.Authorization;
using OneShelf.Admin.Web.Models;
using OneShelf.Billing.Api.Client;
Expand All @@ -21,13 +22,15 @@ public class HomeController : Controller
private readonly IllustrationsApiClient _illustrationsApiClient;
private readonly BillingApiClient _billingApiClient;
private readonly SongsDatabase _songsDatabase;
private readonly AdminOptions _adminOptions;

public HomeController(ILogger<HomeController> logger, IllustrationsApiClient illustrationsApiClient, BillingApiClient billingApiClient, IConfiguration configuration, SongsDatabase songsDatabase)
public HomeController(ILogger<HomeController> logger, IllustrationsApiClient illustrationsApiClient, BillingApiClient billingApiClient, IConfiguration configuration, SongsDatabase songsDatabase, IOptions<AdminOptions> adminOptions)
{
_logger = logger;
_illustrationsApiClient = illustrationsApiClient;
_billingApiClient = billingApiClient;
_songsDatabase = songsDatabase;
_adminOptions = adminOptions.Value;
}

[AllowAnonymous]
Expand Down Expand Up @@ -83,8 +86,12 @@ public async Task<IActionResult> Illustrations(int h = 96, IllustrationsModel.Mo
all.Responses = all.Responses.Where(x => x.Value.LatestCreatedOn < DateTime.Now.AddHours(-h))
.ToDictionary(x => x.Key, x => x.Value);
hidden -= all.Responses.Count;

var urlsToTitles = (await _songsDatabase.Versions.Include(x => x.Song).ThenInclude(x => x.Artists).ToListAsync())

var urlsToTitles = (await _songsDatabase.Versions
.Where(x => x.Song.TenantId == _adminOptions.TenantId)
.Include(x => x.Song)
.ThenInclude(x => x.Artists)
.ToListAsync())
.GroupBy(x => x.Uri)
.ToDictionary(x => x.Key.ToString(), x =>
{
Expand Down
6 changes: 6 additions & 0 deletions OneShelf.Admin/OneShelf.Admin.Web/Models/AdminOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OneShelf.Admin.Web.Models;

public record AdminOptions
{
public required int TenantId { get; set; }
}
4 changes: 3 additions & 1 deletion OneShelf.Admin/OneShelf.Admin.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OneShelf.Admin.Web.Models;
using OneShelf.Billing.Api.Client;
using OneShelf.Common.Database.Songs;
using OneShelf.Illustrations.Api.Client;
Expand All @@ -15,7 +16,8 @@
builder.Services
.AddSongsDatabase()
.AddIllustrationsApiClient(builder.Configuration)
.AddBillingApiClient(builder.Configuration);
.AddBillingApiClient(builder.Configuration)
.Configure<AdminOptions>(o => builder.Configuration.GetSection(nameof(AdminOptions)).Bind(o));

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"CollectivesApiClientOptions": {
"Endpoint": "http://localhost:7284/api/"
},
"AdminOptions": {
"TenantId": 1,
}
}

0 comments on commit e6414a3

Please sign in to comment.