begin new and last rework
This commit is contained in:
25
OwnChar.Server/Api/Endpoint/ApiBuilder.cs
Normal file
25
OwnChar.Server/Api/Endpoint/ApiBuilder.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace OwnChar.ServerNew.Api.Endpoint;
|
||||
|
||||
internal class ApiBuilder(WebApplication app) : IApiBuilder
|
||||
{
|
||||
public void Map(string method, string pattern, Delegate action)
|
||||
{
|
||||
if (method == ApiRequestMethods.Get)
|
||||
app.MapGet(pattern, action);
|
||||
else if (method == ApiRequestMethods.Post)
|
||||
app.MapPost(pattern, action);
|
||||
else if (method == ApiRequestMethods.Put)
|
||||
app.MapPut(pattern, action);
|
||||
else if (method == ApiRequestMethods.Patch)
|
||||
app.MapPatch(pattern, action);
|
||||
else if (method == ApiRequestMethods.Delete)
|
||||
app.MapDelete(pattern, action);
|
||||
else
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void Map(string pattern, Delegate action)
|
||||
{
|
||||
app.Map(pattern, action);
|
||||
}
|
||||
}
|
||||
12
OwnChar.Server/Api/Endpoint/ApiRequestMethods.cs
Normal file
12
OwnChar.Server/Api/Endpoint/ApiRequestMethods.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Net;
|
||||
|
||||
namespace OwnChar.ServerNew.Api.Endpoint;
|
||||
|
||||
public static class ApiRequestMethods
|
||||
{
|
||||
public static string Get => WebRequestMethods.Http.Get;
|
||||
public static string Put => WebRequestMethods.Http.Put;
|
||||
public static string Post => WebRequestMethods.Http.Post;
|
||||
public static string Patch => "PATCH";
|
||||
public static string Delete => "DELETE";
|
||||
}
|
||||
6
OwnChar.Server/Api/Endpoint/IApiBuilder.cs
Normal file
6
OwnChar.Server/Api/Endpoint/IApiBuilder.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace OwnChar.ServerNew.Api.Endpoint;
|
||||
|
||||
public interface IApiBuilder
|
||||
{
|
||||
void Map(string path, Delegate action);
|
||||
}
|
||||
6
OwnChar.Server/Api/Endpoint/IApiEndpoint.cs
Normal file
6
OwnChar.Server/Api/Endpoint/IApiEndpoint.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace OwnChar.ServerNew.Api.Endpoint;
|
||||
|
||||
internal interface IApiEndpoint
|
||||
{
|
||||
void Initialize(IApiBuilder builder);
|
||||
}
|
||||
34
OwnChar.Server/Api/Endpoint/Implementations/CharactersApi.cs
Normal file
34
OwnChar.Server/Api/Endpoint/Implementations/CharactersApi.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace OwnChar.ServerNew.Api.Endpoint.Implementations;
|
||||
|
||||
internal class CharactersApi(IServer server) : IApiEndpoint
|
||||
{
|
||||
public void Initialize(IApiBuilder builder)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private IResult GetCharacter(long characterId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult CreateGroupCharacter(string name, long groupId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult CreateUserCharacter(string name, long userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult UpdateCharacter(long characterId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult DeleteCharacter(long characterId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
48
OwnChar.Server/Api/Endpoint/Implementations/GroupsApi.cs
Normal file
48
OwnChar.Server/Api/Endpoint/Implementations/GroupsApi.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace OwnChar.ServerNew.Api.Endpoint.Implementations;
|
||||
|
||||
internal class GroupsApi(IServer server) : IApiEndpoint
|
||||
{
|
||||
public void Initialize(IApiBuilder builder)
|
||||
{
|
||||
}
|
||||
|
||||
private IResult GetGroups()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult GetGroups(long characterId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult GetGroup(long groupId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult CreateGroup(string name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult UpdateGroup(int groupId, string name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult DeleteGroup(int groupId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult AddMember(int groupId, long memberId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult RemoveMember(int groupId, long memberId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
31
OwnChar.Server/Api/Endpoint/Implementations/LoginApi.cs
Normal file
31
OwnChar.Server/Api/Endpoint/Implementations/LoginApi.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OwnChar.Api.Responses;
|
||||
using OwnChar.Model;
|
||||
|
||||
namespace OwnChar.ServerNew.Api.Endpoint.Implementations;
|
||||
|
||||
internal class LoginApi(ServerContext server) : IApiEndpoint
|
||||
{
|
||||
public void Initialize(IApiBuilder builder)
|
||||
{
|
||||
builder.Map("/auth/login/{username}", Login);
|
||||
builder.Map("/auth/logout/{secret}", Logout);
|
||||
}
|
||||
|
||||
private IResult Login(string username, [FromHeader(Name = "X-USER-PASSWORD")] string password)
|
||||
{
|
||||
if (server.Data != null && server.Data.GetAll<UserAccount>()?.FirstOrDefault(n => n.Username == username && n.Password == password) is UserAccount account)
|
||||
return TypedResults.Ok(new LoginResponse
|
||||
{
|
||||
Secret = server.Login(account),
|
||||
UserAccount = account,
|
||||
});
|
||||
return TypedResults.Unauthorized();
|
||||
}
|
||||
|
||||
private IResult Logout([FromHeader(Name = "X-AUTH-SECRET")] string secret)
|
||||
{
|
||||
server.Logout(secret);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
}
|
||||
44
OwnChar.Server/Api/Endpoint/Implementations/UsersApi.cs
Normal file
44
OwnChar.Server/Api/Endpoint/Implementations/UsersApi.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace OwnChar.ServerNew.Api.Endpoint.Implementations;
|
||||
|
||||
internal class UsersApi(IServer server) : IApiEndpoint
|
||||
{
|
||||
public void Initialize(IApiBuilder builder)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private IResult GetUsers()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult GetUser(long userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult GetUserProfile(long userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult CreateUser(string username, string password)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult DeleteUser(long userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult UpdateUserPassword(long userId, string username, string password)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IResult UpdateUserProfile(long profileId, string displayName)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user