Skip to content
Snippets Groups Projects
Commit b2f929fc authored by DESKTOP-9FO96TP\hehexd's avatar DESKTOP-9FO96TP\hehexd
Browse files

docs

parent fd324f31
No related branches found
No related tags found
1 merge request!43docs
Pipeline #39783 passed
import { getApiDocs } from '@/lib/swagger';
import ReactSwagger from './react-swagger';
export default async function IndexPage() {
const spec = await getApiDocs();
return (
<section className="container">
<ReactSwagger spec={spec} />
</section>
);
}
'use client';
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';
type Props = {
spec: Record<string, any>,
};
function ReactSwagger({ spec }: Props) {
return <SwaggerUI spec={spec} />;
}
export default ReactSwagger;
...@@ -5,6 +5,22 @@ import { IPlatformCategrory } from "@/types/igdb-types" ...@@ -5,6 +5,22 @@ import { IPlatformCategrory } from "@/types/igdb-types"
import { NextRequest, NextResponse } from "next/server" import { NextRequest, NextResponse } from "next/server"
/**
* @swagger
* /api/games:
* get:
* description: Get Games through external API
* content:
* application/json:
* schema:
* responses:
* 200:
* description: list of games
* 500:
* description: error
*/
export async function GET(req: NextRequest) { export async function GET(req: NextRequest) {
const p = req.nextUrl.searchParams const p = req.nextUrl.searchParams
try { try {
......
...@@ -3,6 +3,33 @@ import { z } from "zod" ...@@ -3,6 +3,33 @@ import { z } from "zod"
import { db } from "@/lib/db" import { db } from "@/lib/db"
/**
* @swagger
* /api/gweets/{id}:
* get:
* description: Gives back a List of Gweets
* parameters:
* - name: id
* in: path
* description: ID of Gweet that needs to be fetched
* required: true
* schema:
* type: integer
* format: int64
* content:
* application/json:
* schema:
* responses:
* 200:
* description: fetched gweets!
* 400:
* description: Invalid request body!
* 404:
* description: Gweet not found!
* 500:
* description: Error
*/
export async function GET(request: Request, { params }: { params: { id: string } }) { export async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params const { id } = params
......
...@@ -3,6 +3,36 @@ import { z } from "zod" ...@@ -3,6 +3,36 @@ import { z } from "zod"
import { db } from "@/lib/db" import { db } from "@/lib/db"
/**
* @swagger
* /api/gweets/likes:
* get:
* description: Gets back likeData
* content:
* application/json:
* schema:
* responses:
* 200:
* description: fetched like!
* 500:
* description: Error
*
* post:
* description: Creates Gweet
* responses:
* 200:
* description: Gweet unliked!
* 201:
* description: Gweet liked!
* 401:
* description: Unauthorized
* 404:
* description: Invalid request body !
* 500:
* description: Error
*
*/
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url) const { searchParams } = new URL(request.url)
const user_id = searchParams.get("user_id") || undefined const user_id = searchParams.get("user_id") || undefined
......
...@@ -3,6 +3,24 @@ import { z } from "zod" ...@@ -3,6 +3,24 @@ import { z } from "zod"
import { db } from "@/lib/db" import { db } from "@/lib/db"
/**
* @swagger
* /api/gweets/regweets:
* post:
* description: Creates Regweet
* responses:
* 200:
* description: Deleted gweet regweet!
* 201:
* description: Gweet regweeted!
* 400:
* description: Invalid request body
* 401:
* description: Unauthorized
* 500:
* description: Error
*/
export async function POST(request: Request) { export async function POST(request: Request) {
const { gweet_id, user_id } = await request.json() const { gweet_id, user_id } = await request.json()
......
...@@ -4,6 +4,42 @@ import { z } from "zod" ...@@ -4,6 +4,42 @@ import { z } from "zod"
import { db } from "@/lib/db" import { db } from "@/lib/db"
import { utapi } from "uploadthing/server" import { utapi } from "uploadthing/server"
/**
* @swagger
* /api/gweets:
* get:
* description: Gives back a List of Gweets
* content:
* application/json:
* schema:
* responses:
* 200:
* description: fetched gweets!
* 500:
* description: Error
*
* post:
* description: Creates Gweet
* responses:
* 200:
* description: Gweet created!
* 401:
* description: Unauthorized
* 500:
* description: Error
*
* delete:
* description: Deletes Gweet
* responses:
* 200:
* description: deleted!
* 401:
* description: Unauthorized
* 500:
* description: Error
*/
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url) const { searchParams } = new URL(request.url)
......
...@@ -3,6 +3,33 @@ import { z } from "zod" ...@@ -3,6 +3,33 @@ import { z } from "zod"
import { db } from "@/lib/db" import { db } from "@/lib/db"
/**
* @swagger
* /api/hashtags:
* get:
* description: Gives back a List of Hashtags
* content:
* application/json:
* schema:
* responses:
* 200:
* description: fetched hashtags!
* 500:
* description: Error
*
* post:
* description: Creates Hashtag
* responses:
* 200:
* description: Hashtag created!
* 401:
* description: Unauthorized
* 500:
* description: Error
*
*/
export async function GET() { export async function GET() {
try { try {
const hashtags = await db.hashtag.findMany({ const hashtags = await db.hashtag.findMany({
......
...@@ -3,6 +3,23 @@ import { hash } from 'bcrypt' ...@@ -3,6 +3,23 @@ import { hash } from 'bcrypt'
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
import { normalize } from 'normalize-diacritics' import { normalize } from 'normalize-diacritics'
/**
* @swagger
* /api/signup:
*
* post:
* description: Creates Account after Email was verified
* responses:
* 200:
* description: Verification sent!
* 422:
* description: Email already used
* 500:
* description: Error!
*
*/
export async function POST(req: Request) { export async function POST(req: Request) {
try { try {
const { username, email, password } = await req.json() const { username, email, password } = await req.json()
......
...@@ -3,6 +3,43 @@ import { getCurrentUser } from "@/lib/session" ...@@ -3,6 +3,43 @@ import { getCurrentUser } from "@/lib/session"
import { NextResponse } from "next/server" import { NextResponse } from "next/server"
import { z } from "zod" import { z } from "zod"
/**
* @swagger
* /api/users/follow:
* get:
* description: Get Followers for signed in User
* responses:
* 200:
* description: fetched follows!
* 500:
* description: Error
*
* put:
* description: Creates Following Record from one User to another
* requestBody:
* content:
* application/json:
* schema: # Request body contents
* type: object
* properties:
* follwerid:
* type: string
* followingid:
* type: string
* example: # Sample object
* follwerid:: 10
* followingid:: 12
* responses:
* 200:
* description: Follow handled!
* 401:
* description: Unauthorized
* 500:
* description: Error
*
*/
// get following or followers information // get following or followers information
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url) const { searchParams } = new URL(request.url)
......
...@@ -4,6 +4,21 @@ import { User } from "@prisma/client" ...@@ -4,6 +4,21 @@ import { User } from "@prisma/client"
import { revalidatePath } from "next/cache" import { revalidatePath } from "next/cache"
import { NextRequest, NextResponse } from "next/server" import { NextRequest, NextResponse } from "next/server"
/**
* @swagger
* /api/users/gamelists:
* put:
* description: Changes gamelists of a user
* id in body must match userid
* responses:
* 200:
* description: Request handled!
* 401:
* description: Unauthorized
*
*/
export async function PUT(req: NextRequest) { export async function PUT(req: NextRequest) {
const sessionUser = await getCurrentUser() const sessionUser = await getCurrentUser()
......
import { createSwaggerSpec } from 'next-swagger-doc';
export const getApiDocs = async () => {
const spec = createSwaggerSpec({
apiFolder: 'app/api', // define api folder under app folder
definition: {
openapi: '3.0.0',
info: {
title: 'GameUnity Api Documentation',
version: '1.0',
},
components: {
securitySchemes: {
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
security: [],
},
});
return spec;
};
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment