Fin de "API"

master
Félix MIELCAREK 2 years ago
parent 3252de5cb0
commit f9e7eb79e9

@ -5,6 +5,8 @@ VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp", "BlazorApp\BlazorApp.csproj", "{F86AB906-298D-4275-BC1C-FFC1BB19DFFD}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp", "BlazorApp\BlazorApp.csproj", "{F86AB906-298D-4275-BC1C-FFC1BB19DFFD}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft.Crafting.Api", "..\Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{B90B4831-9749-4C1E-8F20-D6076A440E6B}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Debug|Any CPU.Build.0 = Debug|Any CPU {F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Release|Any CPU.ActiveCfg = Release|Any CPU {F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Release|Any CPU.Build.0 = Release|Any CPU {F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Release|Any CPU.Build.0 = Release|Any CPU
{B90B4831-9749-4C1E-8F20-D6076A440E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B90B4831-9749-4C1E-8F20-D6076A440E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B90B4831-9749-4C1E-8F20-D6076A440E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B90B4831-9749-4C1E-8F20-D6076A440E6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -10,6 +10,9 @@ namespace BlazorApp.Components
{ {
private Item _recipeResult; private Item _recipeResult;
[CascadingParameter]
public Crafting Parent { get; set; }
public Crafting() public Crafting()
{ {
Actions = new ObservableCollection<CraftingAction>(); Actions = new ObservableCollection<CraftingAction>();

@ -13,7 +13,8 @@ public static class ItemFactory
EnchantCategories = item.EnchantCategories, EnchantCategories = item.EnchantCategories,
MaxDurability = item.MaxDurability, MaxDurability = item.MaxDurability,
StackSize = item.StackSize, StackSize = item.StackSize,
ImageContent = imageContent ImageContent = imageContent,
ImageBase64 = string.IsNullOrWhiteSpace(item.ImageBase64) ? Convert.ToBase64String(imageContent) : item.ImageBase64
}; };
} }
@ -28,7 +29,8 @@ public static class ItemFactory
EnchantCategories = model.EnchantCategories, EnchantCategories = model.EnchantCategories,
MaxDurability = model.MaxDurability, MaxDurability = model.MaxDurability,
StackSize = model.StackSize, StackSize = model.StackSize,
CreatedDate = DateTime.Now CreatedDate = DateTime.Now,
ImageBase64 = Convert.ToBase64String(model.ImageContent)
}; };
} }
@ -41,5 +43,6 @@ public static class ItemFactory
item.MaxDurability = model.MaxDurability; item.MaxDurability = model.MaxDurability;
item.StackSize = model.StackSize; item.StackSize = model.StackSize;
item.UpdatedDate = DateTime.Now; item.UpdatedDate = DateTime.Now;
item.ImageBase64 = Convert.ToBase64String(model.ImageContent);
} }
} }

@ -11,5 +11,6 @@
public List<string> RepairWith { get; set; } public List<string> RepairWith { get; set; }
public DateTime CreatedDate { get; set; } public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; } public DateTime? UpdatedDate { get; set; }
public string ImageBase64 { get; set; }
} }
} }

@ -31,5 +31,5 @@
public bool AcceptCondition { get; set; } public bool AcceptCondition { get; set; }
[Required(ErrorMessage = "The image of the item is mandatory!")] [Required(ErrorMessage = "The image of the item is mandatory!")]
public byte[] ImageContent { get; set; } public string ImageBase64 { get; set; }
} }

@ -55,14 +55,7 @@
<p> <p>
<label> <label>
Current Item image: Current Item image:
@if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{itemModel.Name}.png")) <img src="data:image/png;base64, @(itemModel.ImageBase64)" class="img-thumbnail" title="@itemModel.DisplayName" alt="@itemModel.DisplayName" style="min-width: 50px; max-width: 150px" />
{
<img src="images/@(itemModel.Name).png" class="img-thumbnail" title="@itemModel.DisplayName" alt="@itemModel.DisplayName" style="max-width: 150px"/>
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@itemModel.DisplayName" alt="@itemModel.DisplayName" style="max-width: 150px"/>
}
</label> </label>
</p> </p>
<p> <p>

