Skip to content

Commit

Permalink
fix: makes userItem not unique (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
or2e authored Dec 2, 2024
1 parent 1aea5b0 commit f8bf16e
Show file tree
Hide file tree
Showing 8 changed files with 2,365 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Persistence/Configurations/UserItemConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class UserItemConfiguration : IEntityTypeConfiguration<UserItem>
{
public void Configure(EntityTypeBuilder<UserItem> builder)
{
builder.HasIndex(ui => new { ui.UserId, ui.ItemId }).IsUnique();
builder.HasIndex(ui => new { ui.UserId, ui.ItemId });

builder.HasOne(ui => ui.User)
.WithMany(u => u.Items)
Expand Down
2,317 changes: 2,317 additions & 0 deletions src/Persistence/Migrations/20241201174640_DisableUniqueUserItem.Designer.cs

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/Persistence/Migrations/20241201174640_DisableUniqueUserItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Crpg.Persistence.Migrations;

/// <inheritdoc />
public partial class DisableUniqueUserItem : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "ix_user_items_user_id_item_id",
table: "user_items");

migrationBuilder.CreateIndex(
name: "ix_user_items_user_id_item_id",
table: "user_items",
columns: new[] { "user_id", "item_id" });
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "ix_user_items_user_id_item_id",
table: "user_items");

migrationBuilder.CreateIndex(
name: "ix_user_items_user_id_item_id",
table: "user_items",
columns: new[] { "user_id", "item_id" },
unique: true);
}
}
1 change: 0 additions & 1 deletion src/Persistence/Migrations/CrpgDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasDatabaseName("ix_user_items_item_id");

b.HasIndex("UserId", "ItemId")
.IsUnique()
.HasDatabaseName("ix_user_items_user_id_item_id");

b.ToTable("user_items", (string)null);
Expand Down
2 changes: 1 addition & 1 deletion src/WebUI/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ shop:
success: Item was successfully purchased
tooltip:
buy: Buy item
inInventory: The item is already in your inventory
inInventory: The item is already in your inventory ({count})
notEnoughGold: Not enough gold
weaponUsage:
title: Not a primary usage mode
Expand Down
2 changes: 1 addition & 1 deletion src/WebUI/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ shop:
success: Предмет успешно куплен
tooltip:
buy: Купить предмет
inInventory: Предмет уже в инвентаре
inInventory: Предмет уже в инвентаре ({count})
notEnoughGold: Не хватает золота
weaponUsage:
title: Не является основным режимом использования
Expand Down
16 changes: 8 additions & 8 deletions src/WebUI/src/components/shop/ShopGridItemBuyBtn.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { useUserStore } from '~/stores/user'
const { inInventory, notEnoughGold, price, upkeep } = defineProps<{
const { inInventoryCount = 0, notEnoughGold, price, upkeep } = defineProps<{
price: number
upkeep: number
inInventory: boolean
inInventoryCount: number
notEnoughGold: boolean
}>()
Expand Down Expand Up @@ -32,11 +32,11 @@ const isExpensive = computed(() => user.value!.gold - price < upkeep)
:class="{ 'opacity-50': notEnoughGold }"
/>
<Tag
v-if="inInventory"
icon="check"
v-if="inInventoryCount > 0"
size="sm"
variant="success"
variant="primary"
rounded
:label="String(inInventoryCount)"
/>
<Tag
v-if="isExpensive"
Expand All @@ -60,10 +60,10 @@ const isExpensive = computed(() => user.value!.gold - price < upkeep)
</div>

<p
v-if="inInventory"
class="text-status-success"
v-if="inInventoryCount > 0"
class="text-primary"
>
{{ $t('shop.item.buy.tooltip.inInventory') }}
{{ $t('shop.item.buy.tooltip.inInventory', { count: inInventoryCount }) }}
</p>
<p
v-if="notEnoughGold"
Expand Down
2 changes: 1 addition & 1 deletion src/WebUI/src/pages/shop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const newItemCount = computed(
<ShopGridItemBuyBtn
:price="(rawBuckets as number)"
:upkeep="item.upkeep"
:in-inventory="userItemsIds.includes(item.id)"
:in-inventory-count="userItemsIds.filter(id => id === item.id).length"
:not-enough-gold="user!.gold < item.price"
@buy="buyItem(item)"
/>
Expand Down

0 comments on commit f8bf16e

Please sign in to comment.