Skip to content

Commit

Permalink
feat: add gallery for published images
Browse files Browse the repository at this point in the history
  • Loading branch information
polyesterswing committed Jan 24, 2025
1 parent 89fc1ca commit b6c9fa2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions art-gallery/app/controllers/art.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ const index = async (req, res) => {
}
};

const gallery = async (req, res) => {
try {
let { page, limit } = req.query;
page = page || 1;
limit = limit || 10;
const count = await Art.countDocuments();

const arts = await Art.find({published: true})
.populate({ path: "artist", select: "id name" })
.populate("theme")
.skip((page - 1) * limit)
.limit(limit);

return res.status(200).json({
status: "success",
message: "Arts fetched successfully.",
arts: arts,
count: count,
});
} catch (e) {
console.log(e);

return res.status(500).json({
status: "error",
message: "Something went wrong",
});
}
};

const userArts = async (req, res) => {
console.log("hi");

Expand Down Expand Up @@ -394,4 +423,5 @@ module.exports = {
remove,
like,
publish,
gallery,
};
3 changes: 3 additions & 0 deletions art-gallery/routes/art.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
like,
remove,
publish,
gallery,
} = require("../app/controllers/art.controller");
const convertToWebP = require("../app/middlewares/converter.middleware");

Expand All @@ -29,6 +30,8 @@ router.post("/:slug", getUser, like);
router.post("/publish/:slug", getUser, publish);

router.get("/", index);
router.get("/gallery", gallery);

router.get("/:slug", show);
router.put("/:slug", getUser, edit);
router.delete("/:slug", getUser, remove);
Expand Down

0 comments on commit b6c9fa2

Please sign in to comment.