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

commit2

parent b87af869
# for sending response to the api
response_data = [] response_data = []
# creating the response message
def response_data_(fan_name, movie): def response_data_(fan_name, movie):
responses = {"message": "New Marvel Movie Released", responses = {"message": "New Marvel Movie Released",
"Status": "Movie Found", "Status": "Movie Found",
......
...@@ -3,13 +3,21 @@ from scripts.core.handlers.new_marve_movie import NewMarvelMovie ...@@ -3,13 +3,21 @@ from scripts.core.handlers.new_marve_movie import NewMarvelMovie
from scripts.logging.loggers import logger 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): def add_new_marvel(movie):
try: try:
# creating the marvel movie
obj_movie = NewMarvelMovie() obj_movie = NewMarvelMovie()
# creating the fans
fan_boy1 = marvel_fans.Fan1() fan_boy1 = marvel_fans.Fan1()
fan_boy2 = marvel_fans.Fan2() fan_boy2 = marvel_fans.Fan2()
# attaching fans to the observer
obj_movie.attach(fan_boy1) obj_movie.attach(fan_boy1)
obj_movie.attach(fan_boy2) obj_movie.attach(fan_boy2)
# creating the movie
obj_movie.movie_create(movie) obj_movie.movie_create(movie)
except Exception as e: except Exception as e:
logger.error("Exception occurred: ", e) logger.error("Exception occurred: ", e)
......
...@@ -2,19 +2,23 @@ from scripts.constants.api_response import response_data, response_data_ ...@@ -2,19 +2,23 @@ from scripts.constants.api_response import response_data, response_data_
from scripts.logging.loggers import logger from scripts.logging.loggers import logger
# fan 1
class Fan1: class Fan1:
@staticmethod @staticmethod
def update(movie): def update(movie):
try: try:
# appending to the response message
response_data.append(response_data_("Fan 1", movie)) response_data.append(response_data_("Fan 1", movie))
except Exception as e: except Exception as e:
logger.error("Exception occurred: ", e) logger.error("Exception occurred: ", e)
# fan 2
class Fan2: class Fan2:
@staticmethod @staticmethod
def update(movie): def update(movie):
try: try:
# appending to the response message
response_data.append(response_data_("Fan 2", movie)) response_data.append(response_data_("Fan 2", movie))
except Exception as e: except Exception as e:
logger.error("Exception occurred: ", e) logger.error("Exception occurred: ", e)
class MovieObserveStatus: class MovieObserveStatus:
# initializing the list for storing fans to get the movie notifications
def __init__(self): def __init__(self):
self.fans = [] self.fans = []
# notify the fans in subscribe for the notification
def notify(self, new_fan=None): def notify(self, new_fan=None):
for fan in self.fans: for fan in self.fans:
if new_fan != fan: if new_fan != fan:
fan.update(self) fan.update(self)
# append the fan to the fans list
def attach(self, fan): def attach(self, fan):
if fan not in self.fans: if fan not in self.fans:
self.fans.append(fan) self.fans.append(fan)
# remove the fans from the list
def detach(self, fan): def detach(self, fan):
self.fans.remove(fan) self.fans.remove(fan)
...@@ -7,6 +7,7 @@ from scripts.logging.loggers import logger ...@@ -7,6 +7,7 @@ from scripts.logging.loggers import logger
class NewMarvelMovie(MovieObserveStatus): class NewMarvelMovie(MovieObserveStatus):
def __init__(self): def __init__(self):
try: try:
# initializing the movie details
MovieObserveStatus.__init__(self) MovieObserveStatus.__init__(self)
self.movie_name = str self.movie_name = str
self.movie_director = str self.movie_director = str
...@@ -17,6 +18,7 @@ class NewMarvelMovie(MovieObserveStatus): ...@@ -17,6 +18,7 @@ class NewMarvelMovie(MovieObserveStatus):
def movie_create(self, movie): def movie_create(self, movie):
try: try:
# storing the movie data
self.movie_name = movie.movie_name self.movie_name = movie.movie_name
self.movie_director = movie.movie_director self.movie_director = movie.movie_director
self.movie_stars = movie.movie_stars self.movie_stars = movie.movie_stars
......
...@@ -12,6 +12,7 @@ marvel_movies = APIRouter() ...@@ -12,6 +12,7 @@ marvel_movies = APIRouter()
@marvel_movies.post(api_path_config.route_index) @marvel_movies.post(api_path_config.route_index)
def get_movie_details(movie: Marvel): def get_movie_details(movie: Marvel):
try: try:
# creating the movie
add_new_marvel(movie) add_new_marvel(movie)
except Exception as e: except Exception as e:
logger.error("Interruption occurred: ", 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