-
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.
- Loading branch information
1 parent
21c1592
commit 386c958
Showing
34 changed files
with
1,724 additions
and
1,854 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,12 @@ namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration; | |
|
||
public record ClockodoEinstellungen | ||
{ | ||
public required string ApiToken { get; init; } | ||
public required string EmailAddress { get; init; } | ||
public required string ApiToken { get; init; } | ||
public required string EmailAddress { get; init; } | ||
|
||
public TimeEntriesServiceSettings ClockodoCredentials => | ||
new(EmailAddress, ApiToken, "co-IT Clockodo Quick Actions", "[email protected]"); | ||
public TimeEntriesServiceSettings ClockodoCredentials => | ||
new(EmailAddress, ApiToken, "co-IT Clockodo Quick Actions", "[email protected]"); | ||
|
||
public ApiConnectionSettings CreateApiConnectionSettings => | ||
new ApiConnectionSettings( | ||
EmailAddress, | ||
ApiToken, | ||
"co-IT Clockodo Quick Actions", | ||
"[email protected]", | ||
new Uri("https://my.clockodo.com/") | ||
); | ||
public ApiConnectionSettings CreateApiConnectionSettings => | ||
new(EmailAddress, ApiToken, "co-IT Clockodo Quick Actions", "[email protected]", new Uri("https://my.clockodo.com/")); | ||
} |
79 changes: 34 additions & 45 deletions
79
Einstellungen/ClockodoKonfiguration/ClockodoKonfigurationDataTableRepository.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,56 +1,45 @@ | ||
using System.Threading; | ||
using Azure; | ||
using Azure.Data.Tables; | ||
using coIT.Libraries.Clockodo.Absences; | ||
using coIT.Libraries.ConfigurationManager.Cryptography; | ||
using CSharpFunctionalExtensions; | ||
|
||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration | ||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration; | ||
|
||
public class ClockodoKonfigurationDataTableRepository : IClockodoKonfigurationRepository | ||
{ | ||
public class ClockodoKonfigurationDataTableRepository : IClockodoKonfigurationRepository | ||
{ | ||
private readonly ClockodoKonfigurationMapper _mapper; | ||
private readonly TableClient _tableClient; | ||
private readonly ClockodoKonfigurationMapper _mapper; | ||
private readonly TableClient _tableClient; | ||
|
||
public ClockodoKonfigurationDataTableRepository( | ||
string connectionString, | ||
IDoCryptography cryptographyService | ||
) | ||
{ | ||
_mapper = new ClockodoKonfigurationMapper(cryptographyService); | ||
_tableClient = new TableClient( | ||
connectionString, | ||
ClockodoKonfigurationEntity.TabellenName | ||
); | ||
} | ||
public ClockodoKonfigurationDataTableRepository(string connectionString, IDoCryptography cryptographyService) | ||
{ | ||
_mapper = new ClockodoKonfigurationMapper(cryptographyService); | ||
_tableClient = new TableClient(connectionString, ClockodoKonfigurationEntity.TabellenName); | ||
} | ||
|
||
public async Task<Result<ClockodoEinstellungen>> Get( | ||
CancellationToken cancellationToken = default | ||
public async Task<Result<ClockodoEinstellungen>> Get(CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
return await Result | ||
.Success() | ||
.Map( | ||
() => | ||
_tableClient.GetEntityIfExistsAsync<ClockodoKonfigurationEntity>( | ||
ClockodoKonfigurationEntity.TabellenName, | ||
ClockodoKonfigurationEntity.GlobalIdentifier, | ||
cancellationToken: cancellationToken | ||
) | ||
) | ||
{ | ||
try | ||
{ | ||
return await Result | ||
.Success() | ||
.Map( | ||
() => | ||
_tableClient.GetEntityIfExistsAsync<ClockodoKonfigurationEntity>( | ||
ClockodoKonfigurationEntity.TabellenName, | ||
ClockodoKonfigurationEntity.GlobalIdentifier, | ||
cancellationToken: cancellationToken | ||
) | ||
) | ||
.Ensure( | ||
response => response.HasValue, | ||
$"Der Eintrag mit dem Namen '{ClockodoKonfigurationEntity.GlobalIdentifier}' konnte nicht gefunden werden." | ||
) | ||
.Map(response => response.Value) | ||
.Bind(_mapper.VonEntity!); | ||
} | ||
catch (Exception ex) when (ex is RequestFailedException or InvalidOperationException) | ||
{ | ||
return Result.Failure<ClockodoEinstellungen>(ex.Message); | ||
} | ||
} | ||
.Ensure( | ||
response => response.HasValue, | ||
$"Der Eintrag mit dem Namen '{ClockodoKonfigurationEntity.GlobalIdentifier}' konnte nicht gefunden werden." | ||
) | ||
.Map(response => response.Value) | ||
.Bind(_mapper.VonEntity!); | ||
} | ||
catch (Exception ex) when (ex is RequestFailedException or InvalidOperationException) | ||
{ | ||
return Result.Failure<ClockodoEinstellungen>(ex.Message); | ||
} | ||
} | ||
} |
45 changes: 23 additions & 22 deletions
45
Einstellungen/ClockodoKonfiguration/ClockodoKonfigurationEntity.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,30 +1,31 @@ | ||
using Azure; | ||
using Azure.Data.Tables; | ||
|
||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration | ||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration; | ||
|
||
internal class ClockodoKonfigurationEntity : ITableEntity | ||
{ | ||
internal class ClockodoKonfigurationEntity : ITableEntity | ||
{ | ||
internal static readonly string TabellenName = "ClockodoKonfiguration"; | ||
internal static readonly string TabellenName = "ClockodoKonfiguration"; | ||
|
||
// Globale Konfiguration für alle Nutzer | ||
internal static readonly string GlobalIdentifier = "global"; | ||
|
||
public string EmailAddress { get; set; } | ||
Check warning on line 13 in Einstellungen/ClockodoKonfiguration/ClockodoKonfigurationEntity.cs
|
||
public string ApiToken { get; set; } | ||
Check warning on line 14 in Einstellungen/ClockodoKonfiguration/ClockodoKonfigurationEntity.cs
|
||
public string BaseAddress { get; set; } | ||
Check warning on line 15 in Einstellungen/ClockodoKonfiguration/ClockodoKonfigurationEntity.cs
|
||
|
||
// Globale Konfiguration für alle Nutzer | ||
internal static readonly string GlobalIdentifier = "global"; | ||
public string PartitionKey | ||
{ | ||
get => TabellenName; | ||
set { } | ||
} | ||
|
||
public string PartitionKey | ||
{ | ||
get { return TabellenName; } | ||
set { return; } | ||
} | ||
public string RowKey | ||
{ | ||
get { return GlobalIdentifier; } | ||
set { return; } | ||
} | ||
public DateTimeOffset? Timestamp { get; set; } | ||
public ETag ETag { get; set; } | ||
public string RowKey | ||
{ | ||
get => GlobalIdentifier; | ||
set { } | ||
} | ||
|
||
public string EmailAddress { get; set; } | ||
public string ApiToken { get; set; } | ||
public string BaseAddress { get; set; } | ||
} | ||
public DateTimeOffset? Timestamp { get; set; } | ||
public ETag ETag { get; set; } | ||
} |
34 changes: 14 additions & 20 deletions
34
Einstellungen/ClockodoKonfiguration/ClockodoKonfigurationMapper.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,27 +1,21 @@ | ||
using coIT.Libraries.Clockodo.Absences; | ||
using coIT.Libraries.ConfigurationManager.Cryptography; | ||
using CSharpFunctionalExtensions; | ||
|
||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration | ||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration; | ||
|
||
internal class ClockodoKonfigurationMapper | ||
{ | ||
internal class ClockodoKonfigurationMapper | ||
{ | ||
private readonly IDoCryptography _cryptographyService; | ||
private readonly IDoCryptography _cryptographyService; | ||
|
||
public ClockodoKonfigurationMapper(IDoCryptography cryptographyService) | ||
{ | ||
_cryptographyService = cryptographyService; | ||
} | ||
public ClockodoKonfigurationMapper(IDoCryptography cryptographyService) | ||
{ | ||
_cryptographyService = cryptographyService; | ||
} | ||
|
||
public Result<ClockodoEinstellungen> VonEntity(ClockodoKonfigurationEntity entity) | ||
{ | ||
return _cryptographyService | ||
.Decrypt(entity.ApiToken) | ||
.Map(apiToken => new ClockodoEinstellungen | ||
{ | ||
ApiToken = apiToken, | ||
EmailAddress = entity.EmailAddress, | ||
}); | ||
} | ||
} | ||
public Result<ClockodoEinstellungen> VonEntity(ClockodoKonfigurationEntity entity) | ||
{ | ||
return _cryptographyService | ||
.Decrypt(entity.ApiToken) | ||
.Map(apiToken => new ClockodoEinstellungen { ApiToken = apiToken, EmailAddress = entity.EmailAddress }); | ||
} | ||
} |
11 changes: 4 additions & 7 deletions
11
Einstellungen/ClockodoKonfiguration/IClockodoKonfigurationRepository.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,11 +1,8 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration | ||
namespace coIT.Toolkit.QuickActions.Einstellungen.ClockodoKonfiguration; | ||
|
||
public interface IClockodoKonfigurationRepository | ||
{ | ||
public interface IClockodoKonfigurationRepository | ||
{ | ||
public Task<Result<ClockodoEinstellungen>> Get( | ||
CancellationToken cancellationToken = default | ||
); | ||
} | ||
public Task<Result<ClockodoEinstellungen>> Get(CancellationToken cancellationToken = default); | ||
} |
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,7 +1,6 @@ | ||
namespace coIT.Toolkit.QuickActions.Einstellungen.DatabaseKonfiguration | ||
namespace coIT.Toolkit.QuickActions.Einstellungen.DatabaseKonfiguration; | ||
|
||
internal record DatabaseEinstellungen | ||
{ | ||
internal record DatabaseEinstellungen | ||
{ | ||
public required string ConnectionString { get; init; } | ||
} | ||
public required string ConnectionString { get; init; } | ||
} |
Oops, something went wrong.