-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from birongliu/dev
Dev
- Loading branch information
Showing
16 changed files
with
539 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"use server"; | ||
|
||
export default async function getAllPostAction() { | ||
const response = await fetch(`${process.env.API_URL}/api/post`, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error("An error occurred while fetching the post"); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
interface PostData { | ||
title: string; | ||
imageUrl: string; | ||
content: string; | ||
createdBy: string; | ||
createdAt: string; | ||
} | ||
|
||
export async function createPostAction(data: PostData) { | ||
const response = await fetch(`${process.env.API_URL}/api/post`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
if (!response.ok) { | ||
throw new Error("An error occurred while creating the post"); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
export async function getPostByIdAction(id: string) { | ||
const response = await fetch(`${process.env.API_URL}/api/post/${id}`, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error("An error occurred while fetching the post"); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
export async function deletePostAction(id: string) { | ||
const response = await fetch(`${process.env.API_URL}/api/post/${id}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error("An error occurred while deleting the post"); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
|
||
export async function updateVote({ id, vote }: { id: string; vote: number }) { | ||
const response = await fetch(`${process.env.API_URL}/api/post/${id}`, { | ||
method: "PUT", | ||
body: JSON.stringify({ upvote: vote, id }), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
console.log("response", response); | ||
if (!response.ok) { | ||
throw new Error("An error occurred while updating the vote"); | ||
} | ||
console.log(response); | ||
return await response.json(); | ||
} | ||
|
||
|
||
export async function addComment(userId: string, { comment, id }: { comment: string, id: string }) { | ||
console.log(id, comment) | ||
const response = await fetch(`${process.env.API_URL}/api/post/${id}/commentPost`, { | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ comment, userId }), | ||
}); | ||
console.log("response", response); | ||
if (!response.ok) { | ||
throw new Error("An error occurred while creating the comment"); | ||
} | ||
return await response.json(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.