untitled-5321index.ts5 matches
23});
2425// Chat API endpoint
26app.post("/api/chat", async c => {
27try {
28const body: ChatRequest = await c.req.json();
7879} catch (error) {
80console.error("Chat API error:", error);
81return c.json<ChatResponse>({
82message: "",
87});
8889// Image generation API endpoint
90app.post("/api/generate-image", async c => {
91try {
92const body: ImageGenerationRequest = await c.req.json();
29};
3031const response = await fetch('/api/generate-image', {
32method: 'POST',
33headers: {
36};
3738const response = await fetch('/api/chat', {
39method: 'POST',
40headers: {
123124export function getAvatarUrl(name: string): string {
125return `https://ui-avatars.com/api/?name=${encodeURIComponent(name)}&background=6366f1&color=fff&size=40`;
126}
127131}
132133export function capitalizeFirst(text: string): string {
134return text.charAt(0).toUpperCase() + text.slice(1);
135}
128}
129130export interface ApiResponse<T = any> {
131success: boolean;
132data?: T;
5354## Getting Started
551. The backend serves the frontend and API endpoints
562. SQLite database is automatically initialized
573. Sample data is seeded on first run
584. Access the site at the HTTP endpoint URL
5960## API Endpoints
61- `GET /` - Homepage
62- `GET /api/products` - Product listing with filters
63- `GET /api/products/:id` - Product details
64- `POST /api/auth/login` - User authentication
65- `POST /api/cart` - Cart operations
66- `POST /api/orders` - Order placement
67- `GET /admin/*` - Admin dashboard (protected)
jeffiproducts.ts20 matches
9getProductReviews
10} from "../database/queries.ts";
11import type { ProductFilters, ProductSort, PaginationParams, ApiResponse } from "../../shared/types.ts";
1213const products = new Hono();
42const result = await getProducts(filters, sort, pagination);
4344return c.json<ApiResponse>({
45success: true,
46data: result
48} catch (error) {
49console.error("Get products error:", error);
50return c.json<ApiResponse>({
51success: false,
52error: "Failed to fetch products"
61const featuredProducts = await getFeaturedProducts(limit);
6263return c.json<ApiResponse>({
64success: true,
65data: featuredProducts
67} catch (error) {
68console.error("Get featured products error:", error);
69return c.json<ApiResponse>({
70success: false,
71error: "Failed to fetch featured products"
80
81if (isNaN(id)) {
82return c.json<ApiResponse>({
83success: false,
84error: "Invalid product ID"
89
90if (!product) {
91return c.json<ApiResponse>({
92success: false,
93error: "Product not found"
95}
9697return c.json<ApiResponse>({
98success: true,
99data: product
101} catch (error) {
102console.error("Get product error:", error);
103return c.json<ApiResponse>({
104success: false,
105error: "Failed to fetch product"
115
116if (isNaN(id)) {
117return c.json<ApiResponse>({
118success: false,
119error: "Invalid product ID"
123const relatedProducts = await getRelatedProducts(id, limit);
124125return c.json<ApiResponse>({
126success: true,
127data: relatedProducts
129} catch (error) {
130console.error("Get related products error:", error);
131return c.json<ApiResponse>({
132success: false,
133error: "Failed to fetch related products"
142
143if (isNaN(id)) {
144return c.json<ApiResponse>({
145success: false,
146error: "Invalid product ID"
150const reviews = await getProductReviews(id);
151152return c.json<ApiResponse>({
153success: true,
154data: reviews
156} catch (error) {
157console.error("Get product reviews error:", error);
158return c.json<ApiResponse>({
159success: false,
160error: "Failed to fetch product reviews"
168const categories = await getCategories();
169170return c.json<ApiResponse>({
171success: true,
172data: categories
174} catch (error) {
175console.error("Get categories error:", error);
176return c.json<ApiResponse>({
177success: false,
178error: "Failed to fetch categories"
188
189if (!category) {
190return c.json<ApiResponse>({
191success: false,
192error: "Category not found"
194}
195196return c.json<ApiResponse>({
197success: true,
198data: category
200} catch (error) {
201console.error("Get category error:", error);
202return c.json<ApiResponse>({
203success: false,
204error: "Failed to fetch category"
jeffiProductCard.tsx2 matches
3435try {
36const response = await fetch('/api/cart/add', {
37method: 'POST',
38headers: {
5657// Refresh cart
58const cartResponse = await fetch('/api/cart', {
59credentials: 'include'
60});
8} from "../database/queries.ts";
9import { authMiddleware } from "./auth.ts";
10import type { CheckoutRequest, ApiResponse } from "../../shared/types.ts";
1112const orders = new Hono();
24// Validate required fields
25if (!shippingAddress || !billingAddress || !paymentMethod) {
26return c.json<ApiResponse>({
27success: false,
28error: "Missing required checkout information"
34
35if (cartItems.length === 0) {
36return c.json<ApiResponse>({
37success: false,
38error: "Cart is empty"
69await clearCart(user.userId);
7071return c.json<ApiResponse>({
72success: true,
73data: order,
76} catch (error) {
77console.error("Create order error:", error);
78return c.json<ApiResponse>({
79success: false,
80error: "Failed to create order"
89const userOrders = await getUserOrders(user.userId);
9091return c.json<ApiResponse>({
92success: true,
93data: userOrders
95} catch (error) {
96console.error("Get user orders error:", error);
97return c.json<ApiResponse>({
98success: false,
99error: "Failed to fetch orders"
109110if (isNaN(orderId)) {
111return c.json<ApiResponse>({
112success: false,
113error: "Invalid order ID"
119// Check if user owns this order (or is admin)
120if (order.userId !== user.userId && !user.isAdmin) {
121return c.json<ApiResponse>({
122success: false,
123error: "Access denied"
125}
126127return c.json<ApiResponse>({
128success: true,
129data: order
133
134if (error.message === "Order not found") {
135return c.json<ApiResponse>({
136success: false,
137error: "Order not found"
139}
140141return c.json<ApiResponse>({
142success: false,
143error: "Failed to fetch order"