-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
316 additions
and
163 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
src/Inc.TeamAssistant.Appraiser.Backend/Controllers/CheckInController.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
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
52 changes: 9 additions & 43 deletions
52
src/Inc.TeamAssistant.Appraiser.Backend/Services/CheckIn/CheckInService.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,66 +1,32 @@ | ||
using GeoTimeZone; | ||
using Inc.TeamAssistant.Appraiser.Model.CheckIn; | ||
using Inc.TeamAssistant.Appraiser.Model.CheckIn.Queries.GetLocations; | ||
using Inc.TeamAssistant.Appraiser.Model.Common; | ||
using Inc.TeamAssistant.CheckIn.All.Contracts; | ||
using Inc.TeamAssistant.CheckIn.All.Model; | ||
using Inc.TeamAssistant.CheckIn.Model; | ||
using Inc.TeamAssistant.CheckIn.Model.Queries.GetLocations; | ||
using MediatR; | ||
|
||
namespace Inc.TeamAssistant.Appraiser.Backend.Services.CheckIn; | ||
|
||
internal sealed class CheckInService : ICheckInService | ||
{ | ||
private readonly ILocationsRepository _locationsRepository; | ||
private readonly ILogger<CheckInService> _logger; | ||
private readonly IMediator _mediator; | ||
|
||
public CheckInService(ILocationsRepository locationsRepository, ILogger<CheckInService> logger) | ||
public CheckInService(IMediator mediator) | ||
{ | ||
_locationsRepository = locationsRepository ?? throw new ArgumentNullException(nameof(locationsRepository)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); | ||
} | ||
|
||
public async Task<ServiceResult<GetLocationsResult?>> GetLocations(Guid mapId, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var locations = await _locationsRepository.GetLocations(mapId, cancellationToken); | ||
var result = await _mediator.Send(new GetLocationsQuery(mapId), cancellationToken); | ||
|
||
return locations.Any() | ||
? ServiceResult.Success((GetLocationsResult?)new(locations | ||
.GroupBy(l => l.DisplayName) | ||
.ToDictionary(l => l.Key, l => (IReadOnlyCollection<LocationDto>)l | ||
.OrderByDescending(i => i.Created) | ||
.Select(ConvertFrom) | ||
.ToArray()))) | ||
return result.Locations.Any() | ||
? ServiceResult.Success((GetLocationsResult?)result) | ||
: ServiceResult.NotFound<GetLocationsResult?>(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ServiceResult.Failed<GetLocationsResult?>(ex.Message); | ||
} | ||
} | ||
|
||
private LocationDto ConvertFrom(LocationOnMap location) | ||
{ | ||
if (location is null) | ||
throw new ArgumentNullException(nameof(location)); | ||
|
||
TimeSpan? baseUtcOffset = null; | ||
|
||
try | ||
{ | ||
var timeZoneId = TimeZoneLookup.GetTimeZone(location.Latitude, location.Longitude).Result; | ||
var timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); | ||
baseUtcOffset = timeZone.BaseUtcOffset; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogWarning( | ||
ex, | ||
"Can not detect time zone for location (Latitude: {Latitude}, Longitude: {Longitude})", | ||
location.Latitude, | ||
location.Longitude); | ||
} | ||
|
||
return new(location.DisplayName, location.Longitude, location.Latitude, baseUtcOffset); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
src/Inc.TeamAssistant.Appraiser.Backend/Services/CheckIn/DummyLocationBuilder.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
2 changes: 1 addition & 1 deletion
2
src/Inc.TeamAssistant.Appraiser.Backend/Services/CheckIn/TranslateProvider.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
34 changes: 0 additions & 34 deletions
34
src/Inc.TeamAssistant.CheckIn.All/ServiceCollectionExtensions.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...amAssistant.CheckIn.All/CheckInOptions.cs → ...ant.CheckIn.Application/CheckInOptions.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
39 changes: 39 additions & 0 deletions
39
...nt.CheckIn.Application/CommandHandlers/AddLocationToMap/AddLocationToMapCommandHandler.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,39 @@ | ||
using Inc.TeamAssistant.CheckIn.Application.Contracts; | ||
using Inc.TeamAssistant.CheckIn.Domain; | ||
using Inc.TeamAssistant.CheckIn.Model.Commands.AddLocationToMap; | ||
using MediatR; | ||
|
||
namespace Inc.TeamAssistant.CheckIn.Application.CommandHandlers.AddLocationToMap; | ||
|
||
internal sealed class AddLocationToMapCommandHandler : IRequestHandler<AddLocationToMapCommand, AddLocationToMapResult> | ||
{ | ||
private readonly ILocationsRepository _locationsRepository; | ||
|
||
public AddLocationToMapCommandHandler(ILocationsRepository locationsRepository) | ||
{ | ||
_locationsRepository = locationsRepository ?? throw new ArgumentNullException(nameof(locationsRepository)); | ||
} | ||
|
||
public async Task<AddLocationToMapResult> Handle( | ||
AddLocationToMapCommand command, | ||
CancellationToken cancellationToken) | ||
{ | ||
if (command is null) | ||
throw new ArgumentNullException(nameof(command)); | ||
|
||
var existsMap = await _locationsRepository.Find(command.ChatId, cancellationToken); | ||
var map = existsMap ?? new(command.ChatId); | ||
|
||
var location = new LocationOnMap( | ||
command.UserId, | ||
command.DisplayName, | ||
command.Longitude, | ||
command.Latitude, | ||
command.Data, | ||
map); | ||
|
||
await _locationsRepository.Insert(location, cancellationToken); | ||
|
||
return new AddLocationToMapResult(map.Id, FirstLocationOnMap: existsMap is null); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...kIn.All/Contracts/ILocationsRepository.cs → ...ication/Contracts/ILocationsRepository.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
2 changes: 1 addition & 1 deletion
2
...eckIn.All/Contracts/ITranslateProvider.cs → ...plication/Contracts/ITranslateProvider.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
Oops, something went wrong.