🐛 Fixes custom app
This commit is contained in:
parent
a53fcb10dd
commit
cdeed3c318
@ -7,8 +7,11 @@ namespace DysonNetwork.Sphere.Developer;
|
||||
[Route("/developers/apps")]
|
||||
public class CustomAppController(CustomAppService customAppService, PublisherService ps) : ControllerBase
|
||||
{
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> GetApps([FromQuery] Guid publisherId)
|
||||
public record CreateAppRequest(Guid PublisherId, string Name, string Slug);
|
||||
public record UpdateAppRequest(string Name, string Slug);
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ListApps([FromQuery] Guid publisherId)
|
||||
{
|
||||
var apps = await customAppService.GetAppsByPublisherAsync(publisherId);
|
||||
return Ok(apps);
|
||||
@ -25,10 +28,10 @@ public class CustomAppController(CustomAppService customAppService, PublisherSer
|
||||
return Ok(app);
|
||||
}
|
||||
|
||||
[HttpPost("")]
|
||||
public async Task<IActionResult> CreateApp([FromBody] CreateAppDto dto)
|
||||
[HttpPost]
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> UpdateApp(Guid id, [FromBody] UpdateAppDto dto)
|
||||
[HttpPatch("{id:guid}")]
|
||||
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)
|
||||
{
|
||||
return NotFound();
|
||||
@ -58,6 +61,3 @@ public class CustomAppController(CustomAppService customAppService, PublisherSer
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
public record CreateAppDto(Guid PublisherId, string Name, string Slug);
|
||||
public record UpdateAppDto(string Name, string Slug);
|
@ -24,13 +24,6 @@ public class DeveloperController(
|
||||
.Where(e => e.Name == name)
|
||||
.FirstOrDefaultAsync();
|
||||
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);
|
||||
}
|
||||
@ -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");
|
||||
|
||||
// Check if already has a developer feature
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
var hasDeveloperFeature = await db.PublisherFeatures
|
||||
.AnyAsync(f =>
|
||||
f.PublisherId == publisher.Id &&
|
||||
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");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user