Skip to content

Commit

Permalink
Trim string fields during conversion of request DTOs into entities. (#93
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Zifah authored Aug 17, 2024
1 parent f7475da commit b2a4953
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Api/Controllers/SuggestedNameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using Application.Mappers;
using Application.Validation;
using FluentValidation;

namespace Api.Controllers;

Expand All @@ -16,9 +17,9 @@ namespace Api.Controllers;
public class SuggestedNameController : ControllerBase
{
private readonly SuggestedNameService _suggestedNameService;
private readonly CreateSuggestedNameValidator _suggestedNameValidator;
private readonly IValidator<CreateSuggestedNameDto> _suggestedNameValidator;

public SuggestedNameController(SuggestedNameService suggestedNameService, CreateSuggestedNameValidator suggestedNameValidator)
public SuggestedNameController(SuggestedNameService suggestedNameService, IValidator<CreateSuggestedNameDto> suggestedNameValidator)
{
_suggestedNameService = suggestedNameService;
_suggestedNameValidator = suggestedNameValidator;
Expand Down
2 changes: 1 addition & 1 deletion Application/Mappers/NameEntryMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static NameEntry MapToEntity(this NameDto request)
{
return new NameEntry
{
Name = request.Name,
Name = request.Name.Trim(),
Pronunciation = request.Pronunciation?.Trim(),
Meaning = request.Meaning.Trim(),
ExtendedMeaning = request.ExtendedMeaning?.Trim(),
Expand Down
6 changes: 3 additions & 3 deletions Application/Mappers/SuggestedNameMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public static SuggestedName MapToEntity(this CreateSuggestedNameDto request)
return new SuggestedName
{
Id = ObjectId.GenerateNewId().ToString(),
Name = request.Name,
Email = request.Email,
Details = request.Details,
Name = request.Name.Trim(),
Email = request.Email?.Trim(),
Details = request.Details?.Trim(),
GeoLocation = request.GeoLocation.Select(x => new GeoLocation
{
Place = x.Place,
Expand Down
6 changes: 1 addition & 5 deletions Application/Validation/NameValidator.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using Core.Dto;
using Core.Dto.Request;
using Core.Dto.Request;
using FluentValidation;
namespace Application.Validation
{
public class NameValidator : AbstractValidator<NameDto>
{



public NameValidator(GeoLocationValidator geoLocationValidator, EmbeddedVideoValidator embeddedVideoValidator, EtymologyValidator etymologyValidator)
{
RuleLevelCascadeMode = CascadeMode.Stop;
Expand Down
2 changes: 1 addition & 1 deletion Core/Dto/CharacterSeparatedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class CharacterSeparatedString<T> where T : CharacterSeparatedSt

public CharacterSeparatedString(string? value)

Check warning on line 9 in Core/Dto/CharacterSeparatedString.cs

View workflow job for this annotation

GitHub Actions / deploy / deploy

Non-nullable property 'SeparatorOut' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
this.value = value ?? string.Empty;
this.value = value?.Trim() ?? string.Empty;
}

public override string ToString()
Expand Down

0 comments on commit b2a4953

Please sign in to comment.