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

[구은모] sprint4 #39

Open
wants to merge 2 commits into
base: basic-구은모
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/pull-request-template.md

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/auto-label-assign.yml

This file was deleted.

125 changes: 125 additions & 0 deletions ArticleService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
*
*getArticleList : page, pageSize, keyword부분
*/

export async function getProductList(page, pageSize, keyword) {
const res = await fetch(
`https://sprint-mission-api.vercel.app/products?page=${page}&pageSize=${pageSize}&keyword=${keyword}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://sprint-mission-api.vercel.app 이부분까지는 따로 변수로 빼서 사용하는게 가독성도 좋고, 만약 host가 변경되었을때 일일이 수정안해줘도 되어서 좋습니다 ㅎㅎ

)
.then((response) => response.json())
.catch((error) => {
console.log("Error!", error);
throw new Error("데이터를 불러오는데 실패했습니다.");
});

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}

const data = await res.json();
return data;
}

/**
*
*getArticle : 그냥 GET메서드
*/

export async function getArticle(id) {
return fetch(`https://sprint-mission-api.vercel.app/articles/${id}`)
.then((res) => {
if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}
return res.json();
})
.catch((error) => {
console.log("Error!", error);
throw new Error("데이터를 불러오는데 실패했습니다.");
});
}

/**
*
*createArticle : title, content, image
*/

export async function createArticle(title, content, image) {
const res = await fetch("https://sprint-mission-api.vercel.app/articles", {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기는 위에 처럼 return fetch 만 해줘도 될것 같습니다

method: "POST",
body: JSON.stringify({ title, content, image }),
headers: {
"content-type": "application/json",
},
})
.then((res) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에서도 res 값을 써서 헷갈릴수 있으므로 변수를 다르게 가져가는게 좋을듯 합니다!

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}
return res.json();
})
.then((data) => {
return data;
})
.catch((error) => {
console.log("Error!", error);
throw new Error("데이터를 불러오는데 실패했습니다.");
});
}

/**
*
*patchArticle : 그냥 PATCH메서드
*/

export async function patchArticle() {
const res = await fetch("https://sprint-mission-api.vercel.app/articles", {
method: "PATCH",
body: JSON.stringify({ title, content, image }),
headers: {
"content-type": "applocation/json",
},
})
.then((res) => {
if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}
return res.json();
})
.then((data) => {
return data;
})
.catch((error) => {
console.log("Error!", error);
throw new Error("데이터를 불러오는데 실패했습니다.");
});
}

/**
*
*deleteArticle : 그냥 DELETE메서드
*/

export async function deleteArticle() {
const res = await fetch("https://sprint-mission-api.vercel.app/articles", {
method: "DELET",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 method에서 오타입니다.

body: JSON.stringify({ title, content, image }),
headers: {
"content-type": "applocation/json",
},
})
.then((res) => {
if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}
return res.json();
})
.then((data) => {
return data;
})
.catch((error) => {
console.log("Error!", error);
throw new Error("데이터를 불러오는데 실패했습니다.");
});
}
112 changes: 112 additions & 0 deletions ProductService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
*
*getProductList : page, pageSize, keyword부분
*/

export async function getProductList(page, pageSize, keyword) {
try {
const res = await fetch(
`https://sprint-mission-api.vercel.app/products?page=${page}&pageSize=${pageSize}&keyword=${keyword}`
);

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}

const data = await res.json();
return data;
} catch (error) {
console.log("Error!", error);
}
}

/**
*
*getProduct : GET메서드
*/

export async function getProduct(id) {
try {
const res = await fetch(
`https://sprint-mission-api.vercel.app/products/${id}`
);

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}

const data = await res.json();
return data;
} catch (error) {
console.log("Error!!", error);
}
}

/**
*
*createProduct POST메서드 : name, description, price, tags, images부분
*/

export async function createProduct(name, description, price, tags, images) {
try {
const res = await fetch("https://sprint-mission-api.vercel.app/products", {
method: "POST",
body: JSON.stringify({ name, description, price, tags, images }),
headers: {
"content-type": "applocation/json",
},
});

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}

const data = await res.json();
return data;
} catch (error) {
console.log("Error!!!", error);
}
}

// PATCH메서드
export async function patchProduct() {
try {
const res = await fetch("https://sprint-mission-api.vercel.app/products", {
method: "PATCH",
body: JSON.stringify(data),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathProduct 함수 파라미터에 data가 빠져있어서 여기서 참조를 할수 없습니다ㅠ

headers: {
"content-type": "application/json",
},
});

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}

const data = await res.json();
return data;
} catch (error) {
console.log("Error!!!", error);
}
}
// DELETE메서드
export async function deleteProduct() {
try {
const res = await fetch("https://sprint-mission-api.vercel.app/products", {
method: "DELETE",
body: JSON.stringify(),
headers: {
"content-type": "application/json",
},
});

if (!res.ok) {
throw new Error("데이터를 불러오는데 실패했습니다.");
}

const data = await res.json();
return data;
} catch (error) {
console.log("Error!!!", error);
}
}
50 changes: 0 additions & 50 deletions README.md

This file was deleted.

10 changes: 0 additions & 10 deletions faq/faq.html

This file was deleted.

Binary file removed img/Component 2.png
Binary file not shown.
Binary file removed img/Component [email protected]
Binary file not shown.
Binary file removed img/Component [email protected]
Binary file not shown.
Binary file removed img/Component 3.png
Binary file not shown.
Binary file removed img/Component [email protected]
Binary file not shown.
Binary file removed img/Component [email protected]
Binary file not shown.
Binary file removed img/Group 33682.png
Binary file not shown.
Binary file removed img/Group.png
Binary file not shown.
Binary file removed img/Img_home_01.png
Binary file not shown.
Binary file removed img/Img_home_02.png
Binary file not shown.
Binary file removed img/Img_home_bottom.png
Binary file not shown.
Binary file removed img/[email protected]
Binary file not shown.
Binary file removed img/[email protected]
Binary file not shown.
Binary file removed img/Img_home_top.png
Binary file not shown.
Binary file removed img/[email protected]
Binary file not shown.
Binary file removed img/[email protected]
Binary file not shown.
Binary file removed img/Property 1=lg.png
Binary file not shown.
Binary file removed img/Property [email protected]
Binary file not shown.
Binary file removed img/Property [email protected]
Binary file not shown.
Binary file removed img/Vector.png
Binary file not shown.
Binary file removed img/btn_visibility_off_24px.png
Binary file not shown.
3 changes: 0 additions & 3 deletions img/btn_visibility_off_24px.png:Zone.Identifier

This file was deleted.

Binary file removed img/ic_facebook.png
Binary file not shown.
Binary file removed img/ic_twitter.png
Binary file not shown.
Binary file removed img/state=active.png
Binary file not shown.
3 changes: 0 additions & 3 deletions img/state=active.png:Zone.Identifier

This file was deleted.

Binary file removed img/type=solid, status=default.png
Binary file not shown.
3 changes: 0 additions & 3 deletions img/type=solid, status=default.png:Zone.Identifier

This file was deleted.

Loading