-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jssbg-71_crosscutting-files-reminders-and-ti…
…melines
- Loading branch information
Showing
11 changed files
with
85 additions
and
92 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
Backend/src/BuildingBlocks/BuildingBlocks.Domain/GlobalUsing.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
global using MediatR; | ||
global using BuildingBlocks.Domain.Exceptions; |
19 changes: 6 additions & 13 deletions
19
Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
using BuildingBlocks.Domain.Exceptions; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BuildingBlocks.Domain.ValueObjects.Ids; | ||
|
||
public record FileAssetId | ||
[JsonConverter(typeof(FileAssetIdJsonConverter))] | ||
public record FileAssetId : StronglyTypedId | ||
{ | ||
private FileAssetId(Guid value) | ||
{ | ||
Value = value; | ||
} | ||
private FileAssetId(Guid value) : base(value) { } | ||
|
||
public Guid Value { get; } | ||
public static FileAssetId Of(Guid value) => new(value); | ||
|
||
public static FileAssetId Of(Guid value) | ||
{ | ||
if (value == Guid.Empty) throw new EmptyIdException("FileAssetId cannot be empty."); | ||
|
||
return new FileAssetId(value); | ||
} | ||
private class FileAssetIdJsonConverter : StronglyTypedIdJsonConverter<FileAssetId>; | ||
} |
35 changes: 5 additions & 30 deletions
35
Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,13 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BuildingBlocks.Domain.ValueObjects.Ids; | ||
|
||
[JsonConverter(typeof(NodeIdJsonConverter))] | ||
public record NodeId | ||
public record NodeId : StronglyTypedId | ||
{ | ||
private NodeId(Guid value) => Value = value; | ||
private NodeId(Guid value) : base(value) { } | ||
|
||
public Guid Value { get; } | ||
public static NodeId Of(Guid value) => new(value); | ||
|
||
public static NodeId Of(Guid value) | ||
{ | ||
if (value == Guid.Empty) | ||
throw new EmptyIdException("NodeId cannot be empty."); | ||
|
||
return new NodeId(value); | ||
} | ||
|
||
public override string ToString() => Value.ToString(); | ||
} | ||
|
||
public class NodeIdJsonConverter : JsonConverter<NodeId> | ||
{ | ||
public override NodeId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var value = reader.GetString(); | ||
|
||
if (Guid.TryParse(value, out var guid)) | ||
return NodeId.Of(guid); | ||
|
||
throw new JsonException($"Invalid GUID format for NodeId: {value}"); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, NodeId value, JsonSerializerOptions options) => | ||
writer.WriteStringValue(value.Value.ToString()); | ||
private class NodeIdJsonConverter : StronglyTypedIdJsonConverter<NodeId>; | ||
} |
19 changes: 6 additions & 13 deletions
19
Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
using BuildingBlocks.Domain.Exceptions; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BuildingBlocks.Domain.ValueObjects.Ids; | ||
|
||
public record NoteId | ||
[JsonConverter(typeof(NoteIdJsonConverter))] | ||
public record NoteId : StronglyTypedId | ||
{ | ||
private NoteId(Guid value) | ||
{ | ||
Value = value; | ||
} | ||
private NoteId(Guid value) : base(value) { } | ||
|
||
public Guid Value { get; } | ||
public static NoteId Of(Guid value) => new(value); | ||
|
||
public static NoteId Of(Guid value) | ||
{ | ||
if (value == Guid.Empty) throw new EmptyIdException("NoteId cannot be empty."); | ||
|
||
return new NoteId(value); | ||
} | ||
private class NoteIdJsonConverter : StronglyTypedIdJsonConverter<NoteId>; | ||
} |
19 changes: 6 additions & 13 deletions
19
Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
using BuildingBlocks.Domain.Exceptions; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BuildingBlocks.Domain.ValueObjects.Ids; | ||
|
||
public record ReminderId | ||
[JsonConverter(typeof(ReminderIdJsonConverter))] | ||
public record ReminderId : StronglyTypedId | ||
{ | ||
private ReminderId(Guid value) | ||
{ | ||
Value = value; | ||
} | ||
private ReminderId(Guid value) : base(value) { } | ||
|
||
public Guid Value { get; } | ||
public static ReminderId Of(Guid value) => new(value); | ||
|
||
public static ReminderId Of(Guid value) | ||
{ | ||
if (value == Guid.Empty) throw new EmptyIdException("ReminderId cannot be empty."); | ||
|
||
return new ReminderId(value); | ||
} | ||
private class ReminderIdJsonConverter : StronglyTypedIdJsonConverter<ReminderId>; | ||
} |
19 changes: 6 additions & 13 deletions
19
Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
using BuildingBlocks.Domain.Exceptions; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BuildingBlocks.Domain.ValueObjects.Ids; | ||
|
||
public record TimelineId | ||
[JsonConverter(typeof(TimelineIdJsonConverter))] | ||
public record TimelineId : StronglyTypedId | ||
{ | ||
private TimelineId(Guid value) | ||
{ | ||
Value = value; | ||
} | ||
private TimelineId(Guid value) : base(value) { } | ||
|
||
public Guid Value { get; } | ||
public static TimelineId Of(Guid value) => new(value); | ||
|
||
public static TimelineId Of(Guid value) | ||
{ | ||
if (value == Guid.Empty) throw new EmptyIdException("TimelineId cannot be empty."); | ||
|
||
return new TimelineId(value); | ||
} | ||
private class TimelineIdJsonConverter : StronglyTypedIdJsonConverter<TimelineId>; | ||
} |
40 changes: 40 additions & 0 deletions
40
Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/StronglyTypedId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json; | ||
|
||
namespace BuildingBlocks.Domain.ValueObjects; | ||
|
||
public abstract record StronglyTypedId | ||
{ | ||
protected StronglyTypedId(Guid value) | ||
{ | ||
if (value == Guid.Empty) | ||
throw new ArgumentException($"{GetType().Name} cannot be empty.", nameof(value)); | ||
|
||
Value = value; | ||
} | ||
|
||
public Guid Value { get; } | ||
|
||
public override string ToString() => Value.ToString(); | ||
} | ||
|
||
public class StronglyTypedIdJsonConverter<T> : JsonConverter<T> where T : StronglyTypedId | ||
{ | ||
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var value = reader.GetString(); | ||
|
||
if (Guid.TryParse(value, out var guid)) | ||
{ | ||
var constructor = typeof(T).GetConstructor(new[] { typeof(Guid) }); | ||
|
||
if (constructor != null) | ||
return (T)constructor.Invoke(new object[] { guid }); | ||
} | ||
|
||
throw new JsonException($"Invalid GUID format for {typeof(T).Name}: {value}"); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) => | ||
writer.WriteStringValue(value.Value.ToString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters