Add relationships feature and EF migration

This commit is contained in:
Holden
2026-06-26 17:06:15 -05:00
parent dbe33f3148
commit b3028ce741
30 changed files with 536 additions and 8 deletions

View File

@@ -1,5 +1,8 @@
using AutoMapper;
using RecNet.Application.Profiles;
using RecNet.Application.Profiles.Avatar;
using RecNet.Application.Profiles.Relationships;
using RecNet.Application.Profiles.Settings;
namespace RecNet.Application.Common.Mapping;
@@ -9,6 +12,7 @@ public class ApplicationMappingProfile : Profile
{
CreateMap<Domain.Profiles.Profile, ProfileDTO>();
CreateMap<Domain.Profiles.Avatar, AvatarDTO>();
CreateMap<Domain.Profiles.Relationship, RelationshipDTO>();
CreateMap<Domain.Profiles.PlayerSetting, PlayerSettingDTO>();
}
}

View File

@@ -1,6 +1,8 @@
using Microsoft.Extensions.DependencyInjection;
using RecNet.Application.Neutrino;
using RecNet.Application.Profiles;
using RecNet.Application.Profiles.Login;
using RecNet.Application.Profiles.Relationships;
namespace RecNet.Application;
@@ -13,6 +15,7 @@ public static class DependencyInjection
services.AddScoped<NameGenerator>();
services.AddScoped<IProfileService, ProfileService>();
services.AddScoped<IRelationshipService, RelationshipService>();
services.AddScoped<INeutrinoAuthorizationService, NeutrinoAuthorizationService>();
return services;

View File

@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Avatar;
public class AvatarDTO
{

View File

@@ -1,4 +1,4 @@
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Avatar;
public sealed record UpdateAvatarCommand(
string? OutfitSelections,

View File

@@ -1,4 +1,8 @@
using RecNet.Application.Profiles.Avatar;
using RecNet.Application.Profiles.Login;
using RecNet.Application.Profiles.Settings;
namespace RecNet.Application.Profiles;
public interface IProfileService

View File

@@ -1,6 +1,6 @@
using RecNet.Domain.Common;
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Login;
public sealed record LoginProfileCommand(
string AppVersion,

View File

@@ -1,4 +1,4 @@
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Login;

View File

@@ -1,7 +1,7 @@
using RecNet.Application.Common.Interfaces;
using RecNet.Domain.Profiles.Names;
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Login;
public class NameGenerator(IConfigService configService)
{

View File

@@ -1,10 +1,14 @@
using AutoMapper;
using RecNet.Application.Common.Interfaces;
using RecNet.Application.Common.Security;
using RecNet.Application.Profiles.Avatar;
using RecNet.Application.Profiles.Login;
using RecNet.Application.Profiles.Settings;
using RecNet.Domain.Common;
using RecNet.Domain.GameVersions;
using RecNet.Domain.Profiles;
using ProfileEntity = RecNet.Domain.Profiles.Profile;
using AvatarEntity = RecNet.Domain.Profiles.Avatar;
namespace RecNet.Application.Profiles;
@@ -45,7 +49,7 @@ public class ProfileService(
return null;
profile.SetAvatar(
Avatar.Create(
AvatarEntity.Create(
command.OutfitSelections,
command.SkinColor,
command.HairColor

View File

@@ -0,0 +1,7 @@
namespace RecNet.Application.Profiles.Relationships;
public interface IRelationshipService
{
Task<IReadOnlyList<RelationshipDTO>> GetRelationshipsAsync(Guid profileId, CancellationToken ct = default);
Task<RelationshipDTO> UpdateRelationshipAsync(Guid profileId, UpdateRelationshipCommand command, CancellationToken ct = default);
}

View File

@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace RecNet.Application.Profiles.Relationships;
public class RelationshipDTO
{
[JsonPropertyName("ProfileId")]
public Guid ProfileId { get; set; }
[JsonPropertyName("Muted")]
public bool Muted { get; set; }
[JsonPropertyName("Ignored")]
public bool Ignored { get; set; }
}

View File

@@ -0,0 +1,33 @@
using AutoMapper;
using RecNet.Domain.Profiles;
namespace RecNet.Application.Profiles.Relationships;
public class RelationshipService(IRelationshipRepository repository, IMapper mapper) : IRelationshipService
{
public async Task<IReadOnlyList<RelationshipDTO>> GetRelationshipsAsync(
Guid profileId,
CancellationToken ct = default)
{
var relationships = await repository.GetAllOwnedRelationships(profileId, ct);
return mapper.Map<List<RelationshipDTO>>(relationships);
}
public async Task<RelationshipDTO> UpdateRelationshipAsync(Guid profileId, UpdateRelationshipCommand command, CancellationToken ct = default)
{
var relationship = await repository.GetAsync(profileId, command.ProfileId, ct);
if (relationship == null)
{
relationship = Relationship.Create(profileId, command.ProfileId);
await repository.AddAsync(relationship, ct);
}
relationship.Mutate(command.Muted, command.Ignored);
await repository.SaveChangesAsync(ct);
return mapper.Map<RelationshipDTO>(relationship);
}
}

View File

@@ -0,0 +1,6 @@
namespace RecNet.Application.Profiles.Relationships;
public record UpdateRelationshipCommand(
Guid ProfileId,
bool Muted,
bool Ignored);

View File

@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Settings;
public class PlayerSettingDTO
{

View File

@@ -1,4 +1,4 @@
namespace RecNet.Application.Profiles;
namespace RecNet.Application.Profiles.Settings;
public sealed record UpdatePlayerSettingCommand(
string Key,