This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
ExplainBusinessUnit,
|
||||
ExplainGuideStop,
|
||||
ExplainGuideStopPage,
|
||||
ExplainTrack,
|
||||
MuseumExhibit,
|
||||
MuseumHall,
|
||||
@@ -27,6 +28,7 @@ export interface ExplainRepository {
|
||||
listHalls(): Promise<MuseumHall[]>
|
||||
getHallById(id: string): Promise<MuseumHall | null>
|
||||
listGuideStopsByHall(hallId: string): Promise<ExplainGuideStop[]>
|
||||
listGuideStopsPageByHall(hallId: string, pageNo: number, pageSize: number): Promise<ExplainGuideStopPage>
|
||||
listGuideStopsByBusinessUnit(hallId: string, unitId: string): Promise<ExplainGuideStop[]>
|
||||
listTemporaryBusinessUnitsByHall(hallId: string): Promise<ExplainBusinessUnit[]>
|
||||
listTracks(): Promise<ExplainTrack[]>
|
||||
@@ -73,7 +75,36 @@ export class DefaultExplainRepository implements ExplainRepository {
|
||||
}
|
||||
|
||||
async listGuideStopsByHall(hallId: string) {
|
||||
return this.explainContent.listGuideStopsByHall?.(hallId) || []
|
||||
const pageSize = 100
|
||||
const items: ExplainGuideStop[] = []
|
||||
const seen = new Set<string>()
|
||||
for (let pageNo = 1; ; pageNo += 1) {
|
||||
const page = await this.listGuideStopsPageByHall(hallId, pageNo, pageSize)
|
||||
page.items.forEach((item) => {
|
||||
if (!seen.has(item.id)) {
|
||||
seen.add(item.id)
|
||||
items.push(item)
|
||||
}
|
||||
})
|
||||
if (!page.hasMore || items.length >= page.total) return items
|
||||
}
|
||||
}
|
||||
|
||||
async listGuideStopsPageByHall(hallId: string, pageNo: number, pageSize: number) {
|
||||
if (this.explainContent.listGuideStopsPageByHall) {
|
||||
return this.explainContent.listGuideStopsPageByHall(hallId, pageNo, pageSize)
|
||||
}
|
||||
const items = await this.explainContent.listGuideStopsByHall?.(hallId) || []
|
||||
const normalizedPageNo = Math.max(1, Math.floor(pageNo) || 1)
|
||||
const normalizedPageSize = Math.max(1, Math.floor(pageSize) || 20)
|
||||
const offset = (normalizedPageNo - 1) * normalizedPageSize
|
||||
return {
|
||||
items: items.slice(offset, offset + normalizedPageSize),
|
||||
total: items.length,
|
||||
pageNo: normalizedPageNo,
|
||||
pageSize: normalizedPageSize,
|
||||
hasMore: offset + normalizedPageSize < items.length
|
||||
}
|
||||
}
|
||||
|
||||
async listGuideStopsByBusinessUnit(hallId: string, unitId: string) {
|
||||
|
||||
Reference in New Issue
Block a user