From b613d3516aa1c07c3efa1cc604d1243cdff71b60 Mon Sep 17 00:00:00 2001
From: gregor <gregor.schulz@holi.social>
Date: Mon, 24 Mar 2025 09:11:36 +0100
Subject: [PATCH] refactor: consolidate jasd response model naming

---
 app/adapters/jasd/JasdGateway.ts                   | 13 ++++++-------
 app/adapters/jasd/types/appapi.dto.types.ts        |  6 +++---
 app/usecases/QueryEvents.test.ts                   |  8 ++++----
 app/usecases/QueryEvents.ts                        | 10 +++++-----
 app/usecases/dependencies/FetchesJasdActivities.ts | 13 +++++++++++++
 app/usecases/dependencies/FetchesJasdEvents.ts     | 13 -------------
 6 files changed, 31 insertions(+), 32 deletions(-)
 create mode 100644 app/usecases/dependencies/FetchesJasdActivities.ts
 delete mode 100644 app/usecases/dependencies/FetchesJasdEvents.ts

diff --git a/app/adapters/jasd/JasdGateway.ts b/app/adapters/jasd/JasdGateway.ts
index 69f80fc..318c469 100644
--- a/app/adapters/jasd/JasdGateway.ts
+++ b/app/adapters/jasd/JasdGateway.ts
@@ -1,14 +1,13 @@
-import { Activity, AppApiEvent, AppApiResponse } from './types/appapi.dto.types.ts'
-import { FetchesJasdEvents } from '../../usecases/dependencies/FetchesJasdEvents.ts'
+import { ActivitiesPageResponse, Activity, ActivityResult } from './types/appapi.dto.types.ts'
+import { FetchesJasdActivities } from '../../usecases/dependencies/FetchesJasdActivities.ts'
 import { Logs } from '../../usecases/dependencies/Logs.ts'
 import { FetchesJasdActivity } from '../../usecases/dependencies/FetchesJasdActivity.ts'
 import { logger } from '../Logger.ts'
 import NotFound = Deno.errors.NotFound
 
