mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
34 lines
1002 B
C#
34 lines
1002 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.Extensions;
|
|
using RadicadeServer.RecNet.Enums.Inventions;
|
|
using RadicadeServer.RecNet.Inventions;
|
|
|
|
namespace RadicadeServer.API.Inventions.V3
|
|
{
|
|
[Route("api/inventions/v3")]
|
|
public class InventionsV3(RecDBContext db) : Controller
|
|
{
|
|
[HttpGet("publish"), Authorize]
|
|
public async Task<FullInvention?> PublishInvention([FromQuery] long inventionId, [FromQuery] InventionRole permissionLevel, [FromQuery] int? price)
|
|
{
|
|
var userId = User.GetUserId();
|
|
|
|
var invention = await db.Inventions.FirstOrDefaultAsync(x => x.CreatorPlayerId == userId && x.InventionId == inventionId);
|
|
if (invention == null) return null;
|
|
|
|
invention.IsPublished = true;
|
|
invention.HideFromPlayer = false;
|
|
|
|
if (price.HasValue)
|
|
invention.Price = price.Value;
|
|
|
|
await db.SaveChangesAsync();
|
|
|
|
return await invention.ToFullInvention(db);
|
|
}
|
|
}
|
|
}
|