Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEREG #60

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_URI="mongodb+srv://as7ro:[email protected]/?retryWrites=true&w=majority"
PORT=3000
JWT_SECRET=KAOR_SECRET

CLOUD_NAME=dvutkeirc
CLOUD_API_KEY=494123335124295
CLOUD_API_SECRET= tNVl7nbmxJfF1a1FASDlGRtEOkM
11 changes: 0 additions & 11 deletions README.md

This file was deleted.

98 changes: 98 additions & 0 deletions areas/admin/controllers/aboutController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import About from "../../../models/aboutModel.js"
import { v2 as cloudinary } from "cloudinary";
import fs from "fs";




const getAboutDetail = async(req,res)=>{
try {
const about = await About.findById({_id:req.params.id});
res.status(200).render('../areas/admin/views/about/detail',{
about,

})
} catch (error) {
res.status(500).json({
succeded:false,
error
})
}
}

const getAboutUpdate = async(req, res) => {
const about = await About.findById(req.params.id)

res.status(200).render("../areas/admin/views/about/update", {
about
});
}

const updateAbout = async (req, res) => {
try {
const about = await About.findById(req.params.id);

if (req.files && req.files.image) {
if (about.image_id) {
await cloudinary.uploader.destroy(about.image_id);
}

const result = await cloudinary.uploader.upload(req.files.image.tempFilePath, {
use_filename: true,
folder: 'damvev_de'

});

if (result.error) {
throw new Error(result.error.message);
}

about.url = result.secure_url;
about.image_id = result.public_id;

fs.unlinkSync(req.files.image.tempFilePath);
}

// Diğer alanları güncelleme
about.titleAz = req.body.titleAz;
about.titleGe = req.body.titleGe;
about.descriptionAz = req.body.descriptionAz;
about.descriptionGe = req.body.descriptionGe
about.fb = req.body.fb;
about.inst = req.body.inst;
about.youtube = req.body.youtube;

await about.save();

res.status(200).redirect('/admin/about');
} catch (error) {
res.status(500).json({
succeeded: false,
error: error.message
});
}
};



const getAbout =async(req,res)=>{
const about = await About.find({});
res.render('../areas/admin/views/about/about',{
about
})
}

const createAbout = async (req, res) => {
try {
const about = await About.create(req.body);

res.status(201).redirect("/admin/about")
} catch (error) {
res.status(500).json({
succeded: false,
error
})
}
};

export {getAbout,updateAbout,getAboutUpdate,createAbout,getAboutDetail};
75 changes: 75 additions & 0 deletions areas/admin/controllers/contactController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Contact from "../../../models/contactModel.js"





const getContactDetail = async(req,res)=>{
try {
const contact = await Contact.findById({_id:req.params.id});
res.status(200).render('../areas/admin/views/contact/detail',{
contact,

})
} catch (error) {
res.status(500).json({
succeded:false,
error
})
}
}

const getContactUpdate = async(req, res) => {
const contact = await Contact.findById(req.params.id)

res.status(200).render("../areas/admin/views/contact/update", {
contact
});
}




const getContact =async(req,res)=>{
const contact = await Contact.find({});
res.render('../areas/admin/views/contact/contact',{
contact
})
}

const createContact = async (req, res) => {
try {
const contact = await Contact.create(req.body);

res.status(201).redirect("/admin/contact")
} catch (error) {
res.status(500).json({
succeded: false,
error
})
}
};
const updateContact = async (req, res) => {
try {
const contact = await Contact.findById(req.params.id);

// Diğer alanları güncelleme
contact.location = req.body.location;
contact.gmail = req.body.gmail;
contact.tel = req.body.tel;
contact.fb = req.body.fb;
contact.inst = req.body.inst;
contact.youtube = req.body.youtube;

await contact.save();

res.status(200).redirect('/admin/contact');
} catch (error) {
res.status(500).json({
succeeded: false,
error: error.message
});
}
};

export {getContact,getContactUpdate,createContact,getContactDetail,updateContact};
166 changes: 166 additions & 0 deletions areas/admin/controllers/joinUsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import JoinUs from "../../../models/joinUsModel.js";
import { v2 as cloudinary } from "cloudinary";
import fs from "fs";
import path from "path";

const getJoinUsPage = async (req, res) => {
const joinUs = await JoinUs.find({})
res.render('../areas/admin/views/joinUs/joinUs', {
joinUs
})
}

const getJoinUsDetail = async (req, res) => {
try {
const joinUs = await JoinUs.findById({ _id: req.params.id });

res.status(200).render('../areas/admin/views/joinUs/detail', {
joinUs,
});

} catch (error) {
res.status(500).json({
succeeded: false,
error,
});
}
};


const createJoinUs = async (req, res) => {
try {
const uploadedFiles = [];

if (req.files) {
// Check if multiple files are uploaded
if (req.files.files && Array.isArray(req.files.files)) {
for (const file of req.files.files) {
const filePath = `public/files/${file.name}`; // Dosyanın kaydedileceği yol
await file.mv(filePath); // Dosyayı "public" klasörüne kaydet

uploadedFiles.push({
url: `/${file.name}`, // Erişim URL'si
file_id: file.name // Dosya adı olarak public_id'yi kullanabilirsiniz
});
}
} else if (req.files.file) {
// Single file is uploaded
const file = req.files.file;
const filePath = `public/files/${file.name}`; // Dosyanın kaydedileceği yol
await file.mv(filePath); // Dosyayı "public" klasörüne kaydet

uploadedFiles.push({
url: `/${file.name}`, // Erişim URL'si
file_id: file.name // Dosya adı olarak public_id'yi kullanabilirsiniz
});
}
}

// Create the news entry with the uploaded files
const joinUs = new JoinUs({
descriptionAz: req.body.descriptionAz,
descriptionGe: req.body.descriptionGe,

files: uploadedFiles
});

// Save the news entry to the database
await joinUs.save();

res.status(201).redirect("/admin/joinUs");
} catch (error) {
res.status(500).json({
succeeded: false,
error
});
}
};






const getUpdateJoinUs = async (req, res) => {
try {
const joinUs = await JoinUs.findById({ _id: req.params.id });

res.status(200).render('../areas/admin/views/joinUs/update', {
joinUs
})
} catch (error) {
res.status(500).json({
succeded: false,
error
})
}
}


const updateJoinUs = async (req, res) => {
try {
const joinUs = await JoinUs.findById(req.params.id);

if (req.files && req.files.files) {
// Birden fazla dosya yüklendiğinde
// Önce mevcut tüm dosyaları sil
for (const file of joinUs.files) {
const filePath = path.join("public/files", file.file_id);
fs.unlinkSync(filePath);
}

// Yeni dosyaları kaydet
const uploadedFiles = [];
for (const file of req.files.files) {
const filePath = path.join("public/files", file.name);
await file.mv(filePath);
uploadedFiles.push({
url: `/${file.name}`,
file_id: file.name,
});
}

// Eski dosyaları güncelle
joinUs.files = uploadedFiles;
} else if (req.files && req.files.file) {
// Tek dosya yüklendiğinde
if (joinUs.files.length > 0) {
// Mevcut dosyayı sil
const filePath = path.join("public/files", joinUs.files[0].file_id);
fs.unlinkSync(filePath);
}

// Yeni dosyayı kaydet
const file = req.files.file;
const filePath = path.join("public/files", file.name);
await file.mv(filePath);

// Güncellenmiş dosyayı ekle
joinUs.files = [
{
url: `/${file.name}`,
file_id: file.name,
},
];
} else {
// Eğer dosya yüklenmediyse veya dosyalar boşsa, files'i boş bir dizi olarak ayarla
joinUs.files = [];
}

// Diğer alanları güncelle
joinUs.descriptionAz = req.body.descriptionAz;
joinUs.descriptionGe = req.body.descriptionGe;

// Kaydet
await joinUs.save();

res.redirect("/admin/joinUs");
} catch (error) {
res.status(500).json({
succeeded: false,
error,
});
}
};

export { updateJoinUs ,getUpdateJoinUs,createJoinUs,getJoinUsDetail,getJoinUsPage};
Loading