Skip to content

Commit

Permalink
feat: product API
Browse files Browse the repository at this point in the history
  • Loading branch information
HungLV46 committed Aug 14, 2024
1 parent c139083 commit 887c509
Show file tree
Hide file tree
Showing 15 changed files with 532 additions and 182 deletions.
24 changes: 12 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ services:
ports:
- 9200:9200

be:
image: ipscanbe
depends_on:
postgres:
condition: service_healthy
ports:
- '3000:3000'
environment:
REDIS_URL: redis://redis:6379/1
DATABASE_URL: 'postgresql://postgres:password@postgres:5432/ip-scan?schema=public'
networks:
- local
# be:
# image: ipscanbe
# depends_on:
# postgres:
# condition: service_healthy
# ports:
# - '3000:3000'
# environment:
# REDIS_URL: redis://redis:6379/1
# DATABASE_URL: 'postgresql://postgres:password@postgres:5432/ip-scan?schema=public'
# networks:
# - local

networks:
local:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@bull-board/hapi": "^5.21.1",
"@elastic/elasticsearch": "^8.14.0",
"@hapi/boom": "^10.0.1",
"@hapi/hapi": "^21.3.10",
"@hapi/inert": "^7.1.0",
"@hapi/vision": "^7.0.3",
Expand Down
17 changes: 17 additions & 0 deletions prisma/migrations/20240814021956_trigger_updated_at/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE OR REPLACE FUNCTION update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER products_updated_at_timestamp_trigger
BEFORE UPDATE ON products
FOR EACH ROW
EXECUTE FUNCTION update_timestamp();

CREATE TRIGGER collections_updated_at_timestamp_trigger
BEFORE UPDATE ON collections
FOR EACH ROW
EXECUTE FUNCTION update_timestamp();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- AlterTable
ALTER TABLE "collections" ALTER COLUMN "metadata" DROP NOT NULL;

-- AlterTable
ALTER TABLE "ipassets" ALTER COLUMN "metadata" DROP NOT NULL;

-- AlterTable
ALTER TABLE "licenses" ALTER COLUMN "metadata" DROP NOT NULL;

-- AlterTable
ALTER TABLE "nfts" ALTER COLUMN "metadata" DROP NOT NULL;

-- AlterTable
ALTER TABLE "products" ALTER COLUMN "metadata" DROP NOT NULL;

-- AlterTable
ALTER TABLE "users" ALTER COLUMN "additional_info" DROP NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Warnings:
- You are about to drop the column `product_id` on the `collections` table. All the data in the column will be lost.
- Made the column `metadata` on table `collections` required. This step will fail if there are existing NULL values in that column.
- Made the column `metadata` on table `products` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE "collections" DROP CONSTRAINT "collections_product_id_fkey";

-- DropIndex
DROP INDEX "collections_product_id_idx";

-- AlterTable
ALTER TABLE "collections" DROP COLUMN "product_id",
ALTER COLUMN "metadata" SET NOT NULL;

-- AlterTable
ALTER TABLE "products" ALTER COLUMN "metadata" SET NOT NULL;

-- CreateTable
CREATE TABLE "product_collections" (
"id" SERIAL NOT NULL,
"product_id" INTEGER NOT NULL,
"collection_id" INTEGER NOT NULL,

CONSTRAINT "product_collections_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "product_collections_product_id_idx" ON "product_collections"("product_id");

-- CreateIndex
CREATE INDEX "product_collections_collection_id_idx" ON "product_collections"("collection_id");

-- AddForeignKey
ALTER TABLE "product_collections" ADD CONSTRAINT "product_collections_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "product_collections" ADD CONSTRAINT "product_collections_collection_id_fkey" FOREIGN KEY ("collection_id") REFERENCES "collections"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
179 changes: 95 additions & 84 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}

Expand All @@ -15,53 +15,53 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
name String
bio String
email String
wallet_address String
avatar_img String
banner_img String
additional_info Json
name String
bio String
email String
wallet_address String
avatar_img String
banner_img String
additional_info Json?
products Product[]
products Product[]
@@index(name)
@@index(wallet_address)
@@map("users")
}

