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

Cv #80

Merged
merged 2 commits into from
Jan 16, 2024
Merged

Cv #80

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/src/controllers/experienceControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ const getExperiences = (_, res) => {
});
};

const getExperiencesByCvId = (req, res) => {
models.experience
.findAllByCvId(req.params.id)
.then((rows) => {
res.send(rows);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};

const getExperienceById = (req, res) => {
const id = parseInt(req.params.id, 10);

Expand Down Expand Up @@ -90,4 +102,5 @@ module.exports = {
postExperience,
updateExperience,
deleteExperienceById,
getExperiencesByCvId,
};
4 changes: 2 additions & 2 deletions backend/src/models/CvManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class CvManager extends AbstractManager {
super({ table: "cv" });
}

async create(cv) {
async create(userId) {
try {
const [res] = await this.database.query(
`INSERT INTO ${this.table} (user_id) VALUES (?)`,
[cv.userId]
[userId]
);

return res;
Expand Down
13 changes: 13 additions & 0 deletions backend/src/models/ExperienceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ class ExperienceManager extends AbstractManager {
return null;
}
}

async findAllByCvId(cvId) {
try {
const [results] = await this.database.query(
`SELECT * FROM ${this.table} WHERE cv_id = ?`,
[cvId]
);
return results;
} catch (err) {
console.error(err);
return null;
}
}
}

module.exports = ExperienceManager;
7 changes: 6 additions & 1 deletion backend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ router.get(
authMiddleware,
experienceControllers.getExperiences
);
router.get(
"/experiences/by-cv-id/:id([0-9]+)",
authMiddleware,
experienceControllers.getExperiencesByCvId
);
router.get(
"/experience/:id([0-9]+)",
authMiddleware,
Expand Down Expand Up @@ -112,7 +117,7 @@ router.post(
uploadController.create
);
/* CV. */
router.post("/cvs", authMiddleware, authAdminMiddleware, cvControllers.postCv);
router.post("/cvs", authMiddleware, cvControllers.postCv);

// router.post("/signin", userControllers.postUser);
// router.update("/signin", userControllers.putUser);
Expand Down
30 changes: 21 additions & 9 deletions frontend/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import axios from "axios";
import App from "./App";
import Home from "./pages/HomeOffer/Home";
import ReadOffer from "./pages/Offer/ReadOffer";
Expand Down Expand Up @@ -85,21 +84,26 @@ const router = createBrowserRouter([
},
{
path: "/edit-profile",
element: (
<SignContextProvider>
<UserProfileModel />
</SignContextProvider>
),
children: [
{
path: "/edit-profile/cv",
element: <CreateCV />,
loader: async () => {
try {
const data = await axios.get(
"http://localhost:3310/api/users/:id/cvs"
// D'abord, on va chercher le CV de l'utilisateur, ce qui nous intéresse est l'id du CV
const cvData = await apiService.get(
"http://localhost:3310/api/users/5/cvs" // TODO: remplacer le 5 par l'id de l'utilisateur connecté
);
return data;

// Ensuite, on va chercher les expériences de l'utilisateur via l'id du CV qu'on vient de récupérer
// le but est de pouvoir faire SELECT * FROM experiences WHERE cv_id = cvData.data.id
const experienceData = await apiService.get(
`http://localhost:3310/api/experiences/by-cv-id/${cvData.data.id}`
);

return {
experiences: experienceData.data,
};
} catch (err) {
console.error(err.message);
return null;
Expand All @@ -114,6 +118,14 @@ const router = createBrowserRouter([
path: "/edit-profile/formation",
element: <AddFormation />,
},
{
path: "/edit-profile",
element: (
<SignContextProvider>
<UserProfileModel />
</SignContextProvider>
),
},
],
},
{
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/pages/CV/CreateCV.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { useLoaderData } from "react-router-dom";
import Input from "../../components/Inputs/Input";
import ButtonMaxi from "../../components/Boutons/ButtonMaxi";
import AddDetailsCV from "../../components/Add Something/AddSomething";
Expand All @@ -13,6 +14,7 @@ import SuccesMsg from "../../components/Alertes Messages/SuccesMsg";
function CreateCV() {
const { addCv, setAddCv, handleAddCv } = useUserContext();
const { errorMsg, succesMsg, msgContent, handleChange } = useGlobalContext();
const { experiences } = useLoaderData();

return (
<>
Expand Down Expand Up @@ -65,6 +67,16 @@ function CreateCV() {
addDetail="Expériences professionnelles"
url="/edit-profile/experience"
/>
{experiences &&
experiences.map((experience) => (
<div className="card-container" key={experience.id}>
<h3 className="diplome">{experience.title}</h3>
<h4 className="dates">
{experience.date_begin} - {experience.date_end ?? "en cours"}
</h4>
<p className="school">{experience.company}</p>
</div>
))}
<AddDetailsCV addDetail="Formations" url="/edit-profile/formation" />
<div>
{errorMsg && <ErrorMsg message={msgContent} />}
Expand Down
30 changes: 23 additions & 7 deletions frontend/src/pages/Experience/AddExperience.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState, useEffect } from "react";
import { v4 as uuid } from "uuid";
import axios from "axios";

import "./add-experience.css";
// import ButtonMaxi from "../../components/Boutons/ButtonMaxi";
Expand All @@ -26,6 +25,8 @@ function AddExperience() {
setMsgContent,
handleChange,
handleCheckboxChange,
apiService,
user,
} = useGlobalContext();

const [addXp, setAddXp] = useState({
Expand All @@ -38,6 +39,7 @@ function AddExperience() {
dateBegin: "",
dateEnd: null,
description: null,
cvId: null,
});

const [xpSaved, setXpSaved] = useState([]);
Expand All @@ -55,8 +57,7 @@ function AddExperience() {
setTimeout(() => {
setErrorMsg(false);
}, 4000);
}
if (addXp.isWorking === false && addXp.dateBegin === "") {
} else if (addXp.isWorking === false && addXp.dateBegin === "") {
addXp.dateBegin = "1970-01-01";

// Affichage d'un message d'erreur
Expand All @@ -65,17 +66,32 @@ function AddExperience() {
setTimeout(() => {
setErrorMsg(false);
}, 4000);
}
if (addXp.isWorking === true && addXp.dateBegin === "") {
} else if (addXp.isWorking === true && addXp.dateBegin === "") {
setErrorMsg(true);
setMsgContent("Veuillez renseigner les dates");
setTimeout(() => {
setErrorMsg(false);
}, 4000);
} else {
try {
// const data =
await axios.post(`http://localhost:3310/api/experience/`, addXp);
// ici on récupère l'id du cv, et le back fait en sorte
// que si l'utilisateur n'a pas de cv, il en crée un
const { data } = await apiService.get(
`http://localhost:3310/api/users/${user.id}/cvs`
);
const cvId = data.id;

// const personne = {
// prenom: "Marie",
// nom: "Delaire",
// };
// personne.prenom = "Mariiiiiiie";
// console.log(personne);

// peut etre que ca fait un bug, chépa tro
addXp.cvId = cvId;

await apiService.post(`http://localhost:3310/api/experience/`, addXp);

setXpSaved((prevData) => [...prevData, addXp]);
setMsgContent("L'expérience a été ajoutée avec");
Expand Down