feat: завершить проект — добавить недостающие файлы, тесты и CI/CD
- backend/app/schemas/auth.py, ai_match.py, escrow.py (схемы) - frontend/components/ui/button.tsx (UI компонент) - email-validator в requirements.txt - frontend/tsconfig.json, tailwind.config.js, postcss.config.js - frontend: login page, projects/[id] page, ai-match page - Dockerfile для backend и frontend - docker-compose.yml с app-контейнерами и healthcheck - .env.example с полными переменными окружения - backend/tests/ — pytest тесты (conftest + test_health) - .drone.yml — CI/CD пайплайн для Drone CI - README.md — полный гайд по деплою
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
||||
@@ -0,0 +1,86 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function AIMatchPage() {
|
||||
const [projectId, setProjectId] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [matches, setMatches] = useState<any[]>([]);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function handleMatch() {
|
||||
if (!projectId) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch("/api/ai/match-project", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ project_id: projectId, limit: 10 }),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error("Ошибка при поиске совпадений");
|
||||
|
||||
const data = await res.json();
|
||||
setMatches(data);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<header className="bg-white border-b px-6 py-4 flex items-center justify-between">
|
||||
<Link href="/dashboard" className="text-blue-600 hover:text-blue-800">← Назад</Link>
|
||||
<h1 className="text-xl font-bold">AI-матчинг</h1>
|
||||
</header>
|
||||
|
||||
<main className="container mx-auto px-4 py-8 max-w-3xl">
|
||||
<div className="bg-white rounded-xl shadow-sm p-6 mb-6">
|
||||
<h2 className="text-2xl font-bold mb-4">Подобрать фрилансеров</h2>
|
||||
|
||||
<input
|
||||
value={projectId}
|
||||
onChange={(e) => setProjectId(e.target.value)}
|
||||
placeholder="ID проекта"
|
||||
className="w-full px-4 py-3 border rounded-lg mb-4"
|
||||
/>
|
||||
|
||||
{error && (
|
||||
<div className="mb-4 p-3 bg-red-50 text-red-700 rounded">{error}</div>
|
||||
)}
|
||||
|
||||
<Button onClick={handleMatch} disabled={loading}>
|
||||
{loading ? "Поиск..." : "Найти совпадения"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{matches.length > 0 && (
|
||||
<div className="space-y-4">
|
||||
{matches.map((m, i) => (
|
||||
<div key={i} className="bg-white rounded-xl shadow-sm p-6">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<h3 className="font-semibold">{m.name}</h3>
|
||||
<span className="text-green-600 font-bold">{(m.match_score * 100).toFixed(0)}%</span>
|
||||
</div>
|
||||
|
||||
{m.skills_matched.length > 0 && (
|
||||
<p className="text-sm text-gray-500 mb-2">Совпадение навыков: {m.skills_matched.join(", ")}</p>
|
||||
)}
|
||||
|
||||
<ul className="space-y-1">
|
||||
{m.reasons.map((r, j) => (
|
||||
<li key={j} className="text-sm text-gray-600">• {r}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import * as z from "zod";
|
||||
|
||||
const loginSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
|
||||
type FormData = z.infer<typeof loginSchema>;
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const form = useForm<FormData>({ resolver: zodResolver(loginSchema) });
|
||||
|
||||
async function onSubmit(data: FormData) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch("/api/auth/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error("Неверный email или пароль");
|
||||
|
||||
router.push("/dashboard");
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="w-full max-w-md p-8 rounded-xl shadow-sm bg-white">
|
||||
<h1 className="text-2xl font-bold mb-6">Вход</h1>
|
||||
|
||||
{error && (
|
||||
<div className="mb-4 p-3 bg-red-50 text-red-700 rounded">{error}</div>
|
||||
)}
|
||||
|
||||
<input {...form.register("email")} placeholder="Email" className="w-full mb-3 px-4 py-2 border rounded" />
|
||||
{form.formState.errors.email && (
|
||||
<p className="text-sm text-red-500 mb-2">{form.formState.errors.email.message}</p>
|
||||
)}
|
||||
|
||||
<input {...form.register("password")} type="password" placeholder="Пароль" className="w-full mb-4 px-4 py-2 border rounded" />
|
||||
{form.formState.errors.password && (
|
||||
<p className="text-sm text-red-500 mb-2">{form.formState.errors.password.message}</p>
|
||||
)}
|
||||
|
||||
<button type="submit" disabled={loading} className="w-full bg-blue-600 text-white py-3 rounded font-medium">
|
||||
{loading ? "Вход..." : "Войти"}
|
||||
</button>
|
||||
|
||||
<p className="text-center mt-4 text-sm">
|
||||
Нет аккаунта?{" "}
|
||||
<Link href="/auth/register" className="text-blue-600">Зарегистрироваться</Link>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import Link from "next/link";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
async function fetchProject(id: string) {
|
||||
const res = await fetch(`/api/projects/${id}`);
|
||||
if (!res.ok) throw new Error("Проект не найден");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export default function ProjectPage() {
|
||||
const params = useParams<{ id: string }>();
|
||||
const router = useRouter();
|
||||
|
||||
const { data: project, isLoading } = useQuery({
|
||||
queryKey: ["project", params.id],
|
||||
queryFn: () => fetchProject(params.id),
|
||||
});
|
||||
|
||||
if (isLoading) return <div className="min-h-screen flex items-center justify-center">Загрузка...</div>;
|
||||
if (!project) return <div>Проект не найден</div>;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<header className="bg-white border-b px-6 py-4 flex items-center justify-between">
|
||||
<Link href="/dashboard" className="text-blue-600 hover:text-blue-800">← Назад</Link>
|
||||
<h1 className="text-xl font-bold">Freelancer Match</h1>
|
||||
</header>
|
||||
|
||||
<main className="container mx-auto px-4 py-8 max-w-3xl">
|
||||
<div className="bg-white rounded-xl shadow-sm p-6 mb-6">
|
||||
<h2 className="text-2xl font-bold mb-4">{project.title}</h2>
|
||||
<p className="text-gray-700 whitespace-pre-wrap mb-4">{project.description}</p>
|
||||
|
||||
{project.category && (
|
||||
<span className="inline-block px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm">
|
||||
{project.category}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="mt-4 flex gap-2 flex-wrap">
|
||||
{project.required_skills.map((skill: string) => (
|
||||
<span key={skill} className="px-2 py-1 bg-gray-100 rounded text-sm">{skill}</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{(project.budget_min || project.budget_max) && (
|
||||
<div className="mt-4 p-3 bg-green-50 rounded">
|
||||
{project.budget_min ? `${project.budget_min.toLocaleString()}₽` : "—"} —{" "}
|
||||
{project.budget_max ? `${project.budget_max.toLocaleString()}₽` : "до бесконечности"}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{project.deadline && (
|
||||
<p className="mt-2 text-sm text-gray-500">Дедлайн: {new Date(project.deadline).toLocaleDateString("ru-RU")}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button onClick={() => router.push("/auth/login")}>Оставить заявку</Button>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-blue-600 text-white hover:bg-blue-700",
|
||||
destructive: "bg-red-500 text-white hover:bg-red-600",
|
||||
outline: "border border-gray-300 bg-transparent hover:bg-gray-100",
|
||||
secondary: "bg-gray-200 text-gray-900 hover:bg-gray-300",
|
||||
ghost: "hover:bg-gray-100",
|
||||
link: "text-blue-600 underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-10 px-4 py-2",
|
||||
sm: "h-9 rounded-md px-3",
|
||||
lg: "h-11 rounded-md px-8 text-base",
|
||||
icon: "h-10 w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (
|
||||
<Comp
|
||||
className={buttonVariants({ variant, size, className })}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./app/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./components/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [{ "name": "next" }],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user