diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt index f1cb35d2..78b2e426 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt @@ -151,7 +151,7 @@ object ConverterDTO { ) } - fun convertBulkToUserGameRatingDTO(userGameRatings: List): List{ + fun convertBulkToUserGameRatingDTO(userGameRatings: List): List { return userGameRatings.map { userGameRating -> converToUserGameRatingDTO(userGameRating) } } diff --git a/app/frontend/src/components/CommentCard.js b/app/frontend/src/components/CommentCard.js index 6692435c..647eeb6c 100644 --- a/app/frontend/src/components/CommentCard.js +++ b/app/frontend/src/components/CommentCard.js @@ -1,44 +1,49 @@ -import React from 'react'; -import userlogo from '../user.jpg'; -import ReportIcon from "@mui/icons-material/Report"; +import React from 'react' +import userlogo from '../user.jpg' +import ReportIcon from '@mui/icons-material/Report' const CommentCard = ({ comment, onUpvote, onDownvote, currentUser }) => { -const isCurrentUserCreator = comment.creatorUser.username === currentUser.username; + const isCurrentUserCreator = comment.creatorUser.username === currentUser.username -return( - -
-
-
-

{comment.content}

- {isCurrentUserCreator ? null : ( - - )} -
-
-
-
-
- User -
-
-
{comment.creatorUserId}
-
-
- -

{comment.upvotes}

- -

{comment.downvotes}

-
-
-
-
-); -}; -export default CommentCard; \ No newline at end of file + return ( +
+
+
+

{comment.content}

+ {isCurrentUserCreator ? null : ( + + )} +
+
+
+
+
+ User +
+
+
{comment.creatorUserId}
+
+
+ +

{comment.upvotes}

+ +

{comment.downvotes}

+
+
+
+
+ ) +} +export default CommentCard diff --git a/app/frontend/src/components/PostCard.js b/app/frontend/src/components/PostCard.js index 155d557d..c216cfdb 100644 --- a/app/frontend/src/components/PostCard.js +++ b/app/frontend/src/components/PostCard.js @@ -1,72 +1,114 @@ -import React from 'react'; +import React from 'react' // import userlogo from '../user.jpg'; -import ReportIcon from "@mui/icons-material/Report"; -import EditPost from '../pages/ForumPage/EditPost'; +import ReportIcon from '@mui/icons-material/Report' +import EditPost from '../pages/ForumPage/EditPost' +import { deletePost } from '../services/postService' +import { useNavigate } from 'react-router-dom' +import { useParams } from 'react-router-dom' const PostCard = ({ post, currentUser, onUpvote, onDownvote }) => { + const isCurrentUserCreator = currentUser && post.creatorUser.username === currentUser.username ? true : false -const isCurrentUserCreator = post.creatorUser.username === currentUser.username; + const navigate = useNavigate() -return ( -
-
- {isCurrentUserCreator ? ( - - ) : ( - - )} -
-
-

- - {post.title} - -

-

{post.content}

-
- {/* {post.tags.map((tag) => ( + const params = useParams() + // console.log('===>', params) + + const handleDeletePost = async (postId) => { + try { + await deletePost(postId) + navigate('/forum') + } catch (error) { + console.error('Error deleting post:', error) + } + } + + return ( +
+
+ {isCurrentUserCreator && ( + <> + + {params.postId && ( + + )} + + )} + {!isCurrentUserCreator && ( + + )} +
+
+

+ + {post.title} + +

+

{post.content}

+
+ {/* {post.tags.map((tag) => ( #{tag} ))} */} -
-
- -
-
-

{new Date(post.creationDate).toLocaleDateString()}

