.
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VizhTalk.BuildingBlocks.Domain;
|
||||
using VizhTalk.Learning.Domain.TypeIds;
|
||||
using VizhTalk.Learning.Domain.ValueObjects;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.Entities
|
||||
namespace VizhTalk.Learning.Domain.Entities;
|
||||
|
||||
public class Course : Entity<CourseId>
|
||||
{
|
||||
internal class Course
|
||||
private Course()
|
||||
{
|
||||
|
||||
}
|
||||
private Course(CourseTitle title, int order)
|
||||
{
|
||||
Title = title;
|
||||
Order = order;
|
||||
}
|
||||
public CourseTitle Title { get; private set; }
|
||||
public Media Image { get; private set; }
|
||||
public int Order { get; private set; }
|
||||
|
||||
internal static Course CreateNew(CourseTitle title, int order)
|
||||
=> new(title, order);
|
||||
public void SetTitle(CourseTitle title)
|
||||
=> Title = title;
|
||||
public void SetOrder(int order)
|
||||
=> Order = order;
|
||||
public void SetImage(Media media)
|
||||
=> Image = media;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using VizhTalk.BuildingBlocks.Domain;
|
||||
using VizhTalk.Learning.Domain.Exceptions;
|
||||
using VizhTalk.Learning.Domain.TypeIds;
|
||||
using VizhTalk.Learning.Domain.ValueObjects;
|
||||
|
||||
@@ -6,24 +7,40 @@ namespace VizhTalk.Learning.Domain.Entities;
|
||||
|
||||
public class Language : Entity<LanguageId>, IAggregateRoot
|
||||
{
|
||||
public Language()
|
||||
private List<Course> _courses = new();
|
||||
private Language()
|
||||
{
|
||||
// only EF
|
||||
}
|
||||
private Language(LanguageTitle title, Media icon)
|
||||
private Language(LanguageTitle title)
|
||||
{
|
||||
Title = title;
|
||||
Icon = icon;
|
||||
|
||||
}
|
||||
public LanguageTitle Title { get; private set; }
|
||||
public Media Icon { get; private set; }
|
||||
public IReadOnlyList<Course> Courses => _courses;
|
||||
public static Language CreateNew(LanguageTitle title)
|
||||
=> new(title);
|
||||
|
||||
public static Language CreateNew(LanguageTitle title,Media icon)
|
||||
=> new(title, icon);
|
||||
|
||||
public void SetTitle(LanguageTitle title)
|
||||
=> Title = title;
|
||||
public void SetIcon(Media icon)
|
||||
=> Icon = icon;
|
||||
{
|
||||
if (Icon != null)
|
||||
Icon.SetDeleted(true);
|
||||
|
||||
Icon = icon;
|
||||
}
|
||||
public Course AddCourse(CourseTitle courseTitle)
|
||||
{
|
||||
var order = Courses.Count;
|
||||
var course = Course.CreateNew(courseTitle, order);
|
||||
_courses.Add(course);
|
||||
return course;
|
||||
}
|
||||
public Course UpdateCourse(Course course)
|
||||
{
|
||||
var _course = _courses.FirstOrDefault(x => x.Id == course.Id) ?? throw new CourseNotFoundException(Title);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,28 @@ namespace VizhTalk.Learning.Domain.Entities;
|
||||
|
||||
public class Media : Entity<MediaId>
|
||||
{
|
||||
private Media()
|
||||
{
|
||||
|
||||
}
|
||||
private Media(string name,
|
||||
string contentType,
|
||||
int size,
|
||||
EntityType type)
|
||||
{
|
||||
Name = name;
|
||||
ContentType = contentType;
|
||||
Size = size;
|
||||
EntityType = type;
|
||||
}
|
||||
public string Name { get; private set; }
|
||||
public string ContentType { get; private set; }
|
||||
public int Size { get; private set; }
|
||||
public EntityType EntityType { get; private set; }
|
||||
|
||||
public static Media CreateNew(string name,
|
||||
string contentType,
|
||||
int size,
|
||||
EntityType type)
|
||||
=> new(name, contentType, size, type);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using VizhTalk.BuildingBlocks.Domain.Contract;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.Exceptions;
|
||||
|
||||
public class CourseNotFoundException(string languageTitle)
|
||||
: Exception($"course not found in {languageTitle} language"),IGuardException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using VizhTalk.BuildingBlocks.Domain;
|
||||
using VizhTalk.Learning.Domain.Entities;
|
||||
using VizhTalk.Learning.Domain.TypeIds;
|
||||
using VizhTalk.Learning.Domain.ValueObjects;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.Repositories;
|
||||
|
||||
public interface IFileGroupRepository : IRepositoryBase<FileGroup,FileGroupId>
|
||||
{
|
||||
Task<FileGroup> GetByFileGroupKey(FileGroupKey key, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -2,10 +2,9 @@
|
||||
using VizhTalk.Learning.Domain.Entities;
|
||||
using VizhTalk.Learning.Domain.TypeIds;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.Repositories
|
||||
{
|
||||
public interface ILanguageRepository : IRepositoryBase<Language,LanguageId>
|
||||
{
|
||||
namespace VizhTalk.Learning.Domain.Repositories;
|
||||
|
||||
public interface ILanguageRepository : IRepositoryBase<Language,LanguageId>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using VizhTalk.BuildingBlocks.Domain;
|
||||
using VizhTalk.Learning.Domain.Entities;
|
||||
using VizhTalk.Learning.Domain.TypeIds;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.Repositories;
|
||||
|
||||
public interface IMediaRepository : IRepositoryBase<Media,MediaId>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VizhTalk.BuildingBlocks.Domain;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.TypeIds;
|
||||
|
||||
public class CourseId : TypeIdValueBase<long>
|
||||
{
|
||||
public CourseId(long value) : base(value)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using VizhTalk.BuildingBlocks.Domain.Guards;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.ValueObjects;
|
||||
|
||||
public class CourseTitle
|
||||
{
|
||||
public CourseTitle(string title)
|
||||
{
|
||||
title = title.Trim();
|
||||
Guard.NullOrEmpty(title, nameof(LanguageTitle));
|
||||
Guard.MaxLength(title, nameof(LanguageTitle), 60);
|
||||
Value = title;
|
||||
}
|
||||
public string Value { get; private set; }
|
||||
|
||||
public static implicit operator string(CourseTitle title) => title.Value;
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace VizhTalk.Learning.Domain.ValueObjects
|
||||
{
|
||||
public class FileGroupKey : ValueObject
|
||||
{
|
||||
public static FileGroupKey LanguageIcon = new("Language");
|
||||
public static FileGroupKey IconLanguage = new("IconLanguage");
|
||||
public FileGroupKey(string entityName, string? entityId = null)
|
||||
{
|
||||
Guard.NullOrEmpty(entityName, entityName);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Events\" />
|
||||
<Folder Include="Exceptions\" />
|
||||
<Folder Include="Rules\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user