mirror of
https://github.com/NecroticBamboo/QRBee.git
synced 2025-12-21 12:11:53 +00:00
Initial immplementation of QRBeeAPI added
This commit is contained in:
parent
575d0ccf0b
commit
2525e37f83
@ -1,6 +1,6 @@
|
|||||||
namespace QRBee.Core
|
namespace QRBee.Core
|
||||||
{
|
{
|
||||||
internal class RegistrationData
|
public record RegistrationRequest
|
||||||
{
|
{
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
@ -26,6 +26,12 @@
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RegisterAsMerchant
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
22
QRBee.Core/Data/RegistrationResponse.cs
Normal file
22
QRBee.Core/Data/RegistrationResponse.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace QRBee.Core.Data
|
||||||
|
{
|
||||||
|
public record RegistrationResponse
|
||||||
|
{
|
||||||
|
public string ClientId
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Certificate
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
16
QRBee.sln
16
QRBee.sln
@ -9,7 +9,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRBee.iOS", "QRBee\QRBee.iO
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee", "QRBee\QRBee\QRBee.csproj", "{9C717836-BE20-4721-877B-8B6250245FF9}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee", "QRBee\QRBee\QRBee.csproj", "{9C717836-BE20-4721-877B-8B6250245FF9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRBeeApi", "QRBeeApi\QRBeeApi.csproj", "{D985A736-12A3-4A7A-B1A7-502321BD460A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee.Api", "QRBeeApi\QRBee.Api.csproj", "{D985A736-12A3-4A7A-B1A7-502321BD460A}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRBee.Core", "QRBee.Core\QRBee.Core.csproj", "{7C461562-66EF-4894-8AD8-F27F0B94053F}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -87,6 +89,18 @@ Global
|
|||||||
{D985A736-12A3-4A7A-B1A7-502321BD460A}.Release|iPhone.Build.0 = Release|Any CPU
|
{D985A736-12A3-4A7A-B1A7-502321BD460A}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
{D985A736-12A3-4A7A-B1A7-502321BD460A}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
{D985A736-12A3-4A7A-B1A7-502321BD460A}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
{D985A736-12A3-4A7A-B1A7-502321BD460A}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
{D985A736-12A3-4A7A-B1A7-502321BD460A}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String></wpf:ResourceDictionary>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mongo/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
28
QRBeeApi/Controllers/QRBeeController.cs
Normal file
28
QRBeeApi/Controllers/QRBeeController.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using QRBee.Api.Services;
|
||||||
|
using QRBee.Core;
|
||||||
|
using QRBee.Core.Data;
|
||||||
|
|
||||||
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
|
|
||||||
|
namespace QRBee.Api.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class QRBeeController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IQRBeeAPI _service;
|
||||||
|
|
||||||
|
public QRBeeController(IQRBeeAPI service)
|
||||||
|
{
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public Task<RegistrationResponse> Register([FromBody] RegistrationRequest value)
|
||||||
|
{
|
||||||
|
return _service.Register(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
17
QRBeeApi/DatabaseSettings.cs
Normal file
17
QRBeeApi/DatabaseSettings.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace QRBee.Api
|
||||||
|
{
|
||||||
|
public class DatabaseSettings
|
||||||
|
{
|
||||||
|
public string? ConnectionString { get; set;}
|
||||||
|
|
||||||
|
public MongoClientSettings ToMongoDbSettings()
|
||||||
|
{
|
||||||
|
var settings = MongoClientSettings.FromConnectionString(ConnectionString);
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,8 @@
|
|||||||
|
using MongoDB.Driver;
|
||||||
|
using QRBee.Api;
|
||||||
|
using QRBee.Api.Services;
|
||||||
|
using QRBee.Api.Services.Database;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
@ -7,6 +12,11 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<IQRBeeAPI,QRBeeAPI>();
|
||||||
|
builder.Services.AddSingleton<IStorage, Storage>();
|
||||||
|
builder.Services.Configure<DatabaseSettings>(builder.Configuration.GetSection("QRBeeDatabase"));
|
||||||
|
builder.Services.AddSingleton<IMongoClient>( cfg => new MongoClient(cfg.GetRequiredService<DatabaseSettings>().ToMongoDbSettings()));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
19
QRBeeApi/QRBee.Api.csproj
Normal file
19
QRBeeApi/QRBee.Api.csproj
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UserSecretsId>3b7dc7f1-0b82-4746-b99b-73c43c8826e0</UserSecretsId>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\QRBee.Core\QRBee.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,13 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
12
QRBeeApi/Services/Database/IStorage.cs
Normal file
12
QRBeeApi/Services/Database/IStorage.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
|
namespace QRBee.Api.Services
|
||||||
|
{
|
||||||
|
public interface IStorage
|
||||||
|
{
|
||||||
|
|
||||||
|
void PutUserInfo(UserInfo info);
|
||||||
|
UserInfo GetUserInfo(string email);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
17
QRBeeApi/Services/Database/Storage.cs
Normal file
17
QRBeeApi/Services/Database/Storage.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace QRBee.Api.Services.Database
|
||||||
|
{
|
||||||
|
public class Storage: IStorage
|
||||||
|
{
|
||||||
|
public void PutUserInfo(UserInfo info)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserInfo GetUserInfo(string email)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
40
QRBeeApi/Services/Database/UserInfo.cs
Normal file
40
QRBeeApi/Services/Database/UserInfo.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
namespace QRBee.Api.Services;
|
||||||
|
|
||||||
|
public record UserInfo
|
||||||
|
{
|
||||||
|
public UserInfo()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserInfo(string name, string email, string dateOfBirth)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Email = email;
|
||||||
|
DateOfBirth = dateOfBirth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Name
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Email
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? DateOfBirth
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RegisterAsMerchant
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
QRBeeApi/Services/IQRBeeAPI.cs
Normal file
12
QRBeeApi/Services/IQRBeeAPI.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using QRBee.Core;
|
||||||
|
using QRBee.Core.Data;
|
||||||
|
|
||||||
|
namespace QRBee.Api.Services
|
||||||
|
{
|
||||||
|
public interface IQRBeeAPI
|
||||||
|
{
|
||||||
|
Task<RegistrationResponse> Register(RegistrationRequest value);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
74
QRBeeApi/Services/QRBeeAPI.cs
Normal file
74
QRBeeApi/Services/QRBeeAPI.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using QRBee.Core;
|
||||||
|
using QRBee.Core.Data;
|
||||||
|
|
||||||
|
namespace QRBee.Api.Services
|
||||||
|
{
|
||||||
|
public class QRBeeAPI: IQRBeeAPI
|
||||||
|
{
|
||||||
|
private readonly IStorage _storage;
|
||||||
|
|
||||||
|
public QRBeeAPI(IStorage storage)
|
||||||
|
{
|
||||||
|
_storage = storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<RegistrationResponse> Register(RegistrationRequest request)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
Validate(request);
|
||||||
|
|
||||||
|
var info = Convert(request);
|
||||||
|
|
||||||
|
if (UserExists(info))
|
||||||
|
{
|
||||||
|
// throw error
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_storage.PutUserInfo(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Validate(RegistrationRequest request)
|
||||||
|
{
|
||||||
|
if (request == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = request.Name;
|
||||||
|
var email = request.Email;
|
||||||
|
var dateOfBirth = request.DateOfBirth;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(name) || name.All(char.IsLetter)==false || name.Length>=30)
|
||||||
|
{
|
||||||
|
// throw exception
|
||||||
|
}
|
||||||
|
|
||||||
|
var freq = Regex.Matches(email, '@'.ToString()).Count;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(email) || email.Contains('@')==false || freq>=2 || email.Length >= 30)
|
||||||
|
{
|
||||||
|
// throw exception
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateOfBirth check
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserInfo Convert(RegistrationRequest request)
|
||||||
|
{
|
||||||
|
return new UserInfo(request.Name, request.Email, request.DateOfBirth);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool UserExists(UserInfo info)
|
||||||
|
{
|
||||||
|
var user = _storage.GetUserInfo(info.Email);
|
||||||
|
|
||||||
|
return user == info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
"QRBeeDatabase": {
|
||||||
|
"ConnectionString": "mongodb://localhost:27017",
|
||||||
|
"DatabaseName": "QRBee",
|
||||||
|
"User": "",
|
||||||
|
"Password": ""
|
||||||
|
},
|
||||||
|
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user