TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nayalsaurav/Akari-Art/llms.txt
Use this file to discover all available pages before exploring further.
/api/post route handles reading and writing community posts in Akari Art. Posts are MongoDB documents that store the author’s display name, the text prompt used to generate the image, and the resulting Cloudinary image URL. Both the GET and POST handlers connect to MongoDB via dbConnect() before executing any queries.
GET /api/post — List All Posts
Retrieves all community posts from the MongoDBposts collection. This endpoint is used to populate the community gallery.
Endpoint
Authentication
No session cookie is required to read posts. The endpoint is accessible from server components and server-side data fetching calls without any credentials.Request Body
None.Response
200 — Success
Always
true on a successful response.An array of Post objects from the MongoDB collection. Each object contains:
500 — Error
Always
false on error."Failed to fetch posts."The underlying error message from the caught exception.
Example Request
POST /api/post — Create a Post
Creates a new community post in MongoDB. This is called after a user successfully generates an image and chooses to share it with the community.Endpoint
Authentication
A valid NextAuth.js session cookie is required. The middleware enforces authentication before this handler is reached.Request Body
The author’s display name. Leading and trailing whitespace is trimmed before
saving to MongoDB.Example:
"Jane Doe"The text prompt that was used to generate the image. Leading and trailing
whitespace is trimmed before saving.Example:
"A futuristic city skyline at dusk, neon lights reflected in rain"The Cloudinary
secure_url of the generated image, obtained from the
/api/image-generation response.Example: "https://res.cloudinary.com/your-cloud/image/upload/v1234567890/abc123.png"Response
201 — Created
Always
true on successful creation.The newly created MongoDB Post document, including the auto-generated
_id.400 — Missing Fields
Always
false."Missing required fields: name, prompt, or photo." — returned when any of
the three required body fields is absent or falsy.500 — Server Error
Always
false."Failed to create post."The underlying error message from the caught exception.
Example Request
MongoDB Post Schema
ThePost model is defined in model/post.ts: