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

Add Create Reminder and Create Timeline functionality Integration Tests #54

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace BuildingBlocks.Domain.ValueObjects.Ids;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace BuildingBlocks.Domain.ValueObjects.Ids;

[JsonConverter(typeof(ReminderIdJsonConverter))]
public class ReminderId : StronglyTypedId
{
private ReminderId(Guid value) : base(value) { }
Expand All @@ -8,3 +12,44 @@ private ReminderId(Guid value) : base(value) { }

public override string ToString() => Value.ToString();
}

public class ReminderIdJsonConverter : JsonConverter<ReminderId>
{
public override ReminderId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (reader.TokenType)
{
case JsonTokenType.String:
{
var guidString = reader.GetString();
if (!Guid.TryParse(guidString, out var guid))
throw new JsonException($"Invalid GUID format for ReminderId: {guidString}");

return ReminderId.Of(guid);
}
case JsonTokenType.StartObject:
{
using var jsonDoc = JsonDocument.ParseValue(ref reader);

if (!jsonDoc.RootElement.TryGetProperty("id", out JsonElement idElement))
throw new JsonException("Expected property 'id' not found.");

var guidString = idElement.GetString();

if (!Guid.TryParse(guidString, out var guid))
throw new JsonException($"Invalid GUID format for ReminderId: {guidString}");

return ReminderId.Of(guid);
}
default:
throw new JsonException(
$"Unexpected token parsing ReminderId. Expected String or StartObject, got {reader.TokenType}.");
}
}

public override void Write(Utf8JsonWriter writer, ReminderId value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace BuildingBlocks.Domain.ValueObjects.Ids;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace BuildingBlocks.Domain.ValueObjects.Ids;

[JsonConverter(typeof(TimelineIdJsonConverter))]
public class TimelineId : StronglyTypedId
{
private TimelineId(Guid value) : base(value) { }
Expand All @@ -8,3 +12,44 @@ private TimelineId(Guid value) : base(value) { }

public override string ToString() => Value.ToString();
}

public class TimelineIdJsonConverter : JsonConverter<TimelineId>
{
public override TimelineId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (reader.TokenType)
{
case JsonTokenType.String:
{
var guidString = reader.GetString();
if (!Guid.TryParse(guidString, out var guid))
throw new JsonException($"Invalid GUID format for TimelineId: {guidString}");

return TimelineId.Of(guid);
}
case JsonTokenType.StartObject:
{
using var jsonDoc = JsonDocument.ParseValue(ref reader);

if (!jsonDoc.RootElement.TryGetProperty("id", out JsonElement idElement))
throw new JsonException("Expected property 'id' not found.");

var guidString = idElement.GetString();

if (!Guid.TryParse(guidString, out var guid))
throw new JsonException($"Invalid GUID format for TimelineId: {guidString}");

return TimelineId.Of(guid);
}
default:
throw new JsonException(
$"Unexpected token parsing TimelineId. Expected String or StartObject, got {reader.TokenType}.");
}
}

public override void Write(Utf8JsonWriter writer, TimelineId value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Reminders.Application.Entities.Reminders.Commands.CreateReminder;

// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global

namespace Reminders.Api.Endpoints.Reminders;

Expand All @@ -25,7 +27,13 @@ public void AddRoutes(IEndpointRouteBuilder app)
}
}

// ReSharper disable once NotAccessedPositionalProperty.Global
public record CreateReminderRequest(ReminderDto Reminder);
public record CreateReminderRequest
{
public CreateReminderRequest() { }

public CreateReminderRequest(ReminderDto reminder) => Reminder = reminder;

public ReminderDto Reminder { get; set; }
}

public record CreateReminderResponse(ReminderId Id);
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
namespace Reminders.Application.Entities.Reminders.Dtos;

public record ReminderDto(
string Id,
string Title,
string Description,
DateTime DueDateTime,
int Priority,
DateTime NotificationTime,
string Status);
using System.Text.Json.Serialization;

namespace Reminders.Application.Entities.Reminders.Dtos;