- {post.tags.map((tag, index) => ( - - #{tag.name} - - ))} -
-
{post.category}
- - -

{post.upvotes}

- -

{post.downvotes}

-
-
-
-
-); -}; -export default PostCard; +
+
+ +
+
+

{new Date(post.creationDate).toLocaleDateString()}

+ {post.tags.map((tag, index) => ( + + #{tag.name} + + ))} +
+
+ {post.category} +
+ + +

{post.upvotes}

+ +

{post.downvotes}

+
+
+
+
+ ) +} +export default PostCard diff --git a/app/frontend/src/components/SubMenu.js b/app/frontend/src/components/SubMenu.js index 09a54781..f321efd4 100644 --- a/app/frontend/src/components/SubMenu.js +++ b/app/frontend/src/components/SubMenu.js @@ -1,13 +1,17 @@ -import React from 'react'; -import { Link } from 'react-router-dom'; +import React from 'react' +import { Link } from 'react-router-dom' const SubMenu = ({ item }) => { - return ( - - {item.icon} - {item.label} - - ); -}; + return ( + + {item.icon} + {item.label} + + ) +} -export default SubMenu; +export default SubMenu diff --git a/app/frontend/src/pages/PostPage/PostPage.js b/app/frontend/src/pages/PostPage/PostPage.js index 51d32a92..cbafa544 100644 --- a/app/frontend/src/pages/PostPage/PostPage.js +++ b/app/frontend/src/pages/PostPage/PostPage.js @@ -16,20 +16,8 @@ const PostPage = () => { const [post, setPost] = useState(null); const [comments, setComments] = useState([]); - const [currentUser, setCurrentUser] = useState(null); - // const comments = [ - // { - // commentId: 1, - // creatorUserId: "alice123", - // content: "Chess is all about practice and strategy. Start by learning the basics.", - // creationDate: '2023-01-01T12:00:00.000Z', - // upvotes: 5, - // downvotes: 1, - // }, - // ]; - const handleUpvote = async () => { try { const response = await upvotePost(postId); diff --git a/app/frontend/src/services/commentService.js b/app/frontend/src/services/commentService.js index 40e4104f..f987d5e0 100644 --- a/app/frontend/src/services/commentService.js +++ b/app/frontend/src/services/commentService.js @@ -1,52 +1,59 @@ -import axios from 'axios'; - +import axios from 'axios' const axiosInstance = axios.create({ - baseURL: process.env.REACT_APP_API_URL -}); + baseURL: process.env.REACT_APP_API_URL +}) -axiosInstance.defaults.withCredentials = true; +axiosInstance.defaults.withCredentials = true export const getAllCommentsForPost = (postId) => { - return axiosInstance.get(`/comments/post/${postId}`); -}; + return axiosInstance.get(`/comments/post/${postId}`) +} export const createComment = (postId, commentData, sessionId) => { - return axiosInstance.post(`/comments/post/${postId}`, commentData, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.post(`/comments/post/${postId}`, commentData, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const getCommentById = (commentId) => { - return axiosInstance.get(`/comments/${commentId}`); -}; + return axiosInstance.get(`/comments/${commentId}`) +} export const updateComment = (commentId, commentData, sessionId) => { - return axiosInstance.put(`/comments/${commentId}`, commentData, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.put(`/comments/${commentId}`, commentData, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const deleteComment = (commentId, sessionId) => { - return axiosInstance.delete(`/comments/${commentId}`, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.delete(`/comments/${commentId}`, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const upvoteComment = (commentId, sessionId) => { - return axiosInstance.put(`/comments/${commentId}/upvote`, {}, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.put( + `/comments/${commentId}/upvote`, + {}, + { + headers: { Cookie: `SESSIONID=${sessionId}` } + } + ) +} export const downvoteComment = (commentId, sessionId) => { - return axiosInstance.put(`/comments/${commentId}/downvote`, {}, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.put( + `/comments/${commentId}/downvote`, + {}, + { + headers: { Cookie: `SESSIONID=${sessionId}` } + } + ) +} export const reportComment = (commentId, reportData, sessionId) => { - return axiosInstance.post(`/comments/${commentId}/report`, reportData, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.post(`/comments/${commentId}/report`, reportData, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} diff --git a/app/frontend/src/services/gameService.js b/app/frontend/src/services/gameService.js index f4014246..3b339f91 100644 --- a/app/frontend/src/services/gameService.js +++ b/app/frontend/src/services/gameService.js @@ -4,8 +4,7 @@ const axiosInstance = axios.create({ baseURL: process.env.REACT_APP_API_URL }) -axiosInstance.defaults.withCredentials = true; - +axiosInstance.defaults.withCredentials = true export const createGame = (gameData, imageData) => { const formData = new FormData() diff --git a/app/frontend/src/services/gameServise.js b/app/frontend/src/services/gameServise.js index bc0dcf52..29a5f37e 100644 --- a/app/frontend/src/services/gameServise.js +++ b/app/frontend/src/services/gameServise.js @@ -1,7 +1,7 @@ import axios from 'axios' const axiosInstance = axios.create({ - baseURL: process.env.REACT_APP_API_URL + baseURL: process.env.REACT_APP_API_URL }) axiosInstance.defaults.withCredentials = true diff --git a/app/frontend/src/services/postService.js b/app/frontend/src/services/postService.js index 96715cd1..765b9533 100644 --- a/app/frontend/src/services/postService.js +++ b/app/frontend/src/services/postService.js @@ -1,56 +1,64 @@ -import axios from 'axios'; +import axios from 'axios' const axiosInstance = axios.create({ - baseURL: process.env.REACT_APP_API_URL -}); + baseURL: process.env.REACT_APP_API_URL +}) -axiosInstance.defaults.withCredentials = true; +axiosInstance.defaults.withCredentials = true export const getAllPosts = () => { - return axiosInstance.get('/forum/posts'); -}; + return axiosInstance.get('/forum/posts') +} export const createPost = (postData) => { - console.log(postData); - return axiosInstance.post('/forum/posts', postData, { - withCredentials: true - }); -}; + console.log(postData) + return axiosInstance.post('/forum/posts', postData, { + withCredentials: true + }) +} export const getPostById = (postId) => { - return axiosInstance.get(`/forum/posts/${postId}`); -}; + return axiosInstance.get(`/forum/posts/${postId}`) +} export const updatePost = (postId, postData, sessionId) => { - return axiosInstance.put(`/forum/posts/${postId}`, postData, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.put(`/forum/posts/${postId}`, postData, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const deletePost = (postId, sessionId) => { - return axiosInstance.delete(`/forum/posts/${postId}`, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.delete(`/forum/posts/${postId}`, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const upvotePost = (postId, sessionId) => { - return axiosInstance.put(`/forum/posts/${postId}/upvote`, {}, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.put( + `/forum/posts/${postId}/upvote`, + {}, + { + headers: { Cookie: `SESSIONID=${sessionId}` } + } + ) +} export const downvotePost = (postId, sessionId) => { - return axiosInstance.put(`/forum/posts/${postId}/downvote`, {}, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.put( + `/forum/posts/${postId}/downvote`, + {}, + { + headers: { Cookie: `SESSIONID=${sessionId}` } + } + ) +} export const reportPost = (postId, reportData, sessionId) => { - return axiosInstance.post(`/forum/posts/${postId}/report`, reportData, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.post(`/forum/posts/${postId}/report`, reportData, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const getAllTags = () => { - return axiosInstance.get('/tags'); -}; \ No newline at end of file + return axiosInstance.get('/tags') +} diff --git a/app/frontend/src/services/userService.js b/app/frontend/src/services/userService.js index 2067c83d..c01b0bc5 100644 --- a/app/frontend/src/services/userService.js +++ b/app/frontend/src/services/userService.js @@ -1,47 +1,47 @@ -import axios from 'axios'; +import axios from 'axios' const axiosInstance = axios.create({ - baseURL: process.env.REACT_APP_API_URL -}); + baseURL: process.env.REACT_APP_API_URL +}) -axiosInstance.defaults.withCredentials = true; +axiosInstance.defaults.withCredentials = true export const getUserInfoBySessionId = (sessionId) => { - return axiosInstance.get('/user', { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.get('/user', { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const updateUserByUserId = (sessionId, userData) => { - return axiosInstance.post('/user', userData, { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.post('/user', userData, { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const getUserInfoByUsername = (username) => { - return axiosInstance.get(`/user/${username}`); -}; + return axiosInstance.get(`/user/${username}`) +} export const getLikedPosts = (sessionId) => { - return axiosInstance.get('/user/liked-posts', { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.get('/user/liked-posts', { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const getLikedComments = (sessionId) => { - return axiosInstance.get('/user/liked-comments', { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.get('/user/liked-comments', { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const getCreatedPosts = (sessionId) => { - return axiosInstance.get('/user/created-posts', { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.get('/user/created-posts', { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +} export const getCreatedGames = (sessionId) => { - return axiosInstance.get('/user/created-games', { - headers: { Cookie: `SESSIONID=${sessionId}` } - }); -}; + return axiosInstance.get('/user/created-games', { + headers: { Cookie: `SESSIONID=${sessionId}` } + }) +}