model Product {
id Int @id @default(autoincrement())
name String
category String
description String
avatar_img String
banner_img String
metadata Json
owner_id Int
featured_at DateTime?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
stat_total_collection Int?
stat_total_items Int?
stat_total_activities BigInt?
stat_total_volume_all BigInt?
stat_total_volume_12m BigInt?
stat_total_volume_30d BigInt?
stat_total_volume_7d BigInt?
stat_floor_price_all BigInt?
stat_floor_price_12m BigInt?
stat_floor_price_30d BigInt?
stat_floor_price_7d BigInt?
owner User @relation(fields: [owner_id], references: [id])
collections Collection[]
attributes ProductAttribute[]
id Int @id @default(autoincrement())
name String
category String
description String
avatar_img String
banner_img String
metadata Json
owner_id Int
featured_at DateTime?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
stat_total_collection Int?
stat_total_items Int?
stat_total_activities BigInt?
stat_total_volume_all BigInt?
stat_total_volume_12m BigInt?
stat_total_volume_30d BigInt?
stat_total_volume_7d BigInt?
stat_floor_price_all BigInt?
stat_floor_price_12m BigInt?
stat_floor_price_30d BigInt?
stat_floor_price_7d BigInt?
owner User @relation(fields: [owner_id], references: [id])
attributes ProductAttribute[]
product_collections ProductCollection[]
@@unique(name)
@@index(category)
Expand All @@ -71,12 +71,12 @@ model Product {
}

model ProductAttribute {
id Int @id @default(autoincrement())
name String
value String
product_id Int
id Int @id @default(autoincrement())
name String
value String
product_id Int
product Product @relation(fields: [product_id], references: [id])
product Product @relation(fields: [product_id], references: [id])
@@unique([name, value, product_id])
@@index([name, value])
Expand All @@ -85,34 +85,45 @@ model ProductAttribute {
}

model Collection {
id Int @id @default(autoincrement())
name String?
chain_id String
contract_address String
product_id Int
metadata Json
nfts Nft[]
product Product @relation(fields: [product_id], references: [id])
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
id Int @id @default(autoincrement())
name String?
chain_id String
contract_address String
metadata Json
nfts Nft[]
product_collections ProductCollection[]
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@unique([chain_id, contract_address])
@@index(product_id)
@@index(name)
@@map("collections")
}

model ProductCollection {
id Int @id @default(autoincrement())
product_id Int
collection_id Int
product Product @relation(fields: [product_id], references: [id])
collection Collection @relation(fields: [collection_id], references: [id])
@@index([product_id])
@@index([collection_id])
@@map("product_collections")
}

model Nft {
id Int @id @default(autoincrement())
chain_id String
collection_id Int
contract_address String
token_id String
metadata Json
id Int @id @default(autoincrement())
chain_id String
collection_id Int
contract_address String
token_id String
metadata Json?
collection Collection @relation(fields: [collection_id], references: [id])
ipassets Ipasset[]
collection Collection @relation(fields: [collection_id], references: [id])
ipassets Ipasset[]
@@unique([collection_id, token_id])
@@unique([chain_id, contract_address, token_id])
Expand All @@ -121,32 +132,32 @@ model Nft {
}

model Ipasset {
id Int @id @default(autoincrement())
chain_id String
contract_address String
parent_ipasset_id Int?
nft_id Int
metadata Json
nft Nft @relation(fields: [nft_id], references: [id])
parent_ipassets Ipasset? @relation("ParentChildIpasset", fields: [parent_ipasset_id], references: [id])
child_ipassets Ipasset[] @relation("ParentChildIpasset")
licenses License[]
id Int @id @default(autoincrement())
chain_id String
contract_address String
parent_ipasset_id Int?
nft_id Int
metadata Json?
nft Nft @relation(fields: [nft_id], references: [id])
parent_ipassets Ipasset? @relation("ParentChildIpasset", fields: [parent_ipasset_id], references: [id])
child_ipassets Ipasset[] @relation("ParentChildIpasset")
licenses License[]
@@unique([chain_id, contract_address])
@@index(parent_ipasset_id)
@@map("ipassets")
}

model License {
id Int @id @default(autoincrement())
chain_id String
contract_address String
token_id String
ipasset_id Int
metadata Json
ipasset Ipasset @relation(fields: [ipasset_id], references: [id])
id Int @id @default(autoincrement())
chain_id String
contract_address String
token_id String
ipasset_id Int
metadata Json?
ipasset Ipasset @relation(fields: [ipasset_id], references: [id])
@@unique([chain_id, contract_address, token_id])
@@map("licenses")
Expand Down
Loading

0 comments on commit 887c509

Please sign in to comment.