diff options
author | crupest <crupest@outlook.com> | 2021-06-01 23:22:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-01 23:22:47 +0800 |
commit | bd9dacf0566ca542ecab913acbc244f474c6a752 (patch) | |
tree | cfdef1f4ff79be1fca38ef4bf15b06a102279276 /BackEnd/Timeline/Services | |
parent | a3f8daad1706697c6106045f271b74fd241ddcb3 (diff) | |
download | timeline-bd9dacf0566ca542ecab913acbc244f474c6a752.tar.gz timeline-bd9dacf0566ca542ecab913acbc244f474c6a752.tar.bz2 timeline-bd9dacf0566ca542ecab913acbc244f474c6a752.zip |
feat: Add ways to reset timeline or post color.
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/TimelinePostService.cs | 20 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/TimelineService.cs | 11 |
2 files changed, 24 insertions, 7 deletions
diff --git a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs index ee1002e0..ae034767 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs @@ -26,6 +26,7 @@ namespace Timeline.Services.Timeline private readonly IImageService _imageValidator;
private readonly IClock _clock;
private readonly ColorValidator _colorValidator = new ColorValidator();
+ private readonly ColorValidator _colorValidatorAllowEmptyAndDefault = new ColorValidator() { PermitEmpty = true, PermitDefault = true };
public TimelinePostService(ILogger<TimelinePostService> logger, DatabaseContext database, IBasicTimelineService basicTimelineService, IBasicUserService basicUserService, IDataManager dataManager, IImageService imageValidator, IClock clock)
{
@@ -38,9 +39,9 @@ namespace Timeline.Services.Timeline _clock = clock;
}
- private void CheckColor(string color, string paramName)
+ private void CheckColor(string color, string paramName, bool allowEmptyOrDefault)
{
- if (!_colorValidator.Validate(color, out var message))
+ if (!(allowEmptyOrDefault ? _colorValidatorAllowEmptyAndDefault : _colorValidator).Validate(color, out var message))
throw new ArgumentException(string.Format(Resource.ExceptionColorInvalid, message), paramName);
}
@@ -166,7 +167,7 @@ namespace Timeline.Services.Timeline throw new ArgumentNullException(nameof(request));
if (request.Color is not null)
- CheckColor(request.Color, nameof(request));
+ CheckColor(request.Color, nameof(request), false);
if (request.DataList is null)
throw new ArgumentException(Resource.ExceptionDataListNull, nameof(request));
@@ -269,7 +270,7 @@ namespace Timeline.Services.Timeline throw new ArgumentNullException(nameof(request));
if (request.Color is not null)
- CheckColor(request.Color, nameof(request));
+ CheckColor(request.Color, nameof(request), true);
request.Time = request.Time?.MyToUtc();
@@ -287,7 +288,16 @@ namespace Timeline.Services.Timeline entity.Time = request.Time.Value;
if (request.Color is not null)
- entity.Color = request.Color;
+ {
+ if (request.Color.Length == 0 || request.Color == "default")
+ {
+ entity.Color = null;
+ }
+ else
+ {
+ entity.Color = request.Color;
+ }
+ }
entity.LastUpdated = _clock.GetCurrentTime();
diff --git a/BackEnd/Timeline/Services/Timeline/TimelineService.cs b/BackEnd/Timeline/Services/Timeline/TimelineService.cs index 920fcc74..6f22ff05 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelineService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelineService.cs @@ -23,7 +23,7 @@ namespace Timeline.Services.Timeline private readonly IClock _clock;
private readonly TimelineNameValidator _timelineNameValidator = new TimelineNameValidator();
- private readonly ColorValidator _colorValidator = new ColorValidator();
+ private readonly ColorValidator _colorValidator = new ColorValidator() { PermitDefault = true, PermitEmpty = true };
public TimelineService(ILoggerFactory loggerFactory, DatabaseContext database, IBasicUserService userService, IClock clock)
: base(loggerFactory, database, userService, clock)
@@ -119,7 +119,14 @@ namespace Timeline.Services.Timeline if (newProperties.Color is not null)
{
changed = true;
- entity.Color = newProperties.Color;
+ if (newProperties.Color.Length == 0 || newProperties.Color == "default")
+ {
+ entity.Color = null;
+ }
+ else
+ {
+ entity.Color = newProperties.Color;
+ }
}
if (changed)
|