Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
location_microservice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Group 5
location_microservice
Commits
92f6b5cc
Commit
92f6b5cc
authored
2 years ago
by
Dookarun, Jason J (PG/T - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
Content transferred from Mongo Compass to Atlas, with testing completed.
parent
a9596dab
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.env
+3
-1
3 additions, 1 deletion
.env
src/App.js
+38
-27
38 additions, 27 deletions
src/App.js
src/model/ParkingLocation.js
+4
-5
4 additions, 5 deletions
src/model/ParkingLocation.js
with
45 additions
and
33 deletions
.env
+
3
−
1
View file @
92f6b5cc
REACT_APP_GOOGLE_MAPS_API_KEY = "AIzaSyBjY11PT3iGwoczzs6zNw7ot0rsWCVWBDU"
REACT_APP_MONGO_URI = "mongodb://localhost:27017/ParkingLocations"
\ No newline at end of file
REACT_APP_MONGO_URI_LOCAL = "mongodb://localhost:27017/ParkingLocations"
USERNAME= "user"
PASSWORD= "WsfePqVVojP4lgZk"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/App.js
+
38
−
27
View file @
92f6b5cc
const
express
=
require
(
'
express
'
);
const
mongoose
=
require
(
'
mongoose
'
);
const
{
MONGO_URI
,
API_KEY
}
=
APIKeyAccess
();
const
{
MONGO_URI
_LOCAL
,
API_KEY
}
=
APIKeyAccess
();
require
(
'
dotenv
'
).
config
();
const
app
=
express
();
const
port
=
3000
;
...
...
@@ -9,15 +9,21 @@ const bodyParser = require('body-parser');
const
jwt
=
require
(
'
jsonwebtoken
'
);
const
geolib
=
require
(
'
geolib
'
);
const
axios
=
require
(
'
axios
'
);
const
{
MongoClient
,
ServerApiVersion
}
=
require
(
'
mongodb
'
);
const
username
=
process
.
env
.
USERNAME
;
const
password
=
process
.
env
.
PASSWORD
;
function
APIKeyAccess
()
{
const
API_KEY
=
process
.
env
.
REACT_APP_GOOGLE_MAPS_API_KEY
;
const
MONGO_URI
=
"
mongodb://localhost:27017/ParkingLocations
"
;
return
{
MONGO_URI
,
API_KEY
};
//const MONGO_URI_LOCAL = process.env.MONGO_URI_LOCAL;
// const MONGO_URI = "mongodb://localhost:27017/ParkingLocations";
return
{
API_KEY
};
}
app
.
use
(
bodyParser
.
json
());
const
MONGO_URI
=
`mongodb+srv://
${
username
}
:
${
password
}
@locationservice.dqljyov.mongodb.net/ParkingLocations?retryWrites=true&w=majority`
;
mongoose
.
connect
(
MONGO_URI
,
{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
,
...
...
@@ -86,28 +92,35 @@ function isAdmin(request, response, next) {
}
app
.
post
(
'
/parking-locations
'
,
isAdmin
,
async
(
request
,
response
)
=>
{
try
{
const
{
ID
,
Title
,
Description
,
lat
,
lon
,
city
,
postcode
,
spaces_available
,
total_spaces
,
street_address
}
=
request
.
body
;
const
parkingLocation
=
new
ParkingLocation
({
ID
,
Title
,
Description
,
lat
,
lon
,
city
,
postcode
,
total_spaces
,
spaces_available
,
street_address
});
console
.
log
(
'
🤖 Request Body:
'
,
request
.
body
);
await
parkingLocation
.
save
();
response
.
status
(
201
).
json
({
message
:
'
🤖: Parking was successfully added to database.
'
});
}
catch
(
x
)
{
console
.
error
(
x
);
response
.
status
(
500
).
json
({
error
:
'
⛔️: Failed to add parking to database, please try again later.
'
});
}
});
try
{
const
{
Title
,
Description
,
city
,
street_address
,
postcode
,
lat
,
lon
,
spaces_available
,
total_spaces
}
=
request
.
body
;
// Check if street_address already exists in the database
const
existingLocation
=
await
ParkingLocation
.
findOne
({
street_address
});
if
(
existingLocation
)
{
return
response
.
status
(
400
).
json
({
error
:
'
⛔️: A parking location with this street address already exists.
'
});
}
const
parkingLocation
=
new
ParkingLocation
({
Title
,
Description
,
city
,
street_address
,
postcode
,
lat
,
lon
,
spaces_available
,
total_spaces
,
});
console
.
log
(
'
🤖 Request Body:
'
,
request
.
body
);
await
parkingLocation
.
save
();
response
.
status
(
201
).
json
({
message
:
'
🤖: Parking was successfully added to database.
'
});
}
catch
(
x
)
{
console
.
error
(
x
);
response
.
status
(
500
).
json
({
error
:
'
⛔️: Failed to add parking to database, please try again later.
'
});
}
});
...
...
@@ -126,8 +139,6 @@ app.delete('/parking-locations/:id', isAdmin, async (request, response) => {
}
});
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`🤖: Now tuning into http://localhost:
${
port
}
`
);
});
This diff is collapsed.
Click to expand it.
src/model/ParkingLocation.js
+
4
−
5
View file @
92f6b5cc
...
...
@@ -5,9 +5,11 @@ const app = express();
const
port
=
3000
;
const
ParkingLocationsSchema
=
new
mongoose
.
Schema
({
ID
:
Number
,
Title
:
String
,
Description
:
String
,
city
:
String
,
street_address
:
String
,
postcode
:
String
,
lat
:
{
type
:
Number
,
// Define the type as Number
min
:
-
90
,
...
...
@@ -18,11 +20,8 @@ const ParkingLocationsSchema = new mongoose.Schema({
min
:
-
180
,
max
:
180
},
city
:
String
,
postcode
:
String
,
total_spaces
:
Number
,
spaces_available
:
Number
,
street_address
:
String
total_spaces
:
Number
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment