Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing workshop to cache during creation #1604

Merged
merged 28 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
76dde14
Divided WorkshopCreatRequestDto class into 5 classes (WorkshopMainReq…
HlibBondarev Dec 2, 2024
7fe5835
1) Added IReadWriteCacheService interface.
HlibBondarev Dec 2, 2024
25be54b
1) Changed IReadWriteCacheService interface - added: Task RemoveAsync…
HlibBondarev Dec 2, 2024
e9a4a78
1) Added preprocessor directive (#nullable enable) to JsonSerializerH…
HlibBondarev Dec 3, 2024
86ff216
Added generic DraftStorageController<T> class.
HlibBondarev Dec 3, 2024
b3fb788
Changed Startup class - replaced the line of code:
HlibBondarev Dec 3, 2024
7c0e8a1
1) Added the WorkshopDraftStorageController class.
HlibBondarev Dec 3, 2024
fb13a87
Changed MappingProfile class - fixed mapping WorkshopCreateRequestDto…
HlibBondarev Dec 3, 2024
e5a5bf9
Updated version of Microsoft.Extensions.Caching.StackExchangeRedis fr…
HlibBondarev Dec 4, 2024
dfedcc4
Chamged OutOfSchool.Redis.csproj file - added code lines:
HlibBondarev Dec 4, 2024
89c1cb9
Changed OutOfSchool.AuthorizationServer.csproj file - added code lines:
HlibBondarev Dec 4, 2024
11184b1
Updated version of Microsoft.Extensions.Caching.StackExchangeRedis fr…
HlibBondarev Dec 4, 2024
08cabec
Changed project files - OutOfSchool.AuthCommon, OutOfSchool.Backgroun…
HlibBondarev Dec 4, 2024
ad087ce
Changed OutOfSchool.AdminInitializer file - added code lines:
HlibBondarev Dec 4, 2024
1c86f71
Changed OutOfSchool.Migrations file - added code lines:
HlibBondarev Dec 4, 2024
9b2d15f
Changed project files - OutOfSchool.AuthServer.Tests, OutOfSchool.Tes…
HlibBondarev Dec 4, 2024
6f41ba5
Changed version of Microsoft.Extensions.Caching.StackExchangeRedis fr…
HlibBondarev Dec 4, 2024
075316b
Changed project files - added the following lines of code:
HlibBondarev Dec 4, 2024
2e48d65
Added tests to CacheServiceTests class.
HlibBondarev Dec 5, 2024
4782a85
Added tests to CacheServiceTests class.
HlibBondarev Dec 5, 2024
65bcffc
1) Changed Startup class:
HlibBondarev Dec 5, 2024
8d4d3ca
1) Created the WorkshopMainRequiredPropertiesDtoGenerator class.
HlibBondarev Dec 5, 2024
187d64d
1) Created the WorkshopRequiredPropertiesDtoGenerator class.
HlibBondarev Dec 5, 2024
718d413
1) Added [JsonDerivedType(typeof(WorkshopV2CreateRequestDto), typeDis…
HlibBondarev Dec 6, 2024
32bb98c
Fixed code alignment in project file - OutOfSchool.BusinessLogic.
HlibBondarev Dec 6, 2024
ae3f70a
Fixed code alignment after merging in project file - OutOfSchool.Busi…
HlibBondarev Dec 6, 2024
9ca565f
Changed the return value of StoreDraft() method in DraftStorageContr…
HlibBondarev Dec 6, 2024
731ea6c
Fixed StoreDerivedDraft_WhenModelIsValid_ReturnsOkObjectResult() meth…
HlibBondarev Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OutOfSchool/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<!--Elasticsearch-->
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.15.6" />
<!--Redis-->
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="$(RedisVersion)" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="$(RedisVersion)" />
<!--Identity-->
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<NuGetAuditMode>direct</NuGetAuditMode>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>dd058b3f-d89a-4456-a6df-2f32568b56ea</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>

<PropertyGroup>
<PackageId>auth</PackageId>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net8.0</TargetFramework>
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<NuGetAuditMode>direct</NuGetAuditMode>
<UserSecretsId>23768b69-757e-4a20-894f-dcf7181971ca</UserSecretsId>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using OutOfSchool.BusinessLogic.Util.JsonTools;

namespace OutOfSchool.BusinessLogic.Models.Workshops.Drafts;
public class WorkshopContactsDto : WorkshopDescriptionDto
{
[DataType(DataType.Url)]
[MaxLength(Constants.MaxUnifiedUrlLength)]
public string Website { get; set; } = string.Empty;

[DataType(DataType.Url)]
[MaxLength(Constants.MaxUnifiedUrlLength)]
public string Facebook { get; set; } = string.Empty;

[DataType(DataType.Url)]
[MaxLength(Constants.MaxUnifiedUrlLength)]
public string Instagram { get; set; } = string.Empty;

[Required]
public long AddressId { get; set; }

[Required]
[ModelBinder(BinderType = typeof(JsonModelBinder))]
public AddressDto Address { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using OutOfSchool.BusinessLogic.Util.CustomValidation;
using OutOfSchool.BusinessLogic.Util.JsonTools;

namespace OutOfSchool.BusinessLogic.Models.Workshops.Drafts;

public class WorkshopDescriptionDto : WorkshopRequiredPropertiesDto
{
[ModelBinder(BinderType = typeof(JsonModelBinder))]
[CollectionNotEmpty(ErrorMessage = "At least one description item is required")]
public IEnumerable<WorkshopDescriptionItemDto> WorkshopDescriptionItems { get; set; }

public bool WithDisabilityOptions { get; set; } = default;

[MaxLength(200)]
public string DisabilityOptionsDesc { get; set; } = string.Empty;

public Guid? InstitutionId { get; set; }

public Guid? InstitutionHierarchyId { get; set; }

public List<long> DirectionIds { get; set; }

[ModelBinder(BinderType = typeof(JsonModelBinder))]
public IEnumerable<string> Keywords { get; set; } = default;

[MaxLength(500)]
public string AdditionalDescription { get; set; }

public bool AreThereBenefits { get; set; } = default;

[MaxLength(500)]
public string PreferentialTermsOfParticipation { get; set; }

public uint CoverageId { get; set; } = 0;

[ModelBinder(BinderType = typeof(JsonModelBinder))]
public List<long> TagIds { get; set; } = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
using OutOfSchool.BusinessLogic.Util.CustomValidation;
using OutOfSchool.BusinessLogic.Util.JsonTools;
using OutOfSchool.Common.Enums;
using OutOfSchool.Common.Validators;
using OutOfSchool.Services.Enums;

namespace OutOfSchool.BusinessLogic.Models.Workshops.Drafts;

[JsonDerivedType(typeof(WorkshopMainRequiredPropertiesDto), typeDiscriminator: "withMainProperties")]
[JsonDerivedType(typeof(WorkshopRequiredPropertiesDto), typeDiscriminator: "withOtherRequiredProperties")]
[JsonDerivedType(typeof(WorkshopDescriptionDto), typeDiscriminator: "withDescription")]
[JsonDerivedType(typeof(WorkshopContactsDto), typeDiscriminator: "withContacts")]
[JsonDerivedType(typeof(WorkshopCreateRequestDto), typeDiscriminator: "withStaff")]
[JsonDerivedType(typeof(WorkshopV2CreateRequestDto), typeDiscriminator: "withImages")]
public class WorkshopMainRequiredPropertiesDto : IValidatableObject
{
public Guid Id { get; set; }

[Required(ErrorMessage = "Workshop title is required")]
[MinLength(Constants.MinWorkshopTitleLength)]
[MaxLength(Constants.MaxWorkshopTitleLength)]
public string Title { get; set; } = string.Empty;

[Required(ErrorMessage = "Workshop short title is required")]
[MinLength(Constants.MinWorkshopShortTitleLength)]
[MaxLength(Constants.MaxWorkshopShortTitleLength)]
public string ShortTitle { get; set; } = string.Empty;

[DataType(DataType.PhoneNumber)]
[Required(ErrorMessage = "Phone number is required")]
[CustomPhoneNumber(ErrorMessage = Constants.PhoneErrorMessage)]
[DisplayFormat(DataFormatString = Constants.PhoneNumberFormat)]
public string Phone { get; set; } = string.Empty;

[DataType(DataType.EmailAddress)]
[Required(ErrorMessage = "Email is required")]
[MaxLength(256)]
public string Email { get; set; } = string.Empty;

[Required(ErrorMessage = "Children's min age is required")]
[Range(0, 120, ErrorMessage = "Min age should be a number from 0 to 120")]
public int MinAge { get; set; }

[Required(ErrorMessage = "Children's max age is required")]
[Range(0, 120, ErrorMessage = "Max age should be a number from 0 to 120")]
public int MaxAge { get; set; }

[ModelBinder(BinderType = typeof(JsonModelBinder))]
[CollectionNotEmpty(ErrorMessage = "At least one DateTime range is required")]
public List<DateTimeRangeDto> DateTimeRanges { get; set; }

[Required(ErrorMessage = "Form of learning is required")]
[EnumDataType(typeof(FormOfLearning), ErrorMessage = Constants.EnumErrorMessage)]
public FormOfLearning FormOfLearning { get; set; } = FormOfLearning.Offline;

[Required(ErrorMessage = "Property IsPaid is required")]
public bool IsPaid { get; set; } = false;

[Column(TypeName = "decimal(18,2)")]
[Range(0, 100000, ErrorMessage = "Field value should be in a range from 1 to 100 000")]
public decimal? Price { get; set; } = default;

[EnumDataType(typeof(PayRateType), ErrorMessage = Constants.EnumErrorMessage)]
public PayRateType? PayRate { get; set; } = PayRateType.Classes;

[Required(ErrorMessage = "Available seats are required")]
public uint? AvailableSeats { get; set; } = uint.MaxValue;

[Required(ErrorMessage = "Property CompetitiveSelection is required")]
public bool CompetitiveSelection { get; set; }

[MaxLength(500)]
public string CompetitiveSelectionDescription { get; set; }

[Required]
public Guid ProviderId { get; set; }

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
// TODO: Validate DateTimeRanges are not empty when frontend is ready
foreach (var dateTimeRange in DateTimeRanges)
{
if (dateTimeRange.StartTime > dateTimeRange.EndTime)
{
yield return new ValidationResult(
"End date can't be earlier that start date");
}

if (dateTimeRange.Workdays.IsNullOrEmpty() || dateTimeRange.Workdays.Any(workday => workday == DaysBitMask.None))
{
yield return new ValidationResult(
"Workdays are required");
}

var daysHs = new HashSet<DaysBitMask>();
if (!dateTimeRange.Workdays.All(daysHs.Add))
{
yield return new ValidationResult(
"Workdays contain duplications");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations;

namespace OutOfSchool.BusinessLogic.Models.Workshops.Drafts;

public class WorkshopRequiredPropertiesDto : WorkshopMainRequiredPropertiesDto
{
[Required(ErrorMessage = "Short stay is required")]
public bool ShortStay { get; set; } = false;

[Required(ErrorMessage = "Should be indicated if the Workshop operates with funds from parents or benefactors")]
public bool IsSelfFinanced { get; set; } = false;

[Required(ErrorMessage = "Property IsSpecial is required")]
public bool IsSpecial { get; set; } = false;

public uint SpecialNeedsId { get; set; } = 0;

[Required(ErrorMessage = "Property IsInclusive is required")]
public bool IsInclusive { get; set; } = false;

[Required(ErrorMessage = "Educational shift is required")]
public uint EducationalShiftId { get; set; } = 0;

[Required(ErrorMessage = "Language of education is required")]
public uint LanguageOfEducationId { get; set; } = 0;

[Required(ErrorMessage = "Type of age composition is required")]
public uint TypeOfAgeCompositionId { get; set; } = 0;

[Required(ErrorMessage = "Educational disciplines is required")]
public Guid EducationalDisciplines { get; set; } = Guid.Empty;

[Required(ErrorMessage = "Category is required")]
public uint CategoryId { get; set; } = 0;

[Required(ErrorMessage = "GropeType is required")]
public uint GropeTypeId { get; set; } = 0;

public Guid? MemberOfWorkshopId { get; set; }
}
Loading
Loading