🚨 Fix warnings in the codebase
This commit is contained in:
@@ -6,7 +6,7 @@ namespace DysonNetwork.Pass.Account;
|
||||
|
||||
public class ActionLogService(GeoIpService geo, FlushBufferService fbs)
|
||||
{
|
||||
public void CreateActionLog(Guid accountId, string action, Dictionary<string, object?> meta)
|
||||
public void CreateActionLog(Guid accountId, string action, Dictionary<string, object> meta)
|
||||
{
|
||||
var log = new SnActionLog
|
||||
{
|
||||
|
||||
@@ -32,8 +32,8 @@ public class ActionLogServiceGrpc : Shared.Proto.ActionLogService.ActionLogServi
|
||||
try
|
||||
{
|
||||
var meta = request.Meta
|
||||
?.Select(x => new KeyValuePair<string, object?>(x.Key, GrpcTypeHelper.ConvertValueToObject(x.Value)))
|
||||
.ToDictionary() ?? new Dictionary<string, object?>();
|
||||
?.Select(x => new KeyValuePair<string, object>(x.Key, GrpcTypeHelper.ConvertValueToObject(x.Value)))
|
||||
.ToDictionary() ?? new Dictionary<string, object>();
|
||||
|
||||
_actionLogService.CreateActionLog(
|
||||
accountId,
|
||||
@@ -41,6 +41,7 @@ public class ActionLogServiceGrpc : Shared.Proto.ActionLogService.ActionLogServi
|
||||
meta
|
||||
);
|
||||
|
||||
await Task.CompletedTask;
|
||||
return new CreateActionLogResponse();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DysonNetwork.Pass.Leveling;
|
||||
|
||||
public class ExperienceService(AppDatabase db, SubscriptionService subscriptions, ICacheService cache)
|
||||
public class ExperienceService(AppDatabase db, SubscriptionService subscriptions)
|
||||
{
|
||||
public async Task<SnExperienceRecord> AddRecord(string reasonType, string reason, long delta, Guid accountId)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ using Quartz;
|
||||
namespace DysonNetwork.Pass.Wallet;
|
||||
|
||||
public class FundExpirationJob(
|
||||
AppDatabase db,
|
||||
PaymentService paymentService,
|
||||
ILogger<FundExpirationJob> logger
|
||||
) : IJob
|
||||
|
||||
@@ -343,7 +343,7 @@ public class ActivityService(
|
||||
|
||||
private static async Task LoadPostsRealmsAsync(List<SnPost> posts, RemoteRealmService rs)
|
||||
{
|
||||
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId.Value).Distinct().ToList();
|
||||
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId!.Value).Distinct().ToList();
|
||||
if (!postRealmIds.Any()) return;
|
||||
|
||||
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
|
||||
@@ -351,7 +351,7 @@ public class ActivityService(
|
||||
|
||||
foreach (var post in posts.Where(p => p.RealmId != null))
|
||||
{
|
||||
if (post.RealmId != null && realmDict.TryGetValue(post.RealmId.Value, out var realm))
|
||||
if (realmDict.TryGetValue(post.RealmId!.Value, out var realm))
|
||||
{
|
||||
post.Realm = realm;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ public class PostController(
|
||||
|
||||
private static async Task LoadPostsRealmsAsync(List<SnPost> posts, RemoteRealmService rs)
|
||||
{
|
||||
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId.Value).Distinct().ToList();
|
||||
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId!.Value).Distinct().ToList();
|
||||
if (!postRealmIds.Any()) return;
|
||||
|
||||
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
|
||||
@@ -205,7 +205,7 @@ public class PostController(
|
||||
|
||||
foreach (var post in posts.Where(p => p.RealmId != null))
|
||||
{
|
||||
if (post.RealmId != null && realmDict.TryGetValue(post.RealmId.Value, out var realm))
|
||||
if (realmDict.TryGetValue(post.RealmId!.Value, out var realm))
|
||||
{
|
||||
post.Realm = realm;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using Grpc.Core;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime.Serialization.Protobuf;
|
||||
|
||||
namespace DysonNetwork.Sphere.Post;
|
||||
|
||||
@@ -29,7 +30,8 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
||||
return post.ToProtoValue();
|
||||
}
|
||||
|
||||
public override async Task<GetPostBatchResponse> GetPostBatch(GetPostBatchRequest request, ServerCallContext context)
|
||||
public override async Task<GetPostBatchResponse> GetPostBatch(GetPostBatchRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
var ids = request.Ids
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s) && Guid.TryParse(s, out _))
|
||||
@@ -76,9 +78,9 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
||||
{
|
||||
// Simple search, assuming full-text search or title/content contains
|
||||
query = query.Where(p =>
|
||||
EF.Functions.ILike(p.Title, $"%{request.Query}%") ||
|
||||
EF.Functions.ILike(p.Content, $"%{request.Query}%") ||
|
||||
EF.Functions.ILike(p.Description, $"%{request.Query}%"));
|
||||
(p.Title != null && EF.Functions.ILike(p.Title, $"%{request.Query}%")) ||
|
||||
(p.Content != null && EF.Functions.ILike(p.Content, $"%{request.Query}%")) ||
|
||||
(p.Description != null && EF.Functions.ILike(p.Description, $"%{request.Query}%")));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.PublisherId) && Guid.TryParse(request.PublisherId, out var pid))
|
||||
@@ -163,30 +165,16 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
||||
query = query.Where(e => e.Attachments.Count > 0);
|
||||
}
|
||||
|
||||
// Pinned filtering
|
||||
switch (request.Pinned)
|
||||
query = request.Pinned switch
|
||||
{
|
||||
case Shared.Proto.PostPinMode.RealmPage when !string.IsNullOrWhiteSpace(request.RealmId):
|
||||
query = query.Where(p => p.PinMode == Shared.Models.PostPinMode.RealmPage);
|
||||
break;
|
||||
case Shared.Proto.PostPinMode.PublisherPage when !string.IsNullOrWhiteSpace(request.PublisherId):
|
||||
query = query.Where(p => p.PinMode == Shared.Models.PostPinMode.PublisherPage);
|
||||
break;
|
||||
case Shared.Proto.PostPinMode.ReplyPage:
|
||||
query = query.Where(p => p.PinMode == Shared.Models.PostPinMode.ReplyPage);
|
||||
break;
|
||||
default:
|
||||
if (request.Pinned != null)
|
||||
{
|
||||
// Specific pinned mode but conditions not met, or unknown mode
|
||||
query = query.Where(p => p.PinMode == (Shared.Models.PostPinMode)request.Pinned);
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.Where(p => p.PinMode == null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Pinned filtering
|
||||
Shared.Proto.PostPinMode.RealmPage when !string.IsNullOrWhiteSpace(request.RealmId) => query.Where(p =>
|
||||
p.PinMode == Shared.Models.PostPinMode.RealmPage),
|
||||
Shared.Proto.PostPinMode.PublisherPage when !string.IsNullOrWhiteSpace(request.PublisherId) =>
|
||||
query.Where(p => p.PinMode == Shared.Models.PostPinMode.PublisherPage),
|
||||
Shared.Proto.PostPinMode.ReplyPage => query.Where(p => p.PinMode == Shared.Models.PostPinMode.ReplyPage),
|
||||
_ => query.Where(p => p.PinMode == (Shared.Models.PostPinMode)request.Pinned)
|
||||
};
|
||||
|
||||
// Include/exclude replies
|
||||
if (request.IncludeReplies)
|
||||
@@ -199,27 +187,25 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
||||
query = query.Where(e => e.RepliedPostId == null);
|
||||
}
|
||||
|
||||
// TODO: Time range filtering when proto fields are available
|
||||
// if (request.After != null)
|
||||
// {
|
||||
// var afterTime = request.After.ToDateTimeOffset();
|
||||
// query = query.Where(p => (p.CreatedAt >= afterTime) || (p.PublishedAt >= afterTime));
|
||||
// }
|
||||
if (request.After != null)
|
||||
{
|
||||
var afterTime = request.After.ToInstant();
|
||||
query = query.Where(p => (p.CreatedAt >= afterTime) || (p.PublishedAt >= afterTime));
|
||||
}
|
||||
|
||||
// if (request.Before != null)
|
||||
// {
|
||||
// var beforeTime = request.Before.ToDateTimeOffset();
|
||||
// query = query.Where(p => (p.CreatedAt <= beforeTime) || (p.PublishedAt <= beforeTime));
|
||||
// }
|
||||
if (request.Before != null)
|
||||
{
|
||||
var beforeTime = request.Before.ToInstant();
|
||||
query = query.Where(p => (p.CreatedAt <= beforeTime) || (p.PublishedAt <= beforeTime));
|
||||
}
|
||||
|
||||
// TODO: Query text search when proto field is available
|
||||
// if (!string.IsNullOrWhiteSpace(request.Query))
|
||||
// {
|
||||
// query = query.Where(p =>
|
||||
// EF.Functions.ILike(p.Title, $"%{request.Query}%") ||
|
||||
// EF.Functions.ILike(p.Content, $"%{request.Query}%") ||
|
||||
// EF.Functions.ILike(p.Description, $"%{request.Query}%"));
|
||||
// }
|
||||
if (!string.IsNullOrWhiteSpace(request.Query))
|
||||
{
|
||||
query = query.Where(p =>
|
||||
(p.Title != null && EF.Functions.ILike(p.Title, $"%{request.Query}%")) ||
|
||||
(p.Content != null && EF.Functions.ILike(p.Content, $"%{request.Query}%")) ||
|
||||
(p.Description != null && EF.Functions.ILike(p.Description, $"%{request.Query}%")));
|
||||
}
|
||||
|
||||
// Visibility filter (simplified for grpc - no user context)
|
||||
query = query.FilterWithVisibility(null, [], []);
|
||||
@@ -231,7 +217,9 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
||||
var offset = string.IsNullOrEmpty(pageToken) ? 0 : int.Parse(pageToken);
|
||||
|
||||
// Ordering - TODO: Add shuffle when proto field is available
|
||||
var orderedQuery = query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt);
|
||||
var orderedQuery = request.Shuffle
|
||||
? query.OrderBy(e => EF.Functions.Random())
|
||||
: query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt);
|
||||
|
||||
var posts = await orderedQuery
|
||||
.Skip(offset)
|
||||
|
||||
@@ -3,7 +3,6 @@ using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Sphere.Localization;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user