Skip to content

Commit

Permalink
feat: query story manga api
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 17, 2024
1 parent 93c30ab commit ea8cef2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/modules/story-event/dto/query-manga.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiPropertyOptional } from '@nestjs/swagger';

export class QueryMangaParamDto {
@ApiPropertyOptional()
limit: number;

@ApiPropertyOptional()
offset: number;
}
6 changes: 6 additions & 0 deletions src/modules/story-event/story-event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
41 changes: 41 additions & 0 deletions src/modules/story-event/story-event.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,47 @@ export class StoryEventGraphql {
);
}

async queryMangas(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configSvc.get<string>(
'graphql.adminSecret'
),
};

return this.graphqlSvc.query(
this.configSvc.get<string>('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<string>(
Expand Down
10 changes: 10 additions & 0 deletions src/modules/story-event/story-event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit ea8cef2

Please sign in to comment.