♻️ Move most of models to the Shared package
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Sphere.Permission;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
using DysonNetwork.Sphere.Publisher;
|
||||
@ -12,7 +13,7 @@ namespace DysonNetwork.Sphere.Sticker;
|
||||
[Route("/stickers")]
|
||||
public class StickerController(AppDatabase db, StickerService st) : ControllerBase
|
||||
{
|
||||
private async Task<IActionResult> _CheckStickerPackPermissions(Guid packId, Account.Account currentUser,
|
||||
private async Task<IActionResult> _CheckStickerPackPermissions(Guid packId, Shared.Models.Account currentUser,
|
||||
PublisherMemberRole requiredRole)
|
||||
{
|
||||
var pack = await db.StickerPacks
|
||||
@ -39,7 +40,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[FromQuery] string? pubName = null
|
||||
)
|
||||
{
|
||||
Publisher.Publisher? publisher = null;
|
||||
Shared.Models.Publisher? publisher = null;
|
||||
if (pubName is not null)
|
||||
publisher = await db.Publishers.FirstOrDefaultAsync(p => p.Name == pubName);
|
||||
|
||||
@ -78,7 +79,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[RequiredPermission("global", "stickers.packs.create")]
|
||||
public async Task<ActionResult<StickerPack>> CreateStickerPack([FromBody] StickerPackRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
|
||||
|
||||
if (string.IsNullOrEmpty(request.Name))
|
||||
return BadRequest("Name is required");
|
||||
@ -110,7 +111,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[HttpPatch("{id:guid}")]
|
||||
public async Task<ActionResult<StickerPack>> UpdateStickerPack(Guid id, [FromBody] StickerPackRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var pack = await db.StickerPacks
|
||||
@ -141,7 +142,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> DeleteStickerPack(Guid id)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var pack = await db.StickerPacks
|
||||
@ -212,7 +213,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[HttpPatch("{packId:guid}/content/{id:guid}")]
|
||||
public async Task<IActionResult> UpdateSticker(Guid packId, Guid id, [FromBody] StickerRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var permissionCheck = await _CheckStickerPackPermissions(packId, currentUser, PublisherMemberRole.Editor);
|
||||
@ -247,7 +248,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[HttpDelete("{packId:guid}/content/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteSticker(Guid packId, Guid id)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var permissionCheck = await _CheckStickerPackPermissions(packId, currentUser, PublisherMemberRole.Editor);
|
||||
@ -273,7 +274,7 @@ public class StickerController(AppDatabase db, StickerService st) : ControllerBa
|
||||
[RequiredPermission("global", "stickers.create")]
|
||||
public async Task<IActionResult> CreateSticker(Guid packId, [FromBody] StickerRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.Slug))
|
||||
|
Reference in New Issue
Block a user