Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CB.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CB.Tests.Accessors", "src\t
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CB.Tests.Api", "src\tests\CB.Tests.Api\CB.Tests.Api.csproj", "{75AC719F-66B3-4F6F-9083-BE26CB60B496}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CB.Engines", "src\CB.Engines\CB.Engines.csproj", "{49FB930C-0C8E-447A-88EC-39E161B31A6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,10 @@ Global
{75AC719F-66B3-4F6F-9083-BE26CB60B496}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75AC719F-66B3-4F6F-9083-BE26CB60B496}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75AC719F-66B3-4F6F-9083-BE26CB60B496}.Release|Any CPU.Build.0 = Release|Any CPU
{49FB930C-0C8E-447A-88EC-39E161B31A6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49FB930C-0C8E-447A-88EC-39E161B31A6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49FB930C-0C8E-447A-88EC-39E161B31A6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49FB930C-0C8E-447A-88EC-39E161B31A6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
18 changes: 18 additions & 0 deletions src/CB.Accessors/Contracts/IAllowConfigurationAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using CB.Data.Entities;
using CB.Shared.Dtos;

namespace CB.Accessors.Contracts;

public interface IAllowConfigurationAccessor
{
Task<List<AllowConfigurationDto>> GetAllAsync();

Task<AllowConfigurationDto?> GetByIdAsync(string id);

Task<AllowConfigurationDto> CreateAsync(AllowConfiguration entity);

Task<AllowConfigurationDto?> UpdateAsync(string id,
AllowConfigurationDto entity);

Task<bool> DeleteAsync(string id);
}
21 changes: 21 additions & 0 deletions src/CB.Accessors/Contracts/ICreatorAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using CB.Data.Entities;
using CB.Shared.Dtos;
using CB.Shared.Enums;

namespace CB.Accessors.Contracts;

public interface ICreatorAccessor
{
Task<List<CreatorDto>> GetAllAsync();

Task<CreatorDto?> GetByIdAsync(long id);

Check warning on line 11 in src/CB.Accessors/Contracts/ICreatorAccessor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Task<CreatorDto?> GetByChannelIdAndPlatformAsync(string channelId, Platform platform);

Task<CreatorDto> CreateAsync(Creator entity);

Task<CreatorDto?> UpdateAsync(string id,
Creator entity);

Task<bool> DeleteAsync(string id);
}
24 changes: 24 additions & 0 deletions src/CB.Accessors/Contracts/ICreatorChannelAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using CB.Data.Entities;
using CB.Shared.Dtos;
using CB.Shared.Enums;
// ReSharper disable UnusedMember.Global

namespace CB.Accessors.Contracts;

public interface ICreatorChannelAccessor
{
Task<List<CreatorChannelDto>> GetAllAsync();

Task<CreatorChannelDto?> GetAsync(long creatorId,
string channelId,
int channelTypeId);

Task<CreatorChannelDto> CreateAsync(CreatorChannel entity);

Task<CreatorChannelDto?> UpdateAsync(string id,
CreatorChannelDto entity);

Task<bool> DeleteAsync(long creatorId,
string channelId,
int channelTypeId);
}
18 changes: 18 additions & 0 deletions src/CB.Accessors/Contracts/IDropdownPayloadAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using CB.Data.Entities;
using CB.Shared.Dtos;

namespace CB.Accessors.Contracts;

public interface IDropdownPayloadAccessor
{
Task<List<DropdownPayloadDto>> GetAllAsync();

Task<DropdownPayloadDto?> GetByIdAsync(int id);

Check warning on line 10 in src/CB.Accessors/Contracts/IDropdownPayloadAccessor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Task<DropdownPayloadDto> CreateAsync(DropdownPayload entity);

//Task<DropdownPayloadDto?> UpdateAsync(string id,
// DropdownPayload entity);

Task<bool> DeleteAsync(string id);
}
18 changes: 18 additions & 0 deletions src/CB.Accessors/Contracts/IGuildConfigurationAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using CB.Data.Entities;
using CB.Shared.Dtos;

namespace CB.Accessors.Contracts;

public interface IGuildConfigurationAccessor
{
Task<List<GuildConfigurationDto>> GetAllAsync();

Task<GuildConfigurationDto?> GetByIdAsync(string id);

Task<GuildConfigurationDto> CreateAsync(GuildConfiguration entity);

Task<GuildConfigurationDto?> UpdateAsync(string id,
GuildConfigurationDto entity);

Task<bool> DeleteAsync(string id);
}
87 changes: 87 additions & 0 deletions src/CB.Accessors/Implementations/AllowConfigurationAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using CB.Accessors.Contracts;
using CB.Data;
using CB.Data.Entities;
using CB.Shared.Dtos;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class AllowConfigurationAccessor(CbContext context,
IMapper mapper)
: IAllowConfigurationAccessor
{
public Task<List<AllowConfigurationDto>> GetAllAsync() => context
.AllowConfigurations
.AsNoTracking()
.ProjectTo<AllowConfigurationDto>(mapper.ConfigurationProvider)
.ToListAsync();

public Task<AllowConfigurationDto?> GetByIdAsync(string id) => context.AllowConfigurations
.AsNoTracking()
.Where(g => g.GuildId == id)
.ProjectTo<AllowConfigurationDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();

public async Task<AllowConfigurationDto> CreateAsync(AllowConfiguration entity)
{
context.AllowConfigurations.Add(entity);
await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<AllowConfigurationDto>(entity);
}

public async Task<AllowConfigurationDto?> UpdateAsync(string id,
AllowConfigurationDto updated)
{
var allowConfiguration = await context
.AllowConfigurations
.FindAsync(id)
.ConfigureAwait(false);

if (allowConfiguration == null)
{
return null;
}

allowConfiguration.AllowCrosspost = updated.AllowCrosspost;
allowConfiguration.AllowDiscordLive = updated.AllowDiscordLive;
allowConfiguration.AllowFfa = updated.AllowFfa;
allowConfiguration.AllowGoodbyes = updated.AllowGoodbyes;
allowConfiguration.AllowGreetings = updated.AllowGreetings;
allowConfiguration.AllowLive = updated.AllowLive;
allowConfiguration.AllowLiveDiscovery = updated.AllowLiveDiscovery;
allowConfiguration.AllowPublished = updated.AllowPublished;
allowConfiguration.AllowStreamVod = updated.AllowStreamVod;
allowConfiguration.AllowThumbnails = updated.AllowThumbnails;

await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<AllowConfigurationDto>(allowConfiguration);
}

public async Task<bool> DeleteAsync(string id)
{
var allowConfiguration = await context
.AllowConfigurations
.FindAsync(id)
.ConfigureAwait(false);

if (allowConfiguration == null)
{
return false;
}

context.AllowConfigurations.Remove(allowConfiguration);
await context
.SaveChangesAsync()
.ConfigureAwait(false);

return true;
}
}
90 changes: 90 additions & 0 deletions src/CB.Accessors/Implementations/CreatorAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using CB.Accessors.Contracts;
using CB.Data;
using CB.Data.Entities;
using CB.Shared.Dtos;
using CB.Shared.Enums;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class CreatorAccessor(CbContext context,
IMapper mapper)
: ICreatorAccessor
{
public Task<List<CreatorDto>> GetAllAsync() => context
.Creators
.AsNoTracking()
.ProjectTo<CreatorDto>(mapper.ConfigurationProvider)
.ToListAsync();

public Task<CreatorDto?> GetByIdAsync(long id) => context.Creators
.AsNoTracking()
.Where(g => g.Id == id)
.ProjectTo<CreatorDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();

public Task<CreatorDto?> GetByChannelIdAndPlatformAsync(string channelId, Platform platform) => context.Creators
.AsNoTracking()
.Where(g => g.ChannelId == channelId &&
g.PlatformId == (int)platform)
.ProjectTo<CreatorDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();

public async Task<CreatorDto> CreateAsync(Creator entity)
{
entity.CreatedDate = DateTime.UtcNow;
entity.ModifiedDate = DateTime.UtcNow;

context.Creators.Add(entity);
await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<CreatorDto>(entity);
}

public async Task<CreatorDto?> UpdateAsync(string id,
Creator updated)
{
var creator = await context
.Creators
.FindAsync(id)
.ConfigureAwait(false);

if (creator == null)
{
return null;
}

creator.DisplayName = updated.DisplayName;
creator.ModifiedDate = DateTime.UtcNow;

await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<CreatorDto>(creator);
}

public async Task<bool> DeleteAsync(string id)
{
var creator = await context
.Creators
.FindAsync(id)
.ConfigureAwait(false);

if (creator == null)
{
return false;
}

context.Creators.Remove(creator);
await context
.SaveChangesAsync()
.ConfigureAwait(false);

return true;
}
}
87 changes: 87 additions & 0 deletions src/CB.Accessors/Implementations/CreatorChannelAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using CB.Accessors.Contracts;
using CB.Data;
using CB.Data.Entities;
using CB.Shared.Dtos;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class CreatorChannelAccessor(CbContext context,
IMapper mapper)
: ICreatorChannelAccessor
{
public Task<List<CreatorChannelDto>> GetAllAsync() => context
.CreatorChannels
.AsNoTracking()
.ProjectTo<CreatorChannelDto>(mapper.ConfigurationProvider)
.ToListAsync();

public Task<CreatorChannelDto?> GetAsync(long creatorId,
string channelId,
int channelTypeId) => context.CreatorChannels
.AsNoTracking()
.Where(g => g.CreatorId == creatorId &&
g.ChannelId == channelId &&
g.ChannelTypeId == channelTypeId)
.ProjectTo<CreatorChannelDto>(mapper.ConfigurationProvider)
.FirstOrDefaultAsync();

public async Task<CreatorChannelDto> CreateAsync(CreatorChannel entity)
{
context.CreatorChannels.Add(entity);
await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<CreatorChannelDto>(entity);
}

public async Task<CreatorChannelDto?> UpdateAsync(string id,
CreatorChannelDto updated)
{
var creatorChannel = await context
.CreatorChannels
.FindAsync(id)
.ConfigureAwait(false);

if (creatorChannel == null)
{
return null;
}

creatorChannel.CustomMessage = updated.CustomMessage;
creatorChannel.ChannelTypeId = updated.ChannelTypeId;

await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<CreatorChannelDto>(creatorChannel);
}

public async Task<bool> DeleteAsync(long creatorId,
string channelId,
int channelTypeId)
{
var creatorChannel = await context
.CreatorChannels
.FirstOrDefaultAsync(x => x.CreatorId == creatorId &&
x.ChannelId == channelId &&
x.ChannelTypeId == channelTypeId)
.ConfigureAwait(false);

if (creatorChannel == null)
{
return false;
}

context.CreatorChannels.Remove(creatorChannel);
await context
.SaveChangesAsync()
.ConfigureAwait(false);

return true;
}
}
Loading
Loading