Skip to content

Commit

Permalink
feat: update contest api
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Aug 7, 2024
1 parent 33f3672 commit ec5e0b2
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ array_relationships:
table:
name: artworks
schema: public
- name: contest_i18ns
using:
foreign_key_constraint_on:
column: contest_id
table:
name: i18n
schema: public
- name: contest_mangas
using:
foreign_key_constraint_on:
Expand All @@ -20,6 +27,7 @@ select_permissions:
- role: anonymous
permission:
columns:
- isLive
- id
- slug
- created_at
Expand All @@ -31,6 +39,7 @@ select_permissions:
- role: user
permission:
columns:
- isLive
- id
- slug
- created_at
Expand Down
6 changes: 6 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/public_i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ select_permissions:
- role: anonymous
permission:
columns:
- banner_id
- campaign_id
- contest_id
- id
- language_id
- launchpad_id
- quest_id
- data
- created_at
Expand All @@ -20,9 +23,12 @@ select_permissions:
- role: user
permission:
columns:
- banner_id
- campaign_id
- contest_id
- id
- language_id
- launchpad_id
- quest_id
- data
- created_at
Expand Down
34 changes: 21 additions & 13 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1321,32 +1321,40 @@
}
}
}
- name: Public - Get contest by creator id
- name: Public - Get artwork by creator and contest
query: |
query contest ($creator_id: Int!, $limit: Int = 10, $offset: Int = 0) {
contest(where: {_or:[{contest_artworks:{creator_id:{_eq:$creator_id}}},{contest_mangas:{manga_creators:{creator_id:{_eq:$creator_id}}}}]}, limit: $limit, offset: $offset) {
query artwork ($contest_id: Int!, $id: Int!, $limit: Int = 100, $offset: Int = 0) {
artworks(where: {contest_id:{_eq:$contest_id},creator_id:{_eq:$id}}, limit: $limit, offset: $offset) {
id
start_date
end_date
slug
url
source_url
created_at
}
contest_aggregate(where: {_or:[{contest_artworks:{creator_id:{_eq:$creator_id}}},{contest_mangas:{manga_creators:{creator_id:{_eq:$creator_id}}}}]}, limit: $limit, offset: $offset) {
artworks_aggregate(where: {contest_id:{_eq:$contest_id},creator_id:{_eq:$id}}, limit: $limit, offset: $offset) {
aggregate {
count
}
}
}
- name: Public - Get artwork by creator and contest
- name: Public - Get contest by creator id
query: |
query artwork ($contest_id: Int!, $id: Int!, $limit: Int = 100, $offset: Int = 0) {
artworks(where: {contest_id:{_eq:$contest_id},creator_id:{_eq:$id}}, limit: $limit, offset: $offset) {
query contest ($creator_id: Int!, $limit: Int = 10, $offset: Int = 0) {
contest(where: {_or:[{contest_artworks:{creator_id:{_eq:$creator_id}}},{contest_mangas:{manga_creators:{creator_id:{_eq:$creator_id}}}}]}, limit: $limit, offset: $offset) {
id
url
source_url
start_date
end_date
slug
created_at
contest_i18ns {
data
i18n_language {
id
is_main
symbol
}
}
}
artworks_aggregate(where: {contest_id:{_eq:$contest_id},creator_id:{_eq:$id}}, limit: $limit, offset: $offset) {
contest_aggregate(where: {_or:[{contest_artworks:{creator_id:{_eq:$creator_id}}},{contest_mangas:{manga_creators:{creator_id:{_eq:$creator_id}}}}]}, limit: $limit, offset: $offset) {
aggregate {
count
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."i18n" add column "contest_id" integer
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."i18n" add column "contest_id" integer
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."i18n" drop constraint "i18n_contest_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."i18n"
add constraint "i18n_contest_id_fkey"
foreign key ("contest_id")
references "public"."contest"
("id") on update cascade on delete cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."i18n" drop constraint "i18n_language_id_contest_id_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."i18n" add constraint "i18n_language_id_contest_id_key" unique ("language_id", "contest_id");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."contest" add column "isLive" boolean
-- null default 'false';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."contest" add column "isLive" boolean
null default 'false';
11 changes: 11 additions & 0 deletions src/modules/files/dto/upload.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class UploadImageS3Dto {
@ApiProperty()
@IsString()
key: string;

@ApiProperty({ type: 'string', format: 'binary' })
file: Express.Multer.File;
}
36 changes: 36 additions & 0 deletions src/modules/files/files.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
Body,
Controller,
Post,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { AuthGuard } from '../../auth/auth.guard';
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { AuthUserInterceptor } from '../../interceptors/auth-user.interceptor';
import { FileInterceptor } from '@nestjs/platform-express';
import { Roles } from '../../auth/roles.decorator';
import { Role } from '../../auth/role.enum';
import { RolesGuard } from '../../auth/role.guard';
import { FilesService } from './files.service';
import { UploadImageS3Dto } from './dto/upload.dto';

@Controller('files')
@ApiTags('files')
export class FileController {
constructor(private readonly fileSvc: FilesService) {}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Admin)
@Post()
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, FileInterceptor('file'))
create(
@Body() data: UploadImageS3Dto,
@UploadedFile() file: Express.Multer.File
) {
return this.fileSvc.uploadImageToS3(data.key, file);
}
}
4 changes: 4 additions & 0 deletions src/modules/files/files.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Module } from '@nestjs/common';
import { FilesService } from './files.service';
import { FileController } from './files.controller';
import { JwtModule } from '@nestjs/jwt';

@Module({
imports: [JwtModule],
providers: [FilesService],
controllers: [FileController],
exports: [FilesService],
})
export class FilesModule {}

0 comments on commit ec5e0b2

Please sign in to comment.