course
This commit is contained in:
@@ -10,21 +10,26 @@ public class Course : Entity<CourseId>
|
||||
{
|
||||
|
||||
}
|
||||
private Course(CourseTitle title, int order)
|
||||
private Course(CourseTitle title, int order, Media image, CourseDescription? description)
|
||||
{
|
||||
Title = title;
|
||||
Order = order;
|
||||
Image = image;
|
||||
Description = description;
|
||||
}
|
||||
public CourseTitle Title { get; private set; }
|
||||
public Media Image { get; private set; }
|
||||
public CourseDescription? Description { get; set; }
|
||||
public int Order { get; private set; }
|
||||
|
||||
internal static Course CreateNew(CourseTitle title, int order)
|
||||
=> new(title, order);
|
||||
internal static Course CreateNew(CourseTitle title, int order, Media image, CourseDescription? description)
|
||||
=> new(title, order, image, description);
|
||||
public void SetTitle(CourseTitle title)
|
||||
=> Title = title;
|
||||
public void SetOrder(int order)
|
||||
=> Order = order;
|
||||
public void SetImage(Media media)
|
||||
=> Image = media;
|
||||
public void SetDescription(CourseDescription? description)
|
||||
=> Description = description;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Language : Entity<LanguageId>, IAggregateRoot
|
||||
public LanguageTitle Title { get; private set; }
|
||||
public Media Icon { get; private set; }
|
||||
public IReadOnlyList<Course> Courses => _courses;
|
||||
public static Language CreateNew(LanguageTitle title,Media icon)
|
||||
public static Language CreateNew(LanguageTitle title, Media icon)
|
||||
=> new(title, icon);
|
||||
|
||||
public void SetTitle(LanguageTitle title)
|
||||
@@ -32,21 +32,22 @@ public class Language : Entity<LanguageId>, IAggregateRoot
|
||||
|
||||
Icon = icon;
|
||||
}
|
||||
public Course AddCourse(CourseTitle courseTitle)
|
||||
public Course AddCourse(CourseTitle courseTitle, Media image, CourseDescription? courseDescription)
|
||||
{
|
||||
var order = Courses.Count;
|
||||
var course = Course.CreateNew(courseTitle, order);
|
||||
var course = Course.CreateNew(courseTitle, order, image, courseDescription);
|
||||
_courses.Add(course);
|
||||
return course;
|
||||
}
|
||||
public Course UpdateCourse(Course course)
|
||||
{
|
||||
var _course = _courses.FirstOrDefault(x => x.Id == course.Id) ?? throw new CourseNotFoundException(Title);
|
||||
if(course.Image != null)
|
||||
if (course.Image != null)
|
||||
_course.SetImage(course.Image);
|
||||
_course.SetTitle(course.Title);
|
||||
_course.SetDescription(course.Description);
|
||||
|
||||
if(_course.Order != course.Order)
|
||||
if (_course.Order != course.Order)
|
||||
{
|
||||
var orderCourses = _courses.Where(x => x.Id != course.Id)
|
||||
.OrderBy(x => x.Order)
|
||||
|
||||
@@ -6,5 +6,5 @@ namespace VizhTalk.Learning.Domain.Repositories;
|
||||
|
||||
public interface ILanguageRepository : IRepositoryBase<Language,LanguageId>
|
||||
{
|
||||
|
||||
Task<Language?> GetLanguageWithCoursesById(LanguageId languageId ,CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using VizhTalk.BuildingBlocks.Domain;
|
||||
using VizhTalk.BuildingBlocks.Domain.Guards;
|
||||
|
||||
namespace VizhTalk.Learning.Domain.ValueObjects;
|
||||
|
||||
public class CourseDescription : ValueObject
|
||||
{
|
||||
public const short MaxLength = 800;
|
||||
public CourseDescription(string description)
|
||||
{
|
||||
Guard.NullOrEmpty(description,nameof(CourseDescription));
|
||||
Guard.MaxLength(description, nameof(CourseDescription), MaxLength);
|
||||
Value = description;
|
||||
}
|
||||
public string Value { get; set; }
|
||||
|
||||
public static implicit operator string(CourseDescription title) => title.Value;
|
||||
public static implicit operator CourseDescription(string title) => new(title);
|
||||
}
|
||||
@@ -14,5 +14,6 @@ public class CourseTitle
|
||||
public string Value { get; private set; }
|
||||
|
||||
public static implicit operator string(CourseTitle title) => title.Value;
|
||||
public static implicit operator CourseTitle(string title) => new(title);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ public class EntityType : ValueObject
|
||||
}
|
||||
public enum EntityTypeEnum
|
||||
{
|
||||
Language = 0
|
||||
Language = 0,
|
||||
Course = 1
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace VizhTalk.Learning.Domain.ValueObjects
|
||||
public class FileGroupKey : ValueObject
|
||||
{
|
||||
public static FileGroupKey IconLanguage = new("IconLanguage");
|
||||
public static FileGroupKey ImageCourse = new("ImageCourse");
|
||||
public FileGroupKey(string entityName, string? entityId = null)
|
||||
{
|
||||
Guard.NullOrEmpty(entityName, entityName);
|
||||
|
||||
Reference in New Issue
Block a user