Skip to content

Commit

Permalink
feature: admin to upload Media for Mobile App
Browse files Browse the repository at this point in the history
  • Loading branch information
collinsadi committed Jun 20, 2024
1 parent 56a99ce commit e048cbe
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 28 deletions.
41 changes: 31 additions & 10 deletions controllers/mediaController.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
const Media = require("../models/mediaModel");
const { internalServerError } = require("../utils/errorHandler");
const { internalServerError, handleError } = require("../utils/errorHandler");

const uploadMedia = async (request, response) => {
const { title, description, duration, url } = request.body;
const { mediaUrl, title } = request.body;

try {

// check if the required fields are being sent



if (!mediaUrl) {
return response
.status(422)
.json(
handleError(
422,
"Media URL is Required",
"the client did not send the media url"
)
);
}

await Media.create({ mediaUrl, title });

response
.status(200)
.json({ status: true, message: "Media Uploaded Successfully" });
} catch (error) {
console.log(error);
response.status(500).json(internalServerError(error));
}
};

const getAllMedia = async (request, response) => {
try {
const videos = await Media.find().sort({ createdAt: -1 });


response.status(200).json({ status: true, videos });
} catch (error) {
console.log(error);
response.status(500).json(internalServerError(error));
}
};

module.exports = {
uploadMedia
}
uploadMedia,
getAllMedia,
};
2 changes: 1 addition & 1 deletion controllers/merchantController.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const loginMerchant = async (request, response) => {

response
.status(200)
.json({ status: true, message: "Login Successful", token });
.json({ status: true, message: "Login Successful", token, merchant });
} catch (error) {
console.log(error);
response.status(500).json(internalServerError(error));
Expand Down
2 changes: 1 addition & 1 deletion controllers/userAuthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const login = async (request, response) => {

response
.status(200)
.json({ status: true, message: "Login Successful", token });
.json({ status: true, message: "Login Successful", token, user });
} catch (error) {
console.log(error);
response.status(500).json(internalServerError(error));
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const reviewRoutes = require("./routes/review.router");
const adminAuthRoutes = require("./routes/adminRoutes/adminAuthRoutes");
const adminUserManagementRoutes = require("./routes/adminRoutes/usersRouter");
const adminMerchantRoutes = require("./routes/adminRoutes/merchantsRoutes");
const mediaRoutes = require("./routes/adminRoutes/mediaRoutes");

const authenticateSocket = require("./middlewares/authenticateSocket");

Expand All @@ -51,6 +52,11 @@ app.use("/api/v1/review", reviewRoutes);
app.use("/api/v1/admin/auth", adminAuthRoutes);
app.use("/api/v1/admin/user_management", adminUserManagementRoutes);
app.use("/api/v1/admin/merchant_management", adminMerchantRoutes);
app.use("/api/v1/admin/media", mediaRoutes);

app.get("/test", (req, res) => {
res.status(200).json({ message: "Okay" });
});

// Messaging Related Models
const User = require("./models/userModel");
Expand Down
13 changes: 1 addition & 12 deletions models/mediaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ const Schema = mongoose.Schema;

const mediaSchema = new Schema(
{
title: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
previewUrl: String,
duration: {
type: String,
},
title: String,
mediaUrl: {
type: String,
required: true,
Expand Down
11 changes: 7 additions & 4 deletions public/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@
</div>
</div>

<!-- <div class="container">
<div class="container">
<div class="input-group">
<label for="token">Token:</label>
<input
value="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY2M2ExNWJmZTIwOWQxZGFmZmM5ODljOCIsImlhdCI6MTcxNTA4MjY4N30.U128tJ7QrMe-tEZRQbrTX-Ctqb9CuT5QIETYPwf8e7Y"
value="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY2NmQ5N2Y0NmEyYTRlOGUyYmVhNzk4ZCIsImlhdCI6MTcxODQ1ODM1Nn0.aWw1gnowa28_65YWs4orG5sv0UI4sFC9k1c1JqabMRc"
type="text"
id="token"
/>
</div>
<div class="input-group">
<label for="hash">Hash:</label>
<input value="a7db40decd" type="text" id="hash" />
<input value="dbc2e3ef2a" type="text" id="hash" />
</div>
<button onclick="saveCredentials()">Save Credentials</button>
</div> -->
</div>

<script src="./socket-io.js"></script>
<script>
Expand Down Expand Up @@ -154,6 +154,9 @@
socket.on("connect", () => {
console.log("Connected to server");
});
socket.on("connect_error", (err) => {
console.log("Error",err);
});

socket.emit("conversation-opened", {
conversationId: urlparams.get("id"),
Expand Down
12 changes: 12 additions & 0 deletions routes/adminRoutes/mediaRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const express = require("express");
const authenticateAdmin = require("../../middlewares/adminAuthMiddleware");
const {
uploadMedia,
getAllMedia,
} = require("../../controllers/mediaController");
const router = express.Router();

router.post("/upload", authenticateAdmin, uploadMedia);
router.post("/get/all", authenticateAdmin, getAllMedia);

module.exports = router;

0 comments on commit e048cbe

Please sign in to comment.