Add good list

This commit is contained in:
Sakurai Ryota 2025-02-09 10:26:57 +09:00
parent 216944ae66
commit d3a35a4fe2
3 changed files with 36 additions and 2 deletions

View File

@ -20,7 +20,7 @@ public class GoodController : Controller
public async Task<IActionResult> Add(AddGoodModel model)
{
if (ModelState.IsValid)
if (!ModelState.IsValid)
{
return BadRequest();
}
@ -34,7 +34,13 @@ public class GoodController : Controller
return BadRequest();
}
await this.repository.AddGoods(model.Label, model.Barcode, model.Price);
await this.repository.AddGoods(model.Label, model.Barcode, model.Price).ConfigureAwait(false);
return Ok();
}
public async Task<IActionResult> List()
{
var ret = await this.repository.GetGoods(0, 100).ConfigureAwait(false);
return Json(ret);
}
}

View File

@ -0,0 +1,7 @@
namespace Uriagekun.Lib.Data;
public class RangeData
{
public int Start { get; set; }
public int End { get; set; }
}

View File

@ -32,6 +32,27 @@ public class MyRepository
return (int) ret;
}
/// <summary>
/// DBに登録されている商品の一覧から指定範囲を取得します。
/// </summary>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <returns></returns>
public async ValueTask<List<GoodData>> GetGoods(int offset, int count)
{
var range = new RangeData()
{
Start = offset,
End = offset + count,
};
var ret = await this.database.FetchAsync<GoodData>(
$"SELECT * FROM goods WHERE id BETWEEN @Start And @End",
range
).ConfigureAwait(false);
return ret;
}
/// <summary>
/// 指定商品の売上個数を登録します。
/// </summary>