Skip to content

Commit

Permalink
Fix tests, fix places job
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavAntonyuk committed Dec 30, 2024
1 parent e1b37ee commit 4ac56b4
Show file tree
Hide file tree
Showing 33 changed files with 285 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/Client/Client/Controls/RatingControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private Label CreateLabel(State state, int i)

if (AllowRating)
{
label.GestureRecognizers.Add(new TapGestureRecognizer()
label.GestureRecognizers.Add(new TapGestureRecognizer
{
NumberOfTapsRequired = 1,
Command = new Command(() => Value = i)
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Client/Framework/BaseContentPage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Client.Framework;

using CommunityToolkit.Maui.Behaviors;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;

Expand All @@ -12,7 +13,7 @@ protected BaseContentPage(T viewModel)
On<iOS>().SetUseSafeArea(true);
if (OperatingSystem.IsAndroid() || OperatingSystem.IsOSPlatformVersionAtLeast("iOS", 15))
{
Behaviors.Add(new CommunityToolkit.Maui.Behaviors.StatusBarBehavior
Behaviors.Add(new StatusBarBehavior
{
StatusBarColor = BackgroundColor
});
Expand Down
8 changes: 5 additions & 3 deletions src/Client/Client/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ public static MauiApp CreateMauiApp()
#endif
});

builder.UseMauiCommunityToolkit(x =>
{
builder.UseMauiCommunityToolkit(
#if !DEBUG
x =>
{
x.SetShouldSuppressExceptionsInConverters(true);
x.SetShouldSuppressExceptionsInBehaviors(true);
x.SetShouldSuppressExceptionsInAnimations(true);
}
#endif
});
);

builder.Services.AddSingleton<INavigationService, NavigationService>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace WorldExplorer.Modules.Places.Application.Places.DeletePlaces;

using Common.Application.EventBus;
using Common.Application.Messaging;
using Common.Domain;
using Domain.Places;
using IntegrationEvents;
using WorldExplorer.Common.Application.EventBus;

internal sealed class DeletePlacesCommandHandler(IPlaceRepository placeRepository, IEventBus eventBus)
: ICommandHandler<DeletePlacesCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ private Place()

public static Place Create(string name, Point location)
{
var place = new Place()
var place = new Place
{
Id = Guid.CreateVersion7(),
Name = name,
Location = location
Location = location,
CreatedAt = DateTimeOffset.UtcNow
};

place.Raise(new PlaceCreatedDomainEvent(place.Id));
return place;
}

public Guid Id { get; private init; }
public DateTimeOffset CreatedAt { get; private init; }
public string Name { get; private set; }
public Point Location { get; private set; }
public string? Description { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class PointJsonConverterTests
{
private readonly JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions()
private readonly JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
{
Converters =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The output must contain only JSON because I will parse it later. Do not include
}
""";

var options = new ChatOptions()
var options = new ChatOptions
{
ResponseFormat = ChatResponseFormat.Json
};
Expand All @@ -54,7 +54,7 @@ The output must contain only the detailed information because I will parse it la
Dmytro Yavornytsky National Historical Museum of Dnipro is a museum, established in Dnipro (Ukraine) in 1848 by Andriy Fabr, local governor. Its permanent collection consists of 283 thousand objects from ancient Paleolithic implements to display units of World War II. Among its notable objects are the Kurgan stelae, Kernosivsky idol and vast collection of cossack's antiquities.
""";

return GetResponse(generalPrompt, new ChatOptions() { ResponseFormat = ChatResponseFormat.Text }, cancellationToken);
return GetResponse(generalPrompt, new ChatOptions { ResponseFormat = ChatResponseFormat.Text }, cancellationToken);
}

private async Task<string?> GetResponse(string request,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Location = table.Column<Point>(type: "geography", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");

b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetimeoffset");

b.Property<string>("Description")
.HasColumnType("nvarchar(max)");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
using Microsoft.Extensions.Options;
using Quartz;

internal sealed class ConfigureProcessOutboxJob(IOptions<OutboxOptions> outboxOptions)
: IConfigureOptions<QuartzOptions>
internal sealed class ConfigureProcessOutboxJob(IOptions<OutboxOptions> outboxOptions) : IConfigureOptions<QuartzOptions>
{
private readonly OutboxOptions _outboxOptions = outboxOptions.Value;

public void Configure(QuartzOptions options)
{
var jobName = typeof(ProcessOutboxJob).FullName!;

options.AddJob<ProcessOutboxJob>(configure => configure.WithIdentity(jobName))
.AddTrigger(configure =>
configure.ForJob(jobName)
.WithSimpleSchedule(schedule =>
schedule.WithIntervalInSeconds(
_outboxOptions.IntervalInSeconds)
.RepeatForever()));
.AddTrigger(configure =>
{
configure.ForJob(jobName)
.WithSimpleSchedule(schedule =>
{
schedule
.WithIntervalInSeconds(outboxOptions.Value.IntervalInSeconds)
.RepeatForever();
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,42 @@
using Microsoft.Extensions.Options;
using Quartz;

internal sealed class ConfigurePlacesJob : IConfigureOptions<QuartzOptions>
internal sealed class ConfigurePlacesJob(IOptions<PlacesJobOptions> placesJobOptions) : IConfigureOptions<QuartzOptions>
{
public void Configure(QuartzOptions options)
{
var placeLookupJobName = typeof(PlacesLookupJob).FullName!;

options.AddJob<PlacesLookupJob>(configure => configure.WithIdentity(placeLookupJobName))
.AddTrigger(configure => configure.ForJob(placeLookupJobName)
.WithSimpleSchedule(schedule =>
schedule.WithIntervalInSeconds(15)
.RepeatForever()));
.AddTrigger(configure =>
{
configure.ForJob(placeLookupJobName)
.WithSimpleSchedule(schedule =>
{
schedule
.WithIntervalInSeconds(placesJobOptions.Value.IntervalInSeconds)
.RepeatForever();
});
});

var placeConfigurationJobName = typeof(PlaceDetailsJob).FullName!;

options.AddJob<PlaceDetailsJob>(configure => configure.WithIdentity(placeConfigurationJobName))
.AddTrigger(configure => configure.ForJob(placeConfigurationJobName)
.WithSimpleSchedule(schedule =>
schedule.WithIntervalInSeconds(15)
.RepeatForever()));
.AddTrigger(configure =>
{
configure.ForJob(placeConfigurationJobName)
.WithSimpleSchedule(schedule =>
{
schedule
.WithIntervalInSeconds(placesJobOptions.Value.IntervalInSeconds)
.RepeatForever();
});
});
}
}

internal sealed class PlacesJobOptions
{
public int IntervalInSeconds { get; init; }
public int BatchSize { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Image;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Quartz;

[DisallowConcurrentExecution]
Expand All @@ -15,6 +16,7 @@ internal sealed class PlaceDetailsJob(
IUnitOfWork unitOfWork,
IAiService aiService,
IImageSearchService imageSearchService,
IOptions<PlacesJobOptions> placeJobOptions,
ILogger<PlaceDetailsJob> logger) : IJob
{
private const string ModuleName = "Places";
Expand All @@ -27,7 +29,8 @@ public async Task Execute(IJobExecutionContext context)
.AsTracking()
.Include(x => x.Images)
.Where(x => x.Images.Count == 0 || string.IsNullOrEmpty(x.Description))
.OrderBy(x => x.Images.Count)
.OrderBy(x => x.CreatedAt)
.Take(placeJobOptions.Value.BatchSize)
.ToListAsync(context.CancellationToken);

if (notFilledPlaces.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ private static void AddInfrastructure(this IHostApplicationBuilder builder)
builder.Services.AddHttpClient("ImageSearch");
builder.Services.AddSingleton<IImageSearchService, ImageSearchService>();

builder.Services.ConfigureOptions<ConfigurePlacesJob>();
builder.Services.Configure<PlacesSettings>(builder.Configuration);
builder.Services.Configure<PlacesJobOptions>(builder.Configuration.GetSection("Places:Jobs"));
builder.Services.ConfigureOptions<ConfigurePlacesJob>();

builder.Services.Configure<OutboxOptions>(builder.Configuration.GetSection("Places:Outbox"));

builder.Services.ConfigureOptions<ConfigureProcessOutboxJob>();

SerializerSettings.ConfigureJsonSerializerOptionsInstance([new PointJsonConverter()]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace WorldExplorer.Modules.Places.Infrastructure;

using System.Text.Json;
using System.Text.Json.Serialization;
using NetTopologySuite.Geometries;

public class PointJsonConverter : System.Text.Json.Serialization.JsonConverter<Point>
public class PointJsonConverter : JsonConverter<Point>
{
public override Point Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace WorldExplorer.Modules.Places.Presentation.LocationInfoRequests;

using Application.LocationInfoRequests.GetLocationInfoRequest;
using Common.Infrastructure.Authorization;
using Common.Presentation.Endpoints;
using Common.Presentation.Results;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using WorldExplorer.Common.Infrastructure.Authorization;
using WorldExplorer.Common.Presentation.Endpoints;
using WorldExplorer.Common.Presentation.Results;
using WorldExplorer.Modules.Places.Application.LocationInfoRequests.GetLocationInfoRequest;

internal sealed class GetLocationInfoRequest : IEndpoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace WorldExplorer.Modules.Travellers.Application.Travellers.DeleteTraveller;

using WorldExplorer.Common.Application.Messaging;
using Common.Application.Messaging;

public sealed record DeleteTravellerCommand(Guid TravellerId) : ICommand;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace WorldExplorer.Modules.Travellers.Application.Travellers.DeleteTraveller;

using WorldExplorer.Common.Application.Messaging;
using WorldExplorer.Common.Domain;
using WorldExplorer.Modules.Travellers.Abstractions.Data;
using Abstractions.Data;
using Common.Application.Messaging;
using Common.Domain;

internal sealed class DeleteTravellerCommandHandler(ITravellerRepository travellerRepository, IUnitOfWork unitOfWork)
: ICommandHandler<DeleteTravellerCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public class CreateVisitHandler(TravellersDbContext context)
{
public async Task<Visit> CreateVisit(VisitRequest request, CancellationToken ct = default)
{
var visit = new Visit()
var visit = new Visit
{
Id = Guid.CreateVersion7(),
PlaceId = request.PlaceId,
TravellerId = request.TravellerId,
VisitDate = DateTime.UtcNow,
Review = new Review()
Review = new Review
{
Id = Guid.CreateVersion7(),
Comment = request.Comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
using Microsoft.Extensions.Options;
using Quartz;

internal sealed class ConfigureProcessInboxJob(IOptions<InboxOptions> outboxOptions) : IConfigureOptions<QuartzOptions>
internal sealed class ConfigureProcessInboxJob(IOptions<InboxOptions> inboxOptions) : IConfigureOptions<QuartzOptions>
{
private readonly InboxOptions _inboxOptions = outboxOptions.Value;

public void Configure(QuartzOptions options)
{
var jobName = typeof(ProcessInboxJob).FullName!;

options.AddJob<ProcessInboxJob>(configure => configure.WithIdentity(jobName))
.AddTrigger(configure =>
configure.ForJob(jobName)
.WithSimpleSchedule(schedule =>
schedule.WithIntervalInSeconds(
_inboxOptions.IntervalInSeconds)
.RepeatForever()));
{
configure.ForJob(jobName)
.WithSimpleSchedule(schedule =>
{
schedule
.WithIntervalInSeconds(inboxOptions.Value.IntervalInSeconds)
.RepeatForever();
});
});
}
}
Loading

0 comments on commit 4ac56b4

Please sign in to comment.