Skip to content

Commit

Permalink
feat: import artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Aug 2, 2024
1 parent 37b9c6f commit 1eb17e2
Show file tree
Hide file tree
Showing 25 changed files with 747 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table:
name: artworks
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table:
name: contest
schema: public
2 changes: 2 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/tables.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- "!include public_artworks.yaml"
- "!include public_authorizer_sessions.yaml"
- "!include public_authorizer_users.yaml"
- "!include public_authorizer_verification_requests.yaml"
Expand All @@ -7,6 +8,7 @@
- "!include public_chapter_languages.yaml"
- "!include public_chapter_total_likes.yaml"
- "!include public_chapters.yaml"
- "!include public_contest.yaml"
- "!include public_creators.yaml"
- "!include public_email_subscribe.yaml"
- "!include public_i18n.yaml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."contest";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "public"."contest" ("id" serial NOT NULL, "slug" text NOT NULL, "start_date" timestamptz NOT NULL, "end_date" timestamptz NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") );
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_contest_updated_at"
BEFORE UPDATE ON "public"."contest"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_contest_updated_at" ON "public"."contest"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
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"."manga" add column "contest_id" integer
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."manga" add column "contest_id" integer
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."manga" drop constraint "manga_contest_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."manga"
add constraint "manga_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"."contest" drop constraint "contest_start_date_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."contest" add constraint "contest_start_date_key" unique ("start_date");
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."contest" add constraint "contest_start_date_key" unique ("start_date");
alter table "public"."contest" alter column "start_date" set not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."contest" alter column "start_date" drop not null;
alter table "public"."contest" drop constraint "contest_start_date_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."contest" alter column "end_date" set not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."contest" alter column "end_date" drop not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."artworks";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "public"."artworks" ("id" serial NOT NULL, "url" text NOT NULL, "source_url" text, "contest_id" integer, "creator_id" integer NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , FOREIGN KEY ("contest_id") REFERENCES "public"."contest"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("creator_id") REFERENCES "public"."creators"("id") ON UPDATE cascade ON DELETE cascade);
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_artworks_updated_at"
BEFORE UPDATE ON "public"."artworks"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_artworks_updated_at" ON "public"."artworks"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"cosmjs-types": "^0.9.0",
"crypto-addr-codec": "^0.1.8",
"crypto-js": "^4.2.0",
"csv-parse": "^5.5.6",
"decompress": "^4.2.1",
"ethers": "^6.12.0",
"express-ctx": "^0.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { UserModule } from './modules/user/user.module';
import { LaunchpadModule } from './modules/collection/launchpad.module';
import { ChainModule } from './modules/chain/chain.module';
import { ChainGateWayModule } from './chain-gateway/chain-gateway.module';
import { ArtworkModule } from './modules/artwork/artwork.module';

@Module({
imports: [
Expand Down Expand Up @@ -71,6 +72,7 @@ import { ChainGateWayModule } from './chain-gateway/chain-gateway.module';
LaunchpadModule,
ChainModule,
ChainGateWayModule,
ArtworkModule,
],
controllers: [],
providers: [
Expand Down
44 changes: 44 additions & 0 deletions src/modules/artwork/artwork.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Body,
Controller,
Get,
Param,
Post,
Put,
Query,
UploadedFile,
UploadedFiles,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';

import { AuthGuard } from '../../auth/auth.guard';
import { Role } from '../../auth/role.enum';
import { RolesGuard } from '../../auth/role.guard';
import { Roles } from '../../auth/roles.decorator';
import { AuthUserInterceptor } from '../../interceptors/auth-user.interceptor';
import { FileInterceptor } from '@nestjs/platform-express';
import { ArtworkService } from './artwork.service';
import { SetRequestTimeout } from '../../decorators/set-timeout.decorator';
import { ImportArtworkDto } from './dto/import-artwork.dto';

@Controller('artwork')
@ApiTags('artwork')
export class ArtworkController {
constructor(private readonly artworkSvc: ArtworkService) {}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Post('import')
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, FileInterceptor('file'))
@SetRequestTimeout()
@Roles(Role.Admin)
import(
@Body() body: ImportArtworkDto,
@UploadedFile() file: Express.Multer.File
) {
return this.artworkSvc.import(body, file);
}
}
Loading

0 comments on commit 1eb17e2

Please sign in to comment.