feat: добавил ограничение записи на лекции
Backend CI / build-and-test (push) Failing after 32s
Frontend CI / build-and-check (push) Failing after 5m5s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 6s
🚀 Create and publish a Docker image / Build & publish backend image (push) Failing after 1m28s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Failing after 19s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Has been skipped

This commit is contained in:
2026-05-21 19:34:08 +03:00
parent 32b8bdfd24
commit 2e7ce6c2e8
21 changed files with 569 additions and 23 deletions
@@ -6,6 +6,7 @@ using UniVerse.Application.Interfaces;
using UniVerse.Application.Mappings;
using UniVerse.Domain.Entities;
using UniVerse.Domain.Exceptions;
using UniVerse.Domain.Services;
using UniVerse.Infrastructure.Data;
namespace UniVerse.Infrastructure.Services;
@@ -124,6 +125,15 @@ public class LectureService : ILectureService
throw new ConflictException("Lecture is full.");
if (lecture.Enrollments.Any(e => e.UserId == userId))
throw new ConflictException("Already enrolled.");
var level = await _gamification.CalculateLevelAsync(user.Xp);
var enrollmentLimit = EnrollmentSlotPolicy.GetLimitForLevel(level);
var activeEnrollments = await _db.LectureEnrollments
.CountAsync(e => e.UserId == userId && !e.Attended);
if (activeEnrollments >= enrollmentLimit)
throw new ConflictException("Enrollment limit reached for your level.");
_db.LectureEnrollments.Add(new LectureEnrollment { LectureId = lectureId, UserId = userId });
await _db.SaveChangesAsync();
await ScheduleLectureRemindersAsync(lecture, user);
@@ -6,6 +6,7 @@ using UniVerse.Application.Interfaces;
using UniVerse.Application.Mappings;
using UniVerse.Domain.Enums;
using UniVerse.Domain.Exceptions;
using UniVerse.Domain.Services;
using UniVerse.Infrastructure.Data;
namespace UniVerse.Infrastructure.Services;
@@ -55,14 +56,21 @@ public class UserService : IUserService
var attended = await _db.LectureEnrollments.CountAsync(e => e.UserId == id && e.Attended);
var reviews = await _db.Reviews.CountAsync(r => r.UserId == id);
var achievements = await _db.UserAchievements.CountAsync(ua => ua.UserId == id);
var activeEnrollments = await _db.LectureEnrollments
.CountAsync(e => e.UserId == id && !e.Attended);
var level = await _gamification.CalculateLevelAsync(user.Xp);
var levelProgress = await _gamification.GetLevelProgressAsync(user.Xp);
var slotLimit = EnrollmentSlotPolicy.GetLimitForLevel(level);
var slotRules = EnrollmentSlotPolicy.Rules
.Select(rule => new EnrollmentSlotRuleDto(rule.Level, rule.Slots))
.ToList();
return new UserStatsDto(
totalLectures, attended, reviews,
user.Xp, user.Coins, level, achievements,
levelProgress.CurrentLevelXp, levelProgress.NextLevelXp
levelProgress.CurrentLevelXp, levelProgress.NextLevelXp,
activeEnrollments, slotLimit, slotRules
);
}