Skip to content

Commit

Permalink
✨ added increment Counter Request to details View (#102)
Browse files Browse the repository at this point in the history
Co-authored-by: jannik.lange <[email protected]>
  • Loading branch information
langehm and jannik.lange authored Jan 17, 2025
1 parent 8e632c7 commit 3826181
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions anzeigen-frontend/src/composables/api/useAdApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
GetAdRequest,
GetAds200Response,
GetAdsRequest,
IncrementViewRequest,
UpdateAdRequest,
} from "@/api/swbrett";

Expand Down Expand Up @@ -58,3 +59,13 @@ export function useGetAds() {
api.getAds(params)
);
}

export function useIncrementAdView() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const api = inject(DEFAULT_API_KEY)!;

// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
return useApiCall<IncrementViewRequest, void>(
(params: IncrementViewRequest) => api.incrementView(params)
);
}
7 changes: 6 additions & 1 deletion anzeigen-frontend/src/views/AdDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { useRouter } from "vue-router";
import AdNotFound from "@/components/Ad/Details/AdNotFound.vue";
import AdOverview from "@/components/Ad/Details/AdOverview.vue";
import { useGetAd } from "@/composables/api/useAdApi";
import { useGetAd, useIncrementAdView } from "@/composables/api/useAdApi";
import { useClearCacheEventBus } from "@/composables/useEventBus";
const clearCacheEventBus = useClearCacheEventBus();
Expand All @@ -63,6 +63,8 @@ const {
loading,
} = useGetAd();
const { call: incrementView } = useIncrementAdView();
const adDetails = ref<Readonly<AdTO> | null>(null);
const getAd = useMemoize(async (adId: number) => {
Expand All @@ -79,6 +81,9 @@ watch(idQuery, (newId) => {
});
onMounted(async () => {
if (idQuery.value) {
await incrementView({ id: parseInt(idQuery.value.toString()) });
}
await updateAd(idQuery.value?.toString() || "");
});
Expand Down

0 comments on commit 3826181

Please sign in to comment.