♻️ Move most of models to the Shared package
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -8,7 +9,7 @@ namespace DysonNetwork.Sphere.Publisher;
|
||||
|
||||
public class PublisherService(AppDatabase db, FileReferenceService fileRefService, ICacheService cache)
|
||||
{
|
||||
public async Task<Publisher?> GetPublisherByName(string name)
|
||||
public async Task<Shared.Models.Publisher?> GetPublisherByName(string name)
|
||||
{
|
||||
return await db.Publishers
|
||||
.Where(e => e.Name == name)
|
||||
@ -17,12 +18,12 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
|
||||
private const string UserPublishersCacheKey = "accounts:{0}:publishers";
|
||||
|
||||
public async Task<List<Publisher>> GetUserPublishers(Guid userId)
|
||||
public async Task<List<Shared.Models.Publisher>> GetUserPublishers(Guid userId)
|
||||
{
|
||||
var cacheKey = string.Format(UserPublishersCacheKey, userId);
|
||||
|
||||
// Try to get publishers from the cache first
|
||||
var publishers = await cache.GetAsync<List<Publisher>>(cacheKey);
|
||||
var publishers = await cache.GetAsync<List<Shared.Models.Publisher>>(cacheKey);
|
||||
if (publishers is not null)
|
||||
return publishers;
|
||||
|
||||
@ -41,16 +42,16 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
return publishers;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<Guid, List<Publisher>>> GetUserPublishersBatch(List<Guid> userIds)
|
||||
public async Task<Dictionary<Guid, List<Shared.Models.Publisher>>> GetUserPublishersBatch(List<Guid> userIds)
|
||||
{
|
||||
var result = new Dictionary<Guid, List<Publisher>>();
|
||||
var result = new Dictionary<Guid, List<Shared.Models.Publisher>>();
|
||||
var missingIds = new List<Guid>();
|
||||
|
||||
// Try to get publishers from cache for each user
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
var cacheKey = string.Format(UserPublishersCacheKey, userId);
|
||||
var publishers = await cache.GetAsync<List<Publisher>>(cacheKey);
|
||||
var publishers = await cache.GetAsync<List<Shared.Models.Publisher>>(cacheKey);
|
||||
if (publishers != null)
|
||||
result[userId] = publishers;
|
||||
else
|
||||
@ -97,12 +98,12 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
|
||||
public const string SubscribedPublishersCacheKey = "accounts:{0}:subscribed-publishers";
|
||||
|
||||
public async Task<List<Publisher>> GetSubscribedPublishers(Guid userId)
|
||||
public async Task<List<Shared.Models.Publisher>> GetSubscribedPublishers(Guid userId)
|
||||
{
|
||||
var cacheKey = string.Format(SubscribedPublishersCacheKey, userId);
|
||||
|
||||
// Try to get publishers from the cache first
|
||||
var publishers = await cache.GetAsync<List<Publisher>>(cacheKey);
|
||||
var publishers = await cache.GetAsync<List<Shared.Models.Publisher>>(cacheKey);
|
||||
if (publishers is not null)
|
||||
return publishers;
|
||||
|
||||
@ -146,8 +147,8 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
return members;
|
||||
}
|
||||
|
||||
public async Task<Publisher> CreateIndividualPublisher(
|
||||
Account.Account account,
|
||||
public async Task<Shared.Models.Publisher> CreateIndividualPublisher(
|
||||
Shared.Models.Account account,
|
||||
string? name,
|
||||
string? nick,
|
||||
string? bio,
|
||||
@ -155,7 +156,7 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
CloudFile? background
|
||||
)
|
||||
{
|
||||
var publisher = new Publisher
|
||||
var publisher = new Shared.Models.Publisher
|
||||
{
|
||||
Type = PublisherType.Individual,
|
||||
Name = name ?? account.Name,
|
||||
@ -199,9 +200,9 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
return publisher;
|
||||
}
|
||||
|
||||
public async Task<Publisher> CreateOrganizationPublisher(
|
||||
Realm.Realm realm,
|
||||
Account.Account account,
|
||||
public async Task<Shared.Models.Publisher> CreateOrganizationPublisher(
|
||||
Shared.Models.Realm realm,
|
||||
Shared.Models.Account account,
|
||||
string? name,
|
||||
string? nick,
|
||||
string? bio,
|
||||
@ -209,7 +210,7 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
CloudFile? background
|
||||
)
|
||||
{
|
||||
var publisher = new Publisher
|
||||
var publisher = new Shared.Models.Publisher
|
||||
{
|
||||
Type = PublisherType.Organizational,
|
||||
Name = name ?? realm.Slug,
|
||||
|
Reference in New Issue
Block a user