def delete_image(id): try: albums_repository.delete_image(id) return response_json({"message": "Image deleted"}, status=200) except Exception as ex: print(ex) return response_json("Bad params", 400)
def search_images(): try: images = albums_repository.search_images(request.json['caption']) return response_json({"images": images}, status=200) except Exception as ex: print(ex) return response_json("Bad params", 400)
def get_albums_for_logged_user(): try: albums = albums_repository.get_albums(g.user) return response_json(albums, 200) except Exception as ex: print(ex) return response_json("Exception occured", 500)
def algorithm_album(id): try: p = Process(target=process_captions, args=(id, )) p.start() return response_json({"message": "Processing started"}, status=200) except Exception as ex: print(ex) return response_json("Bad params", 400)
def new_image(id): try: images = albums_repository.insert_album_images(id, request.json['images']) return response_json(images, status=200) except Exception as ex: print(ex) return response_json("Bad params", 400)
def new_album(): try: name = request.json.get('name') album = albums_repository.insert_album(name) return response_json(album, 201) except Exception as ex: print(ex) return response_json("Bad params", 400)
def get_dashboard(): try: result = { "galleries": albums_repository.get_number_of_albums(), "images": albums_repository.get_number_of_images(), "runs": albums_repository.get_number_of_runs(), "notifications": albums_repository.get_notifications() } return response_json(result, 200) except Exception as ex: print(ex) return response_json("Exception occured", 500)
def login(): try: email = request.json.get('email') password = base64.b64decode(request.json.get('password')) user = User.query.filter_by(email=email).first() if not user or not user.verify_password(password): return response_json("Wrong email or password", status=400) g.user = user token = user.generate_token(60*60*24) return response_json({'token': token.decode('ascii'), 'duration': 600, 'username': user.name}) except Exception as ex: return response_json("Bad params", status=400)
def new_user(): try: name = request.json.get('name') email = request.json.get('email') password = base64.b64decode(request.json.get('password')) if name is None or email is None or password is None or (password != base64.b64decode(request.json.get('password_confirmation'))): return response_json("Bad params", 400) if User.query.filter_by(email=email).first() is not None: return response_json("User exists", 400) user = User(email=email, name=name) user.hash_password(password) db.session.add(user) db.session.commit() return response_json(user.serialize, 201) except Exception as ex: print(ex) return response_json("Exception occured", 500)
def get_images(): users = Image.query.all() return response_json([u.serialize for u in users], 200)
def get_user(id): user = User.query.get(id) if not user: return response_json({"message": "User not found"}, 404) return response_json(user.serialize, 200)
def get_users(): users = User.query.all() return response_json([u.serialize for u in users], 200)
def get_images_for_logged_album(id): images = albums_repository.get_album_images(id) return response_json(images, 200)