mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
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.V4
|
|
{
|
|
[Route("api/inventions/v4")]
|
|
public class InventionsV4(RecDBContext db) : Controller
|
|
{
|
|
[HttpPost("addversion"), Authorize]
|
|
public async Task<FullInvention?> AddInventionVersion([FromBody] NewInventionVersionDTO req)
|
|
{
|
|
var userId = User.GetUserId();
|
|
|
|
var invention = await db.Inventions.FirstOrDefaultAsync(x => x.CreatorPlayerId == userId && x.InventionId == req.inventionId);
|
|
if (invention == null) return null;
|
|
|
|
var version = new InventionVersion
|
|
{
|
|
BlobName = req.inventionDataFilename,
|
|
ChipsCost = req.chipsCost,
|
|
CloudVariablesCost = req.cloudVariablesCost,
|
|
InstantiationCost = req.instantiationCost,
|
|
InventionId = req.inventionId,
|
|
ReplicationId = invention.ReplicationId,
|
|
LightsCost = invention.LightsCost,
|
|
VersionNumber = invention.CurrentVersionNumber + 1
|
|
};
|
|
|
|
await db.InventionVersions.AddAsync(version);
|
|
await db.SaveChangesAsync();
|
|
|
|
invention.CurrentVersionNumber = version.VersionNumber;
|
|
|
|
invention.BlobName = req.inventionDataFilename;
|
|
|
|
invention.RoomOrigin = req.creationRoomId;
|
|
|
|
invention.ModifiedAt = DateTime.Now;
|
|
|
|
invention.InstantiationCost = req.instantiationCost;
|
|
invention.LightsCost = req.lightsCost;
|
|
invention.ChipsCost = req.chipsCost;
|
|
invention.CloudVariablesCost = req.cloudVariablesCost;
|
|
invention.AICost = req.aiCost;
|
|
|
|
await db.SaveChangesAsync();
|
|
|
|
return await invention.ToFullInvention(db);
|
|
}
|
|
}
|
|
}
|