Skip to content

Commit

Permalink
Merge pull request #14 from codegasms/feat/unify-validations
Browse files Browse the repository at this point in the history
Unify api validations and setup consistent prettier formatting
  • Loading branch information
aahnik authored Dec 3, 2024
2 parents 15c44ac + cfe9120 commit 0b24772
Show file tree
Hide file tree
Showing 83 changed files with 2,764 additions and 1,678 deletions.
22 changes: 22 additions & 0 deletions ,prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 80,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"bracketSameLine": false,
"jsxSingleQuote": false,
"quoteProps": "as-needed",
"useTabs": false,
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"options": {
"parser": "typescript"
}
}
]
}
26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check Prettier Formatting

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Check formatting
run: npm run format:check
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.next
build
dist
19 changes: 10 additions & 9 deletions app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { NextResponse } from 'next/server';
import { db } from '@/db/drizzle';
import { sql } from 'drizzle-orm';
import { NextResponse } from "next/server";
import { db } from "@/db/drizzle";
import { sql } from "drizzle-orm";

export async function GET() {
try {
// Test DB connection
await db.execute(sql`SELECT 1`);

return NextResponse.json(
{ status: 'healthy', timestamp: new Date().toISOString() },
{ status: 200 }
{ status: "healthy", timestamp: new Date().toISOString() },
{ status: 200 },
);
} catch (error) {
return NextResponse.json(
{
status: 'unhealthy',
error: error instanceof Error ? error.message : 'Database connection failed',
timestamp: new Date().toISOString()
status: "unhealthy",
error:
error instanceof Error ? error.message : "Database connection failed",
timestamp: new Date().toISOString(),
},
{ status: 503 }
{ status: 503 },
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { NextRequest } from "next/server";
import { registerParticipantSchema } from "./validation";
import { createParticipantSchema } from "@/lib/validations";
import * as participantService from "./service";
import { IdSchema } from "@/app/api/types";

Expand All @@ -10,7 +10,7 @@ export async function POST(
) {
try {
const contestId = IdSchema.parse(params.contestId);
const data = registerParticipantSchema.parse(await request.json());
const data = createParticipantSchema.parse(await request.json());

const participant = await participantService.registerParticipant(
contestId,
Expand Down
2 changes: 1 addition & 1 deletion app/api/orgs/[orgId]/contests/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createContest } from "./service";
import { db } from "@/db/drizzle";
import { contests } from "@/db/schema";
import { count, eq } from "drizzle-orm";
import { createContestSchema } from "./validation";
import { createContestSchema } from "@/lib/validations";
import { IdSchema } from "@/app/api/types";

export async function POST(
Expand Down
4 changes: 2 additions & 2 deletions app/api/orgs/[orgId]/groups/[groupId]/members/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { NextRequest } from "next/server";
import { addMemberSchema } from "./validation";
import { createMembershipSchema } from "@/lib/validations";
import * as memberService from "./service";
import { IdSchema } from "@/app/api/types";

Expand All @@ -10,7 +10,7 @@ export async function POST(
) {
try {
const groupId = IdSchema.parse(params.groupId);
const data = addMemberSchema.parse(await request.json());
const data = createMembershipSchema.parse(await request.json());

const member = await memberService.addMember(groupId, data.userId);
return Response.json(member, { status: 201 });
Expand Down
2 changes: 1 addition & 1 deletion app/api/orgs/[orgId]/groups/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { NextRequest } from "next/server";
import { createGroupSchema } from "./validation";
import { createGroupSchema } from "@/lib/validations";
import * as groupService from "./service";
import { IdSchema } from "@/app/api/types";

Expand Down
2 changes: 1 addition & 1 deletion app/api/orgs/[orgId]/groups/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";
import { db } from "@/db/drizzle";
import { groups, groupMemberships } from "@/db/schema";
import { eq, and } from "drizzle-orm";
import { createGroupSchema } from "./validation";
import { createGroupSchema } from "@/lib/validations";

export async function createGroup(
orgId: number,
Expand Down
4 changes: 2 additions & 2 deletions app/api/orgs/[orgId]/problems/[problemId]/test-cases/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest } from "next/server";
import { testCaseSchema } from "./validation";
import { createTestCaseSchema } from "@/lib/validations";
import * as testCaseService from "./service";
import { IdSchema } from "@/app/api/types";
import { z } from "zod";
Expand All @@ -26,7 +26,7 @@ export async function POST(
) {
try {
const problemId = IdSchema.parse(params.problemId);
const data = testCaseSchema.parse(await request.json());
const data = createTestCaseSchema.parse(await request.json());

const testCase = await testCaseService.addTestCase(problemId, data);
return Response.json(testCase, { status: 201 });
Expand Down
2 changes: 1 addition & 1 deletion app/api/orgs/[orgId]/problems/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProblemSchema, createTestCaseSchema } from "./validation";
import { createProblemSchema, createTestCaseSchema } from "@/lib/validations";
import * as problemService from "./service";
import { NextRequest } from "next/server";
import { IdSchema } from "../../../types";
Expand Down
2 changes: 1 addition & 1 deletion app/api/orgs/[orgId]/problems/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from "@/db/drizzle";
import { problems, testCases } from "@/db/schema";
import { z } from "zod";
import { createProblemSchema, createTestCaseSchema } from "./validation";
import { createProblemSchema, createTestCaseSchema } from "@/lib/validations";

export async function createProblem(
orgId: number,
Expand Down
2 changes: 1 addition & 1 deletion app/api/users/[userId]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { updateUserSchema } from "../validation";
import { updateUserSchema } from "@/lib/validations";
import { IdSchema } from "../../types";
import * as userService from "../service";
import { NextRequest } from "next/server";
Expand Down
2 changes: 1 addition & 1 deletion app/api/users/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { createUserSchema } from "./validation";
import { createUserSchema } from "@/lib/validations";
import * as userService from "./service";
import { NextRequest } from "next/server";

Expand Down
10 changes: 4 additions & 6 deletions app/code/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { CodeEditor } from "@/components/code-editor"
import { Button } from "@/components/ui/button"
import { CodeEditor } from "@/components/code-editor";
import { Button } from "@/components/ui/button";

export default function CodePage() {
return (
<CodeEditor />
)
}
return <CodeEditor />;
}
5 changes: 2 additions & 3 deletions app/contest/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ContestDetailPage } from '@/components/contest-details-table'
import { ContestDetailPage } from "@/components/contest-details-table";

export default function ContestDetail() {
return <ContestDetailPage />
return <ContestDetailPage />;
}

4 changes: 2 additions & 2 deletions app/contest/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateContest } from "@/components/create-contest"
import { CreateContest } from "@/components/create-contest";

export default function CreateContestPage() {
return <CreateContest />
return <CreateContest />;
}
5 changes: 2 additions & 3 deletions app/contest/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ContestListPage } from '@/components/contestlist'
import { ContestListPage } from "@/components/contestlist";

export default function ContestList() {
return <ContestListPage />
return <ContestListPage />;
}

10 changes: 5 additions & 5 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { AppSidebar } from "@/components/app-sidebar"
import { AppSidebar } from "@/components/app-sidebar";
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { Separator } from "@/components/ui/separator"
} from "@/components/ui/breadcrumb";
import { Separator } from "@/components/ui/separator";
import {
SidebarInset,
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar"
} from "@/components/ui/sidebar";

export default function Page() {
return (
Expand Down Expand Up @@ -46,5 +46,5 @@ export default function Page() {
</div>
</SidebarInset>
</SidebarProvider>
)
);
}
6 changes: 3 additions & 3 deletions app/groups/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GroupsInfoPage } from '@/components/groups-list'
import { GroupsInfoPage } from "@/components/groups-list";

export default function UsersPage() {
return <GroupsInfoPage />
}
return <GroupsInfoPage />;
}
4 changes: 2 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
import '@uiw/react-md-editor/markdown-editor.css';
import '@uiw/react-markdown-preview/markdown.css';
import "@uiw/react-md-editor/markdown-editor.css";
import "@uiw/react-markdown-preview/markdown.css";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
Expand Down
Loading

0 comments on commit 0b24772

Please sign in to comment.