✨ Account status GRPC API
This commit is contained in:
@@ -9,6 +9,7 @@ namespace DysonNetwork.Pass.Account;
|
|||||||
|
|
||||||
public class AccountServiceGrpc(
|
public class AccountServiceGrpc(
|
||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
|
AccountEventService accountEvents,
|
||||||
RelationshipService relationships,
|
RelationshipService relationships,
|
||||||
SubscriptionService subscriptions,
|
SubscriptionService subscriptions,
|
||||||
IClock clock,
|
IClock clock,
|
||||||
@@ -68,6 +69,26 @@ public class AccountServiceGrpc(
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<AccountStatus> GetAccountStatus(GetAccountRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var accountId = Guid.Parse(request.Id);
|
||||||
|
var status = await accountEvents.GetStatus(accountId);
|
||||||
|
return status.ToProtoValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<GetAccountStatusBatchResponse> GetAccountStatusBatch(GetAccountBatchRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var accountIds = request.Id
|
||||||
|
.Select(id => Guid.TryParse(id, out var accountId) ? accountId : (Guid?)null)
|
||||||
|
.Where(id => id.HasValue)
|
||||||
|
.Select(id => id!.Value)
|
||||||
|
.ToList();
|
||||||
|
var statuses = await accountEvents.GetStatuses(accountIds);
|
||||||
|
var response = new GetAccountStatusBatchResponse();
|
||||||
|
response.Statuses.AddRange(statuses.Select(s => s.Value.ToProtoValue()));
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<GetAccountBatchResponse> LookupAccountBatch(LookupAccountBatchRequest request,
|
public override async Task<GetAccountBatchResponse> LookupAccountBatch(LookupAccountBatchRequest request,
|
||||||
ServerCallContext context)
|
ServerCallContext context)
|
||||||
{
|
{
|
||||||
|
@@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using DysonNetwork.Shared.Data;
|
using DysonNetwork.Shared.Data;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
|
using NodaTime.Serialization.Protobuf;
|
||||||
|
|
||||||
namespace DysonNetwork.Pass.Account;
|
namespace DysonNetwork.Pass.Account;
|
||||||
|
|
||||||
@@ -25,6 +26,52 @@ public class Status : ModelBase
|
|||||||
|
|
||||||
public Guid AccountId { get; set; }
|
public Guid AccountId { get; set; }
|
||||||
public Account Account { get; set; } = null!;
|
public Account Account { get; set; } = null!;
|
||||||
|
|
||||||
|
public Shared.Proto.AccountStatus ToProtoValue()
|
||||||
|
{
|
||||||
|
var proto = new Shared.Proto.AccountStatus
|
||||||
|
{
|
||||||
|
Id = Id.ToString(),
|
||||||
|
Attitude = Attitude switch
|
||||||
|
{
|
||||||
|
StatusAttitude.Positive => Shared.Proto.StatusAttitude.Positive,
|
||||||
|
StatusAttitude.Negative => Shared.Proto.StatusAttitude.Negative,
|
||||||
|
StatusAttitude.Neutral => Shared.Proto.StatusAttitude.Neutral,
|
||||||
|
_ => Shared.Proto.StatusAttitude.Unspecified
|
||||||
|
},
|
||||||
|
IsOnline = IsOnline,
|
||||||
|
IsCustomized = IsCustomized,
|
||||||
|
IsInvisible = IsInvisible,
|
||||||
|
IsNotDisturb = IsNotDisturb,
|
||||||
|
Label = Label ?? string.Empty,
|
||||||
|
ClearedAt = ClearedAt?.ToTimestamp(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Status FromProtoValue(Shared.Proto.AccountStatus proto)
|
||||||
|
{
|
||||||
|
var status = new Status
|
||||||
|
{
|
||||||
|
Id = Guid.Parse(proto.Id),
|
||||||
|
Attitude = proto.Attitude switch
|
||||||
|
{
|
||||||
|
Shared.Proto.StatusAttitude.Positive => StatusAttitude.Positive,
|
||||||
|
Shared.Proto.StatusAttitude.Negative => StatusAttitude.Negative,
|
||||||
|
Shared.Proto.StatusAttitude.Neutral => StatusAttitude.Neutral,
|
||||||
|
_ => StatusAttitude.Neutral
|
||||||
|
},
|
||||||
|
IsOnline = proto.IsOnline,
|
||||||
|
IsCustomized = proto.IsCustomized,
|
||||||
|
IsInvisible = proto.IsInvisible,
|
||||||
|
IsNotDisturb = proto.IsNotDisturb,
|
||||||
|
Label = proto.Label,
|
||||||
|
ClearedAt = proto.ClearedAt?.ToInstant(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CheckInResultLevel
|
public enum CheckInResultLevel
|
||||||
|
@@ -34,6 +34,26 @@ message Account {
|
|||||||
google.protobuf.Timestamp updated_at = 15;
|
google.protobuf.Timestamp updated_at = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enum for status attitude
|
||||||
|
enum StatusAttitude {
|
||||||
|
STATUS_ATTITUDE_UNSPECIFIED = 0;
|
||||||
|
POSITIVE = 1;
|
||||||
|
NEGATIVE = 2;
|
||||||
|
NEUTRAL = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountStatus represents the status of an account
|
||||||
|
message AccountStatus {
|
||||||
|
string id = 1;
|
||||||
|
StatusAttitude attitude = 2;
|
||||||
|
bool is_online = 3;
|
||||||
|
bool is_customized = 4;
|
||||||
|
bool is_invisible = 5;
|
||||||
|
bool is_not_disturb = 6;
|
||||||
|
google.protobuf.StringValue label = 7;
|
||||||
|
google.protobuf.Timestamp cleared_at = 8;
|
||||||
|
}
|
||||||
|
|
||||||
// Profile contains detailed information about a user
|
// Profile contains detailed information about a user
|
||||||
message AccountProfile {
|
message AccountProfile {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
@@ -211,6 +231,10 @@ message ActionLog {
|
|||||||
google.protobuf.Timestamp created_at = 9; // When the action log was created
|
google.protobuf.Timestamp created_at = 9; // When the action log was created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GetAccountStatusBatchResponse {
|
||||||
|
repeated AccountStatus statuses = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// ====================================
|
// ====================================
|
||||||
// Service Definitions
|
// Service Definitions
|
||||||
// ====================================
|
// ====================================
|
||||||
@@ -223,6 +247,9 @@ service AccountService {
|
|||||||
rpc LookupAccountBatch(LookupAccountBatchRequest) returns (GetAccountBatchResponse) {}
|
rpc LookupAccountBatch(LookupAccountBatchRequest) returns (GetAccountBatchResponse) {}
|
||||||
rpc ListAccounts(ListAccountsRequest) returns (ListAccountsResponse) {}
|
rpc ListAccounts(ListAccountsRequest) returns (ListAccountsResponse) {}
|
||||||
|
|
||||||
|
rpc GetAccountStatus(GetAccountRequest) returns (AccountStatus) {}
|
||||||
|
rpc GetAccountStatusBatch(GetAccountBatchRequest) returns (GetAccountStatusBatchResponse) {}
|
||||||
|
|
||||||
// Profile Operations
|
// Profile Operations
|
||||||
rpc GetProfile(GetProfileRequest) returns (AccountProfile) {}
|
rpc GetProfile(GetProfileRequest) returns (AccountProfile) {}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user