first commit
This commit is contained in:
parent
cf64de8cd3
commit
d66a462e07
2
.gitignore
vendored
2
.gitignore
vendored
@ -35,3 +35,5 @@ yarn-error.log*
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
|
||||
.env
|
||||
44
README.md
44
README.md
@ -1,34 +1,22 @@
|
||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||
- Add created_at and updated_at for all tables
|
||||
- Feed some users
|
||||
|
||||
## Getting Started
|
||||
# Pages
|
||||
|
||||
First, run the development server:
|
||||
- Create user (Done)
|
||||
- List users (Done)
|
||||
- Update user
|
||||
- Delete user
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
```
|
||||
- Create apps
|
||||
- List app
|
||||
- Update app
|
||||
- Delete app
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
1. Autogenerate certificate
|
||||
2. Request validation
|
||||
3. Add logs to all request
|
||||
|
||||
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
|
||||
SAML certificate (PEM format)
|
||||
|
||||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
|
||||
|
||||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
||||
you need to generate a set of public and private keys and an X.509 certificate that contains the public key. The public keys and certificates must be generated with either the RSA or DSA algorithm and registered with Google.
|
||||
|
||||
39
package-lock.json
generated
39
package-lock.json
generated
@ -6,6 +6,7 @@
|
||||
"": {
|
||||
"name": "fake",
|
||||
"dependencies": {
|
||||
"@prisma/client": "^3.7.0",
|
||||
"next": "12.0.7",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
@ -1114,6 +1115,31 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/client": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.7.0.tgz",
|
||||
"integrity": "sha512-fUJMvBOX5C7JPc0e3CJD6Gbelbu4dMJB4ScYpiht8HMUnRShw20ULOipTopjNtl6ekHQJ4muI7pXlQxWS9nMbw==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/engines-version": "3.7.0-31.8746e055198f517658c08a0c426c7eec87f5a85f"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"prisma": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"prisma": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/engines-version": {
|
||||
"version": "3.7.0-31.8746e055198f517658c08a0c426c7eec87f5a85f",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-3.7.0-31.8746e055198f517658c08a0c426c7eec87f5a85f.tgz",
|
||||
"integrity": "sha512-+qx2b+HK7BKF4VCa0LZ/t1QCXsu6SmvhUQyJkOD2aPpmOzket4fEnSKQZSB0i5tl7rwCDsvAiSeK8o7rf+yvwg=="
|
||||
},
|
||||
"node_modules/@rushstack/eslint-patch": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.1.0.tgz",
|
||||
@ -6183,6 +6209,19 @@
|
||||
"fastq": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@prisma/client": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.7.0.tgz",
|
||||
"integrity": "sha512-fUJMvBOX5C7JPc0e3CJD6Gbelbu4dMJB4ScYpiht8HMUnRShw20ULOipTopjNtl6ekHQJ4muI7pXlQxWS9nMbw==",
|
||||
"requires": {
|
||||
"@prisma/engines-version": "3.7.0-31.8746e055198f517658c08a0c426c7eec87f5a85f"
|
||||
}
|
||||
},
|
||||
"@prisma/engines-version": {
|
||||
"version": "3.7.0-31.8746e055198f517658c08a0c426c7eec87f5a85f",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-3.7.0-31.8746e055198f517658c08a0c426c7eec87f5a85f.tgz",
|
||||
"integrity": "sha512-+qx2b+HK7BKF4VCa0LZ/t1QCXsu6SmvhUQyJkOD2aPpmOzket4fEnSKQZSB0i5tl7rwCDsvAiSeK8o7rf+yvwg=="
|
||||
},
|
||||
"@rushstack/eslint-patch": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.1.0.tgz",
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^3.7.0",
|
||||
"next": "12.0.7",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
|
||||
73
pages/api/apps.ts
Normal file
73
pages/api/apps.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
type ServiceProvider = {
|
||||
sp_acs_url: string;
|
||||
sp_entity_id: string;
|
||||
};
|
||||
|
||||
type IdentityProvider = {
|
||||
idp_sso_url: string;
|
||||
idp_entity_id: string;
|
||||
};
|
||||
|
||||
type App = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
certificate: string;
|
||||
} & ServiceProvider;
|
||||
|
||||
const createApp = async (body: Omit<App, 'id'>): Promise<App> => {
|
||||
return await prisma.app.create({ data: body });
|
||||
};
|
||||
|
||||
const getAllApps = async (): Promise<App[]> => {
|
||||
return await prisma.app.findMany();
|
||||
};
|
||||
|
||||
const getAppById = async (id: string): Promise<App> => {
|
||||
return await prisma.app.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const createKeyPairs = (): any => {};
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<App | App[]>
|
||||
) {
|
||||
const { method } = req;
|
||||
|
||||
// if (method === 'GET') {
|
||||
// const apps = await getAllApps();
|
||||
|
||||
// return res.status(200).json(apps);
|
||||
// }
|
||||
|
||||
if (method === 'GET') {
|
||||
const app = await getAppById('287f8e3d-234c-425c-bac3-cc68878582f5');
|
||||
|
||||
return res.status(200).json(app);
|
||||
}
|
||||
|
||||
if (method === 'POST') {
|
||||
const { name, sp_acs_url, sp_entity_id, description = null } = req.body;
|
||||
const certificate = 'certificate';
|
||||
|
||||
const app = await createApp({
|
||||
name,
|
||||
description,
|
||||
certificate,
|
||||
sp_acs_url,
|
||||
sp_entity_id,
|
||||
});
|
||||
|
||||
return res.status(200).json(app);
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,12 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
type Data = {
|
||||
name: string
|
||||
}
|
||||
name: string;
|
||||
};
|
||||
|
||||
export default function handler(
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
res.status(200).json({ name: 'Kiran' });
|
||||
}
|
||||
|
||||
34
pages/api/users/[id].ts
Normal file
34
pages/api/users/[id].ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
const getUserById = async (id: number): Promise<User> => {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<User>
|
||||
) {
|
||||
const { method } = req;
|
||||
|
||||
if (method === 'GET') {
|
||||
const { id } = req.query;
|
||||
|
||||
const user = await getUserById(Number(id));
|
||||
|
||||
return res.status(200).json(user);
|
||||
}
|
||||
}
|
||||
40
pages/api/users/index.ts
Normal file
40
pages/api/users/index.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
type User = {
|
||||
id: number,
|
||||
first_name: string,
|
||||
last_name: string,
|
||||
email: string,
|
||||
};
|
||||
|
||||
const createUser = async (body: Omit<User, 'id'>): Promise<User> => {
|
||||
return await prisma.user.create({ data: body });
|
||||
};
|
||||
|
||||
const fetchAllUsers = async (): Promise<User[]> => {
|
||||
return await prisma.user.findMany();
|
||||
};
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<User | User[]>
|
||||
) {
|
||||
const { method } = req;
|
||||
|
||||
if (method === 'GET') {
|
||||
const users = await fetchAllUsers();
|
||||
|
||||
return res.status(200).json(users);
|
||||
}
|
||||
|
||||
if (method === 'POST') {
|
||||
const { first_name, last_name, email } = req.body;
|
||||
|
||||
const user = await createUser({ first_name, last_name, email });
|
||||
|
||||
return res.status(200).json(user);
|
||||
}
|
||||
}
|
||||
25
prisma/schema.prisma
Normal file
25
prisma/schema.prisma
Normal file
@ -0,0 +1,25 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
first_name String
|
||||
last_name String
|
||||
email String
|
||||
}
|
||||
|
||||
model App {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
description String?
|
||||
certificate String
|
||||
sp_acs_url String
|
||||
sp_entity_id String
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user