-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented roster item removal. (#16)
- Loading branch information
Showing
15 changed files
with
183 additions
and
67 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
backend/src/PokeData.Application/Roster/Commands/RemoveRosterItemCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using MediatR; | ||
|
||
namespace PokeData.Application.Roster.Commands; | ||
|
||
internal record RemoveRosterItemCommand(ushort SpeciesId) : IRequest<Unit>; |
20 changes: 20 additions & 0 deletions
20
backend/src/PokeData.Application/Roster/Commands/RemoveRosterItemCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using MediatR; | ||
using PokeData.Domain.Roster; | ||
|
||
namespace PokeData.Application.Roster.Commands; | ||
|
||
internal class RemoveRosterItemCommandHandler : IRequestHandler<RemoveRosterItemCommand, Unit> | ||
{ | ||
private readonly IPokemonRosterRepository _rosterRepository; | ||
|
||
public RemoveRosterItemCommandHandler(IPokemonRosterRepository rosterRepository) | ||
{ | ||
_rosterRepository = rosterRepository; | ||
} | ||
|
||
public async Task<Unit> Handle(RemoveRosterItemCommand command, CancellationToken cancellationToken) | ||
{ | ||
await _rosterRepository.DeleteAsync(command.SpeciesId, cancellationToken); | ||
return Unit.Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__VITE_APP_API_BASE_URL="http://localhost:43551/" | ||
VITE_APP_API_BASE_URL="https://localhost:32770/" | ||
VITE_APP_API_BASE_URL="https://localhost:32772/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import type { PokemonRoster, SaveRosterItemPayload, SavedRosterItem } from "@/types/roster"; | ||
import { get, put } from "."; | ||
import { _delete, get, put } from "."; | ||
|
||
export async function readRoster(): Promise<PokemonRoster> { | ||
return (await get<PokemonRoster>("/pokemon/roster")).data; | ||
} | ||
|
||
export async function removeRosterItem(speciesId: number): Promise<SavedRosterItem> { | ||
return (await _delete<SavedRosterItem>(`/pokemon/roster/${speciesId}`)).data; | ||
} | ||
|
||
export async function saveRosterItem(speciesId: number, payload: SaveRosterItemPayload): Promise<SavedRosterItem> { | ||
return (await put<SaveRosterItemPayload, SavedRosterItem>(`/pokemon/roster/${speciesId}`, payload)).data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script setup lang="ts"> | ||
import { TarButton, TarModal } from "logitar-vue3-ui"; | ||
import { ref } from "vue"; | ||
import RosterItem from "./RosterItem.vue"; | ||
import type { RosterItem as RosterItemType, SavedRosterItem } from "@/types/roster"; | ||
import { removeRosterItem } from "@/api/roster"; | ||
const props = defineProps<{ | ||
item?: RosterItemType; | ||
}>(); | ||
const loading = ref<boolean>(false); | ||
const modal = ref<InstanceType<typeof TarModal>>(); | ||
const emit = defineEmits<{ | ||
(e: "removed", item: SavedRosterItem): void; | ||
}>(); | ||
async function onRemove(): Promise<void> { | ||
if (!loading.value && props.item) { | ||
loading.value = true; | ||
try { | ||
const removed = await removeRosterItem(props.item.speciesId); | ||
emit("removed", removed); | ||
loading.value = false; | ||
modal.value.hide(); | ||
} catch (e: unknown) { | ||
loading.value = false; | ||
throw e; | ||
} | ||
} | ||
} | ||
function show(): void { | ||
modal.value.show(); | ||
} | ||
defineExpose({ show }); | ||
</script> | ||
|
||
<template> | ||
<TarModal ref="modal" title="Remove Pokémon"> | ||
<template v-if="item?.destination"> | ||
<p>Do you really want to remove the following Pokémon from the roster?</p> | ||
<RosterItem :pokemon="item.destination" /> | ||
</template> | ||
<template #footer> | ||
<TarButton :icon="['fas', 'ban']" text="Cancel" variant="secondary" @click="modal.hide()" /> | ||
<TarButton :disabled="loading" :icon="['fas', 'trash-can']" :loading="loading" text="Remove" variant="danger" @click="onRemove" /> | ||
</template> | ||
</TarModal> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
import { faArrowUpRightFromSquare, faArrowsRotate, faBan, faCheck, faFloppyDisk, faPenToSquare, faPlus, faTimes } from "@fortawesome/free-solid-svg-icons"; | ||
import { | ||
faArrowUpRightFromSquare, | ||
faArrowsRotate, | ||
faBan, | ||
faCheck, | ||
faFloppyDisk, | ||
faPenToSquare, | ||
faPlus, | ||
faTimes, | ||
faTrashCan, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { library } from "@fortawesome/fontawesome-svg-core"; | ||
|
||
library.add(faArrowUpRightFromSquare, faArrowsRotate, faBan, faCheck, faFloppyDisk, faPenToSquare, faPlus, faTimes); | ||
library.add(faArrowUpRightFromSquare, faArrowsRotate, faBan, faCheck, faFloppyDisk, faPenToSquare, faPlus, faTimes, faTrashCan); |
Oops, something went wrong.