🐛 Fixes custom app

This commit is contained in:
LittleSheep 2025-06-29 19:38:29 +08:00
parent a53fcb10dd
commit cdeed3c318
2 changed files with 13 additions and 19 deletions

View File

@ -7,8 +7,11 @@ namespace DysonNetwork.Sphere.Developer;
[Route("/developers/apps")] [Route("/developers/apps")]
public class CustomAppController(CustomAppService customAppService, PublisherService ps) : ControllerBase public class CustomAppController(CustomAppService customAppService, PublisherService ps) : ControllerBase
{ {
[HttpGet("")] public record CreateAppRequest(Guid PublisherId, string Name, string Slug);
public async Task<IActionResult> GetApps([FromQuery] Guid publisherId) public record UpdateAppRequest(string Name, string Slug);
[HttpGet]
public async Task<IActionResult> ListApps([FromQuery] Guid publisherId)
{ {
var apps = await customAppService.GetAppsByPublisherAsync(publisherId); var apps = await customAppService.GetAppsByPublisherAsync(publisherId);
return Ok(apps); return Ok(apps);
@ -25,10 +28,10 @@ public class CustomAppController(CustomAppService customAppService, PublisherSer
return Ok(app); return Ok(app);
} }
[HttpPost("")] [HttpPost]
public async Task<IActionResult> CreateApp([FromBody] CreateAppDto dto) public async Task<IActionResult> CreateApp([FromBody] CreateAppRequest request)
{ {
var app = await customAppService.CreateAppAsync(dto.PublisherId, dto.Name, dto.Slug); var app = await customAppService.CreateAppAsync(request.PublisherId, request.Name, request.Slug);
if (app == null) if (app == null)
{ {
return BadRequest("Invalid publisher ID or missing developer feature flag"); return BadRequest("Invalid publisher ID or missing developer feature flag");
@ -36,10 +39,10 @@ public class CustomAppController(CustomAppService customAppService, PublisherSer
return CreatedAtAction(nameof(GetApp), new { id = app.Id }, app); return CreatedAtAction(nameof(GetApp), new { id = app.Id }, app);
} }
[HttpPut("{id:guid}")] [HttpPatch("{id:guid}")]
public async Task<IActionResult> UpdateApp(Guid id, [FromBody] UpdateAppDto dto) public async Task<IActionResult> UpdateApp(Guid id, [FromBody] UpdateAppRequest request)
{ {
var app = await customAppService.UpdateAppAsync(id, dto.Name, dto.Slug); var app = await customAppService.UpdateAppAsync(id, request.Name, request.Slug);
if (app == null) if (app == null)
{ {
return NotFound(); return NotFound();
@ -58,6 +61,3 @@ public class CustomAppController(CustomAppService customAppService, PublisherSer
return NoContent(); return NoContent();
} }
} }
public record CreateAppDto(Guid PublisherId, string Name, string Slug);
public record UpdateAppDto(string Name, string Slug);

View File

@ -24,13 +24,6 @@ public class DeveloperController(
.Where(e => e.Name == name) .Where(e => e.Name == name)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
if (publisher is null) return NotFound(); if (publisher is null) return NotFound();
if (publisher.AccountId is null) return Ok(publisher);
var account = await db.Accounts
.Where(a => a.Id == publisher.AccountId)
.Include(a => a.Profile)
.FirstOrDefaultAsync();
publisher.Account = account;
return Ok(publisher); return Ok(publisher);
} }
@ -119,11 +112,12 @@ public class DeveloperController(
if (!isOwner) return StatusCode(403, "You must be the owner of the publisher to join the developer program"); if (!isOwner) return StatusCode(403, "You must be the owner of the publisher to join the developer program");
// Check if already has a developer feature // Check if already has a developer feature
var now = SystemClock.Instance.GetCurrentInstant();
var hasDeveloperFeature = await db.PublisherFeatures var hasDeveloperFeature = await db.PublisherFeatures
.AnyAsync(f => .AnyAsync(f =>
f.PublisherId == publisher.Id && f.PublisherId == publisher.Id &&
f.Flag == PublisherFeatureFlag.Develop && f.Flag == PublisherFeatureFlag.Develop &&
(f.ExpiredAt == null || f.ExpiredAt > SystemClock.Instance.GetCurrentInstant())); (f.ExpiredAt == null || f.ExpiredAt > now));
if (hasDeveloperFeature) return BadRequest("Publisher is already in the developer program"); if (hasDeveloperFeature) return BadRequest("Publisher is already in the developer program");