More Places to Stay module for AirBnB Clone.
- https://github.com/hrr47-fec8-webber/booking-service
- https://github.com/hrr47-fec8-webber/reviews-service
- https://github.com/hrr47-fec8-webber/carousel-service
This module retrieves a list of similar places to stay based on the selected AirBnB property. It displays 12 other location names, prices, and their respective images.
An nvmrc
file is included if using nvm.
Dependencies:
- Node 6.13.0
- Express 4.17.1
- Axios 0.19.2
- React 16.13.1
- Mongoose 5.9.27
- @babel/core 7.11.1
- @babel/preset-env 7.11.0
- @babel/preset-react 7.10.4
- babel-loader 8.1.0
- html-webpack-plugin 4.3.0
- nodemon 2.0.4
- react-dom 16.13.1
- react-slick 0.27.7
- save 2.4.0
- slick-carousel 1.8.1
- supertest 4.0.2
- webpack 4.44.1
- webpack-cli 3.3.12
- webpack-dev-server 3.11.0
From within the root directory:
Install all dependencies listed above.
Seed the database using the following command:
npm run database
This will seed the database with 100 properties including property name, price per night, and an image from S3.
Next, run:
npm run server
This initiates the server, and backend connection to the database. Next, open another terminal window, and run the following command:
npm run build
npm run serve
This initiates Webpack, enabling the user to visualize the module online. Direct your browser to localhost:9000 to visualize module.
To run tests:
npm run test
POST:
/api/moreplacestostay
Create new location
Pass in an object with properties name, price, and imageUrl in the request body.
GET:
/api/moreplacestostay
Return 12 locations
No request body needed.
PUT:
/api/moreplacestostay
Update a location information
Pass in an object with property id for target data, and others for update content in the request body.
DELETE:
/api/moreplacestostay
Delete a location
Pass in an object with property id in the request body.
npm run generateMysqlData
Creating 10000000 data in a text file '10000000mysqldata.csv' in folder named 'data' Takes about 5 minutes. File size 1.07 GB.
Store data in '10000000mysqldata.csv' into database
- Create database and table:
sudo service mysql start
mysql -u root < database/schema.sql
- If facing secure-file-priv problem:
Add following lines to /etc/mysql/my.cnf:
[mysqld]
secure-file-priv = "/"
Copy csv file into mysql folder with:
cp <repo path>/10000000mysqldata.csv /var/lib/mysql/place
- (Optional) Clear table and change settings:
Clear table:
TRUNCATE TABLE place;
Change settings to speed up:
set unique_checks = 0;
set foreign_key_checks = 0;
set sql_log_bin=0;
- Import csv file with mysql shell:
LOAD DATA INFILE '10000000mysqldata.csv' INTO TABLE place FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS (name, price, imageurl);
npm run generateCassandraData
Creating 10000000 data in a text file '10000000cassandradata.csv' in folder named 'data' Takes about 5 minutes. File size 1.15 GB.
- Install cassandra
Make sure java 8 is installed first
Install Cassandra with the following line:
sudo apt-get install cassandra
- Start Cassandra
sudo service cassandra start
cassandra
cqlsh
If having error after inputting 'cassandra', use 'cassandra -R'
- Create keyspace
Keyspaces in Cassandra are similar to databases in MySQL
CREATE KEYSPACE places with replication = {'class':'SimpleStrategy','replication_factor':5};
- Use keyspace
USE places;
- Create table
Create table place
(
id int,
name text,
price int,
imageurl text,
Primary key(id)
);
- (Optional) Truncate table
truncate place;
- Import file
COPY places.place (id,name,price,imageurl) FROM 'data/10000000cassandradata.csv' WITH DELIMITER=',' AND HEADER=TRUE;