uff, lot of work
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Client.Data.Clients;
|
namespace OwnChar.Api.Clients;
|
||||||
|
|
||||||
public class CharactersApiClient(OwnCharApiClient client)
|
public class CharactersApiClient(OwnCharApiClient client)
|
||||||
{
|
{
|
||||||
43
OwnChar/Api/Clients/GroupsApiClient.cs
Normal file
43
OwnChar/Api/Clients/GroupsApiClient.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using OwnChar.Api.Packets.General;
|
||||||
|
using OwnChar.Api.Packets.Groups;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Clients;
|
||||||
|
|
||||||
|
public class GroupsApiClient(OwnCharApiClient client)
|
||||||
|
{
|
||||||
|
public async Task<Group?> GetGroup(long id)
|
||||||
|
{
|
||||||
|
var result = await client.MakeRequest<GetSinlgeObjectRequest, GetSingleObjectResponse<Group>>("/groups/get/byid", new(id));
|
||||||
|
result.EnsureSuccess();
|
||||||
|
return result.Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Group>> GetGroupsForProfile(long userProfileId)
|
||||||
|
{
|
||||||
|
var result = await client.MakeRequest<GetGroupsRequest, GetGroupsResponse>("/groups/get", new()
|
||||||
|
{
|
||||||
|
ProfileId = userProfileId,
|
||||||
|
UseProfileId = true,
|
||||||
|
});
|
||||||
|
result.EnsureSuccess();
|
||||||
|
return result.Groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Group>> GetPublicGroups()
|
||||||
|
{
|
||||||
|
var result = await client.MakeRequest<GetGroupsRequest, GetGroupsResponse>("/groups/get", new());
|
||||||
|
result.EnsureSuccess();
|
||||||
|
return result.Groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Group>> GetAllGroups()
|
||||||
|
{
|
||||||
|
var result = await client.MakeRequest<GetGroupsRequest, GetGroupsResponse>("/groups/get", new()
|
||||||
|
{
|
||||||
|
IncludeNonPublic = true,
|
||||||
|
});
|
||||||
|
result.EnsureSuccess();
|
||||||
|
return result.Groups;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
using OwnChar.Base.Data;
|
using OwnChar.Api.Packets;
|
||||||
using OwnChar.Base.Data.Requests;
|
using OwnChar.Api.Packets.General;
|
||||||
using OwnChar.Base.Data.Responses;
|
using OwnChar.Data.Model.Client;
|
||||||
using OwnChar.Client.Data.Model;
|
|
||||||
using Pilz.Cryptography;
|
using Pilz.Cryptography;
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Clients;
|
namespace OwnChar.Api.Clients;
|
||||||
|
|
||||||
public class LoginApiClient(OwnCharApiClient client)
|
public class LoginApiClient(OwnCharApiClient client)
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Client.Data.Clients;
|
namespace OwnChar.Api.Clients;
|
||||||
|
|
||||||
public class UsersApiClient(OwnCharApiClient client)
|
public class UsersApiClient(OwnCharApiClient client)
|
||||||
{
|
{
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using OwnChar.Api.Exceptions;
|
using Newtonsoft.Json;
|
||||||
using OwnChar.Base.Data;
|
using OwnChar.Api.Clients;
|
||||||
using OwnChar.Client.Data.Clients;
|
using OwnChar.Api.Exceptions;
|
||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
namespace OwnChar.Client.Data;
|
namespace OwnChar.Api;
|
||||||
|
|
||||||
public class OwnCharApiClient
|
public class OwnCharApiClient
|
||||||
{
|
{
|
||||||
@@ -46,17 +48,18 @@ public class OwnCharApiClient
|
|||||||
{
|
{
|
||||||
if (await TryMakeRequest<TRequest, TResponse>(requestUrl, request) is TResponse response)
|
if (await TryMakeRequest<TRequest, TResponse>(requestUrl, request) is TResponse response)
|
||||||
return response;
|
return response;
|
||||||
throw new ApiException(string.Format("The api request to \"{0}\" failed!", requestUrl));
|
throw new ApiException(string.Format("The API request to \"{0}\" failed!", requestUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TResponse?> TryMakeRequest<TRequest, TResponse>(string requestUrl, TRequest request) where TRequest : OwnCharRequest where TResponse : OwnCharResponse
|
public async Task<TResponse?> TryMakeRequest<TRequest, TResponse>(string requestUrl, TRequest request) where TRequest : OwnCharRequest where TResponse : OwnCharResponse
|
||||||
{
|
{
|
||||||
request.AuthSecret = AuthSecret;
|
request.AuthSecret = AuthSecret;
|
||||||
|
|
||||||
var res = await httpClient.PostAsJsonAsync(requestUrl, request);
|
var content = new StringContent(JsonHelpers.SerializeRequest(request)!, MediaTypeHeaderValue.Parse("application/json"));
|
||||||
|
var res = await httpClient.PostAsync(requestUrl, content);
|
||||||
|
|
||||||
if (res.IsSuccessStatusCode)
|
if (res.IsSuccessStatusCode)
|
||||||
return await res.Content.ReadFromJsonAsync<TResponse>();
|
return JsonHelpers.DeserializeResponse<TResponse>(await res.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
8
OwnChar/Api/Packets/General/DeleteObjectRequest.cs
Normal file
8
OwnChar/Api/Packets/General/DeleteObjectRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class DeleteObjectRequest(long objectId) : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long ObjectId { get; } = objectId;
|
||||||
|
}
|
||||||
7
OwnChar/Api/Packets/General/DeleteObjectResponse.cs
Normal file
7
OwnChar/Api/Packets/General/DeleteObjectResponse.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class DeleteObjectResponse : OwnCharResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
9
OwnChar/Api/Packets/General/GetSingleObjectResponse.cs
Normal file
9
OwnChar/Api/Packets/General/GetSingleObjectResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Data;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class GetSingleObjectResponse<T>(T? result) : OwnCharResponse where T : OwnCharObject
|
||||||
|
{
|
||||||
|
public T? Result { get; } = result;
|
||||||
|
}
|
||||||
8
OwnChar/Api/Packets/General/GetSinlgeObjectRequest.cs
Normal file
8
OwnChar/Api/Packets/General/GetSinlgeObjectRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class GetSinlgeObjectRequest(long objectId) : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long ObjectId { get; } = objectId;
|
||||||
|
}
|
||||||
10
OwnChar/Api/Packets/General/LoginRequest.cs
Normal file
10
OwnChar/Api/Packets/General/LoginRequest.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using Pilz.Cryptography;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class LoginRequest(string username, SecureString password) : OwnCharRequest
|
||||||
|
{
|
||||||
|
public new string Username { get; set; } = username;
|
||||||
|
public SecureString Password { get; } = password;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using OwnChar.Client.Data.Model;
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
namespace OwnChar.Base.Data.Responses;
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
public class LoginResponse(UserAccount? account, UserProfile? profile, string? secret) : OwnCharResponse
|
public class LoginResponse(UserAccount? account, UserProfile? profile, string? secret) : OwnCharResponse
|
||||||
{
|
{
|
||||||
7
OwnChar/Api/Packets/General/LogoutRequest.cs
Normal file
7
OwnChar/Api/Packets/General/LogoutRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class LogoutRequest : OwnCharRequest
|
||||||
|
{
|
||||||
|
}
|
||||||
7
OwnChar/Api/Packets/General/LogoutResponse.cs
Normal file
7
OwnChar/Api/Packets/General/LogoutResponse.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class LogoutResponse : OwnCharResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
7
OwnChar/Api/Packets/General/SetOwnerRequest.cs
Normal file
7
OwnChar/Api/Packets/General/SetOwnerRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class SetOwnerRequest : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long ObjectId { get; set; }
|
||||||
|
public bool Enforce { get; set; }
|
||||||
|
}
|
||||||
5
OwnChar/Api/Packets/General/SetOwnerResponse.cs
Normal file
5
OwnChar/Api/Packets/General/SetOwnerResponse.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class SetOwnerResponse : OwnCharResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using OwnChar.Base.Data.Updates;
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Api.Updates;
|
||||||
|
|
||||||
namespace OwnChar.Base.Data.Requests;
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
public class UpdateRequest(OwnCharObjectUpdate update) : OwnCharRequest
|
public class UpdateRequest(OwnCharObjectUpdate update) : OwnCharRequest
|
||||||
{
|
{
|
||||||
7
OwnChar/Api/Packets/General/UpdateResponse.cs
Normal file
7
OwnChar/Api/Packets/General/UpdateResponse.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.General;
|
||||||
|
|
||||||
|
public class UpdateResponse : OwnCharResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
8
OwnChar/Api/Packets/Groups/CreateGroupRequest.cs
Normal file
8
OwnChar/Api/Packets/Groups/CreateGroupRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class CreateGroupRequest : OwnCharRequest
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
9
OwnChar/Api/Packets/Groups/CreateGroupResponse.cs
Normal file
9
OwnChar/Api/Packets/Groups/CreateGroupResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class CreateGroupResponse(Group? group) : OwnCharResponse
|
||||||
|
{
|
||||||
|
public Group? Group { get; } = group;
|
||||||
|
}
|
||||||
8
OwnChar/Api/Packets/Groups/GetGroupMembersRequest.cs
Normal file
8
OwnChar/Api/Packets/Groups/GetGroupMembersRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class GetGroupMembersRequest(long groupId) : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long GroupId { get; } = groupId;
|
||||||
|
}
|
||||||
9
OwnChar/Api/Packets/Groups/GetGroupMembersResponse.cs
Normal file
9
OwnChar/Api/Packets/Groups/GetGroupMembersResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Data;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class GetGroupMembersResponse(List<MemberEntry> members) : OwnCharResponse
|
||||||
|
{
|
||||||
|
public List<MemberEntry> Members { get; } = members;
|
||||||
|
}
|
||||||
10
OwnChar/Api/Packets/Groups/GetGroupsRequest.cs
Normal file
10
OwnChar/Api/Packets/Groups/GetGroupsRequest.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class GetGroupsRequest : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long ProfileId { get; set; } = -1;
|
||||||
|
public bool UseProfileId { get; set; }
|
||||||
|
public bool IncludeNonPublic { get; set; }
|
||||||
|
}
|
||||||
9
OwnChar/Api/Packets/Groups/GetGroupsResponse.cs
Normal file
9
OwnChar/Api/Packets/Groups/GetGroupsResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class GetGroupsResponse(List<Group> groups) : OwnCharResponse
|
||||||
|
{
|
||||||
|
public List<Group> Groups { get; } = groups;
|
||||||
|
}
|
||||||
9
OwnChar/Api/Packets/Groups/GroupMemberAddRequest.cs
Normal file
9
OwnChar/Api/Packets/Groups/GroupMemberAddRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Data;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class GroupMemberAddRequest() : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long GroupId { get; set; } = -1;
|
||||||
|
public Dictionary<long, MemberLevel> Members { get; set; } = [];
|
||||||
|
}
|
||||||
8
OwnChar/Api/Packets/Groups/GroupMemberAddResponse.cs
Normal file
8
OwnChar/Api/Packets/Groups/GroupMemberAddResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.Groups;
|
||||||
|
|
||||||
|
public class GroupMemberAddResponse(List<MemberEntry> addedMembers) : OwnCharResponse
|
||||||
|
{
|
||||||
|
public List<MemberEntry> AddedMembers { get; } = addedMembers;
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using Pilz.Cryptography;
|
using Pilz.Cryptography;
|
||||||
|
|
||||||
namespace OwnChar.Base.Data;
|
namespace OwnChar.Api.Packets;
|
||||||
|
|
||||||
public class OwnCharRequest
|
public class OwnCharRequest
|
||||||
{
|
{
|
||||||
|
public string? Username { get; set; } = null;
|
||||||
public SecureString? AuthSecret { get; set; } = null;
|
public SecureString? AuthSecret { get; set; } = null;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace OwnChar.Base.Data;
|
namespace OwnChar.Api.Packets;
|
||||||
|
|
||||||
public class OwnCharResponse
|
public class OwnCharResponse
|
||||||
{
|
{
|
||||||
|
public OwnCharResponseError ErrorCode { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool IsSuccess => ErrorCode != OwnCharResponseError.None;
|
public bool IsSuccess => ErrorCode != OwnCharResponseError.None;
|
||||||
|
|
||||||
public OwnCharResponseError ErrorCode { get; set; }
|
|
||||||
}
|
}
|
||||||
9
OwnChar/Api/Packets/OwnCharResponseError.cs
Normal file
9
OwnChar/Api/Packets/OwnCharResponseError.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
public enum OwnCharResponseError
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Default,
|
||||||
|
NotFound,
|
||||||
|
StillInUse,
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.UserProfiles;
|
||||||
|
|
||||||
|
public class GetUserProfileRequest(long userProfileId) : OwnCharRequest
|
||||||
|
{
|
||||||
|
public long UserProfileId { get; } = userProfileId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.UserProfiles;
|
||||||
|
|
||||||
|
public class GetUserProfileResponse(UserProfile? profile) : OwnCharResponse
|
||||||
|
{
|
||||||
|
public UserProfile? Profile { get; } = profile;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.UserProfiles;
|
||||||
|
|
||||||
|
public class GetUserProfilesRequest : OwnCharRequest
|
||||||
|
{
|
||||||
|
public bool AllProfiles { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Api.Packets;
|
||||||
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Packets.UserProfiles;
|
||||||
|
|
||||||
|
public class GetUserProfilesResponse(List<UserProfile> profiles) : OwnCharResponse
|
||||||
|
{
|
||||||
|
public List<UserProfile> Profiles { get; } = profiles;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using OwnChar.Client.Data.Model;
|
using OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
namespace OwnChar.Base.Data.Updates;
|
namespace OwnChar.Api.Updates;
|
||||||
|
|
||||||
public class GroupUpdate : OwnCharObjectUpdate
|
public class GroupUpdate : OwnCharObjectUpdate
|
||||||
{
|
{
|
||||||
9
OwnChar/Api/Updates/MemberUpdate.cs
Normal file
9
OwnChar/Api/Updates/MemberUpdate.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using OwnChar.Data;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Updates;
|
||||||
|
|
||||||
|
public class MemberUpdate : OwnCharObjectUpdate
|
||||||
|
{
|
||||||
|
public long GroupId { get; set; }
|
||||||
|
public MemberLevel Level { get; set; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace OwnChar.Base.Data.Updates;
|
using OwnChar.Data;
|
||||||
|
|
||||||
|
namespace OwnChar.Api.Updates;
|
||||||
|
|
||||||
public abstract class OwnCharObjectUpdate
|
public abstract class OwnCharObjectUpdate
|
||||||
{
|
{
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace OwnChar.Base.Data;
|
|
||||||
|
|
||||||
public enum OwnCharResponseError
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Default,
|
|
||||||
NotAuthorized,
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace OwnChar.Base.Data.Requests;
|
|
||||||
|
|
||||||
public class GroupMemberAddRequest : OwnCharRequest
|
|
||||||
{
|
|
||||||
public Dictionary<long, MemberLevel> Members { get; } = [];
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Base.Data.Requests;
|
|
||||||
|
|
||||||
public class GroupMemberRemoveRequest : OwnCharRequest
|
|
||||||
{
|
|
||||||
public List<long> Members { get; } = [];
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using Pilz.Cryptography;
|
|
||||||
|
|
||||||
namespace OwnChar.Base.Data.Requests;
|
|
||||||
|
|
||||||
public class LoginRequest(string username, SecureString password) : OwnCharRequest
|
|
||||||
{
|
|
||||||
public string Username { get; } = username;
|
|
||||||
public SecureString Password { get; } = password;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace OwnChar.Base.Data.Requests;
|
|
||||||
|
|
||||||
public class LogoutRequest : OwnCharRequest
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace OwnChar.Client.Data.Clients;
|
|
||||||
|
|
||||||
public class GroupsApiClient(OwnCharApiClient client)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
public class Group() : GroupBase
|
|
||||||
{
|
|
||||||
internal Group(GroupBase group) : this()
|
|
||||||
{
|
|
||||||
Id = group.Id;
|
|
||||||
Name = group.Name;
|
|
||||||
IsInternal = group.IsInternal;
|
|
||||||
Fandom = group.Fandom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
public class MemberEntry() : MemberEntryBase
|
|
||||||
{
|
|
||||||
internal MemberEntry(MemberEntryBase entry) : this()
|
|
||||||
{
|
|
||||||
Id = entry.Id;
|
|
||||||
User = entry.User;
|
|
||||||
Level = entry.Level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
public class UserAccount() : UserAccountBase
|
|
||||||
{
|
|
||||||
internal UserAccount(UserAccountBase account) : this()
|
|
||||||
{
|
|
||||||
Id = account.Id;
|
|
||||||
Username = account.Username;
|
|
||||||
Email = account.Email;
|
|
||||||
Type = account.Type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
public class UserProfile() : UserProfileBase
|
|
||||||
{
|
|
||||||
internal UserProfile(UserProfileBase profile) : this()
|
|
||||||
{
|
|
||||||
Id = profile.Id;
|
|
||||||
Name = profile.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data;
|
namespace OwnChar.Data;
|
||||||
|
|
||||||
public enum MemberLevel
|
public enum MemberLevel
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
public abstract class CharacterBase : OwnCharObject
|
public abstract class CharacterBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
public abstract class GroupBase : OwnCharObject
|
public abstract class GroupBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using OwnChar.Client.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
namespace OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
public abstract class MemberEntryBase : OwnCharObject
|
public abstract class MemberEntryBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
public abstract class PropertyBase : OwnCharObject
|
public abstract class PropertyBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
public abstract class PropertyCategoryBase : OwnCharObject
|
public abstract class PropertyCategoryBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
public abstract class UserAccountBase : OwnCharObject
|
public abstract class UserAccountBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data.Model;
|
namespace OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
public abstract class UserProfileBase : OwnCharObject
|
public abstract class UserProfileBase : OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
public class Character() : CharacterBase
|
public class Character() : CharacterBase
|
||||||
{
|
{
|
||||||
7
OwnChar/Data/Model.Client/Group.cs
Normal file
7
OwnChar/Data/Model.Client/Group.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
public class Group : GroupBase
|
||||||
|
{
|
||||||
|
}
|
||||||
8
OwnChar/Data/Model.Client/MemberEntry.cs
Normal file
8
OwnChar/Data/Model.Client/MemberEntry.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
public class MemberEntry() : MemberEntryBase
|
||||||
|
{
|
||||||
|
public long UserProfileId { get; set; }
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
public class Property() : PropertyBase
|
public class Property() : PropertyBase
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
namespace OwnChar.Client.Data.Model;
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
public class PropertyCategory() : PropertyCategoryBase
|
public class PropertyCategory() : PropertyCategoryBase
|
||||||
{
|
{
|
||||||
7
OwnChar/Data/Model.Client/UserAccount.cs
Normal file
7
OwnChar/Data/Model.Client/UserAccount.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
public class UserAccount() : UserAccountBase
|
||||||
|
{
|
||||||
|
}
|
||||||
7
OwnChar/Data/Model.Client/UserProfile.cs
Normal file
7
OwnChar/Data/Model.Client/UserProfile.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using OwnChar.Data.Model.Base;
|
||||||
|
|
||||||
|
namespace OwnChar.Data.Model.Client;
|
||||||
|
|
||||||
|
public class UserProfile() : UserProfileBase
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Base.Data;
|
namespace OwnChar.Data;
|
||||||
|
|
||||||
public class OwnCharObject
|
public class OwnCharObject
|
||||||
{
|
{
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
namespace OwnChar.Base.Data;
|
namespace OwnChar.Data;
|
||||||
|
|
||||||
public enum UserType
|
public enum UserType
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Guest,
|
Guest,
|
||||||
User,
|
User,
|
||||||
Admin
|
Admin,
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using OwnChar.Client.Data;
|
using OwnChar.Api;
|
||||||
using OwnChar.Client.Data.Model;
|
using OwnChar.Data.Model.Client;
|
||||||
using OwnChar.Client.Managers;
|
using OwnChar.Modules;
|
||||||
using Pilz.Cryptography;
|
using Pilz.Cryptography;
|
||||||
|
|
||||||
namespace OwnChar.Client;
|
namespace OwnChar;
|
||||||
|
|
||||||
public interface IOwnCharManager
|
public interface IOwnCharManager
|
||||||
{
|
{
|
||||||
39
OwnChar/JsonHelpers.cs
Normal file
39
OwnChar/JsonHelpers.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using OwnChar.Api.Packets;
|
||||||
|
|
||||||
|
namespace OwnChar;
|
||||||
|
|
||||||
|
public static class JsonHelpers
|
||||||
|
{
|
||||||
|
private static JsonSerializerSettings? defaultSerializerSettings;
|
||||||
|
|
||||||
|
public static JsonSerializerSettings DefaultSerializerSettings => defaultSerializerSettings ??= CreateDefaultSerializerSettings();
|
||||||
|
|
||||||
|
private static JsonSerializerSettings CreateDefaultSerializerSettings()
|
||||||
|
{
|
||||||
|
return new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
TypeNameHandling = TypeNameHandling.Auto,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string? SerializeRequest<T>(T request) where T : OwnCharRequest
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(request, DefaultSerializerSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string? SerializeResponse<T>(T request) where T : OwnCharResponse
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(request, DefaultSerializerSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T? DeserializeRequest<T>(string request) where T : OwnCharRequest
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(request, DefaultSerializerSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T? DeserializeResponse<T>(string request) where T : OwnCharResponse
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(request, DefaultSerializerSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using OwnChar.Data;
|
using OwnChar.Data;
|
||||||
using OwnChar.Model;
|
using OwnChar.Model;
|
||||||
|
|
||||||
namespace OwnChar.Client.Managers;
|
namespace OwnChar.Modules;
|
||||||
|
|
||||||
internal class CharacterManager(OwnCharManager manager) : OwnCharManagerModule(manager), ICharacterManager
|
internal class CharacterManager(OwnCharManager manager) : OwnCharManagerModule(manager), ICharacterManager
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
using OwnChar.Data;
|
namespace OwnChar.Modules;
|
||||||
using OwnChar.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Client.Managers;
|
|
||||||
|
|
||||||
internal class GroupsManager(OwnCharManager manager) : OwnCharManagerModule(manager), IGroupsManager
|
internal class GroupsManager(OwnCharManager manager) : OwnCharManagerModule(manager), IGroupsManager
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using OwnChar.Model;
|
using OwnChar.Model;
|
||||||
|
|
||||||
namespace OwnChar.Client.Managers;
|
namespace OwnChar.Modules;
|
||||||
public interface ICharacterManager
|
public interface ICharacterManager
|
||||||
{
|
{
|
||||||
CharacterBase? CreateCharacter(string? name);
|
CharacterBase? CreateCharacter(string? name);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using OwnChar.Model;
|
using OwnChar.Model;
|
||||||
|
|
||||||
namespace OwnChar.Client.Managers;
|
namespace OwnChar.Modules;
|
||||||
public interface IGroupsManager
|
public interface IGroupsManager
|
||||||
{
|
{
|
||||||
IQueryable<GroupBase>? GetGroups(UserProfileBase? profile);
|
IQueryable<GroupBase>? GetGroups(UserProfileBase? profile);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using OwnChar.Model;
|
using OwnChar.Model;
|
||||||
using Pilz.Cryptography;
|
using Pilz.Cryptography;
|
||||||
|
|
||||||
namespace OwnChar.Client.Managers;
|
namespace OwnChar.Modules;
|
||||||
|
|
||||||
public interface IUserManager
|
public interface IUserManager
|
||||||
{
|
{
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using OwnChar.Model;
|
using OwnChar.Model;
|
||||||
using Pilz.Cryptography;
|
using Pilz.Cryptography;
|
||||||
|
|
||||||
namespace OwnChar.Client.Managers;
|
namespace OwnChar.Modules;
|
||||||
|
|
||||||
internal class UserManager(OwnCharManager manager) : OwnCharManagerModule(manager), IUserManager
|
internal class UserManager(OwnCharManager manager) : OwnCharManagerModule(manager), IUserManager
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using OwnChar.Base.Data;
|
using OwnChar.Api.Exceptions;
|
||||||
|
using OwnChar.Api.Packets;
|
||||||
using OwnChar.Data;
|
using OwnChar.Data;
|
||||||
using OwnChar.Model;
|
using OwnChar.Data.Model.Base;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace OwnChar;
|
namespace OwnChar;
|
||||||
@@ -23,55 +24,25 @@ public static class OwnCharExtensions
|
|||||||
return account.Type >= permissions;
|
return account.Type >= permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region OnActionEventArgs
|
public static void EnsureSuccess(this OwnCharResponse response)
|
||||||
|
|
||||||
public static bool SetResult(this OnActionEventArgs @this, object? data)
|
|
||||||
{
|
{
|
||||||
@this.Result = data;
|
if (!response.IsSuccess)
|
||||||
return @this.Result != null;
|
throw new ApiException("This API call failed! Reason: " + response.ErrorCode.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool SetResultT(this OnActionEventArgs @this, object? data)
|
public static T With<T>(this T response, OwnCharResponseError error) where T : OwnCharResponse
|
||||||
{
|
{
|
||||||
@this.Result = data;
|
response.ErrorCode = error;
|
||||||
return true;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool GetParam<T>(this OnActionEventArgs @this, int index, [NotNullWhen(true)] out T? result)
|
public static bool Is(this UserAccountBase user, UserType type)
|
||||||
{
|
{
|
||||||
return @this.Parameters.GetAt(index, out result);
|
return user.Type >= type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool GetObject<T>(this OnActionEventArgs @this, [NotNullWhen(true)] out T? result)
|
public static bool IsNot(this UserAccountBase user, UserType type)
|
||||||
{
|
{
|
||||||
if (@this.Object is T t)
|
return user.Type < type;
|
||||||
{
|
|
||||||
result = t;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Is(this OnActionEventArgs @this, DataManagerActionType actionType)
|
|
||||||
{
|
|
||||||
return @this.ActionType == actionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Is(this OnActionEventArgs @this, DataManagerAction action)
|
|
||||||
{
|
|
||||||
return @this.Action == action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Is(this OnActionEventArgs @this, UserType minLevel)
|
|
||||||
{
|
|
||||||
return @this.CurrentUser.HasPermission(minLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Is(this OnActionEventArgs @this, UserType maxLevel, UserType minLevel, Func<OnActionEventArgs, bool> isOwner)
|
|
||||||
{
|
|
||||||
return @this.Is(maxLevel) || (@this.Is(minLevel) && isOwner(@this));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using OwnChar.Api.Exceptions;
|
using OwnChar.Api;
|
||||||
using OwnChar.Client.Data;
|
using OwnChar.Api.Exceptions;
|
||||||
using OwnChar.Client.Data.Model;
|
using OwnChar.Data.Model.Client;
|
||||||
using OwnChar.Client.Managers;
|
using OwnChar.Modules;
|
||||||
using Pilz.Cryptography;
|
using Pilz.Cryptography;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace OwnChar.Client;
|
namespace OwnChar;
|
||||||
|
|
||||||
internal class OwnCharManager : IOwnCharManager
|
internal class OwnCharManager : IOwnCharManager
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OwnChar.Client;
|
namespace OwnChar;
|
||||||
|
|
||||||
public abstract class OwnCharManagerModule(IOwnCharManager manager)
|
public abstract class OwnCharManagerModule(IOwnCharManager manager)
|
||||||
{
|
{
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace OwnChar.Data;
|
|
||||||
|
|
||||||
public class DatabaseContext(string? dbHost, string? dbUser, string? dbPassword) : DbContext
|
|
||||||
{
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
base.OnModelCreating(modelBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
using OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class CharacterDb : CharacterBase
|
|
||||||
{
|
|
||||||
public UserProfileDb? Owner { get; set; }
|
|
||||||
public List<PropertyCategoryDb> PropCats { get; } = [];
|
|
||||||
public List<PropertyDb> Props { get; } = [];
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Updates;
|
|
||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class GroupDb : GroupBase
|
|
||||||
{
|
|
||||||
public List<CharacterDb> Characters { get; } = [];
|
|
||||||
public List<MemberEntryDb> Members { get; } = [];
|
|
||||||
|
|
||||||
public void Update(GroupUpdate update)
|
|
||||||
{
|
|
||||||
Name = update.Name;
|
|
||||||
Fandom = update.Fandom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
using OwnChar.Client.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class MemberEntryDb() : MemberEntryBase
|
|
||||||
{
|
|
||||||
public virtual UserProfile? User { get; set; }
|
|
||||||
|
|
||||||
internal MemberEntryDb(MemberEntryBase entry) : this()
|
|
||||||
{
|
|
||||||
Id = entry.Id;
|
|
||||||
Level = entry.Level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class PropertyCategoryDb : PropertyCategoryBase
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class PropertyDb : PropertyBase
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class UserAccountDb : UserAccountBase
|
|
||||||
{
|
|
||||||
public virtual string? Password { get; set; }
|
|
||||||
public UserProfileDb? Profile { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using OwnChar.Base.Data.Model;
|
|
||||||
|
|
||||||
namespace OwnChar.Server.Data.Model;
|
|
||||||
|
|
||||||
public class UserProfileDb : UserProfileBase
|
|
||||||
{
|
|
||||||
public List<CharacterDb> Characters { get; } = [];
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user