add architecture skeleton

This commit is contained in:
2026-04-19 13:12:04 +03:00
parent 312708531f
commit 2738f31f26
84 changed files with 2710 additions and 70 deletions
@@ -0,0 +1,27 @@
using GymLogAI.Application.Interfaces;
using GymLogAI.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace GymLogAI.Persistence.Repositories;
public sealed class ExerciseRepository(AppDbContext dbContext) : IExerciseRepository
{
public async Task<Exercise?> GetByNameAsync(string name, CancellationToken cancellationToken)
{
return await dbContext.Exercises.SingleOrDefaultAsync(x => x.Name == name, cancellationToken);
}
public async Task<Exercise> AddAsync(Exercise exercise, CancellationToken cancellationToken)
{
dbContext.Exercises.Add(exercise);
await dbContext.SaveChangesAsync(cancellationToken);
return exercise;
}
public async Task<Exercise> UpdateAsync(Exercise exercise, CancellationToken cancellationToken)
{
dbContext.Exercises.Update(exercise);
await dbContext.SaveChangesAsync(cancellationToken);
return exercise;
}
}
@@ -0,0 +1,37 @@
using GymLogAI.Application.Interfaces;
using GymLogAI.Core.Entities;
using GymLogAI.Core.Enums;
using Microsoft.EntityFrameworkCore;
namespace GymLogAI.Persistence.Repositories;
public sealed class TelegramMessageRepository(AppDbContext dbContext) : ITelegramMessageRepository
{
public async Task<TelegramMessage> AddAsync(TelegramMessage message, CancellationToken cancellationToken)
{
dbContext.TelegramMessages.Add(message);
await dbContext.SaveChangesAsync(cancellationToken);
return message;
}
public async Task<TelegramMessage?> GetByIdAsync(Guid id, CancellationToken cancellationToken)
{
return await dbContext.TelegramMessages.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);
}
public async Task<IReadOnlyCollection<TelegramMessage>> GetPendingAsync(int take, CancellationToken cancellationToken)
{
return await dbContext.TelegramMessages
.Where(x => x.ParsingStatus == ParsingStatus.Pending)
.OrderBy(x => x.ImportedAtUtc)
.Take(take)
.ToListAsync(cancellationToken);
}
public async Task<TelegramMessage> UpdateAsync(TelegramMessage message, CancellationToken cancellationToken)
{
dbContext.TelegramMessages.Update(message);
await dbContext.SaveChangesAsync(cancellationToken);
return message;
}
}
@@ -0,0 +1,32 @@
using GymLogAI.Application.Interfaces;
using GymLogAI.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace GymLogAI.Persistence.Repositories;
public sealed class UserRepository(AppDbContext dbContext) : IUserRepository
{
public async Task<User?> GetByIdAsync(Guid id, CancellationToken cancellationToken)
{
return await dbContext.Users.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);
}
public async Task<User?> GetByTelegramUserIdAsync(long telegramUserId, CancellationToken cancellationToken)
{
return await dbContext.Users.SingleOrDefaultAsync(x => x.TelegramUserId == telegramUserId, cancellationToken);
}
public async Task<User> AddAsync(User user, CancellationToken cancellationToken)
{
dbContext.Users.Add(user);
await dbContext.SaveChangesAsync(cancellationToken);
return user;
}
public async Task<User> UpdateAsync(User user, CancellationToken cancellationToken)
{
dbContext.Users.Update(user);
await dbContext.SaveChangesAsync(cancellationToken);
return user;
}
}
@@ -0,0 +1,28 @@
using GymLogAI.Application.Interfaces;
using GymLogAI.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace GymLogAI.Persistence.Repositories;
public sealed class WorkoutRepository(AppDbContext dbContext) : IWorkoutRepository
{
public async Task<Workout> AddAsync(Workout workout, CancellationToken cancellationToken)
{
dbContext.Workouts.Add(workout);
await dbContext.SaveChangesAsync(cancellationToken);
return workout;
}
public async Task<IReadOnlyCollection<Workout>> GetHistoryAsync(Guid userId, CancellationToken cancellationToken)
{
return await dbContext.Workouts
.AsNoTracking()
.Include(x => x.WorkoutExercises)
.ThenInclude(x => x.Exercise)
.Include(x => x.WorkoutExercises)
.ThenInclude(x => x.Sets)
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.PerformedAtUtc)
.ToListAsync(cancellationToken);
}
}