✨ Done with social credits
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using DysonNetwork.Pass.Auth;
|
using DysonNetwork.Pass.Auth;
|
||||||
|
using DysonNetwork.Pass.Credit;
|
||||||
using DysonNetwork.Pass.Wallet;
|
using DysonNetwork.Pass.Wallet;
|
||||||
using DysonNetwork.Shared.Error;
|
using DysonNetwork.Shared.Error;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -15,7 +16,8 @@ public class AccountController(
|
|||||||
AuthService auth,
|
AuthService auth,
|
||||||
AccountService accounts,
|
AccountService accounts,
|
||||||
SubscriptionService subscriptions,
|
SubscriptionService subscriptions,
|
||||||
AccountEventService events
|
AccountEventService events,
|
||||||
|
SocialCreditService socialCreditService
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("{name}")]
|
[HttpGet("{name}")]
|
||||||
@@ -48,6 +50,25 @@ public class AccountController(
|
|||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
return account is null ? NotFound(ApiError.NotFound(name, traceId: HttpContext.TraceIdentifier)) : account.Badges.ToList();
|
return account is null ? NotFound(ApiError.NotFound(name, traceId: HttpContext.TraceIdentifier)) : account.Badges.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("{name}/credits")]
|
||||||
|
[ProducesResponseType<double>(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult<double>> GetSocialCredits(string name)
|
||||||
|
{
|
||||||
|
var account = await db.Accounts
|
||||||
|
.Where(a => a.Name == name)
|
||||||
|
.Select(a => new { a.Id })
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (account is null)
|
||||||
|
{
|
||||||
|
return NotFound(ApiError.NotFound(name, traceId: HttpContext.TraceIdentifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
var credits = await socialCreditService.GetSocialCredit(account.Id);
|
||||||
|
return credits;
|
||||||
|
}
|
||||||
|
|
||||||
public class AccountCreateRequest
|
public class AccountCreateRequest
|
||||||
{
|
{
|
||||||
|
@@ -4,6 +4,8 @@ using NodaTime;
|
|||||||
|
|
||||||
namespace DysonNetwork.Pass.Credit;
|
namespace DysonNetwork.Pass.Credit;
|
||||||
|
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
|
||||||
public class SocialCreditRecord : ModelBase
|
public class SocialCreditRecord : ModelBase
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
@@ -14,4 +16,20 @@ public class SocialCreditRecord : ModelBase
|
|||||||
|
|
||||||
public Guid AccountId { get; set; }
|
public Guid AccountId { get; set; }
|
||||||
public Account.Account Account { get; set; } = null!;
|
public Account.Account Account { get; set; } = null!;
|
||||||
|
|
||||||
|
public Shared.Proto.SocialCreditRecord ToProto()
|
||||||
|
{
|
||||||
|
var proto = new Shared.Proto.SocialCreditRecord
|
||||||
|
{
|
||||||
|
Id = Id.ToString(),
|
||||||
|
ReasonType = ReasonType,
|
||||||
|
Reason = Reason,
|
||||||
|
Delta = Delta,
|
||||||
|
AccountId = AccountId.ToString(),
|
||||||
|
CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()),
|
||||||
|
UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset())
|
||||||
|
};
|
||||||
|
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
}
|
}
|
27
DysonNetwork.Pass/Credit/SocialCreditServiceGrpc.cs
Normal file
27
DysonNetwork.Pass/Credit/SocialCreditServiceGrpc.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using DysonNetwork.Shared.Proto;
|
||||||
|
using Grpc.Core;
|
||||||
|
|
||||||
|
namespace DysonNetwork.Pass.Credit;
|
||||||
|
|
||||||
|
public class SocialCreditServiceGrpc(SocialCreditService creditService) : Shared.Proto.SocialCreditService.SocialCreditServiceBase
|
||||||
|
{
|
||||||
|
public override async Task<Shared.Proto.SocialCreditRecord> AddRecord(AddSocialCreditRecordRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var accountId = Guid.Parse(request.AccountId);
|
||||||
|
var record = await creditService.AddRecord(
|
||||||
|
request.ReasonType,
|
||||||
|
request.Reason,
|
||||||
|
request.Delta,
|
||||||
|
accountId);
|
||||||
|
|
||||||
|
return record.ToProto();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<SocialCreditResponse> GetSocialCredit(GetSocialCreditRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var accountId = Guid.Parse(request.AccountId);
|
||||||
|
var amount = await creditService.GetSocialCredit(accountId);
|
||||||
|
|
||||||
|
return new SocialCreditResponse { Amount = amount };
|
||||||
|
}
|
||||||
|
}
|
@@ -3,6 +3,8 @@ using DysonNetwork.Shared.Data;
|
|||||||
|
|
||||||
namespace DysonNetwork.Pass.Leveling;
|
namespace DysonNetwork.Pass.Leveling;
|
||||||
|
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
|
||||||
public class ExperienceRecord : ModelBase
|
public class ExperienceRecord : ModelBase
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
@@ -13,4 +15,21 @@ public class ExperienceRecord : ModelBase
|
|||||||
|
|
||||||
public Guid AccountId { get; set; }
|
public Guid AccountId { get; set; }
|
||||||
public Account.Account Account { get; set; } = null!;
|
public Account.Account Account { get; set; } = null!;
|
||||||
|
|
||||||
|
public Shared.Proto.ExperienceRecord ToProto()
|
||||||
|
{
|
||||||
|
var proto = new Shared.Proto.ExperienceRecord
|
||||||
|
{
|
||||||
|
Id = Id.ToString(),
|
||||||
|
ReasonType = ReasonType,
|
||||||
|
Reason = Reason,
|
||||||
|
Delta = Delta,
|
||||||
|
BonusMultiplier = BonusMultiplier,
|
||||||
|
AccountId = AccountId.ToString(),
|
||||||
|
CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()),
|
||||||
|
UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset())
|
||||||
|
};
|
||||||
|
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
}
|
}
|
19
DysonNetwork.Pass/Leveling/ExperienceServiceGrpc.cs
Normal file
19
DysonNetwork.Pass/Leveling/ExperienceServiceGrpc.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using DysonNetwork.Shared.Proto;
|
||||||
|
using Grpc.Core;
|
||||||
|
|
||||||
|
namespace DysonNetwork.Pass.Leveling;
|
||||||
|
|
||||||
|
public class ExperienceServiceGrpc(ExperienceService experienceService) : Shared.Proto.ExperienceService.ExperienceServiceBase
|
||||||
|
{
|
||||||
|
public override async Task<Shared.Proto.ExperienceRecord> AddRecord(AddExperienceRecordRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var accountId = Guid.Parse(request.AccountId);
|
||||||
|
var record = await experienceService.AddRecord(
|
||||||
|
request.ReasonType,
|
||||||
|
request.Reason,
|
||||||
|
request.Delta,
|
||||||
|
accountId);
|
||||||
|
|
||||||
|
return record.ToProto();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,8 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using DysonNetwork.Pass.Account;
|
using DysonNetwork.Pass.Account;
|
||||||
using DysonNetwork.Pass.Auth;
|
using DysonNetwork.Pass.Auth;
|
||||||
|
using DysonNetwork.Pass.Credit;
|
||||||
|
using DysonNetwork.Pass.Leveling;
|
||||||
using DysonNetwork.Pass.Permission;
|
using DysonNetwork.Pass.Permission;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
@@ -76,6 +78,8 @@ public static class ApplicationConfiguration
|
|||||||
app.MapGrpcService<AuthServiceGrpc>();
|
app.MapGrpcService<AuthServiceGrpc>();
|
||||||
app.MapGrpcService<ActionLogServiceGrpc>();
|
app.MapGrpcService<ActionLogServiceGrpc>();
|
||||||
app.MapGrpcService<PermissionServiceGrpc>();
|
app.MapGrpcService<PermissionServiceGrpc>();
|
||||||
|
app.MapGrpcService<SocialCreditServiceGrpc>();
|
||||||
|
app.MapGrpcService<ExperienceServiceGrpc>();
|
||||||
app.MapGrpcService<BotAccountReceiverGrpc>();
|
app.MapGrpcService<BotAccountReceiverGrpc>();
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
83
DysonNetwork.Shared/Proto/leveling.proto
Normal file
83
DysonNetwork.Shared/Proto/leveling.proto
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package proto;
|
||||||
|
|
||||||
|
option csharp_namespace = "DysonNetwork.Shared.Proto";
|
||||||
|
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
|
import "google/protobuf/empty.proto";
|
||||||
|
import "google/protobuf/field_mask.proto";
|
||||||
|
|
||||||
|
// ====================================
|
||||||
|
// Message Definitions
|
||||||
|
// ====================================
|
||||||
|
|
||||||
|
// SocialCreditRecord represents a record of social credit changes for an account
|
||||||
|
message SocialCreditRecord {
|
||||||
|
string id = 1; // UUID string
|
||||||
|
string reason_type = 2;
|
||||||
|
string reason = 3;
|
||||||
|
double delta = 4;
|
||||||
|
string account_id = 5; // UUID string
|
||||||
|
google.protobuf.Timestamp created_at = 6;
|
||||||
|
google.protobuf.Timestamp updated_at = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExperienceRecord represents a record of experience points gained by an account
|
||||||
|
message ExperienceRecord {
|
||||||
|
string id = 1; // UUID string
|
||||||
|
string reason_type = 2;
|
||||||
|
string reason = 3;
|
||||||
|
int64 delta = 4;
|
||||||
|
double bonus_multiplier = 5;
|
||||||
|
string account_id = 6; // UUID string
|
||||||
|
google.protobuf.Timestamp created_at = 7;
|
||||||
|
google.protobuf.Timestamp updated_at = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====================================
|
||||||
|
// Request/Response Messages
|
||||||
|
// ====================================
|
||||||
|
|
||||||
|
// Social Credit Requests/Responses
|
||||||
|
message AddSocialCreditRecordRequest {
|
||||||
|
string reason_type = 1;
|
||||||
|
string reason = 2;
|
||||||
|
double delta = 3;
|
||||||
|
string account_id = 4; // UUID string
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSocialCreditRequest {
|
||||||
|
string account_id = 1; // UUID string
|
||||||
|
}
|
||||||
|
|
||||||
|
message SocialCreditResponse {
|
||||||
|
double amount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Experience Requests/Responses
|
||||||
|
message AddExperienceRecordRequest {
|
||||||
|
string reason_type = 1;
|
||||||
|
string reason = 2;
|
||||||
|
int64 delta = 3;
|
||||||
|
string account_id = 4; // UUID string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====================================
|
||||||
|
// Service Definitions
|
||||||
|
// ====================================
|
||||||
|
|
||||||
|
// SocialCreditService provides operations for managing social credit scores
|
||||||
|
service SocialCreditService {
|
||||||
|
// Adds a new social credit record for an account
|
||||||
|
rpc AddRecord(AddSocialCreditRecordRequest) returns (SocialCreditRecord);
|
||||||
|
|
||||||
|
// Gets the current social credit score for an account
|
||||||
|
rpc GetSocialCredit(GetSocialCreditRequest) returns (SocialCreditResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExperienceService provides operations for managing experience points
|
||||||
|
service ExperienceService {
|
||||||
|
// Adds a new experience record for an account
|
||||||
|
rpc AddRecord(AddExperienceRecordRequest) returns (ExperienceRecord);
|
||||||
|
}
|
Reference in New Issue
Block a user