Skip to content

Commit

Permalink
Merge pull request #86 from fdhhhdjd/release-#79
Browse files Browse the repository at this point in the history
#79  Frontend product comment
  • Loading branch information
fdhhhdjd committed Oct 20, 2022
2 parents 0eb7ee2 + c294e1b commit d4eb1db
Show file tree
Hide file tree
Showing 52 changed files with 2,533 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const {
getallProductUserDetail,
} = require("./getproduct.service");
const Products = require("../../../models/ProductModel");
const {
handleGetCommentProductId,
} = require("../review.service/review.service");
module.exports = {
HandleGetProduct: async () => {
const products = await getallProductUser();
Expand All @@ -26,7 +29,10 @@ module.exports = {
return {
status: 200,
success: true,
element: product_detail,
element: {
product_detail,
comment: await handleGetCommentProductId(product_id),
},
};
},
handleAddToCart: async ({ user_id, product_id, quantity }) => {
Expand Down
11 changes: 11 additions & 0 deletions backend/src/v1/user_api/services/review.service/review.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,15 @@ module.exports = {
},
};
},
handleGetCommentProductId: async (product_id) => {
return await Products.findById(product_id)
.populate({
path: "reviews",
populate: {
path: "user",
select: { name: 1, email: 1, image: 1 },
},
})
.select("reviews");
},
};
Binary file modified dump.rdb
Binary file not shown.
8 changes: 6 additions & 2 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { Route, Routes } from "react-router-dom";
import { ToastContainer } from "react-toastify";
import "./App.css";
import RoutesDataUser from "./v1/router/index";
import { Loading_Pages_Users } from "./v1/user_ui/imports/General_Global_Import";
import { NotFound, Header } from "./v1/user_ui/imports/Page_Layout_Main_Import";
import {
Loading_Pages_Users,
ScrollTop,
} from "./v1/user_ui/imports/General_Global_Import";
import { Header, NotFound } from "./v1/user_ui/imports/Page_Layout_Main_Import";
function App() {
return (
<React.Fragment>
<Suspense fallback={<Loading_Pages_Users />}>
<ToastContainer position="top-center" />
<ScrollTop />
<Header />
<Routes>
{/* User */}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/v1/configs/Apis/Carousel_Api/Api_Carousel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const API_CAROUSEL = {
//* GET ALL CAROUSEL
GET_ALL_CAROUSEL: "/api/carousel",
};
export default API_CAROUSEL;
11 changes: 11 additions & 0 deletions frontend/src/v1/configs/Apis/Comment_Api/Api_Comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const API_COMMENT = {
//* CREATE COMMENT
API_CREATE_COMMENT: "/api/review/create",

//* UPDATE COMMENT
API_UPDATE_COMMENT: "/api/review",

//* DELETE COMMENT
API_DELETE_COMMENT: "/api/review",
};
export default API_COMMENT;
8 changes: 8 additions & 0 deletions frontend/src/v1/configs/Apis/Products_Api/Api_Product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const API_PRODUCT = {
//* GET ALL PRODUCT
GET_ALL_PRODUCT: "/api/product",

//* GET DETAIL PRODUCT
GET_DETAIL_PRODUCT: "/api/product/detail",
};
export default API_PRODUCT;
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
Register_Users_Initial,
Reset_Users_Initial,
Update_Info_Users_Initial,
} from "../authentication_slice/Api_Redux_Thunk";
} from "./Api_Redux_Thunk";
const initialState = {
loading: false,
loading_profile: false,
error: null,
error_access: null,
error_profile: null,
auth: [],
auth_changePassword: null,
accessToken: null,
profile: null,
update_users: null,
Expand All @@ -34,7 +35,7 @@ const Authentication = createSlice({
state.profile = null;
},
reset_changePassword: (state) => {
state.auth = [];
state.auth_changePassword = null;
},
reset_error: (state) => {
state.error = null;
Expand Down Expand Up @@ -179,7 +180,7 @@ const Authentication = createSlice({
},
[Change_Password_Users_Initial.fulfilled]: (state, action) => {
state.loading = false;
state.auth = action.payload.element;
state.auth_changePassword = action.payload.element;
},
[Change_Password_Users_Initial.rejected]: (state, action) => {
state.loading = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import API_CAROUSEL from "../../configs/Apis/Carousel_Api/Api_Carousel";

export const Get_All_Carousel_Initial = createAsyncThunk(
"Carousel/Get/All",
async () => {
try {
const response = await axios.get(`${API_CAROUSEL.GET_ALL_CAROUSEL}`);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return error.response.data;
}
}
);
33 changes: 33 additions & 0 deletions frontend/src/v1/redux/carousel_slice.js/Carousel_Slice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createSlice } from "@reduxjs/toolkit";
import { Get_All_Carousel_Initial } from "./Api_Redux_Thunk_Carousel";
const initialState = {
loading: false,
error: null,
result_carousel: null,
};
const Carousels = createSlice({
name: "carousels",
initialState,
reducers: {
reset_carousel: (state) => {
state.result_carousel = null;
},
},
extraReducers: {
//* Get All Carousel
[Get_All_Carousel_Initial.pending]: (state, action) => {
state.loading = true;
},
[Get_All_Carousel_Initial.fulfilled]: (state, action) => {
state.loading = false;
state.result_carousel = action.payload.element.carousels;
},
[Get_All_Carousel_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
},
});
const Carousels_Slice = Carousels.reducer;
export const { reset_carousel } = Carousels.actions;
export default Carousels_Slice;
82 changes: 82 additions & 0 deletions frontend/src/v1/redux/comment_Slice/Api_Redux_Thunk_Comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import API_COMMENT from "../../configs/Apis/Comment_Api/Api_Comment";

export const Create_Comment_Initial = createAsyncThunk(
"Comment/Create",
async ({ id, rating, comment, accessToken }, { rejectWithValue }) => {
const config = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
try {
const response = await axios.post(
`${API_COMMENT.API_CREATE_COMMENT}/${id}`,
{
rating,
comment,
},
config
);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return rejectWithValue(error.response.data);
}
}
);

export const Update_Comment_Initial = createAsyncThunk(
"Comment/Update",
async (
{ productId, commentId, comment, accessToken },
{ rejectWithValue }
) => {
const config = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
try {
const response = await axios.post(
`${API_COMMENT.API_UPDATE_COMMENT}/${productId}/update/${commentId}`,
{
comment,
},
config
);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return rejectWithValue(error.response.data);
}
}
);

export const Delete_Comment_Initial = createAsyncThunk(
"Comment/Delete",
async ({ productId, commentId, accessToken }, { rejectWithValue }) => {
const config = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
try {
const response = await axios.delete(
`${API_COMMENT.API_DELETE_COMMENT}/${productId}/delete/${commentId}`,
config
);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return rejectWithValue(error.response.data);
}
}
);
66 changes: 66 additions & 0 deletions frontend/src/v1/redux/comment_Slice/Comment_Slice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { createSlice } from "@reduxjs/toolkit";
import {
Create_Comment_Initial,
Update_Comment_Initial,
Delete_Comment_Initial,
} from "./Api_Redux_Thunk_Comment";
const initialState = {
loading: false,
error: null,
reviews: null,
review_edit: null,
};
const Comment_Product = createSlice({
name: "Comment",
initialState,
reducers: {
reset_review: (state) => {
state.reviews = null;
state.review_edit = null;
},
reset_review_error: (state) => {
state.error = null;
},
},
extraReducers: {
//* Create Comment
[Create_Comment_Initial.pending]: (state, action) => {
state.loading = true;
},
[Create_Comment_Initial.fulfilled]: (state, action) => {
state.loading = false;
state.reviews = action.payload.element;
},
[Create_Comment_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
//* Update Comment
[Update_Comment_Initial.pending]: (state, action) => {
state.loading = true;
},
[Update_Comment_Initial.fulfilled]: (state, action) => {
state.loading = false;
state.review_edit = action.payload.element;
},
[Update_Comment_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
//* Delete Comment
[Delete_Comment_Initial.pending]: (state, action) => {
state.loading = true;
},
[Delete_Comment_Initial.fulfilled]: (state, action) => {
state.loading = false;
state.reviews = action.payload.element;
},
[Delete_Comment_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
},
});
const Comment_Slice = Comment_Product.reducer;
export const { reset_review, reset_review_error } = Comment_Product.actions;
export default Comment_Slice;
35 changes: 35 additions & 0 deletions frontend/src/v1/redux/product_slice/Api_Redux_Thunk_Products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import API_PRODUCT from "../../configs/Apis/Products_Api/Api_Product";

export const Get_All_Product_Initial = createAsyncThunk(
"Product/Get/All",
async () => {
try {
const response = await axios.get(`${API_PRODUCT.GET_ALL_PRODUCT}`);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return error.response.data;
}
}
);

export const Get_Detail_Product_Initial = createAsyncThunk(
"Product/Get/Detail",
async (id) => {
try {
const response = await axios.get(
`${API_PRODUCT.GET_DETAIL_PRODUCT}/${id}`
);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return error.response.data;
}
}
);
Loading

2 comments on commit d4eb1db

@vercel
Copy link

@vercel vercel bot commented on d4eb1db Oct 20, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

serversendemailshopshoes – ./server_send_email

serversendemailshopshoes-fdhhhdjd.vercel.app
full-stack-shop-shoes-bootstrap.vercel.app
serversendemailshopshoes-git-main-fdhhhdjd.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d4eb1db Oct 20, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.