This commit is contained in:
2021-01-19 00:53:49 +00:00
parent 247c600e15
commit 4e15728207
6 changed files with 66 additions and 5 deletions

2
.vscode/launch.json vendored
View File

@@ -53,7 +53,7 @@
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles",
"AYANOVA_SERVER_TEST_MODE": "true",
"AYANOVA_SERVER_TEST_MODE": "false",
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7",
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\"

View File

@@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
@@ -125,7 +127,7 @@ namespace AyaNova.Api.Controllers
else
return BadRequest(new ApiErrorResponse(biz.Errors));
}
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));;
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency })); ;
}
/// <summary>
@@ -150,6 +152,25 @@ namespace AyaNova.Api.Controllers
/// <summary>
/// Get Part serial numbers for part id
/// </summary>
/// <param name="id"></param>
/// <returns>Part</returns>
[HttpGet("serials/{id}")]
public async Task<IActionResult> GetPartSerials([FromRoute] long id)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Part))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var o = await ct.PartSerial.AsNoTracking().Where(z => z.PartId == id).OrderBy(z => z.Serial).Select(z => z.Serial).ToListAsync();
// if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return Ok(ApiOkResponse.Response(o));
}
//------------

View File

@@ -40,6 +40,7 @@ namespace AyaNova.Models
public virtual DbSet<Notification> Notification { get; set; }
public virtual DbSet<NotifyDeliveryLog> NotifyDeliveryLog { get; set; }
public virtual DbSet<Part> Part { get; set; }
public virtual DbSet<PartSerial> PartSerial { get; set; }
public virtual DbSet<PartAssembly> PartAssembly { get; set; }
public virtual DbSet<PartAssemblyItem> PartAssemblyItem { get; set; }
public virtual DbSet<PM> PM { get; set; }

View File

@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace AyaNova.Models
{
public class PartSerial
{
public long Id { get; set; }
public uint Concurrency { get; set; }
[Required]
public long PartId { get; set; }
[Required]
public string Serial { get; set; }
}//eoc
}//eons

View File

@@ -22,8 +22,8 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 15;
internal const long EXPECTED_COLUMN_COUNT = 666;
internal const long EXPECTED_INDEX_COUNT = 115;
internal const long EXPECTED_COLUMN_COUNT = 669;
internal const long EXPECTED_INDEX_COUNT = 117;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
@@ -665,6 +665,10 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
"cost decimal(19,4) not null, retail decimal(19,4) not null, unitofmeasure text, upc text " +
" )");
//PARTSERIAL
await ExecQueryAsync("CREATE TABLE apartserial (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial text not null, "+
"partid bigint not null REFERENCES apart on delete cascade, CONSTRAINT UNQ_PartSerialPart UNIQUE (partid, serial) )");//ensure not duplicate partid/serial combo
//PARTASSEMBLY
await ExecQueryAsync("CREATE TABLE apartassembly (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text not null unique, active bool not null, " +
"notes text, wiki text, customfields text, tags varchar(255) ARRAY )");

View File

@@ -1522,7 +1522,7 @@ namespace AyaNova.Util
o.Retail = o.Cost * 1.2m;
o.UnitOfMeasure = "each";
//This seems wrong to do in a loop but is 4 times faster this way ?!?
using (AyContext ct = ServiceProviderProvider.DBContext)
@@ -1536,6 +1536,19 @@ namespace AyaNova.Util
log.LogError(err);
throw new System.Exception(err);
}
// 50% chance it has serial numbers
//MIGRATE_OUTSTANDING this is just temporary until inventory is coded fully
if (Fake.Random.Number() == 1)
{
var serialCount = Fake.Random.Number(1, 5);
for (int y = 0; y < serialCount; y++)
{
await ct.PartSerial.AddAsync(new PartSerial() { PartId = NewObject.Id, Serial = Fake.Finance.Account().ToString() + y.ToString() });
}
await ct.SaveChangesAsync();
}
}
}
}