Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final project-ParkHive #59

Open
wants to merge 130 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
972dd01
database set
trista1987 May 27, 2024
f32e442
park data update. Added introduction to each park
trista1987 May 28, 2024
d8bbb85
auth first version done
trista1987 May 28, 2024
a412a47
changed the routes
trista1987 May 28, 2024
bf96f29
Merge pull request #1 from trista1987/parkdata
trista1987 May 28, 2024
6b17440
updated backend README
trista1987 May 28, 2024
471fc18
login and signup first function done. sometimes work and sometimes do…
trista1987 May 30, 2024
d73fd28
Merge pull request #2 from trista1987/signup
trista1987 May 31, 2024
bee2b5d
basic components done and changed routes
trista1987 May 31, 2024
e9f1b47
navbar added
trista1987 May 31, 2024
a0f190f
aboutus structure done and icons added
trista1987 May 31, 2024
9dd443c
weather done, but weather for home page?
trista1987 Jun 1, 2024
e63129d
fixed weather in sweden
trista1987 Jun 1, 2024
d7603b8
changed moment to moment-timezone
trista1987 Jun 1, 2024
8bb80b4
updated README
trista1987 Jun 1, 2024
d7ca5a4
back to top btn made
trista1987 Jun 2, 2024
482843a
Merge pull request #3 from trista1987/components
trista1987 Jun 2, 2024
d46faf5
park data fetched, routes for each park not done yet
trista1987 Jun 2, 2024
e3fb432
park data fetched and routes done
trista1987 Jun 3, 2024
065ae9f
map fetched
trista1987 Jun 3, 2024
afdcdc0
most of components done
trista1987 Jun 3, 2024
e0c6020
Merge pull request #4 from trista1987/park
trista1987 Jun 3, 2024
6674071
set tailwind
trista1987 Jun 5, 2024
379f556
background images uploaded
Jun 5, 2024
b186cf0
parks images added
Jun 6, 2024
f34ee2d
weather color done
trista1987 Jun 6, 2024
20d34e0
D
trista1987 Jun 6, 2024
4e73ae1
changed scroll top btn style
trista1987 Jun 6, 2024
23edd97
Merge pull request #5 from trista1987/styFooter
trista1987 Jun 6, 2024
c40c9c4
all park fetched for home page
trista1987 Jun 6, 2024
96e68a1
park images uploaded and fetched
trista1987 Jun 7, 2024
ab6231b
mobile and tablet slides done
trista1987 Jun 7, 2024
f262b36
changed scroll to top btn, style done
trista1987 Jun 7, 2024
585c159
changed padding for scroll to top btn
trista1987 Jun 7, 2024
1e6c5ff
Merge pull request #6 from trista1987/slides
trista1987 Jun 7, 2024
bd5b96a
Pageheader & SE FI parts
Jun 8, 2024
308e510
fixed image route
Jun 8, 2024
61aad98
updated images
Jun 8, 2024
ad45f60
Trying to make navibar transparent
Jun 9, 2024
529f81a
bg not fixed
Jun 9, 2024
e0c1c9d
try to style the signup button
Jun 9, 2024
09b730c
NavBarNoHover added
Jun 10, 2024
cd6c4a8
hover transition added
Jun 10, 2024
12bdfd7
Merge pull request #8 from trista1987/navbar
Citronskal Jun 10, 2024
81f448b
buttons updated
Jun 10, 2024
a6f543f
adjust footer logo
Jun 10, 2024
ee28183
updated logo size
Jun 10, 2024
41fe07d
updated about us text
Jun 10, 2024
1e374eb
rest database
trista1987 Jun 11, 2024
06c94ef
updated park info page
trista1987 Jun 11, 2024
8b27578
About us components updated
Jun 11, 2024
185cfa9
devcard adjusted
Jun 11, 2024
6592f88
login form basic done
trista1987 Jun 11, 2024
713b1a1
login and signup form done
trista1987 Jun 12, 2024
1c16ce5
changed arrow style
trista1987 Jun 12, 2024
2578810
Merge pull request #10 from trista1987/form
trista1987 Jun 12, 2024
744c83e
page after login done
trista1987 Jun 12, 2024
68ae059
Merge pull request #11 from trista1987/logged
trista1987 Jun 12, 2024
3418ced
added loading animation
trista1987 Jun 12, 2024
4988265
updated dependencie
trista1987 Jun 12, 2024
a43fab4
clear up codes
Jun 12, 2024
1e07a57
Merge pull request #12 from trista1987/about-us
Citronskal Jun 12, 2024
9ccb429
countrycard updated
Jun 12, 2024
5bf5827
midbanner updated
Jun 12, 2024
1a20bc0
Merge pull request #13 from trista1987/park-middle
Citronskal Jun 12, 2024
337b4f1
nav fixed
Jun 12, 2024
34cf462
about us-visit finland text color
Jun 12, 2024
f01a7b1
padding changed finland card
Jun 12, 2024
eb3f36c
finland padding
Jun 12, 2024
b81efa2
deleted style
Jun 13, 2024
edcd4b2
deleted style in Sweden
Jun 13, 2024
912951f
footer logo change fixed
Jun 13, 2024
305d8c9
changed images and scroll btn
trista1987 Jun 14, 2024
7080142
changed weather
trista1987 Jun 14, 2024
f592390
loading done
trista1987 Jun 15, 2024
daba0a6
Merge pull request #14 from trista1987/loading
trista1987 Jun 15, 2024
1aa10f1
corrected login and signup
trista1987 Jun 16, 2024
5f38f54
authorization done
trista1987 Jun 16, 2024
252199e
debugged auth on logged page and changed navbar according to the auth…
trista1987 Jun 16, 2024
e763c77
Merge pull request #15 from trista1987/auth
trista1987 Jun 16, 2024
a1c5daa
fav list function done
trista1987 Jun 17, 2024
afbf085
Merge pull request #16 from trista1987/favorite
trista1987 Jun 17, 2024
840f676
deleted some extra code
trista1987 Jun 17, 2024
56bf531
cleaned up some code
trista1987 Jun 17, 2024
c0971d6
homepage save parks done
trista1987 Jun 19, 2024
4b4ad18
heart icon style done
trista1987 Jun 19, 2024
745e6e2
logged page styling done
trista1987 Jun 19, 2024
62d03d3
fixed some function error
trista1987 Jun 19, 2024
d509904
filter buttons done
trista1987 Jun 19, 2024
94a630f
adjusted tailwind for different browsers
trista1987 Jun 19, 2024
246809e
Merge pull request #17 from trista1987/stretch
trista1987 Jun 19, 2024
f65b376
change map markicon
trista1987 Jun 19, 2024
8d297cd
tried another way to fix the map marker
trista1987 Jun 19, 2024
a430e04
changed icon
trista1987 Jun 19, 2024
accf7f7
updated README, added logo to favicon
trista1987 Jun 19, 2024
6b5d991
README updated
trista1987 Jun 19, 2024
ecd10b7
Update README.md
trista1987 Jun 19, 2024
23182f8
Update README.md
trista1987 Jun 19, 2024
e8c6a2d
Update README.md
trista1987 Jun 19, 2024
760a629
Update README.md
trista1987 Jun 19, 2024
30fbb7b
Update README.md
trista1987 Jun 19, 2024
56d184b
Update README.md
trista1987 Jun 19, 2024
10f8e71
changed the route if save parks before login
trista1987 Jun 20, 2024
ef57671
parkinfo responsiveness fixed
trista1987 Jun 20, 2024
df7dae7
Merge pull request #18 from trista1987/fix
trista1987 Jun 20, 2024
3b0dd11
added hover to back to home btn
trista1987 Jun 20, 2024
ec8799b
image compressed
Jun 20, 2024
aa8e6be
adjusted font
Jun 20, 2024
240e734
deleted unused navbar
Jun 20, 2024
0aa0ca3
devcard width adjusted
Jun 20, 2024
0803a0a
about us updated
Jun 20, 2024
e945549
button aria-label added
Jun 22, 2024
2936c7d
aria-label added
Jun 22, 2024
8225601
Merge pull request #20 from trista1987/accessibility
Citronskal Jun 22, 2024
da0520e
accessible update
Jun 22, 2024
c55df63
Merge branch 'main' of https://github.com/trista1987/project-final in…
Jun 22, 2024
a5403c1
accessibility update
Jun 22, 2024
4959c56
park slider update
Jun 22, 2024
52f89ff
navbar update
Jun 22, 2024
6d656ab
sign up fixed
Jun 22, 2024
1d3d1b3
signup page update
Jun 22, 2024
f75501b
delete error signup
Jun 23, 2024
5a07422
added all carousel images hover
trista1987 Jun 23, 2024
2e77c90
accessibility fixed
Jun 25, 2024
12f109b
added env files
trista1987 Jun 25, 2024
0ce21c4
changed env
trista1987 Jun 25, 2024
69c3e98
cleaned code
trista1987 Jun 25, 2024
2b61852
cleaned console log
trista1987 Jun 25, 2024
22b2fb8
add meta description
Jun 25, 2024
52ed201
changed park name to center in carousel
trista1987 Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
# Final Project
<h1 align="center">
<a href="">
<img src="./parkHive-cover.png" alt="Project Banner Image">
</a>
</h1>

