-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from moreal/tip
feat(api): provide tip index
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 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,19 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Mimir.Models.Metadata; | ||
using Mimir.Repositories; | ||
|
||
namespace Mimir.Controllers; | ||
|
||
[ApiController] | ||
[Route("{network}")] | ||
public class MetadataController : ControllerBase | ||
{ | ||
[HttpGet("tip")] | ||
public async Task<GetTipResponse> GetTip( | ||
string network, | ||
MetadataRepository metadataRepository | ||
) | ||
{ | ||
return new GetTipResponse(await metadataRepository.GetLatestBlockIndex(network)); | ||
} | ||
} |
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,5 @@ | ||
namespace Mimir.Models.Metadata; | ||
|
||
public record GetTipResponse( | ||
long Index | ||
); |
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,26 @@ | ||
using Mimir.Models.Avatar; | ||
using Mimir.Services; | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
|
||
namespace Mimir.Repositories; | ||
|
||
public class MetadataRepository : BaseRepository<BsonDocument> | ||
{ | ||
public MetadataRepository(MongoDBCollectionService mongoDBCollectionService) | ||
: base(mongoDBCollectionService) | ||
{ | ||
} | ||
|
||
protected override string GetCollectionName() | ||
{ | ||
return "metadata"; | ||
} | ||
|
||
public async Task<long> GetLatestBlockIndex(string network) | ||
{ | ||
var filter = Builders<BsonDocument>.Filter.Eq("_id", "SyncContext"); | ||
var doc = await GetCollection(network).FindSync(filter).FirstAsync(); | ||
return doc.GetValue("LatestBlockIndex").AsInt64; | ||
} | ||
} |