public class ReminderDto(
string? id,
string title,
string description,
DateTime dueDateTime,
int priority,
DateTime notificationTime,
string status)
{
[JsonPropertyName("id")] public string? Id { get; } = id;

[JsonPropertyName("title")] public string Title { get; } = title;

[JsonPropertyName("description")] public string Description { get; } = description;

[JsonPropertyName("dueDateTime")] public DateTime DueDateTime { get; } = dueDateTime;

[JsonPropertyName("priority")] public int Priority { get; } = priority;

[JsonPropertyName("notificationTime")] public DateTime NotificationTime { get; } = notificationTime;

[JsonPropertyName("status")] public string Status { get; } = status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Timelines.Application.Entities.Timelines.Commands.CreateTimeline;

// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global

namespace Timelines.Api.Endpoints.Timelines;

Expand All @@ -25,7 +27,13 @@ public void AddRoutes(IEndpointRouteBuilder app)
}
}

// ReSharper disable once NotAccessedPositionalProperty.Global
public record CreateTimelineRequest(TimelineDto Timeline);
public record CreateTimelineRequest
{
public CreateTimelineRequest() { }

public CreateTimelineRequest(TimelineDto timeline) => Timeline = timeline;

public TimelineDto Timeline { get; set; }
}

public record CreateTimelineResponse(TimelineId Id);
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
namespace Timelines.Application.Entities.Timelines.Dtos;
using System.Text.Json.Serialization;

public record TimelineDto(
string Id,
string Title);
namespace Timelines.Application.Entities.Timelines.Dtos;

public class TimelineDto(
string? id,
string title)
{
[JsonPropertyName("id")] public string? Id { get; } = id;

[JsonPropertyName("title")] public string Title { get; } = title;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global

using Core.Api.Sdk.Contracts.Reminders.Dtos;

namespace Core.Api.Sdk.Contracts.Reminders.Commands;

public class CreateReminderRequest
{
public required ReminderDto Reminder { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable ClassNeverInstantiated.Global

using Core.Api.Sdk.Contracts.Reminders.ValueObjects;

namespace Core.Api.Sdk.Contracts.Reminders.Commands;

public class CreateReminderResponse
{
public required ReminderId Id { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedMember.Global

namespace Core.Api.Sdk.Contracts.Reminders.Dtos;

public class ReminderDto
{
public string? Id { get; set; }
public required string Title { get; init; }
public required string Description { get; init; }
public required DateTime DueDateTime { get; init; }
public required int Priority { get; init; }
public required DateTime NotificationTime { get; init; }
public required string Status { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable ClassNeverInstantiated.Global

using Core.Api.Sdk.Contracts.Reminders.Dtos;

namespace Core.Api.Sdk.Contracts.Reminders.Queries;

public class GetReminderByIdResponse
{
public required ReminderDto ReminderDto { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global

namespace Core.Api.Sdk.Contracts.Reminders.ValueObjects;

public class ReminderId
{
public ReminderId() { }

public ReminderId(Guid value) => Value = value;

public Guid Value { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global

using Core.Api.Sdk.Contracts.Timelines.Dtos;

namespace Core.Api.Sdk.Contracts.Timelines.Commands;

public class CreateTimelineRequest
{
public required TimelineDto Timeline { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable ClassNeverInstantiated.Global

using Core.Api.Sdk.Contracts.Timelines.ValueObjects;

namespace Core.Api.Sdk.Contracts.Timelines.Commands;

public class CreateTimelineResponse
{
public required TimelineId Id { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedMember.Global

namespace Core.Api.Sdk.Contracts.Timelines.Dtos;

public class TimelineDto
{
public string? Id { get; set; }
public required string Title { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable ClassNeverInstantiated.Global

using Core.Api.Sdk.Contracts.Timelines.Dtos;

namespace Core.Api.Sdk.Contracts.Timelines.Queries;

public class GetTimelineByIdResponse
{
public required TimelineDto TimelineDto { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global

namespace Core.Api.Sdk.Contracts.Timelines.ValueObjects;

public class TimelineId
{
public TimelineId() { }

public TimelineId(Guid value) => Value = value;

public Guid Value { get; init; }
}
2 changes: 2 additions & 0 deletions Backend/src/Sdk/Core.Api.Sdk/Core.Api.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<ItemGroup>
<ProjectReference Include="..\..\Modules\Nodes\Nodes.Api\Nodes.Api.csproj" />
<ProjectReference Include="..\..\Modules\Reminders\Reminders.Api\Reminders.Api.csproj" />
<ProjectReference Include="..\..\Modules\Timelines\Timelines.Api\Timelines.Api.csproj" />
</ItemGroup>

</Project>
Loading
Loading