Replace this readme with your own information about your project.
# Final Project

Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.
ParkHive is a website about introducing national parks both in Finland and Sweden. For nature lovers in Sweden and Finland to gather information about national parks.

## The problem

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
- This is the first project we combine both frontend and backend. Setting database is relatively easy since our data is small. But we want to make the website as real as possible, we want user can save parks to their own account, we had to change the api for adding and removing parks. We also use localStorage to keep the data. Now once the user login.

- [Leaflet](https://leafletjs.com/) has been implemented in our work to display each parks' location. At the beginning we use the default code but the marker didn't show on the map after deployment. We checked the official website again as well as youtube to find other people's solution. In the end, we use custom icon instead of default marker.

- It was not hard if only use libraries' code, but to figure out the customize one was not easy especially in a limited time. For example, the arrows of carousel, marker icon of the map. We will work on cusomized arrows of carousel later.

## Documentation

We have documented all the resources and libraries in separate README files for both the backend and frontend. You can find the detailed documentation in the respective directories:
- [Backend README](./backend/README.md)
- [Frontend README](./frontend/README.md)

## Design inspiration

Our website design was mainly inpired by [Visit Finland](https://www.visitfinland.com/en/), combined with our own style to create ParkHive.
We also took inspiration from [Skåne](https://visitskane.com/).

[Design in Figma](https://www.figma.com/design/WACN2weddzXbjb0yrVwHyx/National-Parks?node-id=20-576&t=1mGpOpHNuaNr9GFL-1)

## View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.
- [ParkHive Frontend Link](https://parkhive.netlify.app)
- [ParkHive Backend Link](https://parkhive.onrender.com)

## Collabrators' portfolio
- [Yia Tsai](https://yia-porfolio.netlify.app/)
- [Trista Shan](https://trista-portfolio.netlify.app/)
11 changes: 7 additions & 4 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Backend part of Final Project
# Backend part of Final Project - Park Hive

This project includes the packages and babel setup for an express server, and is just meant to make things a little simpler to get up and running with.

## Getting Started
## Description

1. Install the required dependencies using `npm install`.
2. Start the development server using `npm run dev`.
National parks' JSON file was made by ChatGPT. Database has been set up on mongo compass.
For login/sign up, we will try Passport if we have time before deadline.

### Live
[ParkHive API](https://parkhive.onrender.com/)
275 changes: 275 additions & 0 deletions backend/data/park.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
"@babel/core": "^7.17.9",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.17.3",
"express-list-endpoints": "^7.1.0",
"mongodb": "^6.6.2",
"mongoose": "^8.4.0",
"nodemon": "^3.0.1"
}
}
}
234 changes: 230 additions & 4 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,257 @@
import express from "express";
import cors from "cors";
import mongoose from 'mongoose'
import mongoose, {Schema, model}from 'mongoose'
import expressListEndpoints from 'express-list-endpoints';
import dotenv from "dotenv"
import bcrypt from "bcrypt"
import parkData from "./data/park.json"

const mongoUrl = process.env.MONGO_URL || "mongodb://localhost/flowershop"

dotenv.config()

const mongoUrl = process.env.MONGO_URL || "mongodb://localhost/park-hive"
mongoose.connect(mongoUrl)
mongoose.Promise = Promise

//setup Schema
const parkSchema = new Schema({
"nation": String,
"name": String,
"address": String,
"rating": Number,
"opening_hours": String,
"parking_info": String,
"location": {
"latitude": Number,
"longitude": Number,
},
"introduction": String
});

const userSchema = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
token: {
type: String,
default: () => bcrypt.genSaltSync()
},
favourites: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Park"
}]
})
//set model
const Park = mongoose.model ("Park", parkSchema)
const User = mongoose.model ("User", userSchema)

//seed the database
if(process.env.RESET_DATABASE){
console.log("restting database")
const seedDatabase = async() => {

await Park.deleteMany()
parkData.forEach(park => {
new Park(park).save()
})
}
seedDatabase()
}
// Defines the port the app will run on. Defaults to 8080, but can be overridden
// when starting the server. Example command to overwrite PORT env variable value:
// PORT=9000 npm start
const port = process.env.PORT || 8080;
const app = express();

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
// Add middlewares to enable cors and json body parsing
app.use(cors());
app.use(express.json());

// Start defining your routes here
// http://localhost:8080/
app.get("/", (req, res) => {
res.send("Hello Technigo!");
const endpoints = expressListEndpoints(app);
res.json(endpoints)
});

app.get("/parks", async (req, res) => {
try {
// Check if query parameters are provided
const nationName = req.query.nation;
const parkName = req.query.name;

if (nationName) {
const escapedNationName = escapeRegExp(nationName);
const nationRegex = new RegExp(escapedNationName, "i");

const nationResult = await Park.find({ nation: nationRegex });

if (nationResult.length > 0) {
return res.json(nationResult);
} else {
return res.status(404).send("No park data was found for the specified nation.");
}
}

if (parkName) {
const escapedParkName = escapeRegExp(parkName);
const nameRegex = new RegExp(escapedParkName, "i");

const nameResult = await Park.find({ name: nameRegex });

if (nameResult.length > 0) {
return res.json(nameResult);
} else {
return res.status(404).send("No park data was found for the specified name.");
}
}

// If no query parameters, return all parks
const allParks = await Park.find();
if (allParks.length > 0) {
return res.json(allParks);
} else {
return res.status(404).send("No park data was found.");
}

} catch (err) {
res.status(500).send("An error occurred while fetching park data.");
}
});


app.get("/parks/:id", async (req, res) => {

try {
const id = req.params.id;
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(400).send("Invalid park ID.");
}

const parkById = await Park.findById(id);
if (parkById) {
res.json(parkById);
} else {
res.status(404).send("No park data was found.");
}
} catch (err) {
res.status(500).send("An error occurred while fetching park data.");
}
})

//auth
app.post("/register", (req,res) => {
try{
const {name, email, password} = req.body
const salt = bcrypt.genSaltSync()
const user = new User({
name,
email,
password:bcrypt.hashSync(password, salt)
})
user.save()
res
.status(201)
.json({
success: true,
message: "User created",
id: user._id,
accessToken: user.accessToken
});
} catch (err) {
res.redirect("/register")
res.status(400).json({
message: "Could not create user.",
errors: err.errors,
});
}
})

app.post("/login", async (req, res) => {
const matchUser = await User.findOne({
email: req.body.email,
});
if (matchUser && bcrypt.compareSync(req.body.password, matchUser.password)) {
res.json({
message: "User logged in.",
matchUserId: matchUser._id,
token: matchUser.token,
});
} else {
res.redirect("/register")
res.json({ message: "User not found." });
}
});

const authenticateUser = async (req, res, next) => {
const user = await User.findOne({
token: req.header("Authorization"),
});
if (user) {
req.user = user;
next();
} else {
res.status(401).json({
message: "failed.",
});
}
};

app.get("/secrets", authenticateUser);
app.get("/secrets", (req, res) => {
res.json({
secret: "This is secrets.",
});
});

app.post ("/add-favourite", authenticateUser, async (req, res) => {
try {
const user = req.user
const parkId = req.body.parkId
user.favourites.push(parkId)
await user.save()
res.status(200).json({message: "park added to favourites"})
} catch (error) {
res.status(500).json({message: "Failed to add park to favourites", error})
}
})

app.post ("/remove-favourite", authenticateUser, async (req, res) => {
try {
const user = req.user
const parkId = req.body.parkId
user.favourites.pull(parkId)
await user.save()
res.status(200).json({message: "park removed from favourites"})
} catch (error) {
res.status(500).json({message: "Failed to remove park to favourites", error})
}
})

app.get("/favourites", authenticateUser, async (req, res) => {
try {
const user = req.user
const favourites = await User.findById(user._id).populate("favourites").exec()
res.status(200).json(favourites)
} catch( error) {
es.status(500).json({ message: 'Failed to get favourites', error });
}
})

// Start the server
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
});
33 changes: 29 additions & 4 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
# Frontend part of Final Project