@ -42,10 +42,6 @@ public partial class Edit
var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.png"); var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.png");
if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{itemModel.Name}.png"))
{
fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/{item.Name}.png");
}
// Set the model with the item // Set the model with the item
itemModel = ItemFactory.ToModel(item, fileContent); itemModel = ItemFactory.ToModel(item, fileContent);

@ -14,37 +14,11 @@ Welcome to your new app.
<b>CurrentCulture</b>: @CultureInfo.CurrentCulture <b>CurrentCulture</b>: @CultureInfo.CurrentCulture
</p> </p>
<Card Item="CakeItem">
<CardHeader Context="headContext">
<div class="card-header">
Cake Token Number - @headContext.Id
</div>
</CardHeader>
<CardBody Context="bodyContext">
<div class="card-body">
<div>@bodyContext.Name</div>
<div>$ @bodyContext.Cost</div>
</div>
</CardBody>
</Card>
<ShowItems Items="Cakes" >
<ShowTemplate Context="CakeContext">
<div class="card text-center">
<div class="card-header">
Cake Token Id - @CakeContext.Id
</div>
<div class="card-body">
<h5 class="card-title">@CakeContext.Name</h5>
<p class="card-text">Price $@CakeContext.Cost</p>
</div>
<div class="card-footer text-muted">
Click Here
</div>
</div>
</ShowTemplate>
</ShowItems>
<TestRenderFragment> <TestRenderFragment>
<div>Content of my TestRenderFragment</div> <div>Content of my TestRenderFragment</div>
</TestRenderFragment> </TestRenderFragment>
<div>
<Crafting Items="Items" Recipes="Recipes" />
</div>

@ -1,35 +1,31 @@
namespace BlazorApp.Pages; namespace BlazorApp.Pages;
using BlazorApp.Components;
using BlazorApp.Models; using BlazorApp.Models;
using BlazorApp.Services;
using Microsoft.AspNetCore.Components;
public partial class Index public partial class Index
{ {
private Cake CakeItem = new Cake [Inject]
{ public IDataService DataService { get; set; }
Id = 1,
Name = "Black Forest",
Cost = 50
};
public List<Cake> Cakes { get; set; } public List<Item> Items { get; set; } = new List<Item>();
protected override Task OnAfterRenderAsync(bool firstRender) private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>();
{
LoadCakes();
StateHasChanged();
return base.OnAfterRenderAsync(firstRender);
}
public void LoadCakes() protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
Cakes = new List<Cake> base.OnAfterRenderAsync(firstRender);
if (!firstRender)
{ {
// items hidden for display purpose return;
new Cake }
{
Id = 1, Items = await DataService.List(0, await DataService.Count());
Name = "Red Velvet", Recipes = await DataService.GetRecipes();
Cost = 60
}, StateHasChanged();
};
} }
} }

