def get(self, user_id, channel): """ Method get in order to add channel to one user :param user_id: id user :type param: string :param channel: channel name :type channel: string :rtype: Json """ data = Database() res = {} try: data.start_transaction() channel_id = data.channel_is_in_database(channel) if channel_id and data.user_has_channel(user_id, channel_id) is None: return {"code": "FORBIDDEN", "result": None} data.add_channel(channel, user_id, channel_id) data.commit() except DatabaseError as error: print_exception_function(error, "Can not add channel to user") data.rollback() res = data.get_channel_from_user(user_id) return {"code": "ALL_OK", "result": res}
def get(self, user, channel): """ Method get to add user and channel to database :param user: username :type user: string :param channel: channel name :type channel: string :rtype: Json """ data = Database() res = {} try: data.start_transaction() channel_id = data.channel_is_in_database(channel) user_id = data.user_is_in_database(user) if user_id and channel_id: return {"code": "UNAUTHORIZED", "result": None} user_id = data.add_user(user, channel, channel_id) data.add_channel(channel, user_id) data.commit() except DatabaseError as error: print_exception_function(error, "Can not add user and channel") data.rollback() res = data.get_user_from_channel(channel_id) return {"code": "ALL_OK", "result": res}