Skip to content

Commit

Permalink
🩹 Fix: Few Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdra committed Sep 18, 2024
1 parent 0a2ede3 commit 107bfef
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 70 deletions.
25 changes: 19 additions & 6 deletions backend/controllers/userShopController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@ import Shop from '../models/shopModel.js';
import asyncHandler from '../middlewares/asyncHandler.js'
import mongoose from 'mongoose';


export const getShops = asyncHandler(async (req, res) => {
const page = parseInt(req.query.page) || 1; // Default to page 1
const limit = parseInt(req.query.limit) || 10; // Default to 10 shops per page
const skip = (page - 1) * limit; // Calculate the number of shops to skip

try {
const shops = await Shop.find() // Fetch only the shops belonging to the logged-in farmer
res.json(shops)
const shops = await Shop.find()
.skip(skip) // Skip the first `skip` number of shops
.limit(limit); // Limit to `limit` number of shops

const totalShops = await Shop.countDocuments(); // Count total number of shops

res.json({
shops,
totalPages: Math.ceil(totalShops / limit), // Total pages
currentPage: page, // Current page number
totalShops, // Total shops count
});
} catch (error) {
res.status(500)
throw new Error('Failed to fetch shops: ' + error.message)
res.status(500);
throw new Error('Failed to fetch shops: ' + error.message);
}
})
});

// Fetch shop details and its products
export const getShopById = asyncHandler(async (req, res) => {
Expand Down
13 changes: 0 additions & 13 deletions frontend/src/Components/Footer.jsx

This file was deleted.

13 changes: 0 additions & 13 deletions frontend/src/Components/Header.jsx

This file was deleted.

26 changes: 0 additions & 26 deletions frontend/src/Components/NavBar.jsx

This file was deleted.

18 changes: 8 additions & 10 deletions frontend/src/Pages/Shop/ShopList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import axios from 'axios';
import { Link } from 'react-router-dom';
import Loading from '../../Components/Loading';
import DistrictsData from '../../lib/DistrictData'

const ShopList = () => {
const [shops, setShops] = useState([]);
Expand All @@ -15,13 +16,8 @@ const ShopList = () => {
useEffect(() => {
const fetchShops = async () => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`,
},
};
const { data } = await axios.get('/api/userShops', config);
setShops(data);
const { data } = await axios.get('/api/userShops');
setShops(data.shops);
} catch (error) {
console.error('Error fetching shops:', error);
} finally {
Expand Down Expand Up @@ -92,9 +88,11 @@ const ShopList = () => {
className="border p-2 rounded w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
>
<option value="">All Districts</option>
<option value="Gampaha">Gampaha</option>
<option value="Badulla">Badulla</option>
{/* Add more district options as needed */}
{Object.keys(DistrictsData).map((district) => (
<option key={district} value={district}>
{district}
</option>
))}
</select>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/lib/constants/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ export const process = [
},
{
id: "03",
title: "Making your own box",
desc: "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a t",
},
{
id: "04",
title: "Delivering",
desc: "Your order is on the way! We ensure timely and careful delivery to make sure your products arrive in perfect condition.",
},
{
id: "04",
id: "05",
title: "In Your Hands",
desc: "Receive your order right at your doorstep. Unbox and enjoy your products, knowing they’ve been delivered with care.",
},
];


export const sampleShopData = [
{
shop_id: "shop001",
Expand Down

0 comments on commit 107bfef

Please sign in to comment.