Skip to content

Commit da7fdaf

Browse files
committed
fix(host): test
1 parent c247c7c commit da7fdaf

File tree

7 files changed

+72
-40
lines changed

7 files changed

+72
-40
lines changed

spez-backend/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ venv/
22
alembic/
33
.env
44
alembic.ini
5-
__pycache__/
5+
__pycache__/
6+
/myenv

spez-backend/app/main.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
description="SPez app",
1414
version="0.2.0",
1515
)
16-
origins = [
17-
"http://localhost",
18-
"http://localhost:3000",
19-
"http://localhost:8000"
20-
# Add your frontend domain here
21-
]
22-
16+
# origins = [
17+
# "https://spez.hungnq.online/*",
18+
# "http://localhost",
19+
# "http://localhost:3000",
20+
# "http://localhost:8000"
21+
# # Add your frontend domain here
22+
# ]
2323
app.add_middleware(
2424
CORSMiddleware,
25-
allow_origins=origins,
25+
allow_origins=["*"], # Allows all origins
2626
allow_credentials=True,
27-
allow_methods=["*"],
28-
allow_headers=["*"],
27+
allow_methods=["*"], # Allows all methods
28+
allow_headers=["*"], # Allows all headers
2929
)
30+
3031
# Include the items router
3132
app.include_router(route.router)

spez-frontend/src/app/post/[id]/page.tsx

+55-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
11
"use client"
2-
import svPost from "@/utils/svPost";
2+
import svPost from "../../../utils/svPost"
33
import Link from "next/link";
44
import Comment from "@/components/Comment";
55
import Parser from 'html-react-parser'
6+
import Image from "next/image";
7+
import EagleEmoji from '../../../../public/eagle_emoji.png'
68
import CmtForm from "@/components/CmtForm";
79
import { getRelativeTime } from "@/utils/getRelativeTime";
10+
import axios from "axios";
811
import { GoTrash } from "react-icons/go";
9-
import { IPost, IComment } from "@/types";
10-
import LikeButton from "@/components/LikeButton";
12+
import { useEffect } from "react";
1113
type Props = {
1214
params: { id: string };
1315
};
14-
// interface getILike{
15-
// like: number
16-
// }
1716
export default async function Post({ params }: Props) {
1817
const id: string = params.id;
19-
const { getPost, getLike, getComment, delPost } = svPost();
18+
const { getPost, getLike, getComment, delPost } = await svPost();
19+
useEffect(aysnc () => {
20+
const info: any = await getPost(id);
21+
const likes: any = await getLike(id);
22+
const comment: any = await getComment(id);
23+
const author_url = "/user/" + info.author.id;
2024

21-
const info: IPost = await getPost(id);
22-
const likes: number = await getLike(id);
23-
console.log(likes)
24-
const comment: IComment[] = await getComment(id);
25-
const author_url = "/user/" + info.author.id;
26-
const handleDelPost = async () => {
27-
let token: string | null = null
25+
},[])
26+
const handleLikeButton = async (e: React.FormEvent) => {
27+
e.preventDefault();
28+
try {
29+
// Send a POST request to your FastAPI backend
30+
let token: any
31+
if (typeof window !== 'undefined')
32+
token = localStorage.getItem('jwt')
33+
await axios.post(`http://spezbe.hungnq.online/likes/?post_id=${id}`,
34+
{
35+
headers: {
36+
'accept': 'application/json',
37+
'Authorization': `Bearer ${token}`
38+
}
39+
}
40+
);
41+
42+
// Redirect or give feedback upon success
43+
// alert('Post created successfully!');
44+
} catch (error) {
45+
console.error('Error posting data:', error);
46+
alert('Failed to create like.');
47+
}
48+
};
49+
const handleDelPost = async (e: React.FormEvent) => {
50+
let token: any
2851
if (typeof window !== 'undefined')
2952
token = localStorage.getItem('jwt')
30-
await delPost(id, token);
53+
const deletePost:any = await delPost(id, token);
54+
console.log(deletePost)
3155

3256
}
3357
return (
@@ -45,22 +69,28 @@ export default async function Post({ params }: Props) {
4569
<div className="pl-2 text-2xl font-bold">{info.title}</div>
4670
<div className="p-2">{Parser(info.content)}</div>
4771
<div className="flex flex-row">
48-
<LikeButton initialLikes={likes} post_id={id} />
72+
<button onClick={handleLikeButton} className="w-auto flex flex-row border-2 border-black rounded-full px-2">
73+
<p className="pt-[0.35rem]"> Ưng</p>
74+
<Image
75+
src={EagleEmoji}
76+
alt = "eagle_img"
77+
width={30}
78+
height={50} />
79+
<p className="pt-[0.35rem]">: {likes} </p>
80+
</button>
4981
<div className="w-auto mt-[0.35rem] ml-5 border-2 rounded-full px-2 border-black">Phản hồi: {comment.length}</div>
50-
</div>
82+
</div>
5183
<CmtForm postId={id} />
5284
</div>
5385
<div className="border-2 border-slate-950 p-2 text-black rounded shadow h-full w-1/2 space-y-5">
5486
<a className="font-bold text-2xl">Bình Loạn</a>
55-
{comment.map((element: IComment) => (
87+
{comment.map((e: any) => (
5688
<Comment
57-
key={element.id}
58-
id = {element.id}
59-
author = {element.author}
60-
content= {element.content}
61-
created_at = {element.created_at}
62-
updated_at= {element.updated_at}
63-
post_id= {element.post_id}
89+
// author_id = {comment.author}
90+
id = {e.id}
91+
author = {e.author}
92+
content= {e.content}
93+
date = {e.created_at}
6494
/>
6595
))}
6696
</div>

spez-frontend/src/components/CmtForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function CmtForm({ postId }: Props) {
2828
if (token === undefined) router.push("/");
2929
// console.log(token)
3030
await axios.post(
31-
`http://localhost:8000/posts/cmt/${postId}`,
31+
`https://spezbe.hungnq.online/posts/cmt/${postId}`,
3232
{
3333
content: content,
3434
},

spez-frontend/src/components/LoginForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function LoginForm() {
2424
// console.log(body)
2525
// API call to authenticate using x-www-form-urlencoded
2626
try {
27-
const res = await fetch('http://localhost:8000/token', {
27+
const res = await fetch('https://spezbe.hungnq.online/token', {
2828
method: 'POST',
2929
headers: {
3030
'Content-Type': 'application/x-www-form-urlencoded',

spez-frontend/src/components/PostForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function PostForm () {
2727
token = localStorage.getItem('jwt')
2828
if(token === undefined)
2929
router.push('/')
30-
await axios.post('http://localhost:8000/posts/',
30+
await axios.post('https://spezbe.hungnq.online/posts/',
3131
{
3232

3333
title: title,

spez-frontend/src/utils/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const BE_URI = 'http://localhost:8000'
1+
export const BE_URI = 'https://spezbe.hungnq.online'

0 commit comments

Comments
 (0)