-export class JasdGateway implements FetchesJasdEvents, FetchesJasdActivity {
+export class JasdGateway implements FetchesJasdActivities, FetchesJasdActivity {
   private readonly APP_API_BASE_URL_V1 = 'https://gemeinschaftswerk-nachhaltigkeit.de/app/api/v1'
   private readonly APP_API_BASE_URL_V2 = 'https://gemeinschaftswerk-nachhaltigkeit.de/app/api/v2'
-  private readonly APP_FILES_BASE_URL = 'https://gemeinschaftswerk-nachhaltigkeit.de/app/api/v1/files'
 
   constructor(private readonly logger: Logs) {
   }
@@ -62,18 +61,18 @@ export class JasdGateway implements FetchesJasdEvents, FetchesJasdActivity {
     }
   }
 
-  async fetchEvents(
+  async fetchActivities(
     limit: number,
     offset: number,
     localOnly: boolean,
     location?: string,
-  ): Promise<{ events: AppApiEvent[]; totalCount: number }> {
+  ): Promise<{ events: ActivityResult[]; totalCount: number }> {
     const url = this.buildQueryUrl(limit, offset, localOnly, location)
     this.logger.debug(`Fetching events from ${url}`)
 
     try {
       const response = await fetch(url)
-      const data = await response.json() as AppApiResponse
+      const data = await response.json() as ActivitiesPageResponse
 
       const events = data.content
         .flat()
diff --git a/app/adapters/jasd/types/appapi.dto.types.ts b/app/adapters/jasd/types/appapi.dto.types.ts
index 12fffe7..86b705c 100644
--- a/app/adapters/jasd/types/appapi.dto.types.ts
+++ b/app/adapters/jasd/types/appapi.dto.types.ts
@@ -120,7 +120,7 @@ type Pageable = {
 
 type ResultType = 'ACTIVITY' | string
 
-export type AppApiEvent = {
+export type ActivityResult = {
   name: string
   description: string
   resultType: ResultType
@@ -128,8 +128,8 @@ export type AppApiEvent = {
   location: Location
 }
 
-export type AppApiResponse = {
-  content: AppApiEvent[]
+export type ActivitiesPageResponse = {
+  content: ActivityResult[]
   pageable: Pageable
   totalPages: number
   totalElements: number
diff --git a/app/usecases/QueryEvents.test.ts b/app/usecases/QueryEvents.test.ts
index 047e174..cd38f79 100644
--- a/app/usecases/QueryEvents.test.ts
+++ b/app/usecases/QueryEvents.test.ts
@@ -2,7 +2,7 @@ import { assertEquals } from '@std/assert'
 import { describe, it } from '@std/testing/bdd'
 
 import { QueryEvents } from './QueryEvents.ts'
-import { AppApiEvent } from '../adapters/jasd/types/appapi.dto.types.ts'
+import { ActivityResult } from '../adapters/jasd/types/appapi.dto.types.ts'
 import { LocalTimedEvent } from '../adapters/jasd/tests/fixtures.ts'
 
 export type ResponsePayload = Record<string, unknown> | Error
@@ -16,7 +16,7 @@ describe('QueryEvents', () => {
 
   it('can make sense of an empty response', async () => {
     const jasdGatewayMock = {
-      fetchEvents() {
+      fetchActivities() {
         return Promise.resolve({ events: [], totalCount: 0 })
       },
     }
@@ -33,9 +33,9 @@ describe('QueryEvents', () => {
 
   it('can return a jsad event', async () => {
     const jasdGatewayMock = {
-      fetchEvents(): Promise<{ events: AppApiEvent[]; totalCount: number }> {
+      fetchActivities(): Promise<{ events: ActivityResult[]; totalCount: number }> {
         return Promise.resolve({
-          events: [LocalTimedEvent as AppApiEvent],
+          events: [LocalTimedEvent as ActivityResult],
           totalCount: 1,
         })
       },
diff --git a/app/usecases/QueryEvents.ts b/app/usecases/QueryEvents.ts
index 78457ac..7888e77 100644
--- a/app/usecases/QueryEvents.ts
+++ b/app/usecases/QueryEvents.ts
@@ -1,8 +1,8 @@
-import { FetchesJasdEvents } from './dependencies/FetchesJasdEvents.ts'
+import { FetchesJasdActivities } from './dependencies/FetchesJasdActivities.ts'
 import { ResolvesCity } from './dependencies/ResolvesCity.ts'
 import { HoliEvent } from '../domain/HoliEvent.ts'
 import { Logs } from './dependencies/Logs.ts'
-import { AppApiEvent } from '../adapters/jasd/types/appapi.dto.types.ts'
+import { ActivityResult } from '../adapters/jasd/types/appapi.dto.types.ts'
 
 export interface QueryEventsInput {
   limit: number
@@ -20,7 +20,7 @@ const APP_FILES_BASE_URL = 'https://gemeinschaftswerk-nachhaltigkeit.de/app/api/
 
 export class QueryEvents {
   constructor(
-    private readonly jasdApi: FetchesJasdEvents,
+    private readonly jasdApi: FetchesJasdActivities,
     private readonly geoApi: ResolvesCity,
     private readonly logger: Logs,
   ) {}
@@ -32,7 +32,7 @@ export class QueryEvents {
     try {
       const location = input.geolocationId ? await this.geoApi.resolveCityName(input.geolocationId) : undefined
 
-      const jasdEvents = await this.jasdApi.fetchEvents(
+      const jasdEvents = await this.jasdApi.fetchActivities(
         input.limit,
         input.offset,
         input.localOnly,
@@ -52,7 +52,7 @@ export class QueryEvents {
     }
   }
 
-  private toDomainEvent(event: AppApiEvent): HoliEvent {
+  private toDomainEvent(event: ActivityResult): HoliEvent {
     return {
       id: event.activity.id.toString(),
       title: event.name,
diff --git a/app/usecases/dependencies/FetchesJasdActivities.ts b/app/usecases/dependencies/FetchesJasdActivities.ts
new file mode 100644
index 0000000..158b4f7
--- /dev/null
+++ b/app/usecases/dependencies/FetchesJasdActivities.ts
@@ -0,0 +1,13 @@
+import { ActivityResult } from '../../adapters/jasd/types/appapi.dto.types.ts'
+
+export interface FetchesJasdActivities {
+  fetchActivities(
+    limit: number,
+    offset: number,
+    localOnly: boolean,
+    location?: string,
+  ): Promise<{
+    events: ActivityResult[]
+    totalCount: number
+  }>
+}
diff --git a/app/usecases/dependencies/FetchesJasdEvents.ts b/app/usecases/dependencies/FetchesJasdEvents.ts
deleted file mode 100644
index d06164e..0000000
--- a/app/usecases/dependencies/FetchesJasdEvents.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { AppApiEvent } from '../../adapters/jasd/types/appapi.dto.types.ts'
-
-export interface FetchesJasdEvents {
-  fetchEvents(
-    limit: number,
-    offset: number,
-    localOnly: boolean,
-    location?: string,
-  ): Promise<{
-    events: AppApiEvent[]
-    totalCount: number
-  }>
-}
-- 
GitLab