diff --git a/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml b/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml index 746a725..a14f6dc 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml @@ -1,3 +1,10 @@ table: name: story_manga schema: public +object_relationships: + - name: manga + using: + foreign_key_constraint_on: manga_id + - name: story_ip_asset + using: + foreign_key_constraint_on: story_ip_asset_id diff --git a/src/modules/story-event/dto/query-manga.dto.ts b/src/modules/story-event/dto/query-manga.dto.ts new file mode 100644 index 0000000..06eb06a --- /dev/null +++ b/src/modules/story-event/dto/query-manga.dto.ts @@ -0,0 +1,9 @@ +import { ApiPropertyOptional } from '@nestjs/swagger'; + +export class QueryMangaParamDto { + @ApiPropertyOptional() + limit: number; + + @ApiPropertyOptional() + offset: number; +} diff --git a/src/modules/story-event/story-event.controller.ts b/src/modules/story-event/story-event.controller.ts index 8bd58c1..8d9ed33 100644 --- a/src/modules/story-event/story-event.controller.ts +++ b/src/modules/story-event/story-event.controller.ts @@ -25,6 +25,7 @@ import { SubmitCharacterRequestDto } from './dto/submit-character.dto'; import { SubmitMangaRequestDto } from './dto/submit-manga.dto'; import { StoryEventService } from './story-event.service'; import { UpdateCharacterStatusRequestDto } from './dto/approve-story-character.dto'; +import { QueryMangaParamDto } from './dto/query-manga.dto'; @Controller('story-event') @ApiTags('story-event') @@ -107,6 +108,11 @@ export class StoryEventController { return this.storyEventSvc.queryCharacter(query); } + @Get('manga') + getManga(@Query() query: QueryMangaParamDto) { + return this.storyEventSvc.queryManga(query); + } + @Get('character/collected') @UseGuards(AuthGuard, RolesGuard) @ApiBearerAuth() diff --git a/src/modules/story-event/story-event.graphql.ts b/src/modules/story-event/story-event.graphql.ts index 4858c39..17b9762 100644 --- a/src/modules/story-event/story-event.graphql.ts +++ b/src/modules/story-event/story-event.graphql.ts @@ -340,6 +340,47 @@ export class StoryEventGraphql { ); } + async queryMangas(variables: any) { + const headers = { + 'x-hasura-admin-secret': this.configSvc.get( + 'graphql.adminSecret' + ), + }; + + return this.graphqlSvc.query( + this.configSvc.get('graphql.endpoint'), + '', + `query story_manga($limit: Int = 10, $offset: Int = 0) { + story_manga_aggregate(where: {manga: {status: {_eq: "On-Going"}}}) { + aggregate { + count + } + } + story_manga(where: {manga: {status: {_eq: "On-Going"}}}, limit: $limit, offset: $offset) { + id + manga { + id + slug + banner + poster + manga_languages { + title + description + } + } + story_ip_asset { + ip_asset_id + } + created_at + } + } + `, + 'story_manga', + variables, + headers + ); + } + async queryCollectedCharacters(variables: any) { const headers = { 'x-hasura-admin-secret': this.configSvc.get( diff --git a/src/modules/story-event/story-event.service.ts b/src/modules/story-event/story-event.service.ts index 42d1e7f..2000673 100644 --- a/src/modules/story-event/story-event.service.ts +++ b/src/modules/story-event/story-event.service.ts @@ -27,6 +27,7 @@ import { import { StoryEventGraphql } from './story-event.graphql'; import { getBytes32FromIpfsHash } from './utils'; import { UpdateCharacterStatusRequestDto } from './dto/approve-story-character.dto'; +import { QueryMangaParamDto } from './dto/query-manga.dto'; @Injectable() export class StoryEventService { @@ -471,6 +472,15 @@ export class StoryEventService { ); } + async queryManga(data: QueryMangaParamDto) { + const { limit, offset } = data; + + return this.storyEventGraphql.queryMangas({ + limit, + offset, + }); + } + async queryCollectedCharacter() { const { userId } = ContextProvider.getAuthUser(); return this.storyEventGraphql.queryCollectedCharacters({