@ -19,9 +19,9 @@
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="#" /> <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="#" />
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image"> <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image">
<DisplayTemplate> <DisplayTemplate>
@if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{context.Name}.png")) @if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{ {
<img src="images/@(context.Name).png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 150px" /> <img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 50px; max-width: 150px" />
} }
else else
{ {

@ -36,5 +36,6 @@
<link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" /> <link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
<script src="_content/Blazored.Modal/blazored.modal.js"></script> <script src="_content/Blazored.Modal/blazored.modal.js"></script>
<script src="Components/Crafting.razor.js"></script>
</body> </body>
</html> </html>

@ -21,7 +21,7 @@ builder.Services
.AddBootstrapProviders() .AddBootstrapProviders()
.AddFontAwesomeIcons() .AddFontAwesomeIcons()
.AddBlazoredLocalStorage(); .AddBlazoredLocalStorage();
builder.Services.AddScoped<IDataService, DataLocalService>(); builder.Services.AddScoped<IDataService, DataApiService>();
builder.Services.AddBlazoredModal(); builder.Services.AddBlazoredModal();
// Add the controller of the app // Add the controller of the app

@ -0,0 +1,58 @@
using BlazorApp.Components;
using BlazorApp.Models;
namespace BlazorApp.Services
{
public class DataApiService : IDataService
{
private readonly HttpClient _http;
public DataApiService(
HttpClient http)
{
_http = http;
}
public async Task Add(ItemModel model)
{
// Get the item
var item = ItemFactory.Create(model);
// Save the data
await _http.PostAsJsonAsync("https://localhost:7234/api/Crafting/", item);
}
public async Task<int> Count()
{
return await _http.GetFromJsonAsync<int>("https://localhost:7234/api/Crafting/count");
}
public async Task<List<Item>> List(int currentPage, int pageSize)
{
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
}
public async Task<Item> GetById(int id)
{
return await _http.GetFromJsonAsync<Item>($"https://localhost:7234/api/Crafting/{id}");
}
public async Task Update(int id, ItemModel model)
{
// Get the item
var item = ItemFactory.Create(model);
await _http.PutAsJsonAsync($"https://localhost:7234/api/Crafting/{id}", item);
}
public async Task Delete(int id)
{
await _http.DeleteAsync($"https://localhost:7234/api/Crafting/{id}");
}
public async Task<List<CraftingRecipe>> GetRecipes()
{
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:7234/api/Crafting/recipe");
}
}
}

@ -1,4 +1,5 @@
using BlazorApp.Models; using BlazorApp.Components;
using BlazorApp.Models;
using Blazored.LocalStorage; using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
namespace BlazorApp.Services; namespace BlazorApp.Services;
@ -33,20 +34,6 @@ public class DataLocalService : IDataService
// Add the item to the current data // Add the item to the current data
currentData.Add(ItemFactory.Create(model)); currentData.Add(ItemFactory.Create(model));
// Save the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
// Check if the folder "images" exist
if (!imagePathInfo.Exists)
{
imagePathInfo.Create();
}
// Determine the image name
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
// Write the file content
await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
// Save the data // Save the data
await _localStorage.SetItemAsync("data", currentData); await _localStorage.SetItemAsync("data", currentData);
@ -115,31 +102,7 @@ public class DataLocalService : IDataService
throw new Exception($"Unable to found the item with ID: {id}"); throw new Exception($"Unable to found the item with ID: {id}");
} }
// Save the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
// Check if the folder "images" exist
if (!imagePathInfo.Exists)
{
imagePathInfo.Create();
}
// Delete the previous image
if (item.Name != model.Name)
{
var oldFileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
if (oldFileName.Exists)
{
File.Delete(oldFileName.FullName);
}
}
// Determine the image name
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
// Write the file content
await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
// Modify the content of the item // Modify the content of the item
item.DisplayName = model.DisplayName; item.DisplayName = model.DisplayName;
@ -165,16 +128,28 @@ public class DataLocalService : IDataService
// Delete item in // Delete item in
currentData.Remove(item); currentData.Remove(item);
// Delete the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
if (fileName.Exists)
{
File.Delete(fileName.FullName);
}
// Save the data // Save the data
await _localStorage.SetItemAsync("data", currentData); await _localStorage.SetItemAsync("data", currentData);
} }
public Task<List<CraftingRecipe>> GetRecipes()
{
var items = new List<CraftingRecipe>
{
new CraftingRecipe
{
Give = new Item { DisplayName = "Diamond", Name = "diamond" },
Have = new List<List<string>>
{
new List<string> { "dirt", "dirt", "dirt" },
new List<string> { "dirt", null, "dirt" },
new List<string> { "dirt", "dirt", "dirt" }
}
}
};
return Task.FromResult(items);
}
} }

@ -1,4 +1,5 @@
using BlazorApp.Models; using BlazorApp.Components;
using BlazorApp.Models;
namespace BlazorApp.Services; namespace BlazorApp.Services;
public interface IDataService public interface IDataService
@ -13,4 +14,5 @@ public interface IDataService
Task Update(int id, ItemModel model); Task Update(int id, ItemModel model);
Task Delete(int id); Task Delete(int id);
Task<List<CraftingRecipe>> GetRecipes();
} }

