🐛 Dozens of bug fixes
This commit is contained in:
@@ -24,7 +24,8 @@ public class AccountCurrentController(
|
|||||||
AccountEventService events,
|
AccountEventService events,
|
||||||
AuthService auth,
|
AuthService auth,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs
|
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||||
|
Credit.SocialCreditService creditService
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@@ -268,7 +269,9 @@ public class AccountCurrentController(
|
|||||||
.OrderByDescending(x => x.CreatedAt)
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
return result is null ? NotFound(ApiError.NotFound("check-in", traceId: HttpContext.TraceIdentifier)) : Ok(result);
|
return result is null
|
||||||
|
? NotFound(ApiError.NotFound("check-in", traceId: HttpContext.TraceIdentifier))
|
||||||
|
: Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("check-in")]
|
[HttpPost("check-in")]
|
||||||
@@ -323,10 +326,11 @@ public class AccountCurrentController(
|
|||||||
TraceId = HttpContext.TraceIdentifier
|
TraceId = HttpContext.TraceIdentifier
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
true when !await auth.ValidateCaptcha(captchaToken!) => BadRequest(ApiError.Validation(new Dictionary<string, string[]>
|
true when !await auth.ValidateCaptcha(captchaToken!) => BadRequest(ApiError.Validation(
|
||||||
{
|
new Dictionary<string, string[]>
|
||||||
["captchaToken"] = new[] { "Invalid captcha token." }
|
{
|
||||||
}, traceId: HttpContext.TraceIdentifier)),
|
["captchaToken"] = new[] { "Invalid captcha token." }
|
||||||
|
}, traceId: HttpContext.TraceIdentifier)),
|
||||||
_ => await events.CheckInDaily(currentUser, backdated)
|
_ => await events.CheckInDaily(currentUser, backdated)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -823,4 +827,60 @@ public class AccountCurrentController(
|
|||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("leveling")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<ExperienceRecord>> GetLevelingHistory(
|
||||||
|
[FromQuery] int take = 20,
|
||||||
|
[FromQuery] int offset = 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var queryable = db.ExperienceRecords
|
||||||
|
.Where(r => r.AccountId == currentUser.Id)
|
||||||
|
.OrderByDescending(r => r.CreatedAt)
|
||||||
|
.AsQueryable();
|
||||||
|
|
||||||
|
var totalCount = await queryable.CountAsync();
|
||||||
|
Response.Headers["X-Total"] = totalCount.ToString();
|
||||||
|
|
||||||
|
var records = await queryable
|
||||||
|
.Skip(offset)
|
||||||
|
.Take(take)
|
||||||
|
.ToListAsync();
|
||||||
|
return Ok(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("credits")]
|
||||||
|
public async Task<ActionResult<bool>> GetSocialCredit()
|
||||||
|
{
|
||||||
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var credit = await creditService.GetSocialCredit(currentUser.Id);
|
||||||
|
return Ok(credit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("credits/history")]
|
||||||
|
public async Task<ActionResult<SocialCreditRecord>> GetCreditHistory(
|
||||||
|
[FromQuery] int take = 20,
|
||||||
|
[FromQuery] int offset = 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var queryable = db.SocialCreditRecords
|
||||||
|
.Where(r => r.AccountId == currentUser.Id)
|
||||||
|
.OrderByDescending(r => r.CreatedAt)
|
||||||
|
.AsQueryable();
|
||||||
|
|
||||||
|
var totalCount = await queryable.CountAsync();
|
||||||
|
Response.Headers["X-Total"] = totalCount.ToString();
|
||||||
|
|
||||||
|
var records = await queryable
|
||||||
|
.Skip(offset)
|
||||||
|
.Take(take)
|
||||||
|
.ToListAsync();
|
||||||
|
return Ok(records);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,11 +1,10 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using DysonNetwork.Shared.Data;
|
using DysonNetwork.Shared.Data;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
|
using NodaTime.Serialization.Protobuf;
|
||||||
|
|
||||||
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; }
|
||||||
@@ -26,8 +25,8 @@ public class SocialCreditRecord : ModelBase
|
|||||||
Reason = Reason,
|
Reason = Reason,
|
||||||
Delta = Delta,
|
Delta = Delta,
|
||||||
AccountId = AccountId.ToString(),
|
AccountId = AccountId.ToString(),
|
||||||
CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()),
|
CreatedAt = CreatedAt.ToTimestamp(),
|
||||||
UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset())
|
UpdatedAt = UpdatedAt.ToTimestamp()
|
||||||
};
|
};
|
||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using DysonNetwork.Shared.Data;
|
using DysonNetwork.Shared.Data;
|
||||||
|
using NodaTime.Serialization.Protobuf;
|
||||||
|
|
||||||
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();
|
||||||
@@ -26,8 +25,8 @@ public class ExperienceRecord : ModelBase
|
|||||||
Delta = Delta,
|
Delta = Delta,
|
||||||
BonusMultiplier = BonusMultiplier,
|
BonusMultiplier = BonusMultiplier,
|
||||||
AccountId = AccountId.ToString(),
|
AccountId = AccountId.ToString(),
|
||||||
CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()),
|
CreatedAt = CreatedAt.ToTimestamp(),
|
||||||
UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset())
|
UpdatedAt = UpdatedAt.ToTimestamp()
|
||||||
};
|
};
|
||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
|
Reference in New Issue
Block a user