This boilerplate is designed to give you a head start in your React projects, with a focus on understanding the structure and components. As a student of Technigo, you'll find this guide helpful in navigating and utilizing the repository.
[ParkHive](https://parkhive.netlify.app/)

## Getting Started
## Libraries and recources

1. Install the required dependencies using `npm install`.
2. Start the development server using `npm run dev`.
During the process of our final project, it was fun to explore more libraries for implementation.

1. Weather in Helsinki and stockholm will be displayed on web pages.
- Regarding the time zone, we use [Moment Timezone](https://momentjs.com/timezone/)
- External API [Open Weather](https://openweathermap.org/current)
- Icon

2. Back-to-top button
- [react-scroll-to-top](https://www.npmjs.com/package/react-scroll-to-top)

3. Map for each parks
- Since Google map API is only for free 3 months, so we use [React Leaflet](https://react-leaflet.js.org/) instead of using Google Map.

4. Carousel
- We use [react-multi-carousel](https://www.npmjs.com/package/react-multi-carousel) for displaying parks.

5. Styling
- Tailwind CSS

6. Timezone
- This website introduces parks from two countries: Finland and Sweden. [Moment Timezone](https://momentjs.com/timezone/) has been used.

7. Animation
- [LottieFiles](https://lottiefiles.com/) when data is loading.

8. Forms
- Signup, login forms and parks' rating: [MUI](https://mui.com/)
Loading