Move Data.MongoDB to Data
This commit is contained in:
parent
6e412f4f26
commit
005eea35e2
11 changed files with 55 additions and 10 deletions
10
src/Robware.Data/ApiKeyRepository.cs
Normal file
10
src/Robware.Data/ApiKeyRepository.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using Robware.Auth.API;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Robware.Data {
|
||||
public class ApiKeyRepository : IApiKeys {
|
||||
public Task<ApiKey> Get(string key) {
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
15
src/Robware.Data/Robware.Data.csproj
Normal file
15
src/Robware.Data/Robware.Data.csproj
Normal file
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.10.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Robware.Auth\Robware.Auth.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
23
src/Robware.Data/UserRepository.cs
Normal file
23
src/Robware.Data/UserRepository.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using MongoDB.Driver;
|
||||
using Robware.Auth.Users;
|
||||
using Robware.Data.Users;
|
||||
using Robware.Data.Users.States;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Robware.Data {
|
||||
public class UserRepository : IUsers {
|
||||
IMongoCollection<UserState> _collection;
|
||||
|
||||
public UserRepository(IMongoDatabase database) {
|
||||
_collection = database.GetCollection<UserState>("users");
|
||||
}
|
||||
|
||||
public async Task<User> GetByEmail(string email) {
|
||||
var result = (await _collection.FindAsync(user => user.Email == email)).FirstOrDefault();
|
||||
if (result == null)
|
||||
throw new UserNotFoundException(email);
|
||||
|
||||
return new DatabaseUser(result);
|
||||
}
|
||||
}
|
||||
}
|
11
src/Robware.Data/Users/DatabaseUser.cs
Normal file
11
src/Robware.Data/Users/DatabaseUser.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Robware.Auth.Users;
|
||||
using Robware.Data.Users.States;
|
||||
|
||||
namespace Robware.Data.Users {
|
||||
public class DatabaseUser : User {
|
||||
public DatabaseUser(UserState state) {
|
||||
Username = state.Email;
|
||||
Password = state.Password;
|
||||
}
|
||||
}
|
||||
}
|
12
src/Robware.Data/Users/States/UserState.cs
Normal file
12
src/Robware.Data/Users/States/UserState.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
|
||||
namespace Robware.Data.Users.States {
|
||||
public class UserState {
|
||||
[BsonId]
|
||||
public int Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public DateTime Created{ get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue