Skip to content

Commit

Permalink
Merge pull request #136 from GeeksHacking/trying-to-get-apiv2-to-work…
Browse files Browse the repository at this point in the history
…-at-2-am-

Trying to get apiv2 to work at 2 am
  • Loading branch information
jer123se12 authored Dec 22, 2023
2 parents 037a743 + 7c17d4f commit d43da1a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 72 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions src/components/PMApi/PMApi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
class PMApi {
constructor(authToken) {
this.baseUrl = process.env.API_URL;
this.baseUrl = `${process.env.API_URL}`;
this.basePagelength=100;
axios.defaults.headers.common["Authorization"] = `Bearer ${authToken}`;
}
Expand Down Expand Up @@ -49,15 +49,27 @@ class PMApi {
projImg
) {
try {
const { data } = await axios.post(`${this.baseUrl}/posts`, {
projectName: projName,
description: projDesc,
creatorUserID: projMakerId,
contact: projContact,
tags: projTags,
technologies: projTech,
images: projImg,
});
console.log(projImg)
let formData=new FormData();
for (let i=0;i<projImg.length;i++){
formData.append("images", projImg[i])
}
formData.append("projectName",projName)
formData.append("description",projDesc)
formData.append("creatorUserID",projMakerId)
formData.append("contact",projContact)
formData.append("tags",projTags)
formData.append("technologies",projTech)
console.log(formData)
const apiOptions={
method:"POST",
url:`${this.baseUrl}/posts`,
headers:{
"Content-Type": "multipart/form-data",
},
data:formData
}
const { data } = await axios.request(apiOptions)
return data;
} catch (err) {
throw new Error(`failed to create posts with err:\n${err}`);
Expand Down
Binary file added src/components/Rating/.StarsContainer.js.swp
Binary file not shown.
69 changes: 21 additions & 48 deletions src/pages/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,7 @@ export default function CreateProject() {
tag.toLowerCase().includes(tagQuery.toLowerCase())
);

// Send POST Request to store images
const createImageURL = async (project) => {
var formData = new FormData();

for (let i = 0; i < project.images.length; i++) {
formData.append("files", project.images[i]);
}
formData.append("projectName", project.projectName);
formData.append("creatorUserID", project.creatorUserID);

const apiOptions = {
method: "POST",
url: `${process.env.API_URL}/images`,
headers: {
Authorization: `Bearer ${localStorage.getItem("authorisation_token")}`,
"Content-Type": "multipart/form-data",
},
data: formData,
};
axios.request(apiOptions).then(function (res) {
if (res.status == 200) {
const imageURLs = res.data.imageURL;

api
.createPost(
project.projectName,
project.description,
project.creatorUserID,
project.contact,
project.tags,
project.technologies,
imageURLs
)
.then((res) => {
if (res != -1 && res.insertedProjectWithID !== "") {
router.push(`Project?id=${res.insertedProjectWithID}`);
}
});
}
});
};


// Process and Send Data
const handleSubmission = async (event) => {
Expand All @@ -128,8 +88,21 @@ export default function CreateProject() {
images: projectImages,
contact: event.target.projectContact.value,
};
api.createPost(
project.projectName,
project.description,
project.creatorUserID,
project.contact,
project.tags,
project.technologies,
project.images
)
.then((res) => {
if (res != -1 && res.insertedProjectWithID !== "") {
router.push(`Project?id=${res.insertedProjectWithID}`);
}
});

await createImageURL(project);
}
};

Expand Down Expand Up @@ -197,10 +170,10 @@ export default function CreateProject() {
</div>

<h2 className="mt-10 text-3xl font-medium">
Tags <RequiredIcon />
Technologies <RequiredIcon />
</h2>
<p className="mt-1 text-lg">
Add tags to help users find your project!
Let users know what Programming Language/Framework you use!
</p>
<Combobox
value={selectedTags}
Expand Down Expand Up @@ -232,7 +205,7 @@ export default function CreateProject() {
<div className="group h-11 w-full rounded-lg bg-[#D3D3D3] p-0.5 duration-300 focus-within:bg-logo-blue">
<Combobox.Input
className="h-full w-full rounded-md px-2 outline-none"
placeholder="Enter your project's tags!"
placeholder="Enter your project’s technologies! e.g. SwiftUI, React, JavaScript"
onChange={(e) => setTagQuery(e.target.value)}
/>
</div>
Expand Down Expand Up @@ -274,18 +247,18 @@ export default function CreateProject() {
</p>

<h2 className="relative mt-10 text-3xl font-medium">
Technologies
Tags
<RequiredIcon />
</h2>
<p className="mt-1 text-lg">
Let users know what Programming Language/Framework you use!
Add tags to help users find your project!
</p>
<div className="group h-11 w-[70%] rounded-lg bg-[#D3D3D3] p-0.5 duration-300 focus-within:bg-logo-blue">
<input
type="text"
name="projectTech"
id="projectTech"
placeholder="Enter your project’s technologies! e.g. SwiftUI, React, JavaScript"
placeholder="Enter your project's tags!"
className="h-full w-full rounded-md px-2 outline-none"
required={true}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const getServerSideProps = withPageAuthRequired({
let posts = []
let memusers = []


try {
// Get All Posts
await api.getPosts().then(function (rawPosts) {
Expand Down Expand Up @@ -183,4 +184,4 @@ export const getServerSideProps = withPageAuthRequired({
}
}
},
});
});
2 changes: 1 addition & 1 deletion src/pages/Load.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ export default function Load() {
)
}

export const getServerSideProps = withPageAuthRequired();
export const getServerSideProps = withPageAuthRequired();

0 comments on commit d43da1a

Please sign in to comment.