Skip to content

Commit

Permalink
deleting an item works
Browse files Browse the repository at this point in the history
  • Loading branch information
m-GDEV committed Oct 5, 2024
1 parent d5dbf63 commit 73997c0
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 31 deletions.
4 changes: 2 additions & 2 deletions WardrobeManager.Api/Endpoints/ClothingEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public static async Task<IResult> EditClothingItem(
// Delete one clothing item
// ---------------------
public static async Task<IResult> DeleteClothingItem(
int itemId, IClothingItemService clothingItemService, HttpContext context, IUserService userService, DatabaseContext _context
int id, IClothingItemService clothingItemService, HttpContext context, IUserService userService, DatabaseContext _context
){
User? user = context.Items["user"] as User;
Debug.Assert(user != null, "Cannot get user");

await clothingItemService.DeleteClothingItem(user.Id,itemId);
await clothingItemService.DeleteClothingItem(user.Id,id);

return Results.Ok("Deleted");
}
Expand Down
50 changes: 30 additions & 20 deletions WardrobeManager.Presentation/Componenets/Clothing/ItemSummary.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,38 @@

<div class="flex flex-row justify-between py-4 px-8 bg-primary-content w-full rounded-lg items-center">
@* Left section *@
<div class="w-1/5">
<img src="@ProjectConstants.ApiUrl/images/@Item.ImageGuid" class="" />
</div>
@* Middle section *@
<div class="flex flex-col items-center justify-between w-3/5 h-full gap-5">
<div>
<div class="flex flex-row gap-10 items-center">
<p class="subtitle-text text-primary">@Item.Name</p>
<span class="body-text bi bi-stars text-accent"></span>
</div>
<div class="flex flex-row gap-5 pt-2">
<Tag Label="@ProjectConstants.GetNameWithSpacesAndEmoji(Item.Category)" AdditionalCss="text-secondary-content bg-secondary" />
<Tag Label="@ProjectConstants.GetNameWithSpacesAndEmoji(Item.Season)" AdditionalCss="text-secondary-content bg-secondary" />
</div>
<div class="flex flex-row gap-5 grow items-center">
<div class="w-1/5">
<img src="@ProjectConstants.ApiUrl/images/@Item.ImageGuid" class="" />
</div>
@* Text part *@
<div class="flex flex-col justify-between grow h-full gap-5">
<div>
<div class="flex flex-row gap-2 items-center">
<p class="subtitle-text text-primary">@Item.Name</p>
<span class="body-text bi bi-stars text-accent"></span>
</div>
<div class="flex flex-row gap-5 pt-2">
<Tag Label="@ProjectConstants.GetNameWithSpacesAndEmoji(Item.Category)" AdditionalCss="text-secondary-content bg-secondary" />
<Tag Label="@ProjectConstants.GetNameWithSpacesAndEmoji(Item.Season)" AdditionalCss="text-secondary-content bg-secondary" />
</div>
</div>

<p class="body-text text-primary">
Last updated: @Item.DateUpdated.ToString("MMMM d, yyyy")
</p>
<p class="body-text text-primary">
Last updated: @Item.DateUpdated.ToString("MMMM d, yyyy")
</p>
</div>
</div>
@* Right section *@
<div class="flex flex-col items-center justify-between w-1/6 h-full gap-3">
@* Maybe not the best way but it works *@
<div @onclick="HandleView">
<SmallButton Label="View" AdditionalCss="text-accent-content bg-accent" />

<SmallButton Label="View" AdditionalCss="text-accent-content bg-accent" />
</div>
<SmallButton Label="Edit" AdditionalCss="text-primary-content bg-primary" />
<SmallButton Label="Delete" AdditionalCss="text-secondary-content bg-secondary" />
<div @onclick="HandleDelete">
<SmallButton Label="Delete" AdditionalCss="text-secondary-content bg-secondary" />
</div>
</div>
</div>

Expand All @@ -50,9 +54,15 @@
// This method is a callback from the parent that does stuff when the 'view' button is clicked
[Parameter]
public EventCallback<ServerClothingItem> ViewMethod { get; set; }
[Parameter]
public EventCallback<ServerClothingItem> DeleteMethod { get; set; }

public async Task HandleView()
{
await ViewMethod.InvokeAsync(Item);
}
public async Task HandleDelete()
{
await DeleteMethod.InvokeAsync(Item);
}
}
20 changes: 17 additions & 3 deletions WardrobeManager.Presentation/Pages/Authenticated/Clothing.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@using System.Text.RegularExpressions