@ -16,6 +16,11 @@
}, },
"runtime": { "runtime": {
"BlazorApp.dll": {} "BlazorApp.dll": {}
},
"resources": {
"fr-FR/BlazorApp.resources.dll": {
"locale": "fr-FR"
}
} }
}, },
"Blazored.LocalStorage/4.3.0": { "Blazored.LocalStorage/4.3.0": {

File diff suppressed because one or more lines are too long

@ -1 +1 @@
494cb91ea2c0ce87048f23e99a2141488636a055 39274d75b57d84777f566ef84223f08050df1afc

@ -41,3 +41,10 @@ C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\ne
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\Blazored.LocalStorage.dll C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\Blazored.LocalStorage.dll
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\Blazored.Modal.dll C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\Blazored.Modal.dll
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\Microsoft.JSInterop.WebAssembly.dll C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\Microsoft.JSInterop.WebAssembly.dll
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\bin\Debug\net6.0\fr-FR\BlazorApp.resources.dll
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\net6.0\BlazorApp.Ressources.Pages.List.resources
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\net6.0\BlazorApp.Ressources.Pages.List.fr-FR.resources
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\net6.0\BlazorApp.csproj.GenerateResource.cache
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\net6.0\fr-FR\BlazorApp.resources.dll
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\net6.0\scopedcss\Components\Crafting.razor.rz.scp.css
C:\Users\felix\Documents\BUT2\Blazor\TP\Sources\BlazorApp\BlazorApp\obj\Debug\net6.0\scopedcss\Components\CraftingItem.razor.rz.scp.css

@ -1,5 +1,32 @@
@import '_content/Blazored.Modal/Blazored.Modal.bundle.scp.css'; @import '_content/Blazored.Modal/Blazored.Modal.bundle.scp.css';
/* _content/BlazorApp/Components/Crafting.razor.rz.scp.css */
.css-grid[b-0c7vkjpwvp] {
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
display: grid;
width: 286px;
}
.css-recipe[b-0c7vkjpwvp] {
grid-template-columns: repeat(3,minmax(0,1fr));
gap: 10px;
display: grid;
width: 212px;
}
.actions[b-0c7vkjpwvp] {
border: 1px solid black;
height: 250px;
overflow: scroll;
}
/* _content/BlazorApp/Components/CraftingItem.razor.rz.scp.css */
.item[b-syyk20fth2] {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}
/* _content/BlazorApp/Shared/MainLayout.razor.rz.scp.css */ /* _content/BlazorApp/Shared/MainLayout.razor.rz.scp.css */
.page[b-3dsd3z3yec] { .page[b-3dsd3z3yec] {
position: relative; position: relative;

@ -1,3 +1,30 @@
/* _content/BlazorApp/Components/Crafting.razor.rz.scp.css */
.css-grid[b-0c7vkjpwvp] {
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
display: grid;
width: 286px;
}
.css-recipe[b-0c7vkjpwvp] {
grid-template-columns: repeat(3,minmax(0,1fr));
gap: 10px;
display: grid;
width: 212px;
}
.actions[b-0c7vkjpwvp] {
border: 1px solid black;
height: 250px;
overflow: scroll;
}
/* _content/BlazorApp/Components/CraftingItem.razor.rz.scp.css */
.item[b-syyk20fth2] {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}
/* _content/BlazorApp/Shared/MainLayout.razor.rz.scp.css */ /* _content/BlazorApp/Shared/MainLayout.razor.rz.scp.css */
.page[b-3dsd3z3yec] { .page[b-3dsd3z3yec] {
position: relative; position: relative;

@ -1,6 +1,6 @@
{ {
"Version": 1, "Version": 1,
"Hash": "aNWl4wC7DnYoeTkAvfsSHS3tjWq/GAa35L4SUl4sYgM=", "Hash": "r7w1GpW1tljT4kfmPObJ5ka2dDGzb1/DxGboajAVDq0=",
"Source": "BlazorApp", "Source": "BlazorApp",
"BasePath": "_content/BlazorApp", "BasePath": "_content/BlazorApp",
"Mode": "Default", "Mode": "Default",
@ -679,6 +679,23 @@
"CopyToPublishDirectory": "PreserveNewest", "CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "C:\\Users\\felix\\.nuget\\packages\\blazorise\\1.1.3.1\\staticwebassets\\vendors\\Pickr.js" "OriginalItemSpec": "C:\\Users\\felix\\.nuget\\packages\\blazorise\\1.1.3.1\\staticwebassets\\vendors\\Pickr.js"
}, },
{
"Identity": "C:\\Users\\felix\\Documents\\BUT2\\Blazor\\TP\\Sources\\BlazorApp\\BlazorApp\\Components\\Crafting.razor.js",
"SourceId": "BlazorApp",
"SourceType": "Discovered",
"ContentRoot": "C:\\Users\\felix\\Documents\\BUT2\\Blazor\\TP\\Sources\\BlazorApp\\BlazorApp\\",
"BasePath": "_content/BlazorApp",
"RelativePath": "Components/Crafting.razor.js",
"AssetKind": "All",
"AssetMode": "All",
"AssetRole": "Primary",
"RelatedAsset": "",
"AssetTraitName": "",
"AssetTraitValue": "",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "Components\\Crafting.razor.js"
},
{ {
"Identity": "C:\\Users\\felix\\Documents\\BUT2\\Blazor\\TP\\Sources\\BlazorApp\\BlazorApp\\obj\\Debug\\net6.0\\scopedcss\\bundle\\BlazorApp.styles.css", "Identity": "C:\\Users\\felix\\Documents\\BUT2\\Blazor\\TP\\Sources\\BlazorApp\\BlazorApp\\obj\\Debug\\net6.0\\scopedcss\\bundle\\BlazorApp.styles.css",
"SourceId": "BlazorApp", "SourceId": "BlazorApp",
@ -1001,6 +1018,23 @@
"CopyToOutputDirectory": "Never", "CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest", "CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "wwwroot\\images\\lefel.png" "OriginalItemSpec": "wwwroot\\images\\lefel.png"
},
{
"Identity": "C:\\Users\\felix\\Documents\\BUT2\\Blazor\\TP\\Sources\\BlazorApp\\BlazorApp\\wwwroot\\index.html",
"SourceId": "BlazorApp",
"SourceType": "Discovered",
"ContentRoot": "C:\\Users\\felix\\Documents\\BUT2\\Blazor\\TP\\Sources\\BlazorApp\\BlazorApp\\wwwroot\\",
"BasePath": "_content/BlazorApp",
"RelativePath": "index.html",
"AssetKind": "All",
"AssetMode": "All",
"AssetRole": "Primary",
"RelatedAsset": "",
"AssetTraitName": "",
"AssetTraitValue": "",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "wwwroot\\index.html"
} }
] ]
} }

File diff suppressed because one or more lines are too long

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
window.convertArray = (win1251Array) => {
var win1251decoder = new TextDecoder('windows-1251');
var bytes = new Uint8Array(win1251Array);
var decodedArray = win1251decoder.decode(bytes);
console.log(decodedArray);
return decodedArray;
};
</script>
<script>
window.displayTickerAlert1 = (symbol, price) => {
alert(`${symbol}: $${price}!`);
};
</script>
</body>
</html>

@ -0,0 +1,364 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CraftingController.cs" company="UCA Clermont-Ferrand">
// Copyright (c) UCA Clermont-Ferrand All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Minecraft.Crafting.Api.Controllers
{
using Microsoft.AspNetCore.Mvc;
using Minecraft.Crafting.Api.Models;
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
/// The crafting controller.
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class CraftingController : ControllerBase
{
/// <summary>
/// The json serializer options.
/// </summary>
private readonly JsonSerializerOptions _jsonSerializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
};
/// <summary>
/// Adds the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>The async task.</returns>
[HttpPost]
[Route("")]
public Task Add(Item item)
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
data.Add(item);
System.IO.File.WriteAllText("Data/items.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.CompletedTask;
}
/// <summary>
/// Count the number of items.
/// </summary>
/// <returns>The number of items.</returns>
[HttpGet]
[Route("count")]
public Task<int> Count()
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
return Task.FromResult(data.Count);
}
/// <summary>
/// Deletes the specified identifier.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>The async task.</returns>
[HttpDelete]
[Route("{id}")]
public Task Delete(int id)
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
var item = data.FirstOrDefault(w => w.Id == id);
if (item == null)
{
throw new Exception($"Unable to found the item with ID: {id}");
}
data.Remove(item);
System.IO.File.WriteAllText("Data/items.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.CompletedTask;
}
/// <summary>
/// Gets the item by identifier.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>The item.</returns>
[HttpGet]
[Route("{id}")]
public Task<Item> GetById(int id)
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
var item = data.FirstOrDefault(w => w.Id == id);
if (item == null)
{
throw new Exception($"Unable to found the item with ID: {id}");
}
return Task.FromResult(item);
}
/// <summary>
/// Gets the recipes.
/// </summary>
/// <returns>The recipes.</returns>
[HttpGet]
[Route("recipe")]
public Task<List<Recipe>> GetRecipe()
{
if (!System.IO.File.Exists("Data/convert-recipes.json"))
{
ResetRecipes();
}
var data = JsonSerializer.Deserialize<List<Recipe>>(System.IO.File.ReadAllText("Data/convert-recipes.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the recipes.");
}
return Task.FromResult(data);
}
/// <summary>
/// Get the items with pagination.
/// </summary>
/// <param name="currentPage">The current page.</param>
/// <param name="pageSize">Size of the page.</param>
/// <returns>The items.</returns>
[HttpGet]
[Route("")]
public Task<List<Item>> List(int currentPage, int pageSize)
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
return Task.FromResult(data.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList());
}
/// <summary>
/// Resets the items.
/// </summary>
/// <returns>The async task.</returns>
[HttpGet]
[Route("reset-items")]
public Task ResetItems()
{
if (!System.IO.File.Exists("Data/items.json"))
{
System.IO.File.Delete("Data/items.json");
}
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items-original.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
var defaultImage = Convert.ToBase64String(System.IO.File.ReadAllBytes("Images/default.png"));
foreach (var item in data)
{
var imageFilepath = defaultImage;
if (System.IO.File.Exists($"Images/{item.Name}.png"))
{
imageFilepath = Convert.ToBase64String(System.IO.File.ReadAllBytes($"Images/{item.Name}.png"));
}
item.ImageBase64 = imageFilepath;
}
System.IO.File.WriteAllText("Data/items.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.FromResult(data);
}
/// <summary>
/// Resets the recipes.
/// </summary>
/// <returns>The async task.</returns>
[HttpGet]
[Route("reset-recipes")]
public Task ResetRecipes()
{
if (!System.IO.File.Exists("Data/convert-recipes.json"))
{
System.IO.File.Delete("Data/convert-recipes.json");
}
ConvertRecipes();
return Task.CompletedTask;
}
/// <summary>
/// Updates the specified identifier.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="item">The item.</param>
/// <returns>The async task.</returns>
[HttpPut]
[Route("{id}")]
public Task Update(int id, Item item)
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
var itemOriginal = data?.FirstOrDefault(w => w.Id == id);
if (itemOriginal == null)
{
throw new Exception($"Unable to found the item with ID: {id}");
}
itemOriginal.Id = item.Id;
itemOriginal.Name = item.Name;
itemOriginal.CreatedDate = item.CreatedDate;
itemOriginal.DisplayName = item.DisplayName;
itemOriginal.EnchantCategories = item.EnchantCategories;
itemOriginal.MaxDurability = item.MaxDurability;
itemOriginal.RepairWith = item.RepairWith;
itemOriginal.StackSize = item.StackSize;
itemOriginal.UpdatedDate = item.UpdatedDate;
System.IO.File.WriteAllText("Data/items.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.CompletedTask;
}
/// <summary>
/// Gets the name of the item.
/// </summary>
/// <param name="items">The items.</param>
/// <param name="inShape">The in shape.</param>
/// <param name="line">The line.</param>
/// <param name="row">The row.</param>
/// <returns>The name of the item.</returns>
private static string GetItemName(List<Item> items, InShape[][] inShape, int line, int row)
{
if (inShape.Length < line + 1)
{
return null;
}
if (inShape[line].Length < row + 1)
{
return null;
}
var id = inShape[line][row].Integer ?? inShape[line][row].IngredientClass?.Id;
if (id == null)
{
return null;
}
return GetItemName(items, id.Value);
}
/// <summary>
/// Gets the name of the item.
/// </summary>
/// <param name="items">The items.</param>
/// <param name="id">The identifier.</param>
/// <returns>The name of the item.</returns>
private static string GetItemName(List<Item> items, long id)
{
var item = items.FirstOrDefault(w => w.Id == id);
return item?.Name;
}
/// <summary>
/// Converts the recipes.
/// </summary>
private void ConvertRecipes()
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
return;
}
var recipes = Recipes.FromJson(System.IO.File.ReadAllText("Data/recipes.json"));
var items = new List<Recipe>();
foreach (var recipe in recipes.SelectMany(s => s.Value))
{
if (recipe.InShape == null)
{
continue;
}
var giveItem = data.FirstOrDefault(w => w.Id == recipe.Result.Id);
if (giveItem == null)
{
continue;
}
items.Add(new Recipe
{
Give = new Item { DisplayName = giveItem.DisplayName, Name = giveItem.Name },
Have = new List<List<string>>
{
new()
{
GetItemName(data, recipe.InShape, 0, 0),
GetItemName(data, recipe.InShape, 0, 1),
GetItemName(data, recipe.InShape, 0, 2)
},
new()
{
GetItemName(data, recipe.InShape, 1, 0),
GetItemName(data, recipe.InShape, 1, 1),
GetItemName(data, recipe.InShape, 1, 2)
},
new()
{
GetItemName(data, recipe.InShape, 2, 0),
GetItemName(data, recipe.InShape, 2, 1),
GetItemName(data, recipe.InShape, 2, 2)
}
}
});
}
System.IO.File.WriteAllText("Data/convert-recipes.json", JsonSerializer.Serialize(items, _jsonSerializerOptions));
}
}
}

