-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
744 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/HuppyService/HuppyService.Core/Abstraction/BaseRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace HuppyService.Core.Abstraction; | ||
|
||
public class BaseRepository<TKeyType, TEntity, TContext> : IRepository<TKeyType, TEntity> | ||
where TKeyType : IConvertible | ||
where TEntity : DbModel<TKeyType>, new() | ||
where TContext : DbContext, new() | ||
{ | ||
protected internal readonly TContext _context; | ||
public BaseRepository(TContext context) | ||
{ | ||
_context = context ?? new TContext(); | ||
} | ||
|
||
public virtual async Task<bool> AddAsync(TEntity? entity) | ||
{ | ||
if (entity is null) return false; | ||
|
||
var doesExist = await _context.Set<TEntity>().AnyAsync(entry => entry.Id.Equals(entity.Id)); | ||
|
||
if (doesExist) return false; | ||
|
||
await _context.Set<TEntity>().AddAsync(entity); | ||
return true; | ||
} | ||
|
||
public virtual async Task<bool> AddRangeAsync(IEnumerable<TEntity> entities) | ||
{ | ||
if (entities is null) return false; | ||
|
||
await _context.Set<TEntity>().AddRangeAsync(entities); | ||
return true; | ||
} | ||
|
||
public virtual Task<IQueryable<TEntity>> GetAllAsync() | ||
{ | ||
return Task.FromResult(_context.Set<TEntity>().AsQueryable()); | ||
} | ||
|
||
public virtual async Task<TEntity?> GetAsync(TKeyType id) | ||
{ | ||
return await _context.Set<TEntity>().FirstOrDefaultAsync(entry => entry.Id.Equals(id)); | ||
} | ||
|
||
public virtual async Task<bool> RemoveAsync(TKeyType id) | ||
{ | ||
TEntity entity = new() { Id = id }; | ||
|
||
var doesExist = await _context.Set<TEntity>().AnyAsync(entry => entry.Id.Equals(entity.Id)); | ||
|
||
if (!doesExist) return false; | ||
|
||
_context.Set<TEntity>().Remove(entity); | ||
|
||
return true; | ||
} | ||
|
||
public virtual async Task<bool> RemoveAsync(TEntity? entity) | ||
{ | ||
if (entity is null) return false; | ||
|
||
var doesExist = await _context.Set<TEntity>().AnyAsync(entry => entry.Id.Equals(entity.Id)); | ||
if (!doesExist) return false; | ||
|
||
_context.Set<TEntity>().Remove(entity); | ||
|
||
return true; | ||
} | ||
|
||
public virtual Task UpdateAsync(TEntity? entity) | ||
{ | ||
if (entity is null) return Task.CompletedTask; | ||
|
||
_context.Set<TEntity>().Update(entity); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public virtual Task UpdateRange(IEnumerable<TEntity> entities) | ||
{ | ||
_context.Set<TEntity>().UpdateRange(entities); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public virtual async Task SaveChangesAsync() | ||
{ | ||
await _context.SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace HuppyService.Core.Abstraction | ||
{ | ||
|
||
public class DbModel<TKey> where TKey : IConvertible | ||
{ | ||
public virtual TKey Id { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/HuppyService/HuppyService.Core/Abstraction/IRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
namespace HuppyService.Core.Abstraction | ||
{ | ||
public interface IRepository<Tkey, TEntity> where Tkey : IConvertible where TEntity : DbModel<Tkey> | ||
{ | ||
Task<TEntity?> GetAsync(Tkey id); | ||
Task<IQueryable<TEntity>> GetAllAsync(); | ||
Task<bool> AddAsync(TEntity? entity); | ||
Task<bool> AddRangeAsync(IEnumerable<TEntity> entities); | ||
Task<bool> RemoveAsync(Tkey id); | ||
Task<bool> RemoveAsync(TEntity? entity); | ||
Task UpdateAsync(TEntity? entity); | ||
Task UpdateRange(IEnumerable<TEntity> entities); | ||
Task SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace HuppyService.Core.Entities | ||
{ | ||
public class AiUser | ||
{ | ||
public string? Username; | ||
public int Count; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ppyService.Service/Entities/GPTRequest.cs → .../HuppyService.Core/Entities/GPTRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pyService.Service/Entities/GPTResponse.cs → ...HuppyService.Core/Entities/GPTResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/HuppyService/HuppyService.Core/Entities/Options/GPTOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace HuppyService.Core.Entities.Options | ||
{ | ||
public class GPTOptions | ||
{ | ||
public string? BaseUrl { get; set; } | ||
public string? ApiKey { get; set; } | ||
public string? Orgranization { get; set; } | ||
public int FreeMessageQuota { get; set; } | ||
public string? AiContextMessage { get; set; } | ||
public bool IsEnabled { get; set; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/HuppyService/HuppyService.Core/Entities/Options/MiscellaneousOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace HuppyService.Core.Entities.Options | ||
{ | ||
public class MiscellaneousOptions | ||
{ | ||
public string? BotToken { get; set; } | ||
public string? DatabaseConnectionString { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/HuppyService/HuppyService.Core/Entities/Options/UrbanApiOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace HuppyService.Core.Entities.Options | ||
{ | ||
public class UrbanApiOptions | ||
{ | ||
public string? BaseUrl { get; set; } | ||
public string? Host { get; set; } | ||
public string? Key { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/HuppyService/HuppyService.Core/HuppyService.Core.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Utilities\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
src/HuppyService/HuppyService.Core/Interfaces/IRepositories/ICommandLogRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using HuppyService.Core.Abstraction; | ||
using HuppyService.Core.Entities; | ||
using HuppyService.Core.Models; | ||
|
||
namespace HuppyService.Core.Interfaces.IRepositories | ||
{ | ||
public interface ICommandLogRepository : IRepository<int, CommandLog> | ||
{ | ||
Task<int> GetCount(); | ||
Task<Dictionary<ulong, AiUser>> GetAiUsage(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/HuppyService/HuppyService.Core/Interfaces/IRepositories/IReminderRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using HuppyService.Core.Abstraction; | ||
using HuppyService.Core.Models; | ||
|
||
namespace HuppyService.Core.Interfaces.IRepositories | ||
{ | ||
public interface IReminderRepository : IRepository<int, Reminder> | ||
{ | ||
Task<Reminder?> GetAsync(ulong userId, int id); | ||
Task RemoveRangeAsync(ICollection<int> reminderIds); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/HuppyService/HuppyService.Core/Interfaces/IRepositories/IServerRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using HuppyService.Core.Abstraction; | ||
using HuppyService.Core.Models; | ||
|
||
namespace HuppyService.Core.Interfaces.IRepositories | ||
{ | ||
public interface IServerRepository : IRepository<ulong, Server> | ||
{ | ||
Task<Server> GetOrCreateAsync(ulong guildId, ulong defaultChannel, string guildName); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/HuppyService/HuppyService.Core/Interfaces/IRepositories/ITicketRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using HuppyService.Core.Abstraction; | ||
using HuppyService.Core.Models; | ||
|
||
namespace HuppyService.Core.Interfaces.IRepositories | ||
{ | ||
public interface ITicketRepository : IRepository<string, Ticket> | ||
{ | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/HuppyService/HuppyService.Core/Interfaces/IRepositories/IUserRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using HuppyService.Core.Abstraction; | ||
using HuppyService.Core.Models; | ||
|
||
namespace HuppyService.Core.Interfaces.IRepositories | ||
{ | ||
public interface IUserRepository : IRepository<ulong, User> | ||
{ | ||
Task<Dictionary<ulong, string?>> GetUsersForCacheAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using HuppyService.Core.Abstraction; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace HuppyService.Core.Models; | ||
|
||
public class CommandLog : DbModel<int> | ||
{ | ||
[Key] | ||
public override int Id { get; set; } | ||
public string? CommandName { get; set; } | ||
public string? ErrorMessage { get; set; } | ||
public DateTime? Date { get; set; } | ||
public bool IsSuccess { get; set; } | ||
public long ExecutionTimeMs { get; set; } | ||
public ulong ChannelId { get; set; } | ||
|
||
[ForeignKey("UserId")] | ||
public ulong UserId { get; set; } | ||
public virtual User? User { get; set; } | ||
|
||
[ForeignKey("GuildId")] | ||
public ulong? GuildId { get; set; } | ||
public virtual Server? Guild { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using HuppyService.Core.Abstraction; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace HuppyService.Core.Models | ||
{ | ||
public class Reminder : DbModel<int> | ||
{ | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public override int Id { get; set; } | ||
public DateTime RemindDate { get; set; } | ||
public string Message { get; set; } = null!; | ||
|
||
[ForeignKey("UserId")] | ||
public ulong UserId { get; set; } | ||
public virtual User? User { get; set; } = null!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using HuppyService.Core.Abstraction; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace HuppyService.Core.Models | ||
{ | ||
public class Server : DbModel<ulong> | ||
{ | ||
[Key] | ||
public override ulong Id { get; set; } | ||
public string? ServerName { get; set; } | ||
public bool UseGreet { get; set; } | ||
public string? GreetMessage { get; set; } | ||
public ulong RoleID { get; set; } | ||
|
||
[ForeignKey("ServerRoomsId")] | ||
public ulong? ServerRoomsID { get; set; } | ||
public virtual ServerRooms? Rooms { get; set; } | ||
} | ||
} |
Oops, something went wrong.