Skip to content

Commit

Permalink
Refactor namespace structure for Features and Entities
Browse files Browse the repository at this point in the history
- Updated namespaces in multiple files to simplify the structure and improve organization.
  • Loading branch information
0xF6 committed Dec 4, 2024
1 parent d8d713b commit a50b25c
Show file tree
Hide file tree
Showing 59 changed files with 83 additions and 213 deletions.
5 changes: 1 addition & 4 deletions src/Argon.Api/Entities/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
namespace Argon.Api.Entities;
namespace Argon.Entities;

using System.Drawing;
using System.Linq.Expressions;
using Contracts.Models;
using Contracts.Models.ArchetypeModel;
using Features.EF;
using Microsoft.EntityFrameworkCore;

public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Entities/UserAgreements.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Argon.Api.Entities;
namespace Argon.Entities;

using System.ComponentModel.DataAnnotations;
using Contracts.Models;

[MessagePackObject(true)]
public record UserAgreements
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Captcha/CaptchaFeature.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

using Microsoft.Extensions.Configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Captcha/CaptchaKind.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

public enum CaptchaKind
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Captcha/CaptchaOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

public class CaptchaOptions
{
Expand Down
5 changes: 1 addition & 4 deletions src/Argon.Api/Features/Captcha/CloudflareCaptcha.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

using Argon.Features;
using Extensions;
using Flurl.Http;
using Microsoft.Extensions.Options;

public class CloudflareCaptcha(IHttpContextAccessor accessor, ILogger<ICaptchaFeature> logger, IOptions<CaptchaOptions> options) : ICaptchaFeature
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Captcha/ICaptchaFeature.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

public interface ICaptchaFeature
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Captcha/NullCaptcha.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

public class NullCaptcha : ICaptchaFeature
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Captcha/YandexCaptcha.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Captcha;
namespace Argon.Features.Captcha;

public class YandexCaptcha : ICaptchaFeature
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/EF/ColourConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.EF;
namespace Argon.Features.EF;

using System.Drawing;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace Argon.Api.Features.EF;
namespace Argon.Features.EF;

using Contracts.Models;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore;

public class TimeStampAndSoftDeleteInterceptor : SaveChangesInterceptor
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Env/EnvironmentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Env;
namespace Argon.Features.Env;

using static File;

Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Jwt/JwtFeature.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Jwt;
namespace Argon.Features.Jwt;

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
Expand Down
4 changes: 2 additions & 2 deletions src/Argon.Api/Features/Jwt/JwtOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Argon.Api.Features.Jwt;
namespace Argon.Features.Jwt;

using Argon.Api.Services;
using Argon.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;

public record JwtOptions
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Jwt/TokenAuthorization.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Argon.Api.Features.Jwt;
namespace Argon.Features.Jwt;

using System.IdentityModel.Tokens.Jwt;
using Contracts;
using Microsoft.IdentityModel.Tokens;

public class TokenAuthorization(TokenValidationParameters tokenValidation)
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Jwt/TokenUserData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Jwt;
namespace Argon.Features.Jwt;

[GenerateSerializer, Alias("Argon.Api.Features.Jwt.TokenUserData")]
public record TokenUserData(Guid id, Guid machineId);
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Orleanse/BalanceRule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Argon.Api.Features;
namespace Argon.Features;

using System.Collections.Concurrent;
using System.Globalization;
using Env;
using k8s;
Expand Down
3 changes: 0 additions & 3 deletions src/Argon.Api/Features/Orleanse/MemoryPackCodec.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using MemoryPack;
using MessagePack;
using Microsoft.Extensions.Options;
using Orleans.Serialization.Buffers;
using Orleans.Serialization.Buffers.Adaptors;
using Orleans.Serialization.Cloning;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features;
namespace Argon.Features;

using System.Runtime.CompilerServices;
using MemoryPack;
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Orleanse/RedisExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Argon.Api.Extensions;
namespace Argon.Extensions;

using Features.Orleanse.Storages;
using Microsoft.Extensions.Options;
using Orleans.Configuration;
using Orleans.Runtime.Hosting;
using Orleans.Storage;
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Orleanse/Storages/RedisStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Argon.Api.Features.Orleanse.Storages;
namespace Argon.Features.Orleanse.Storages;

using Microsoft.Extensions.Options;
using Orleans.Configuration;
using Orleans.Configuration.Overrides;
using Orleans.Providers;
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Orleanse/Streams/ClientArgonStream.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Argon.Api.Features.Rpc;
namespace Argon.Features.Rpc;

using Orleans.Streams;
using System.Threading.Channels;
using Contracts;

public sealed class ClientArgonStream<T> : IArgonStream<T> where T : IArgonEvent
{
Expand Down
11 changes: 1 addition & 10 deletions src/Argon.Api/Features/Orleanse/Streams/IArgonStream.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
namespace Argon.Api.Features.Rpc;
namespace Argon.Features.Rpc;

using ActualLab.Rpc;
using Contracts;
using Orleans.Streams;

public interface IArgonStream<T> :
IAsyncObserver<T>, IAsyncEnumerable<T>, IAsyncDisposable where T : IArgonEvent
{
public RpcStream<T> AsRpcStream() => new(this);
ValueTask Fire(T ev);
}
4 changes: 1 addition & 3 deletions src/Argon.Api/Features/Orleanse/Streams/IStreamExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace Argon.Api.Features.Rpc;

using Contracts;
namespace Argon.Features.Rpc;

public interface IStreamExtension
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace Argon.Api.Features.OrleansStreamingProviders;
namespace Argon.Features.OrleansStreamingProviders;

using System.Collections.Concurrent;
using Argon.Features;
using NATS.Client.Core;
using NATS.Client.JetStream;
using Orleans.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Argon.Api.Features.OrleansStreamingProviders;
namespace Argon.Features.OrleansStreamingProviders;

using Argon.Features;
using NATS.Client.JetStream;
using NATS.Client.JetStream.Models;
using NATS.Net;
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Orleanse/Streams/ServerArgonStream.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Argon.Api.Features.Rpc;
namespace Argon.Features.Rpc;

using Contracts;
using Orleans.Streams;

public sealed class ServerArgonStream<T>(IAsyncStream<IArgonEvent> stream) : IArgonStream<T> where T : IArgonEvent
Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Otp/OtpGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Argon.Api.Features.Otp;
namespace Argon.Features.Otp;

using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Options;
using OtpNet;
using Services;

Expand Down
7 changes: 1 addition & 6 deletions src/Argon.Api/Features/Pex/IPermissionProvider.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
namespace Argon.Api.Features.Pex;

using ActualLab.Collections;
using Contracts.Models.ArchetypeModel;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace Argon.Features.Pex;

public static class PexFeature
{
Expand Down
7 changes: 1 addition & 6 deletions src/Argon.Api/Features/Repositories/IServerRepository.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
namespace Argon.Api.Features.Repositories;
namespace Argon.Features.Repositories;

using System.Diagnostics;
using Contracts.Models;
using Contracts.Models.ArchetypeModel;
using Entities;
using Grains.Interfaces;
using Microsoft.EntityFrameworkCore;

public static class TemplateFeature
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Sentry/SentryOrleansFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Features.Sentry;
namespace Argon.Features.Sentry;

public class SentryGrainCallFilter : IIncomingGrainCallFilter
{
Expand Down
1 change: 0 additions & 1 deletion src/Argon.Api/Features/Sfu/ArgonSelectiveForwardingUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Argon.Sfu;
using Flurl.Http;
using LiveKit.Proto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;

#if DEBUG
Expand Down
1 change: 0 additions & 1 deletion src/Argon.Api/Features/Sfu/SfuFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Flurl.Http;
using Flurl.Http.Newtonsoft;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

Expand Down
3 changes: 1 addition & 2 deletions src/Argon.Api/Features/Template/TemplateFeature.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Argon.Api.Features.Template;
namespace Argon.Features.Template;

using System.Collections.Concurrent;
using Fluid;

public static class TemplateFeature
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Utils/ActorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Extensions;
namespace Argon.Extensions;

public static class ActorExtensions
{
Expand Down
6 changes: 1 addition & 5 deletions src/Argon.Api/Features/Utils/ObjDiff.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
namespace Argon.Features;

using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection;
using ActualLab.Collections;
using ActualLab.Text;

public static class ObjDiff
{
Expand Down Expand Up @@ -46,7 +42,7 @@ public static PropertyBag Compare<T>(T prev, T next)
var updatedValue = prop.GetValue(next)!;

if (!IsAreEqual(prop.PropertyType, prevValue, updatedValue))
props.Set(new Symbol(prop.Name), updatedValue);
props.Set(prop.Name, updatedValue);
}

return props;
Expand Down
2 changes: 1 addition & 1 deletion src/Argon.Api/Features/Utils/SwaggerExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api.Extensions;
namespace Argon.Extensions;

using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
Expand Down
11 changes: 3 additions & 8 deletions src/Argon.Api/Grains/AuthorizationGrain.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
namespace Argon.Api.Grains;
namespace Argon.Grains;

using Contracts;
using Contracts.Models;
using Entities;
using Features.Otp;
using Interfaces;
using Microsoft.EntityFrameworkCore;
using Services;

public class AuthorizationGrain(
Expand All @@ -15,7 +10,7 @@ public class AuthorizationGrain(
IPasswordHashingService passwordHashingService,
ApplicationDbContext context) : Grain, IAuthorizationGrain
{
public async Task<Either<JwtToken, AuthorizationError>> Authorize(UserCredentialsInput input, UserConnectionInfo connectionInfo)
public async Task<Either<string, AuthorizationError>> Authorize(UserCredentialsInput input, UserConnectionInfo connectionInfo)
{
var user = await context.Users.FirstOrDefaultAsync(u => u.Email == input.Email);
if (user is null)
Expand Down Expand Up @@ -125,5 +120,5 @@ await strategy.ExecuteAsync(async () =>
return Maybe<RegistrationError>.None();
}

private async Task<JwtToken> GenerateJwt(User User, Guid machineId) => new(await managerService.GenerateJwt(User.Id, machineId));
private async Task<string> GenerateJwt(User User, Guid machineId) => await managerService.GenerateJwt(User.Id, machineId);
}
24 changes: 14 additions & 10 deletions src/Argon.Api/Grains/ChannelGrain.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
namespace Argon.Api.Grains;
namespace Argon.Grains;

using Contracts;
using Contracts.Models;
using Entities;
using Features.Rpc;
using Interfaces;
using Microsoft.EntityFrameworkCore;
using Persistence.States;
using Sfu;
using Argon.Servers;

public class ChannelGrain(
IArgonSelectiveForwardingUnit sfu,
ApplicationDbContext context,
[PersistentState("channelGrainState", "OrleansStorage")]
[PersistentState("channelGrainState", "OrleansStorage")]
IPersistentState<ChannelGrainState> state) : Grain, IChannelGrain
{
private IArgonStream<IArgonEvent> _userStateEmitter = null!;


private Channel _self { get; set; }
private Channel _self { get; set; }
private ArgonServerId ServerId => new(_self.ServerId);
private ArgonChannelId ChannelId => new(ServerId, this.GetPrimaryKey());

Expand All @@ -36,8 +32,16 @@ public async Task<Maybe<RealtimeToken>> Join(Guid userId)
if (_self.ChannelType != ChannelType.Voice)
return Maybe<RealtimeToken>.None();

state.State.Users.Add(userId, new ChannelRealtimeMember(userId));
await state.WriteStateAsync();
if (state.State.Users.ContainsKey(userId))
{
//await _userStateEmitter.Fire(
// new OnChannelUserChangedState(userId, ON_LEAVED));
}
else
{
state.State.Users.Add(userId, new ChannelRealtimeMember(userId));
await state.WriteStateAsync();
}

//await _userStateEmitter.Fire(
// new OnChannelUserChangedState(userId, ON_JOINED));
Expand Down
Loading

0 comments on commit a50b25c

Please sign in to comment.