Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
M
MicroServices
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammad.salama
MicroServices
Commits
c44eabf8
Commit
c44eabf8
authored
Apr 26, 2024
by
mohammad.salama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Weather Added , DB logic is isolatedm new URLs Created
parent
d09c6d47
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
264 additions
and
34 deletions
+264
-34
pom.xml
MicroServices/DataBase/pom.xml
+20
-0
DataBaseApp.java
...ices/DataBase/src/main/java/org/database/DataBaseApp.java
+36
-0
Flight.java
...oServices/DataBase/src/main/java/org/database/Flight.java
+11
-0
FlightDB.java
...ervices/DataBase/src/main/java/org/database/FlightDB.java
+10
-2
User.java
MicroServices/DataBase/src/main/java/org/database/User.java
+11
-7
UserDB.java
...oServices/DataBase/src/main/java/org/database/UserDB.java
+9
-1
application.properties
...rvices/DataBase/src/main/resources/application.properties
+1
-0
pom.xml
MicroServices/UserService/pom.xml
+6
-0
UserService.java
...serService/src/main/java/org/userservice/UserService.java
+37
-3
UserServiceApp.java
...Service/src/main/java/org/userservice/UserServiceApp.java
+6
-15
application.properties
...ces/UserService/src/main/resources/application.properties
+1
-1
pom.xml
MicroServices/WeatherService/pom.xml
+6
-0
Weather.java
...herService/src/main/java/org/wheatherservice/Weather.java
+94
-1
WeatherService.java
...ice/src/main/java/org/wheatherservice/WeatherService.java
+15
-3
application.properties
.../WeatherService/src/main/resources/application.properties
+1
-1
No files found.
MicroServices/DataBase/pom.xml
View file @
c44eabf8
...
...
@@ -10,6 +10,26 @@
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
DataBase
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
<version>
3.2.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
<version>
6.1.1
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
<version>
6.1.1
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>
17
</maven.compiler.source>
...
...
MicroServices/DataBase/src/main/java/org/database/DataBaseApp.java
0 → 100644
View file @
c44eabf8
package
org
.
database
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
java.util.Date
;
@SpringBootApplication
public
class
DataBaseApp
{
public
static
void
main
(
String
[]
args
)
{
init
();
SpringApplication
.
run
(
DataBaseApp
.
class
,
args
);
}
public
static
void
init
()
{
Date
date
=
new
Date
();
Flight
flight1
=
new
Flight
(
"Las Vegas"
,
date
,
"LA21"
);
Flight
flight2
=
new
Flight
(
"Tartous"
,
date
,
"SY11"
);
Flight
flight3
=
new
Flight
(
"Venice"
,
date
,
"VEN584"
);
FlightDB
.
addFlight
(
flight1
);
FlightDB
.
addFlight
(
flight2
);
FlightDB
.
addFlight
(
flight3
);
User
user1
=
new
User
(
"1"
,
"Salameh"
,
flight3
);
user1
.
addFlight
(
flight2
);
User
user2
=
new
User
(
"2"
,
"Einstein"
,
flight2
);
user2
.
addFlight
(
flight1
);
User
user3
=
new
User
(
"3"
,
"Gambler "
,
flight1
);
user1
.
addFlight
(
flight3
);
UserDB
.
addUser
(
user1
);
UserDB
.
addUser
(
user2
);
UserDB
.
addUser
(
user3
);
}
}
MicroServices/DataBase/src/main/java/org/database/Flight.java
View file @
c44eabf8
...
...
@@ -18,4 +18,15 @@ public class Flight
{
return
flightID
;
}
public
String
getDestination
()
{
return
destination
;
}
@Override
public
String
toString
()
{
return
"Flight ID : "
+
flightID
+
"\nDestination is : "
+
destination
+
"\nDate: "
+
date
;
}
}
MicroServices/DataBase/src/main/java/org/database/FlightDB.java
View file @
c44eabf8
package
org
.
database
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Date
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/flights-db"
)
public
class
FlightDB
{
public
static
Map
<
String
,
Flight
>
flightsDB
;
...
...
@@ -12,9 +19,10 @@ public class FlightDB
flightsDB
.
put
(
id
,
flight
);
}
public
static
Flight
getFlight
(
String
flightID
)
@RequestMapping
(
"/{flightID}"
)
public
static
Flight
getFlight
(
@PathVariable
(
"flightID"
)
String
flightID
)
{
if
(
flightsDB
.
containsKey
(
flightID
))
return
flightsDB
.
get
(
flightID
);
return
n
ull
;
return
n
ew
Flight
(
""
,
new
Date
(),
""
)
;
}
}
MicroServices/DataBase/src/main/java/org/database/User.java
View file @
c44eabf8
...
...
@@ -16,18 +16,22 @@ public class User
flights
.
add
(
flight
.
getFlightID
());
FlightDB
.
addFlight
(
flight
);
}
public
void
addFlight
(
Flight
flight
)
{
flights
.
add
(
flight
.
getFlightID
());
FlightDB
.
addFlight
(
flight
);
}
public
String
getUserID
()
{
return
userID
;
}
public
List
<
Flight
>
getFlight
s
()
public
List
<
String
>
getFlightsID
s
()
{
List
<
Flight
>
ans
=
new
ArrayList
<>();
for
(
String
id
:
flights
)
{
ans
.
add
(
FlightDB
.
getFlight
(
id
));
}
return
ans
;
return
flights
;
}
public
String
getName
()
{
return
name
;
}
}
MicroServices/DataBase/src/main/java/org/database/UserDB.java
View file @
c44eabf8
package
org
.
database
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/users-db"
)
public
class
UserDB
{
public
static
Map
<
String
,
User
>
usersDB
;
...
...
@@ -11,7 +17,9 @@ public class UserDB
if
(
usersDB
.
containsKey
(
id
))
return
;
usersDB
.
put
(
id
,
user
);
}
public
static
User
getUser
(
String
userID
)
@RequestMapping
(
"/{userID}"
)
public
static
User
getUser
(
@PathVariable
(
"userID"
)
String
userID
)
{
if
(
usersDB
.
containsKey
(
userID
))
return
usersDB
.
get
(
userID
);
return
null
;
...
...
MicroServices/DataBase/src/main/resources/application.properties
0 → 100644
View file @
c44eabf8
server.port
=
8081
\ No newline at end of file
MicroServices/UserService/pom.xml
View file @
c44eabf8
...
...
@@ -27,6 +27,12 @@
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.example
</groupId>
<artifactId>
WeatherService
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<properties>
...
...
MicroServices/UserService/src/main/java/org/userservice/UserService.java
View file @
c44eabf8
package
org
.
userservice
;
import
org.database.Flight
;
import
org.database.User
;
import
org.database.UserDB
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
org.wheatherservice.Weather
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -12,11 +19,38 @@ import java.util.List;
@RequestMapping
(
"/flights"
)
public
class
UserService
{
@Autowired
RestTemplate
restTemplate
;
String
UserDBURL
=
"http://localhost:8081/users-db/"
;
String
FlightDBURL
=
"http://localhost:8081/flights-db/"
;
String
WeatherURL
=
"http://localhost:8083/weather/"
;
@RequestMapping
(
"/{userID}"
)
public
List
<
Flight
>
getFlights
(
@PathVariable
(
"userID"
)
String
userID
)
{
User
user
=
UserDB
.
getUser
(
userID
);
if
(
user
==
null
)
return
null
;
return
user
.
getFlights
();
User
user
=
restTemplate
.
getForObject
(
UserDBURL
+
userID
,
User
.
class
);
if
(
user
==
null
)
return
new
ArrayList
<>();
System
.
out
.
println
(
"Welcome : "
+
user
.
getName
());
List
<
Flight
>
ans
=
new
ArrayList
<>();
for
(
String
flightID
:
user
.
getFlightsIDs
())
{
Flight
flight
=
restTemplate
.
getForObject
(
FlightDBURL
+
flightID
,
Flight
.
class
);
ans
.
add
(
flight
);
}
System
.
out
.
println
(
ans
);
return
ans
;
}
@RequestMapping
(
"/weather/{flightID}"
)
public
Weather
getWeather
(
@PathVariable
(
"flightID"
)
String
flightID
)
{
Flight
flight
=
restTemplate
.
getForObject
(
FlightDBURL
+
flightID
,
Flight
.
class
);
if
(
flight
.
getDestination
().
isEmpty
()
)
return
new
Weather
();
String
city
=
flight
.
getDestination
();
Weather
weather
=
restTemplate
.
getForObject
(
WeatherURL
+
city
,
Weather
.
class
);
System
.
out
.
println
(
weather
);
return
null
;
}
}
MicroServices/UserService/src/main/java/org/userservice/UserServiceApp.java
View file @
c44eabf8
...
...
@@ -6,31 +6,22 @@ import org.database.User;
import
org.database.UserDB
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.Date
;
@SpringBootApplication
public
class
UserServiceApp
{
public
static
void
main
(
String
[]
args
)
{
init
();
SpringApplication
.
run
(
UserServiceApp
.
class
,
args
);
}
public
static
void
init
()
@Bean
public
RestTemplate
getRestTemplate
()
{
Date
date
=
new
Date
();
Flight
flight1
=
new
Flight
(
"Las Vegas"
,
date
,
"LA21"
);
Flight
flight2
=
new
Flight
(
"Tartous"
,
date
,
"SY11"
);
Flight
flight3
=
new
Flight
(
"Venice"
,
date
,
"VEN584"
);
FlightDB
.
addFlight
(
flight1
);
FlightDB
.
addFlight
(
flight2
);
FlightDB
.
addFlight
(
flight3
);
User
user1
=
new
User
(
"1"
,
"Salameh"
,
flight3
);
User
user2
=
new
User
(
"2"
,
"Einstein"
,
flight2
);
User
user3
=
new
User
(
"3"
,
"Gambler "
,
flight1
);
UserDB
.
addUser
(
user1
);
UserDB
.
addUser
(
user2
);
UserDB
.
addUser
(
user3
);
return
new
RestTemplate
();
}
}
\ No newline at end of file
MicroServices/UserService/src/main/resources/application.properties
View file @
c44eabf8
server.port
=
8081
\ No newline at end of file
server.port
=
8082
\ No newline at end of file
MicroServices/WeatherService/pom.xml
View file @
c44eabf8
...
...
@@ -21,6 +21,12 @@
<artifactId>
spring-web
</artifactId>
<version>
6.0.13
</version>
</dependency>
<dependency>
<groupId>
org.example
</groupId>
<artifactId>
DataBase
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<properties>
...
...
MicroServices/WeatherService/src/main/java/org/wheatherservice/Weather.java
View file @
c44eabf8
package
org
.
wheatherservice
;
public
class
Weather
{
public
class
Weather
{
/**
*
*
ErrorWarning.Text = forecastInformation.CityName;
WeatherDescription.Text += forecastInformation.WeatherDescription;
Temperature.Text += forecastInformation.Temperature.ToString()+ " Celecius";
Humidity.Text += forecastInformation.Humidity.ToString() + "%";
WindSpeed.Text += forecastInformation.WindSpeed.ToString() + "km per hour";
string myAPIKey = "d5e468d45e234c749b9123443230105";
string url = "http://api.weatherapi.com/v1/current.json?key=" + myAPIKey + "&q=" + cityName + "&aqi=yes";
var response = JsonConvert.DeserializeObject<dynamic>(result);
var forecastInformation = new ForecastInformation
{
CityName = response.location.name,
WeatherDescription = response.current.condition.text,
Temperature = response.current.temp_c,
Humidity = response.current.humidity,
WindSpeed = response.current.wind_kph
};
return forecastInformation;
* */
String
cityName
;
String
weatherDescription
;
double
temperature
;
double
humidity
;
double
windSpeed
;
public
Weather
()
{
cityName
=
""
;
weatherDescription
=
""
;
temperature
=
humidity
=
windSpeed
=
0.0
;
}
public
String
getCityName
()
{
return
cityName
;
}
public
void
setCityName
(
String
cityName
)
{
this
.
cityName
=
cityName
;
}
public
String
getWeatherDescription
()
{
return
weatherDescription
;
}
public
void
setWeatherDescription
(
String
weatherDescription
)
{
this
.
weatherDescription
=
weatherDescription
;
}
public
double
getTemperature
()
{
return
temperature
;
}
public
void
setTemperature
(
double
temperature
)
{
this
.
temperature
=
temperature
;
}
public
double
getHumidity
()
{
return
humidity
;
}
public
void
setHumidity
(
double
humidity
)
{
this
.
humidity
=
humidity
;
}
public
double
getWindSpeed
()
{
return
windSpeed
;
}
public
void
setWindSpeed
(
double
windSpeed
)
{
this
.
windSpeed
=
windSpeed
;
}
@Override
public
String
toString
()
{
if
(
cityName
.
isEmpty
())
{
return
"No Information to be Printed"
;
}
String
ans
=
"Forecast in "
+
cityName
+
" : \n"
;
ans
+=
"Temperature = "
+
temperature
+
" degree\n"
;
ans
+=
"Wind Speed = "
+
windSpeed
+
" km/h\n"
;
ans
+=
"Humidity : "
+
humidity
+
"\n"
;
ans
+=
"Further More : "
+
weatherDescription
;
return
ans
;
}
}
MicroServices/WeatherService/src/main/java/org/wheatherservice/WeatherService.java
View file @
c44eabf8
package
org
.
wheatherservice
;
import
org.database.Flight
;
import
org.database.FlightDB
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -14,10 +16,20 @@ public class WeatherService
@Autowired
RestTemplate
restTemplate
;
@RequestMapping
(
"/{flightID}"
)
public
Weather
getWeather
(
@PathVariable
(
"flightID"
)
String
flightID
)
String
FlightDBURL
=
"http://localhost:8081/flights-db/"
;
String
myAPIKey
=
"d5e468d45e234c749b9123443230105"
;
String
prefURL
=
"http://api.weatherapi.com/v1/current.json?key="
+
myAPIKey
+
"&q="
;
String
sufURL
=
"&aqi=yes"
;
@RequestMapping
(
"/{city}"
)
public
Weather
getWeather
(
@PathVariable
(
"city"
)
String
city
)
{
if
(
city
.
isEmpty
())
{
return
new
Weather
();
}
return
null
;
String
url
=
prefURL
+
city
+
sufURL
;
Weather
weather
=
restTemplate
.
getForObject
(
url
,
Weather
.
class
);
return
weather
;
}
}
MicroServices/WeatherService/src/main/resources/application.properties
View file @
c44eabf8
server.port
=
8082
\ No newline at end of file
server.port
=
8083
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment