generated from fossapps/Micro.Starter
-
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.
feat(API): publish federation compatiable API (#45)
* feat(API): publish federation compatiable API
- Loading branch information
Showing
14 changed files
with
117 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Business; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace API.Tests; | ||
|
||
public class QueryTest | ||
{ | ||
[Test] | ||
public async Task TestKeysReturnsKeys() | ||
{ | ||
var mockKeyService = new Mock<IKeyService>(); | ||
mockKeyService.Setup(x => x.FetchAllKeys()).ReturnsAsync(new List<Key> | ||
{ | ||
new() {Body = "body1", Id = "id1"}, | ||
new() {Body = "body2", Id = "id2"} | ||
}); | ||
var query = new Query(); | ||
var queryResponse = await query.Keys(mockKeyService.Object); | ||
var enumerable = queryResponse.ToList(); | ||
Assert.AreEqual(enumerable.First().Body, "body1"); | ||
Assert.AreEqual(enumerable.First().Id, "id1"); | ||
Assert.AreEqual(enumerable.ElementAt(1).Body, "body2"); | ||
Assert.AreEqual(enumerable.ElementAt(1).Id, "id2"); | ||
} | ||
} |
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,11 @@ | ||
namespace API; | ||
|
||
public class ExceptionHandler : IErrorFilter | ||
{ | ||
public IError OnError(IError error) | ||
{ | ||
return error.Exception == null | ||
? error | ||
: error.WithMessage(error.Exception.Message); | ||
} | ||
} |
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,13 @@ | ||
using API.Types; | ||
using Business; | ||
using Key = API.Types.Key; | ||
|
||
namespace API; | ||
|
||
public class Mutation | ||
{ | ||
public Task<Key> RegisterPublicKey([Service] IKeyService keyService, string publicKey) | ||
public async Task<Key> RegisterPublicKey([Service] IKeyService keyService, string publicKey) | ||
{ | ||
return keyService.Create(publicKey); | ||
return (await keyService.Create(publicKey)).ToGraphQl(); | ||
} | ||
} |
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,17 +1,13 @@ | ||
using API.types; | ||
using API.Types; | ||
using Business; | ||
using Key = API.Types.Key; | ||
|
||
namespace API; | ||
|
||
public class Query | ||
{ | ||
public Task<User> Me() | ||
public async Task<IEnumerable<Key>> Keys([Service] IKeyService keyService) | ||
{ | ||
return Task.FromResult(new User("user_id")); | ||
} | ||
|
||
public Task<IEnumerable<Key>> Keys([Service] IKeyService keyService) | ||
{ | ||
return keyService.FetchAllKeys(); | ||
return (await keyService.FetchAllKeys()).Select(x => x.ToGraphQl()); | ||
} | ||
} |
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,27 @@ | ||
using Business; | ||
|
||
namespace API.Types; | ||
|
||
public sealed record Key | ||
{ | ||
[Key] public string Id { set; get; } | ||
|
||
public string Body { set; get; } | ||
|
||
public static async Task<Key> GetKeyById([Service] IKeyService keyService, string Id) | ||
{ | ||
return (await keyService.FindById(Id)).ToGraphQl(); | ||
} | ||
} | ||
|
||
public static class BusinessKeyExtension | ||
{ | ||
public static Key ToGraphQl(this Business.Key key) | ||
{ | ||
return new Key | ||
{ | ||
Body = key.Body, | ||
Id = key.Id | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Business.Exceptions; | ||
|
||
public class KeyNotFoundException : Exception | ||
{ | ||
public KeyNotFoundException(string? message) : base(message) | ||
{ | ||
} | ||
} |
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
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