@inject IApiService ApiService
@inject IApiService _apiService
@inject INotificationService _notificationService
@* @inject HttpClient Http *@
@* @inject IHttpClientFactory ClientFactory *@
Expand Down Expand Up @@ -106,7 +106,7 @@
{
foreach (var item in clothing)
{
<ItemSummary Item="item" ViewMethod="ChangeSelectedItem" />
<ItemSummary Item="item" ViewMethod="ChangeSelectedItem" DeleteMethod="DeleteItem" />
}
}
</div>
Expand Down Expand Up @@ -170,7 +170,7 @@
{
try
{
clothing = await ApiService.GetClothing();
clothing = await _apiService.GetClothing();

}
catch (AccessTokenNotAvailableException exception)
Expand All @@ -189,6 +189,20 @@
{
selectedItem = item;
}
public async Task DeleteItem(ServerClothingItem item)
{
try
{

await _apiService.Delete(item);
clothing = await _apiService.GetClothing();
StateHasChanged();
}
catch (HttpRequestException ex)
{
_notificationService.AddNotification($"Cannot fetch clothing: {ex.Message}", NotificationType.Error);
}
}

@* Static Variables *@
public class FilterModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ public async Task Update(NewOrEditedClothingItemDTO clothing)

public async Task Delete(ServerClothingItem clothing)
{
var res = await _httpClient.DeleteAsync( "/clothingitem?id={clothing.Id}");
var res = await _httpClient.DeleteAsync($"/clothing/{clothing.Id}");
res.EnsureSuccessStatusCode();
}
public async Task Wear(ServerClothingItem clothing)
{
var res = await _httpClient.GetAsync($"/actions/wear/{clothing.Id}");
res.EnsureSuccessStatusCode();
}
public async Task Wash(ServerClothingItem clothing)
{
var res = await _httpClient.GetAsync($"/actions/wear/{clothing.Id}");
res.EnsureSuccessStatusCode();
}

Expand Down
13 changes: 9 additions & 4 deletions WardrobeManager.Presentation/Services/Interfaces/IApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ namespace WardrobeManager.Presentation.Services.Interfaces;
public interface IApiService
{
ValueTask DisposeAsync();
Task<List<ServerClothingItem>?> GetClothing();

// Things to do with new/edited items
Task Add(NewOrEditedClothingItemDTO clothing);
Task Delete(ServerClothingItem clothing);
Task Update(NewOrEditedClothingItemDTO clothing);
// Task<bool> IsUserInitialized();
// Task CreateUser();

// Things to do with existing items
Task<List<ServerClothingItem>?> GetClothing();
Task Delete(ServerClothingItem clothing);
Task Wear(ServerClothingItem clothing);
Task Wash(ServerClothingItem clothing);

}
2 changes: 1 addition & 1 deletion WardrobeManager.Shared/Misc/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ProjectConstants
{
public static string Name = "Wardrobe Manager";
public static string ApiUrl = "https://localhost:7026"; // should probably change this, also it should not be in the Shared project
public static string ProfileImage = "https://upload.internal.connectwithmusa.com/upload/eel-falcon-pig";
public static string ProfileImage = "https://upload.internal.connectwithmusa.com/file/eel-falcon-pig";
public static string DefaultItemImage = "https://image.hm.com/assets/hm/a3/f5/a3f56f6e47160e931b78296bb9e479bfbcab3554.jpg?imwidth=2160";

public static string GetEmoji(ClothingCategory category)
Expand Down

0 comments on commit 73997c0

Please sign in to comment.