Skip to content

Commit

Permalink
[RetroFunding API] Implement projects endpoints (#336)
Browse files Browse the repository at this point in the history
* import prisma schema for attested projects

* implement /projects endpoint

* implement /retrofunding/round/.../projects endpoint

* update projects api docs

* fix docs

* fix docs typo

* prettier

* import prisma
  • Loading branch information
stepandel authored Jun 28, 2024
1 parent 0e9dd3d commit b6ba723
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 152 deletions.
53 changes: 53 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,59 @@ model projects_data {
@@schema("retro_funding")
}

view project_applicants {
project_id String @unique
application_id String?
round String?
farcaster_id String?
name String?
category String?
description String?
project_avatar_url String?
project_cover_image_url String?
oso_slug String?
team Json? @db.Json
github Json? @db.Json
packages Json? @db.Json
contracts Json? @db.Json
social_links_website Json? @db.Json
social_links_farcaster Json? @db.Json
social_links_twitter String?
social_links_mirror String?
grants_and_funding_venture_funding Json? @db.Json
grants_and_funding_grants Json? @db.Json
grants_and_funding_revenue Json? @db.Json
@@schema("retro_funding")
}

view projects {
project_id String @unique
attestation_id String?
farcaster_id String?
name String?
category String?
parent_project_id String?
metadata_url String?
description String?
project_avatar_url String?
project_cover_image_url String?
oso_slug String?
team Json? @db.Json
github Json? @db.Json
packages Json? @db.Json
contracts Json? @db.Json
social_links_website Json? @db.Json
social_links_farcaster Json? @db.Json
social_links_twitter String?
social_links_mirror String?
grants_and_funding_venture_funding Json? @db.Json
grants_and_funding_grants Json? @db.Json
grants_and_funding_revenue Json? @db.Json
@@schema("retro_funding")
}

view OptimismVotes {
transaction_hash String @unique @db.VarChar(66)
proposal_id String
Expand Down
119 changes: 56 additions & 63 deletions spec/oas_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -786,34 +786,33 @@ components:
Information about a project submitted for Retroactive Public Goods Funding on Agora.
type: object
properties:
avatarUrl:
type: string
coverImageUrl:
type: string
attestationUid:
type: string
approvalAttestationUid:
id:
type: string
name:
type: string
category:
type: string
description:
type: string
externalLink:
profileAvatarUrl:
type: string
proejctCoverImageUrl:
type: string
socialLinks:
$ref: "#/components/schemas/SocialLinks"
team:
type: array
items:
$ref: "#/components/schemas/ProjectMember"
repositories:
summary: Repository URLs for the project
description: >
URLs for the project's repositories, such as GitHub, GitLab, NPM and other platforms.
type: string
github:
type: array
items:
type: string
packages:
type: array
items:
type: string
deployedContracts:
contracts:
summary: Deployed contracts for the project
description: >
Information about the contracts deployed by the project, including the contract address, chain ID, deployer, and creation block.
Expand All @@ -823,41 +822,60 @@ components:
- $ref: "#/components/schemas/Contract"
- type: object
properties:
verificationProof:
summary: Proof of contract verification
description: Verification of ownership of contract on chain.
address:
summary: Address of the deployed contract
description: The address of the deployed contract.
type: string
openSourceObserverSlug:
summary: Open source observer verification slug
description: >
Slug for the open source observer external verification.
deploymentTxHash:
summary: Transaction hash of the deployment
description: The transaction hash of the deployment transaction.
type: string
categories:
type: array
items:
$ref: "#/components/schemas/RetroFundingCategory"
funding:
deployerAddress:
summary: Address of the deployer
description: The address of the entity which deployed the contract.
type: string
chainId:
summary: Chain ID of the contract
description: The chain ID on which the contract was deployed.
type: string
grantsAndFunding:
type: object
properties:
ventureCapital:
ventureFunding:
type: array
items:
$ref: "#/components/schemas/FundingInfo"
type: object
properties:
amount:
type: string
year:
type: string
details:
type: string
grants:
type: array
items:
$ref: "#/components/schemas/FundingInfo"
optimismGrants:
type: object
properties:
grant:
type: string
link:
type: string
amount:
type: string
date:
type: string
details:
type: string
revenue:
type: array
items:
allOf:
- $ref: "#/components/schemas/FundingInfo"
- type: object
properties:
link:
type: string
type:
$ref: "#/components/schemas/OptimismGrantType"
type: object
properties:
amount:
type: string
details:
type: string
SocialLinks:
summary: Social media links for a project
description: >
Expand All @@ -872,31 +890,6 @@ components:
type: string
website:
type: string
OptimismGrantType:
summary: Type of Optimism grant
description: Enum description of the type of Optimism grant.
type: string
enum:
- DEVELOPMENT
- RESEARCH
- COMMUNITY
- ECOSYSTEM
- OTHER
FundingInfo:
summary: Information about funding for a project
description: >
Information about funding for a project, including the amount and source.
type: object
properties:
amount:
type: string
source:
type: string
date:
type: string
format: date-time
details:
type: string
RetroFundingBallotMetricsAllocation:
summary: A vote for an RetroFunding ballot
description: >
Expand Down
139 changes: 56 additions & 83 deletions src/app/api/common/projects/getProjects.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,66 @@
import { paginateResultEx } from "@/app/lib/pagination";
import { cache } from "react";
import prisma from "@/app/lib/prisma";

// TODO: Implement span for projects retrieval
async function getProjectsApi() {
const pageMetadata = {
hasNext: true,
totalReturned: 1,
nextOffset: 1,
};
const defaultSocialLinks = {
twitter: "@flip_liquide",
farcaster: "@flip-liquid",
mirror: "",
website: "flipliquid.xyz",
};
async function getProjectsApi({
limit,
offset,
round,
}: {
limit: number;
offset: number;
round?: string;
}) {
const projects = await paginateResultEx(
async (skip, take) => {
if (round) {
return prisma.project_applicants.findMany({
where: {
round: round,
},
skip,
take,
});
}

const defaultTeam = [
{
farcasterId: defaultSocialLinks.farcaster,
return prisma.projects.findMany({
skip,
take,
});
},
];

const defaultVCFunding = [
{
amount: "1000000000 Double Dollars",
source: "Weyland-Yutani Venture Capital",
date: "2024-04-20",
details: "Seed round",
},
];
limit,
offset,
}
);

const defaultDeployedContracts = [
{
address: "0xcDF27F107725988f2261Ce2256bDfCdE8B382B10",
chainId: "10",
deployer: "0x42004661285881D4B0F245B1eD3774d8166CF314",
creationBlock: "71801427",
transactionId:
"0x6ff5f386e46b2fb0099a78429ecd104f552fe545c65d51068098211d8b11560d",
verificationProof: "trust me ;)",
openSourceObserverSlug: "---",
},
];
const defaultOptiGrants = [
{
amount: "2000000000 OP",
source: "OP Foundation",
date: "2024-04-20",
details: "Great job!",
link: "---",
type: "DEVELOPMENT",
},
];
const defaultGrants = [
{
amount: "100 ETH",
source: "Ethereum Foundation",
date: "2024-04-20",
details: "For being nice with it",
},
];
const defaultFunding = {
ventureCapital: defaultVCFunding,
grants: defaultGrants,
optimismGrants: defaultOptiGrants,
};
const defaultCategories = [
{
name: "string",
description: "string",
},
];
const defaultProject = {
avatarUrl: "string",
coverImageUrl: "string",
attestationUid: "string",
approvalAttestationUid: "string",
name: "string",
description: "string",
externalLink: "string",
socialLinks: defaultSocialLinks,
team: defaultTeam,
repositories: ["https://github.com/voteagora/agora-next"],
deployedContracts: defaultDeployedContracts,
categories: defaultCategories,
funding: defaultFunding,
};
return {
metadata: pageMetadata,
projects: [defaultProject],
meta: projects.meta,
data: projects.data.map((project) => {
return {
id: project.project_id,
category: project.category,
name: project.name,
description: project.description,
profileAvatarUrl: project.project_avatar_url,
proejctCoverImageUrl: project.project_cover_image_url,
socialLinks: {
twitter: project.social_links_twitter,
farcaster: project.social_links_farcaster,
mirror: project.social_links_mirror,
website: project.social_links_website,
},
team: project.team,
github: project.github,
packages: project.packages,
contracts: project.contracts,
grantsAndFunding: {
ventureFunding: project.grants_and_funding_venture_funding,
grants: project.grants_and_funding_grants,
revenue: project.grants_and_funding_revenue,
},
};
}),
};
}

Expand Down
Loading

0 comments on commit b6ba723

Please sign in to comment.