Skip to content

Commit

Permalink
Refactor code and fix bugs close #19
Browse files Browse the repository at this point in the history
Co-Authored-By: ruru <[email protected]>
  • Loading branch information
ruru-m07 and ruru-m07 committed Feb 8, 2024
1 parent a70e8a7 commit 4774d99
Show file tree
Hide file tree
Showing 47 changed files with 12,816 additions and 7,502 deletions.
40 changes: 40 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"workbench.colorTheme": "Tokyo Night",
"workbench.startupEditor": "none",
"files.autoSave": "afterDelay",
"glassit.alpha": 245,
"glassit.force_sway": true,
"workbench.iconTheme": "material-icon-theme",
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"hediet.vscode-drawio.resizeImages": null,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"tabnine.experimentalAutoImports": true,
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.updateImportsOnFileMove.enabled": "always",
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"glassit.step": 500,
"bitoAI.codeCompletion.enableCommentToCode": true,
"bitoAI.codeCompletion.enableAutoCompletion": true,
"cmake.options.statusBarVisibility": "hidden"
}
13 changes: 13 additions & 0 deletions actions/findImageUrlByUserName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use server";

import { db } from "@/lib/db";

export const findImageUrlByUserName = async (userName: string) => {
const user = await db.user.findUnique({
where: {
username: userName,
},
});
let image = user?.image;
return image;
};
18 changes: 18 additions & 0 deletions actions/repo/branchCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use server";

import { db } from "@/lib/db";

export const fetchrepo = async (username: string, repository: string) => {
if (!username && !repository) {
return { error: "Invalid user!" };
}

const repo = await db.repository.findFirst({
where: {
name: repository,
author: username,
},
});
console.log(repo)
return { repo: repo };
};
19 changes: 19 additions & 0 deletions actions/repo/commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use server";

import { db } from "@/lib/db";

export const create = async () => {
const commitresult = await db.commit.create({
data: {
commitId: "3",
title: "Initial Commit",
description: " Initial Commit of the repository",
branch: "master",
repositoryId: "65c339bbf67715e59d92337d",
},
});
return {
success: "create commit Successfully! 🎉",
commitresult: commitresult,
};
};
59 changes: 59 additions & 0 deletions actions/repo/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use server";

import * as z from "zod";

import { db } from "@/lib/db";
import { RepoSchema } from "@/schemas";
import { User } from "@prisma/client";

export const create = async (
values: z.infer<typeof RepoSchema>,
user: User
) => {
const validatedFields = RepoSchema.safeParse(values);

if (!validatedFields.success) {
return { error: "Invalid fields!" };
}

const { name, description, visibility, branch } = validatedFields.data;

if (!user?.username) {
return { error: "Invalid user!" };
}
const existingRepo = await db.repository.findFirst({
where: {
name: name,
author: user?.username,
},
});

console.log(existingRepo);

if (existingRepo) {
return { error: "Repository already exist with this name!" };
}

if (user?.username && user?.id) {
const repository = await db.repository.create({
data: {
name: name,
description: description,
Visibility: visibility,
author: user?.username,
authorId: user?.id,
DefualtBranch: branch,
},
});

await db.branch.create({
data: {
name: branch,
repositoryId: repository.id,
},
});
return { success: "Repository create Successfully! 🎉" };
} else {
return { error: "Invalid user!" };
}
};
45 changes: 45 additions & 0 deletions actions/repo/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use server";

import { db } from "@/lib/db";
import { User } from "@prisma/client";

export const fetchRepo = async (
username: string,
repository: string,
user?: User | null
) => {
if (!username || !repository) {
return { error: "Invalid user or repository!" };
}

let repo;

if (user?.username === username) {
repo = await db.repository.findFirst({
where: {
name: repository,
author: username,
},
});
} else {
repo = await db.repository.findFirst({
where: {
name: repository,
author: username,
Visibility: "public",
},
});
}

if (!repo) {
return { error: "Repository not found!", statuscode: 404 };
}

const branches = await db.branch.findMany({
where: {
repositoryId: repo.id,
},
});

return { repo, branchCount: branches.length };
};
Loading

0 comments on commit 4774d99

Please sign in to comment.