Skip to content

Commit

Permalink
Fixed bug with child creation when entering a name longer than 30 cha…
Browse files Browse the repository at this point in the history
…ractersand replace magic numbers with constants for improved code readability
  • Loading branch information
VitaliyYuras committed Aug 18, 2023
1 parent 4f7b9f4 commit 61d22fa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions OutOfSchool/OutOfSchool.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public static class Constants
public const string AdminKeyword = "Admin";

public const char MappingSeparator = '¤';

public const int NameMaxLength = 60;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

internal class ModelsConfigurationConstants
{
public const int NameMaxLength = 30;


// TODO: validate what this lengs for ?
public const int ImageMaxLength = 256;
Expand Down
8 changes: 5 additions & 3 deletions OutOfSchool/OutOfSchool.DataAccess/Models/Child.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Reflection.Metadata;
using OutOfSchool.Common;
using OutOfSchool.Services.Enums;

namespace OutOfSchool.Services.Models;
Expand All @@ -9,13 +11,13 @@ public class Child : IKeyedEntity<Guid>
{
public Guid Id { get; set; }

[MaxLength(60)]
[MaxLength(Constants.NameMaxLength)]
public string FirstName { get; set; } = string.Empty;

[MaxLength(60)]
[MaxLength(Constants.NameMaxLength)]
public string LastName { get; set; } = string.Empty;

[MaxLength(60)]
[MaxLength(Constants.NameMaxLength)]
public string MiddleName { get; set; } = string.Empty;

public DateTime? DateOfBirth { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using OutOfSchool.Common;
using OutOfSchool.Services.Common;
using OutOfSchool.Services.Enums;

Expand All @@ -14,15 +14,15 @@ public void Configure(EntityTypeBuilder<Child> builder)

builder.Property(x => x.FirstName)
.IsRequired()
.HasMaxLength(ModelsConfigurationConstants.NameMaxLength);
.HasMaxLength(Constants.NameMaxLength);

builder.Property(x => x.LastName)
.IsRequired()
.HasMaxLength(ModelsConfigurationConstants.NameMaxLength);
.HasMaxLength(Constants.NameMaxLength);

builder.Property(x => x.MiddleName)
.IsRequired()
.HasMaxLength(ModelsConfigurationConstants.NameMaxLength);
.HasMaxLength(Constants.NameMaxLength);

builder.Property(x => x.DateOfBirth)
.IsRequired()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using OutOfSchool.Common;
using OutOfSchool.Services.Common;

namespace OutOfSchool.Services.Models.Configurations;
Expand All @@ -14,15 +14,15 @@ public void Configure(EntityTypeBuilder<Teacher> builder)

builder.Property(x => x.FirstName)
.IsRequired()
.HasMaxLength(ModelsConfigurationConstants.NameMaxLength);
.HasMaxLength(Constants.NameMaxLength);

builder.Property(x => x.LastName)
.IsRequired()
.HasMaxLength(ModelsConfigurationConstants.NameMaxLength);
.HasMaxLength(Constants.NameMaxLength);

builder.Property(x => x.MiddleName)
.IsRequired()
.HasMaxLength(ModelsConfigurationConstants.NameMaxLength);
.HasMaxLength(Constants.NameMaxLength);

builder.Property(x => x.DateOfBirth)
.IsRequired()
Expand Down

0 comments on commit 61d22fa

Please sign in to comment.