-
Notifications
You must be signed in to change notification settings - Fork 51
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
56b20d3
commit 96fd79d
Showing
23 changed files
with
1,937 additions
and
190 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
|
||
using Amazon.SecurityToken.Model; | ||
|
||
using LiteDB; | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
using WitsmlExplorer.Api.Models; | ||
using WitsmlExplorer.Api.Repositories; | ||
using WitsmlExplorer.Api.Services; | ||
|
||
namespace WitsmlExplorer.Api.HttpHandlers | ||
{ | ||
public static class UidMappingHandler | ||
{ | ||
[Produces(typeof(UidMapping))] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status409Conflict)] | ||
public static async Task<IResult> CreateUidMapping([FromBody] UidMapping uidMapping, [FromServices] IUidMappingService uidMappingService, HttpContext httpContext) | ||
{ | ||
if (!Validate(uidMapping)) | ||
{ | ||
return TypedResults.BadRequest(); | ||
} | ||
|
||
var result = await uidMappingService.CreateUidMapping(uidMapping, httpContext); | ||
|
||
if (result != null) | ||
{ | ||
return TypedResults.Ok(uidMapping); | ||
} | ||
else | ||
{ | ||
return TypedResults.Conflict(); | ||
} | ||
} | ||
|
||
[Produces(typeof(UidMapping))] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
public static async Task<IResult> UpdateUidMapping([FromBody] UidMapping uidMapping, [FromServices] IUidMappingService uidMappingService, HttpContext httpContext) | ||
{ | ||
if (!Validate(uidMapping)) | ||
{ | ||
return TypedResults.BadRequest(); | ||
} | ||
|
||
var result = await uidMappingService.UpdateUidMapping(uidMapping, httpContext); | ||
|
||
if (result != null) | ||
{ | ||
return TypedResults.Ok(uidMapping); | ||
} | ||
else | ||
{ | ||
return TypedResults.NotFound(); | ||
} | ||
} | ||
|
||
[Produces(typeof(ICollection<UidMapping>))] | ||
public static async Task<IResult> QueryUidMapping([FromBody] UidMappingDbQuery query, [FromServices] IUidMappingService uidMappingService) | ||
{ | ||
return TypedResults.Ok(await uidMappingService.QueryUidMapping(query)); | ||
} | ||
|
||
[ProducesResponseType(StatusCodes.Status204NoContent)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
public static async Task<IResult> QueryDeleteUidMapping([FromBody] UidMappingDbQuery query, [FromServices] IUidMappingService uidMappingService) | ||
{ | ||
if (await uidMappingService.QueryDeleteUidMapping(query)) | ||
{ | ||
return TypedResults.NoContent(); | ||
} | ||
else | ||
{ | ||
return TypedResults.NotFound(); | ||
} | ||
} | ||
|
||
private static bool Validate(UidMapping uidMapping) | ||
{ | ||
return !(uidMapping == null || uidMapping.SourceServerId == Guid.Empty || uidMapping.TargetServerId == Guid.Empty | ||
|| uidMapping.SourceWellId.IsNullOrEmpty() || uidMapping.TargetWellId.IsNullOrEmpty() | ||
|| uidMapping.SourceWellboreId.IsNullOrEmpty() || uidMapping.TargetWellboreId.IsNullOrEmpty()); | ||
} | ||
|
||
} | ||
} |
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,81 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
using WitsmlExplorer.Api.Repositories; | ||
|
||
namespace WitsmlExplorer.Api.Models | ||
{ | ||
public class UidMapping | ||
{ | ||
[JsonPropertyName("sourceServerId")] | ||
public Guid SourceServerId { get; set; } | ||
|
||
[JsonPropertyName("sourceWellId")] | ||
public string SourceWellId { get; set; } | ||
|
||
[JsonPropertyName("sourceWellboreId")] | ||
public string SourceWellboreId { get; set; } | ||
|
||
[JsonPropertyName("targetServerId")] | ||
public Guid TargetServerId { get; set; } | ||
|
||
[JsonPropertyName("targetWellId")] | ||
public string TargetWellId { get; set; } | ||
|
||
[JsonPropertyName("targetWellboreId")] | ||
public string TargetWellboreId { get; set; } | ||
|
||
[JsonPropertyName("username")] | ||
public string Username { get; set; } | ||
|
||
[JsonPropertyName("timestamp")] | ||
public DateTime? Timestamp { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
} | ||
|
||
public class UidMappingDbQuery | ||
{ | ||
[JsonPropertyName("sourceServerId")] | ||
public Guid SourceServerId { get; set; } | ||
|
||
[JsonPropertyName("sourceWellId")] | ||
public string SourceWellId { get; set; } | ||
|
||
[JsonPropertyName("sourceWellboreId")] | ||
public string SourceWellboreId { get; set; } | ||
|
||
[JsonPropertyName("targetServerId")] | ||
public Guid TargetServerId { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
} | ||
|
||
public class UidMappingKey | ||
{ | ||
public UidMappingKey() { } | ||
public UidMappingKey(Guid sourceServerId, Guid targetServerId) | ||
{ | ||
SourceServerId = sourceServerId; | ||
TargetServerId = targetServerId; | ||
} | ||
|
||
[JsonPropertyName("sourceServerId")] | ||
public Guid SourceServerId { get; set; } | ||
|
||
[JsonPropertyName("targetServerId")] | ||
public Guid TargetServerId { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
} | ||
} |
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,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
using WitsmlExplorer.Api.Repositories; | ||
|
||
namespace WitsmlExplorer.Api.Models | ||
{ | ||
public class UidMappingCollection : DbDocument<UidMappingKey> | ||
{ | ||
public UidMappingCollection(UidMappingKey id) : base(id) | ||
{ | ||
MappingCollection = new List<UidMapping>(); | ||
} | ||
|
||
[JsonPropertyName("mappingCollection")] | ||
public List<UidMapping> MappingCollection { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
} | ||
} |
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.