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
context: .
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:
from_secret: SECRET_REGISTRY_USERNAME
password:
@ -74,8 +74,8 @@ steps:
- name: deploy-container
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment:
IMAGENAME: hub.codefirst.iut.uca.fr/aurian.jault/projet-blazor
CONTAINERNAME: projet-blazor
IMAGENAME: hub.codefirst.iut.uca.fr/remi.arnal/blazor:latest
CONTAINERNAME: blazor-web
COMMAND: create
OVERWRITE: true
depends_on: [docker-build]

@ -1,11 +1,20 @@
using Blazor.Models;
namespace Blazor.Factories
{
{
/// <summary>
/// A static factory for creating and updating ItemModel and Item.
/// </summary>
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)
{
{
return new ItemModel
{
Id = item.Id,
@ -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)
{
return new Item
@ -35,7 +49,12 @@ namespace Blazor.Factories
ImageBase64 = Convert.ToBase64String(model.ImageContent)
};
}
/// <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)
{
item.DisplayName = model.DisplayName;

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

@ -1,24 +1,43 @@
using System.Collections;
namespace Blazor.Models
{
{
/// <summary>
/// Represents an item in a player's inventory.
/// </summary>
public class InventoryItem
{
public Item item;
int stack;
/// <summary>
/// The number of items in the stack.
/// </summary>
public int Stack { get; set; }
/// <summary>
/// Constructor for InventoryItem with no parameters.
/// </summary>
public InventoryItem()
{
item = new Item();
Stack = 64;
}
/// <summary>
/// Constructor for InventoryItem with a single item.
/// </summary>
/// <param name="item">The item.</param>
public InventoryItem(Item item)
{
this.item = item;
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)
{
this.item = item;

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

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

@ -1,7 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace Blazor.Models
{
{
/// <summary>
/// Model for creating or updating an item.
/// </summary>
public class ItemModel
{
public int Id { get; set; }

@ -4,16 +4,32 @@ using Blazor.Services;
using Microsoft.AspNetCore.Components;
namespace Blazor.Pages
{
{
/// <summary>
/// Partial class for the Index page.
/// </summary>
public partial class Index
{
{
/// <summary>
/// The data service for accessing item and recipe data.
/// </summary>
[Inject]
public IDataService DataService { get; set; }
/// <summary>
/// List of items to display on the page.
/// </summary>
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>();
/// <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)
{
base.OnAfterRenderAsync(firstRender);

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

@ -9,9 +9,12 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace Blazor.Pages
{
{
/// <summary>
/// Partial class for the List page.
/// </summary>
public partial class List
{
{
private List<Item> items;
private int totalItem;
@ -22,15 +25,29 @@ namespace Blazor.Pages
[Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; }
/// <summary>
/// The navigation manager for navigating between pages.
/// </summary>
[Inject]
public NavigationManager NavigationManager { get; set; }
/// <summary>
/// The modal service for displaying modal dialogs
/// </summary>
[CascadingParameter]
public IModalService Modal { get; set; }
/// <summary>
/// The localizer for the List page.
/// </summary>
[Inject]
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)
{
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)
{
var parameters = new ModalParameters();

@ -7,7 +7,7 @@
<head>
<meta charset="utf-8" />
<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 href="css/site.css" rel="stylesheet" />
<link href="Blazor.styles.css" rel="stylesheet" />

@ -3,16 +3,27 @@ using Blazor.Factories;
using Blazor.Models;
namespace Blazor.Services
{
{
/// <summary>
/// Service for interacting with a data API.
/// </summary>
public class DataApiService : IDataService
{
private readonly HttpClient _http;
/// <summary>
/// Constructor for DataApiService.
/// </summary>
/// <param name="http">HttpClient for making API requests.</param>
public DataApiService(HttpClient 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)
{
// 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);
}
/// <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()
{
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)
{
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()
{
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)
{
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)
{
// 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);
}
/// <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)
{
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()
{
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
# coucou bhj
## 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).
@ -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.
### 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

Loading…
Cancel
Save