@ -0,0 +1,143 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InventoryController.cs" company="UCA Clermont-Ferrand">
// Copyright (c) UCA Clermont-Ferrand All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Minecraft.Crafting.Api.Controllers
{
using Microsoft.AspNetCore.Mvc;
using Minecraft.Crafting.Api.Models;
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
/// The inventory controller.
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class InventoryController : ControllerBase
{
/// <summary>
/// The json serializer options.
/// </summary>
private readonly JsonSerializerOptions _jsonSerializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
};
/// <summary>
/// Adds to inventory.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>The async task.</returns>
[HttpPost]
[Route("")]
public Task AddToInventory(InventoryModel item)
{
var data = JsonSerializer.Deserialize<List<InventoryModel>>(System.IO.File.ReadAllText("Data/inventory.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the inventory.");
}
data.Add(item);
System.IO.File.WriteAllText("Data/inventory.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.CompletedTask;
}
/// <summary>
/// Deletes from inventory.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>The async task.</returns>
[HttpDelete]
[Route("")]
public Task DeleteFromInventory(InventoryModel item)
{
if (!System.IO.File.Exists("Data/inventory.json"))
{
throw new Exception($"Unable to found the item with name: {item.ItemName}");
}
var data = JsonSerializer.Deserialize<List<InventoryModel>>(System.IO.File.ReadAllText("Data/inventory.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the inventory.");
}
var inventoryItem = data.FirstOrDefault(w => w.ItemName == item.ItemName && w.Position == item.Position);
if (inventoryItem == null)
{
throw new Exception($"Unable to found the item with name: {item.ItemName} at position: {item.Position}");
}
data.Remove(inventoryItem);
System.IO.File.WriteAllText("Data/inventory.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.CompletedTask;
}
/// <summary>
/// Gets the inventory.
/// </summary>
/// <returns>The inventory.</returns>
[HttpGet]
[Route("")]
public Task<List<InventoryModel>> GetInventory()
{
if (!System.IO.File.Exists("Data/inventory.json"))
{
return Task.FromResult(new List<InventoryModel>());
}
var data = JsonSerializer.Deserialize<List<InventoryModel>>(System.IO.File.ReadAllText("Data/inventory.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the inventory.");
}
return Task.FromResult(data);
}
/// <summary>
/// Updates the inventory.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>The async task.</returns>
[HttpPut]
[Route("")]
public Task UpdateInventory(InventoryModel item)
{
var data = JsonSerializer.Deserialize<List<InventoryModel>>(System.IO.File.ReadAllText("Data/inventory.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the inventory.");
}
var inventoryItem = data.FirstOrDefault(w => w.ItemName == item.ItemName && w.Position == item.Position);
if (inventoryItem == null)
{
throw new Exception($"Unable to found the item with name: {item.ItemName} at position: {item.Position}");
}
inventoryItem.ItemName = item.ItemName;
inventoryItem.Position = item.Position;
System.IO.File.WriteAllText("Data/inventory.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));
return Task.CompletedTask;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

@ -0,0 +1,22 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Minecraft.Crafting.Api/Minecraft.Crafting.Api.csproj", "Minecraft.Crafting.Api/"]
RUN dotnet restore "Minecraft.Crafting.Api/Minecraft.Crafting.Api.csproj"
COPY . .
WORKDIR "/src/Minecraft.Crafting.Api"
RUN dotnet build "Minecraft.Crafting.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Minecraft.Crafting.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Minecraft.Crafting.Api.dll"]

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save