Commit d3273873 authored by arun.uday's avatar arun.uday

commit2

parent b87af869
# for sending response to the api
response_data = []
# creating the response message
def response_data_(fan_name, movie):
responses = {"message": "New Marvel Movie Released",
"Status": "Movie Found",
......
......@@ -3,13 +3,21 @@ from scripts.core.handlers.new_marve_movie import NewMarvelMovie
from scripts.logging.loggers import logger
# Creating the objects of the class and adding the fans for getting the notifications
def add_new_marvel(movie):
try:
# creating the marvel movie
obj_movie = NewMarvelMovie()
# creating the fans
fan_boy1 = marvel_fans.Fan1()
fan_boy2 = marvel_fans.Fan2()
# attaching fans to the observer
obj_movie.attach(fan_boy1)
obj_movie.attach(fan_boy2)
# creating the movie
obj_movie.movie_create(movie)
except Exception as e:
logger.error("Exception occurred: ", e)
......
......@@ -2,19 +2,23 @@ from scripts.constants.api_response import response_data, response_data_
from scripts.logging.loggers import logger
# fan 1
class Fan1:
@staticmethod
def update(movie):
try:
# appending to the response message
response_data.append(response_data_("Fan 1", movie))
except Exception as e:
logger.error("Exception occurred: ", e)
# fan 2
class Fan2:
@staticmethod
def update(movie):
try:
# appending to the response message
response_data.append(response_data_("Fan 2", movie))
except Exception as e:
logger.error("Exception occurred: ", e)
class MovieObserveStatus:
# initializing the list for storing fans to get the movie notifications
def __init__(self):
self.fans = []
# notify the fans in subscribe for the notification
def notify(self, new_fan=None):
for fan in self.fans:
if new_fan != fan:
fan.update(self)
# append the fan to the fans list
def attach(self, fan):
if fan not in self.fans:
self.fans.append(fan)
# remove the fans from the list
def detach(self, fan):
self.fans.remove(fan)
......@@ -7,6 +7,7 @@ from scripts.logging.loggers import logger
class NewMarvelMovie(MovieObserveStatus):
def __init__(self):
try:
# initializing the movie details
MovieObserveStatus.__init__(self)
self.movie_name = str
self.movie_director = str
......@@ -17,6 +18,7 @@ class NewMarvelMovie(MovieObserveStatus):
def movie_create(self, movie):
try:
# storing the movie data
self.movie_name = movie.movie_name
self.movie_director = movie.movie_director
self.movie_stars = movie.movie_stars
......
......@@ -12,6 +12,7 @@ marvel_movies = APIRouter()
@marvel_movies.post(api_path_config.route_index)
def get_movie_details(movie: Marvel):
try:
# creating the movie
add_new_marvel(movie)
except Exception as e:
logger.error("Interruption occurred: ", e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment