Compare commits

..

8 Commits

Author SHA1 Message Date
remrem 852a6b795d Update 'Blazor/Blazor/Pages/_Layout.cshtml'
continuous-integration/drone/push Build is passing Details
2 years ago
remrem d523f07b9c Update 'Blazor/Blazor/Pages/_Layout.cshtml'
continuous-integration/drone/push Build is passing Details
2 years ago
Aurian JAULT 2aebc338d9 Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
remrem c6439a5562 add docs for a lot of class
continuous-integration/drone/push Build is passing Details
2 years ago
remrem 7cba21a0e4 Merge branch 'master' of https://codefirst.iut.uca.fr/git/remi.arnal/blazor
continuous-integration/drone/push Build is passing Details
2 years ago
remrem 763b94cb11 add doc for DataApiService
2 years ago
Aurian JAULT f67569da8a supr README
continuous-integration/drone/push Build is passing Details
2 years ago
Aurian JAULT fa450864f2 Ajouter 'Blazor/README.md'
continuous-integration/drone/push Build is passing Details
2 years ago

@ -61,7 +61,7 @@ steps:
dockerfile: Blazor/Blazor/Dockerfile dockerfile: Blazor/Blazor/Dockerfile
context: . context: .
registry: hub.codefirst.iut.uca.fr registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/aurian.jault/projet-blazor repo: hub.codefirst.iut.uca.fr/remi.arnal/blazor
username: username:
from_secret: SECRET_REGISTRY_USERNAME from_secret: SECRET_REGISTRY_USERNAME
password: password:
@ -74,8 +74,8 @@ steps:
- name: deploy-container - name: deploy-container
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment: environment:
IMAGENAME: hub.codefirst.iut.uca.fr/aurian.jault/projet-blazor IMAGENAME: hub.codefirst.iut.uca.fr/remi.arnal/blazor:latest
CONTAINERNAME: projet-blazor CONTAINERNAME: blazor-web
COMMAND: create COMMAND: create
OVERWRITE: true OVERWRITE: true
depends_on: [docker-build] depends_on: [docker-build]

@ -2,8 +2,17 @@
namespace Blazor.Factories namespace Blazor.Factories
{ {
/// <summary>
/// A static factory for creating and updating ItemModel and Item.
/// </summary>
public static class ItemFactory public static class ItemFactory
{ {
/// <summary>
/// Converts an Item to an ItemModel
/// </summary>
/// <param name="item">The item to convert.</param>
/// <param name="imageContent">The image content of the ItemModel</param>
/// <returns>An ItemModel with the same properties as the item.</returns>
public static ItemModel ToModel(Item item, byte[] imageContent) public static ItemModel ToModel(Item item, byte[] imageContent)
{ {
return new ItemModel return new ItemModel
@ -20,6 +29,11 @@ namespace Blazor.Factories
}; };
} }
/// <summary>
/// Creates an Item from an ItemModel.
/// </summary>
/// <param name="model">The ItemModel to create the Itemfrom.</param>
/// <returns>An Item with the same properties as the ItemModel.</returns>
public static Item Create(ItemModel model) public static Item Create(ItemModel model)
{ {
return new Item return new Item
@ -36,6 +50,11 @@ namespace Blazor.Factories
}; };
} }
/// <summary>
/// Updates an Item with the properties of an ItemModel.
/// </summary>
/// <param name="item"> The Item to update </param>
/// <param name="model"> The ItemModel used to update the item </param>
public static void Update(Item item, ItemModel model) public static void Update(Item item, ItemModel model)
{ {
item.DisplayName = model.DisplayName; item.DisplayName = model.DisplayName;

@ -6,17 +6,28 @@ using Microsoft.AspNetCore.Components;
namespace Blazor.Modals namespace Blazor.Modals
{ {
/// <summary>
/// Partial class for the delete confirmation modal.
/// </summary>
public partial class DeleteConfirmation public partial class DeleteConfirmation
{ {
/// <summary>
/// The modal instance
/// </summary>
[CascadingParameter] [CascadingParameter]
public BlazoredModalInstance ModalInstance { get; set; } public BlazoredModalInstance ModalInstance { get; set; }
[Inject] [Inject]
public IDataService DataService { get; set; } public IDataService DataService { get; set; }
/// <summary>
/// The id of the item to delete
/// </summary>
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
private Item item = new Item(); private Item item = new Item();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -25,11 +36,17 @@ namespace Blazor.Modals
item = await DataService.GetById(Id); item = await DataService.GetById(Id);
} }
/// <summary>
/// Confirms the deletion of the item.
/// </summary>
void ConfirmDelete() void ConfirmDelete()
{ {
ModalInstance.CloseAsync(ModalResult.Ok(true)); ModalInstance.CloseAsync(ModalResult.Ok(true));
} }
/// <summary>
/// Cancels the deletion of the item.
/// </summary>
void Cancel() void Cancel()
{ {
ModalInstance.CancelAsync(); ModalInstance.CancelAsync();

@ -2,23 +2,42 @@
namespace Blazor.Models namespace Blazor.Models
{ {
/// <summary>
/// Represents an item in a player's inventory.
/// </summary>
public class InventoryItem public class InventoryItem
{ {
public Item item; public Item item;
int stack; int stack;
/// <summary>
/// The number of items in the stack.
/// </summary>
public int Stack { get; set; } public int Stack { get; set; }
/// <summary>
/// Constructor for InventoryItem with no parameters.
/// </summary>
public InventoryItem() public InventoryItem()
{ {
item = new Item(); item = new Item();
Stack = 64; Stack = 64;
} }
/// <summary>
/// Constructor for InventoryItem with a single item.
/// </summary>
/// <param name="item">The item.</param>
public InventoryItem(Item item) public InventoryItem(Item item)
{ {
this.item = item; this.item = item;
Stack = 1; Stack = 1;
} }
/// <summary>
/// Constructor for InventoryItem with a stack of items.
/// </summary>
/// <param name="item">The item</param>
/// <param name="stock">The number of items in the stack.</param>
public InventoryItem(Item item, int stock) public InventoryItem(Item item, int stock)
{ {
this.item = item; this.item = item;

@ -2,11 +2,22 @@
namespace Blazor.Models namespace Blazor.Models
{ {
/// <summary>
/// Represents a list of items in a player's inventory.
/// </summary>
public partial class InventoryList public partial class InventoryList
{ {
static public int size = 18; static public int size = 18;
/// <summary>
/// List of inventory items.
/// </summary>
public List<InventoryItem> inventoryItems = new List<InventoryItem>(new InventoryItem[size]); public List<InventoryItem> inventoryItems = new List<InventoryItem>(new InventoryItem[size]);
/// <summary>
/// Constructor for InventoryList.
/// </summary>
public InventoryList() public InventoryList()
{ {
inventoryItems[0] = new InventoryItem(); inventoryItems[0] = new InventoryItem();

@ -1,5 +1,8 @@
namespace Blazor.Models namespace Blazor.Models
{ {
/// <summary>
/// Represents an item.
/// </summary>
public class Item public class Item
{ {
public int Id { get; set; } public int Id { get; set; }
@ -12,6 +15,10 @@
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; } public string ImageBase64 { get; set; }
/// <summary>
/// Constructor for Item.
/// </summary>
public Item() public Item()
{ {
Id = 2; Id = 2;

@ -2,6 +2,9 @@
namespace Blazor.Models namespace Blazor.Models
{ {
/// <summary>
/// Model for creating or updating an item.
/// </summary>
public class ItemModel public class ItemModel
{ {
public int Id { get; set; } public int Id { get; set; }

@ -5,15 +5,31 @@ using Microsoft.AspNetCore.Components;
namespace Blazor.Pages namespace Blazor.Pages
{ {
/// <summary>
/// Partial class for the Index page.
/// </summary>
public partial class Index public partial class Index
{ {
/// <summary>
/// The data service for accessing item and recipe data.
/// </summary>
[Inject] [Inject]
public IDataService DataService { get; set; } public IDataService DataService { get; set; }
/// <summary>
/// List of items to display on the page.
/// </summary>
public List<Item> Items { get; set; } = new List<Item>(); public List<Item> Items { get; set; } = new List<Item>();
/// <summary>
/// List of crafting recipes possible.
/// </summary>
private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>(); private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>();
/// <summary>
/// Method that runs after the component has finished rendering.
/// </summary>
/// <param name="firstRender">Indicates whether this is the first render of the component.</param>
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
base.OnAfterRenderAsync(firstRender); base.OnAfterRenderAsync(firstRender);

@ -4,9 +4,14 @@ using Microsoft.Extensions.Localization;
namespace Blazor.Pages namespace Blazor.Pages
{ {
/// <summary>
/// Partial class for the InventoryPage.
/// </summary>
public partial class InventoryPage public partial class InventoryPage
{ {
/// <summary>
/// The localizer for the InventoryPage.
/// </summary>
[Inject] [Inject]
public IStringLocalizer<InventoryPage> Localizer { get; set; } public IStringLocalizer<InventoryPage> Localizer { get; set; }

@ -10,6 +10,9 @@ using Microsoft.Extensions.Localization;
namespace Blazor.Pages namespace Blazor.Pages
{ {
/// <summary>
/// Partial class for the List page.
/// </summary>
public partial class List public partial class List
{ {
private List<Item> items; private List<Item> items;
@ -22,15 +25,29 @@ namespace Blazor.Pages
[Inject] [Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; } public IWebHostEnvironment WebHostEnvironment { get; set; }
/// <summary>
/// The navigation manager for navigating between pages.
/// </summary>
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public NavigationManager NavigationManager { get; set; }
/// <summary>
/// The modal service for displaying modal dialogs
/// </summary>
[CascadingParameter] [CascadingParameter]
public IModalService Modal { get; set; } public IModalService Modal { get; set; }
/// <summary>
/// The localizer for the List page.
/// </summary>
[Inject] [Inject]
public IStringLocalizer<List> Localizer { get; set; } public IStringLocalizer<List> Localizer { get; set; }
/// <summary>
/// Event handler for reading data in the data grid.
/// </summary>
/// <param name="e">The event arguments.</param>
/// <returns>A task representing the asynchronous operation.</returns>
private async Task OnReadData(DataGridReadDataEventArgs<Item> e) private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{ {
if (e.CancellationToken.IsCancellationRequested) if (e.CancellationToken.IsCancellationRequested)
@ -45,6 +62,10 @@ namespace Blazor.Pages
} }
} }
/// <summary>
/// Event handler for deleting an item.
/// </summary>
/// <param name="id">The id of the item to delete.</param>
private async void OnDelete(int id) private async void OnDelete(int id)
{ {
var parameters = new ModalParameters(); var parameters = new ModalParameters();

@ -7,7 +7,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="https://codefirst.iut.uca.fr/containers/projet-blazor-aurianjault/" /> <base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" /> <link href="css/site.css" rel="stylesheet" />
<link href="Blazor.styles.css" rel="stylesheet" /> <link href="Blazor.styles.css" rel="stylesheet" />

@ -4,15 +4,26 @@ using Blazor.Models;
namespace Blazor.Services namespace Blazor.Services
{ {
/// <summary>
/// Service for interacting with a data API.
/// </summary>
public class DataApiService : IDataService public class DataApiService : IDataService
{ {
private readonly HttpClient _http; private readonly HttpClient _http;
/// <summary>
/// Constructor for DataApiService.
/// </summary>
/// <param name="http">HttpClient for making API requests.</param>
public DataApiService(HttpClient http) public DataApiService(HttpClient http)
{ {
_http = http; _http = http;
} }
/// <summary>
/// Add a new item to the API.
/// </summary>
/// <param name="model">Model containing data for the new item.</param>
public async Task Add(ItemModel model) public async Task Add(ItemModel model)
{ {
// Get the item // Get the item
@ -22,26 +33,50 @@ namespace Blazor.Services
await _http.PostAsJsonAsync("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/", item); await _http.PostAsJsonAsync("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/", item);
} }
/// <summary>
/// Get the number of items in the API.
/// </summary>
/// <returns>Task representing the asynchronous operation, returning the number of items.</returns>
public async Task<int> Count() public async Task<int> Count()
{ {
return await _http.GetFromJsonAsync<int>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/count"); return await _http.GetFromJsonAsync<int>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/count");
} }
/// <summary>
/// Get a list of items from the API, paginated.
/// </summary>
/// <param name="currentPage">The current page number.</param>
/// <param name="pageSize">The number of items per page.</param>
/// <returns>Task representing the asynchronous operation, returning a list of items.</returns>
public async Task<List<Item>> List(int currentPage, int pageSize) public async Task<List<Item>> List(int currentPage, int pageSize)
{ {
return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
} }
/// <summary>
/// Get a list of all items from the API.
/// </summary>
/// <returns>Task representing the asynchronous operation, returning a list of items.</returns>
public async Task<List<Item>> getAll() public async Task<List<Item>> getAll()
{ {
return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all"); return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all");
} }
/// <summary>
/// Get a single item from the API by its ID.
/// </summary>
/// <param name="id">The ID of the item to retrieve.</param>
/// <returns>Task representing the asynchronous operation, returning the item with the specified ID.</returns>
public async Task<Item> GetById(int id) public async Task<Item> GetById(int id)
{ {
return await _http.GetFromJsonAsync<Item>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}"); return await _http.GetFromJsonAsync<Item>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}");
} }
/// <summary>
/// Update an existing item in the API.
/// </summary>
/// <param name="id">The ID of the item to update.</param>
/// <param name="model">Model containing the updated data for the item.</param>
public async Task Update(int id, ItemModel model) public async Task Update(int id, ItemModel model)
{ {
// Get the item // Get the item
@ -50,11 +85,19 @@ namespace Blazor.Services
await _http.PutAsJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}", item); await _http.PutAsJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}", item);
} }
/// <summary>
/// Delete an existing item from the API.
/// </summary>
/// <param name="id">The ID of the item to delete.</param>
public async Task Delete(int id) public async Task Delete(int id)
{ {
await _http.DeleteAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}"); await _http.DeleteAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}");
} }
/// <summary>
/// Get a list of crafting recipes from the API.
/// </summary>
/// <returns>Task representing the asynchronous operation, returning a list of crafting recipes.</returns>
public async Task<List<CraftingRecipe>> GetRecipes() public async Task<List<CraftingRecipe>> GetRecipes()
{ {
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/recipe"); return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/recipe");

@ -1,5 +1,5 @@
# Projet blazor # Projet blazor
# coucou bhj
## Présentation ## Présentation
Le projet de notre dépôt contient tous les éléments de la consignes (hors bonus), indiqué à [cette adresse](https://codefirst.iut.uca.fr/documentation/julien.riboulet/docusaurus/Blazor/your-next-steps). Le projet de notre dépôt contient tous les éléments de la consignes (hors bonus), indiqué à [cette adresse](https://codefirst.iut.uca.fr/documentation/julien.riboulet/docusaurus/Blazor/your-next-steps).
@ -8,7 +8,7 @@ Le projet de notre dépôt contient tous les éléments de la consignes (hors bo
Plusieurs méthodes sont disponibles pour lancer le projet. Plusieurs méthodes sont disponibles pour lancer le projet.
### Via Docker ### Via Docker
Une version déployée du projet est déjà disponible à l'URL https://codefirst.iut.uca.fr/containers/blazor-web-aurianjault Une version déployée du projet est déjà disponible à l'URL https://codefirst.iut.uca.fr/containers/projet-blazor-aurianjault
### Via Visual Studio ### Via Visual Studio

Loading…
Cancel
Save