Exemplo n.º 1
0
    def create(request):
        description = request.json[
            'description'] if 'description' in request.json else ''
        total = request.json['total'] if 'total' in request.json else None
        address = request.json['address'] if 'address' in request.json else ''
        invoiceable_type = request.json[
            'invoiceable_type'] if 'invoiceable_type' in request.json else None
        invoiceable_id = request.json[
            'invoiceable_id'] if 'invoiceable_id' in request.json else None

        payload = {
            'description': description,
            'total': total,
            'address': address,
            'invoiceable_type': invoiceable_type,
            'invoiceable_id': invoiceable_id
        }
        if None in payload:
            return BaseController.send_error_api(None, 'payload invalid')

        result = invoiceservice.create(payload)
        if result['error']:
            return BaseController.send_error_api(None, result['message'])
        return BaseController.send_response_api(result['data'],
                                                result['message'])
Exemplo n.º 2
0
    def update(request, user_id=None, booth_id=None):
        if user_id is not None:
            booth_id = db.session.query(Booth).filter_by(
                user_id=user_id).first().as_dict()['id']

        name = request.json['name'] if 'name' in request.json else ''
        stage_id = request.json[
            'stage_id'] if 'stage_id' in request.json else None
        stage_id = None if stage_id < 0 else stage_id
        points = request.json['points'] if 'points' in request.json else None
        summary = request.json['summary'] if 'summary' in request.json else None

        if points and summary:
            payloads = {
                'name': name,
                'stage_id': stage_id,
                'points': points,
                'summary': summary
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        result = boothservice.update(payloads, booth_id)

        if not result['error']:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
        else:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
Exemplo n.º 3
0
    def update(id, request):
        name = request.form['name'] if 'name' in request.form else None
        email = request.form['email'] if 'email' in request.form else None
        website = request.form['website'] if 'website' in request.form else None
        type = request.form['type'] if 'type' in request.form else None
        photo = request.files[
            'image_file'] if 'image_file' in request.files else None
        if name and website and type:
            payloads = {
                'name': name,
                'email': email,
                'website': website,
                'photo': photo,
                'type': type
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')
        result = partnerservice.update(payloads, id)

        if not result['error']:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
        else:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
Exemplo n.º 4
0
    def update(request, id):
        stage_id = request.json[
            'stage_id'] if 'stage_id' in request.json else None
        event_id = request.json[
            'event_id'] if 'event_id' in request.json else None
        time_start = request.json[
            'time_start'] if 'time_start' in request.json else None
        time_end = request.json[
            'time_end'] if 'time_end' in request.json else None
        if stage_id and event_id and time_start and time_end:
            payloads = {
                'stage_id': stage_id,
                'event_id': event_id,
                'time_start': time_start,
                'time_end': time_end
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        result = scheduleservice.update(payloads, id)

        if not result['error']:
            return BaseController.send_response_api(
                result['data'], 'schedule succesfully updated',
                result['included'])
        else:
            return BaseController.send_error_api(None, result['data'])
Exemplo n.º 5
0
    def create(request, user_id):
        report_type = request.json[
            'report_type'] if 'report_type' in request.json else None
        feed_id = request.json['feed_id'] if 'feed_id' in request.json else None
        if user_id and report_type and feed_id:
            payloads = {
                'user_id': user_id,
                'report_type': report_type,
                'feed_id': feed_id
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        feed_report = db.session.query(FeedReport).filter(
            and_(FeedReport.user_id == user_id,
                 FeedReport.feed_id == feed_id)).first()
        if feed_report is not None:
            return BaseController.send_error_api(
                None, 'You already report this feed')

        result = feedreportservice.create(payloads)

        if result['error']:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
        else:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
Exemplo n.º 6
0
    def create(request):
        owner_type = request.json[
            'owner_type'] if 'owner_type' in request.json else None
        owner_id = request.json[
            'owner_id'] if 'owner_id' in request.json else None
        discount_amount = request.json[
            'discount_amount'] if 'discount_amount' in request.json else 0.1
        referal_code = request.json[
            'referal_code'] if 'referal_code' in request.json else ''
        quota = request.json['quota'] if 'quota' in request.json else 1

        if discount_amount and referal_code and quota and owner_type and owner_id:
            payloads = {
                'owner_type': owner_type,
                'owner_id': owner_id,
                'discount_amount': discount_amount,
                'referal_code': referal_code,
                'quota': quota
            }
        else:
            return BaseController.send_error_api({'payload_invalid': True},
                                                 'field is not complete')

        result = referalservice.create(payloads)

        if not result['error']:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
        else:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
    def update(request, id):
        major = request.json['major'] if 'major' in request.json else None
        minor = request.json['minor'] if 'minor' in request.json else None
        point = request.json['point'] if 'point' in request.json else None
        type = request.json['type'] if 'type' in request.json else None
        type_id = request.json['type_id'] if 'type_id' in request.json else None
        description = request.json[
            'description'] if 'description' in request.json else ''

        if major and minor and type and type_id:
            payloads = {
                'major': major,
                'minor': minor,
                'point': point,
                'type': type,
                'type_id': type_id,
                'description': description,
            }
        else:
            return BaseController.send_error_api(None, 'invalid payload')

        result = beaconservice.update(payloads, id)

        if result['error']:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
        return BaseController.send_response_api(result['data'],
                                                result['message'])
Exemplo n.º 8
0
 def update(request, user, id):
     if (user['role_id'] == ROLE['speaker']):
         speaker = db.session.query(Speaker).filter_by(
             user_id=user['id']).first()
         if speaker is None:
             return BaseController.send_error_api(None, 'speaker not found')
         summary = request.json[
             'summary'] if 'summary' in request.json else ''
         title = request.json['title'] if 'title' in request.json else ''
         is_used = request.json[
             'is_used'] if 'is_used' in request.json else 0
         if speaker.as_dict()['id']:
             payloads = {
                 'title': title,
                 'summary': summary,
                 'is_used': is_used
             }
         else:
             return BaseController.send_error_api(None,
                                                  'field is not complete')
         result = speakerdocumentservice.update(payloads, id)
         if not result['error']:
             return BaseController.send_response_api(
                 result['data'], result['message'])
         else:
             return BaseController.send_error_api(result['data'],
                                                  result['message'])
     else:
         return BaseController.send_error_api(None, 'Unauthorized user')
Exemplo n.º 9
0
    def create(request, user_id):
        order_details = request.json[
            'order_details'] if 'order_details' in request.json else None
        referal_code = request.json[
            'referal_code'] if 'referal_code' in request.json else None
        payment_type = request.json[
            'payment_type'] if 'payment_type' in request.json else None

        if order_details is None or len(order_details) < 1:
            return BaseController.send_error_api({'payload_invalid': True},
                                                 'payload is invalid')

        payloads = {
            'user_id': user_id,
            'order_details': order_details,
            'referal_code': referal_code,
            'payment_type': payment_type
        }

        result = orderservice.create(payloads)

        if not result['error']:
            return BaseController.send_response_api(
                result['data'], 'order succesfully created',
                result['included'])
        else:
            return BaseController.send_error_api(None, result['data'])
Exemplo n.º 10
0
    def update(request, id):
        description = request.json[
            'description'] if 'description' in request.json else None
        location = request.json[
            'location'] if 'location' in request.json else None
        time_start = request.json[
            'time_start'] if 'time_start' in request.json else None
        time_end = request.json[
            'time_end'] if 'time_end' in request.json else None

        if description and location and time_start and time_end:
            payloads = {
                'description': description,
                'time_start': time_start,
                'time_end': time_end,
                'location': location
            }
            result = rundownlistservice.update(payloads, id)
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        if not result['error']:
            return BaseController.send_response_api(
                result['data'], 'rundown succesfully updated',
                result['included'])
        else:
            return BaseController.send_error_api(None, result['data'])
Exemplo n.º 11
0
    def add(request):
        first_name = request.json[
            'first_name'] if 'first_name' in request.json else None
        last_name = request.json[
            'last_name'] if 'last_name' in request.json else ''
        email = request.json['email'] if 'email' in request.json else None
        username = request.json[
            'username'] if 'username' in request.json else None
        role_id = request.json['role_id'] if 'role_id' in request.json else None
        includes = request.json[
            'includes'] if 'includes' in request.json else None
        referal = request.json['referal'] if 'referal' in request.json else None

        if first_name and email and username and role_id:
            payloads = {
                'first_name': first_name,
                'last_name': last_name,
                'email': email,
                'username': username,
                'role_id': role_id,
                'includes': includes,
                'referal': referal
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        result = userservice.add(payloads)

        if not result['error']:
            return BaseController.send_response_api(result['data'],
                                                    'user succesfully added')
        else:
            return BaseController.send_error_api(None, result['data'])
	def create(request, user):
		order_details = request.json['order_details'] if 'order_details' in request.json else None
		referal_code = request.json['referal_code'] if 'referal_code' in request.json else None
		payment_type = request.json['payment_type'] if 'payment_type' in request.json else None
		hacker_team_name = request.json['hacker_team_name'] if 'hacker_team_name' in request.json else None

		if order_details is None or len(order_details) < 1:
			return BaseController.send_error_api({'payload_invalid': True}, 'payload is invalid')

		payloads = {
			'user_id': user['id'],
			'order_details': order_details,
			'referal_code': referal_code,
			'payment_type': payment_type,
			'hacker_team_name': hacker_team_name
		}
		
		result = orderservice.create(payloads, user)

		if not result['error']:
			send_notification = FCMService().send_single_notification('Order Status', 'Your order have been succesfully placed.', user['id'], ROLE['admin'])
			if SLACK['notification']:
				slackorder = SlackOrder(user, result, payment_type)
				slackservice.send_message(slackorder.build())
			return BaseController.send_response_api(result['data'], 'order succesfully created', result['included'])
		else:
			return BaseController.send_error_api(None, result['message'])
    def checkin(request, user_id):
        booth_type = request.json[
            'booth_type'] if 'booth_type' in request.json else None
        booth_id = request.json[
            'booth_id'] if 'booth_id' in request.json else None
        speed_dating = request.json[
            'speed_dating'] if 'speed_dating' in request.json else False
        # booth_type:
        # exhibitor -> booth
        # sponsor -> sponsor
        if booth_type and booth_id:
            payloads = {
                'booth_type': booth_type,
                'booth_id': booth_id,
                'speed_dating': speed_dating,
                'user_id': user_id
            }
        else:
            return BaseController.send_error_api(None, 'invalid payload')

        result = boothcheckinservice.checkin(payloads)
        if result['error']:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
        return BaseController.send_response_api(result['data'],
                                                result['message'])
Exemplo n.º 14
0
    def update(request, id):
        user_id = request.json['user_id'] if 'user_id' in request.json else None
        job = request.json['job'] if 'job' in request.json else None
        summary = request.json['summary'] if 'summary' in request.json else None
        information = request.json[
            'information'] if 'information' in request.json else None

        if user_id and job and summary and information:
            payloads = {
                'user_id': user_id,
                'job': job,
                'summary': summary,
                'information': information
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        result = speakerservice.update(payloads, id)

        if not result['error']:
            return BaseController.send_response_api(
                result['data'], 'speaker succesfully updated',
                result['included'])
        else:
            return BaseController.send_error_api(None, result['data'])
 def broadcast_notification(requests, user):
     message = requests.json[
         'message'] if 'message' in requests.json else None
     audience = requests.json[
         'audience'] if 'audience' in requests.json else None
     type = requests.json['type'] if 'type' in requests.json else None
     result = None
     if message and type:
         if audience == 'users':
             result = fcmservice.broadcast_notification(
                 type, message, user['id'])
         elif audience == 'hackers':
             hackers = db.session.query(User).filter(
                 User.role_id == ROLE['hackaton']).all()
             if len(hackers) < 1:
                 return BaseController.send_error_api(
                     None, 'No hackaton user found')
             for hacker in hackers:
                 result = fcmservice.send_single_notification(
                     type, message, hacker.id, 1)
     else:
         return BaseController.send_error_api(None, 'payload not valid')
     if result['error']:
         return BaseController.send_error_api(result['data'],
                                              result['message'])
     return BaseController.send_response_api(result['data'],
                                             result['message'])
Exemplo n.º 16
0
    def update(request, id):
        ticket_type = request.form[
            'ticket_type'] if 'ticket_type' in request.form else None
        price = request.form['price'] if 'price' in request.form else None
        information = request.form[
            'information'] if 'information' in request.form else ''
        type = request.form['type'] if 'type' in request.form else ''
        proposal_url = request.files[
            'proposal_url'] if 'proposal_url' in request.files else None
        usd_price = request.form[
            'usd_price'] if 'usd_price' in request.form else None
        quota = request.form['quota'] if 'quota' in request.form else None

        if ticket_type and price:
            payloads = {
                'ticket_type': ticket_type,
                'price': price,
                'information': information,
                'type': type,
                'proposal_url': proposal_url,
                'usd_price': usd_price,
                'quota': quota
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        result = ticketservice.update(payloads, id)

        if not result['error']:
            return BaseController.send_response_api(
                result['data'], 'ticket succesfully updated')
        else:
            return BaseController.send_error_api(None, result['data'])
Exemplo n.º 17
0
    def update(request, id):
        quota = request.json['quota'] if 'quota' in request.json else 1
        discount_amount = request.json[
            'discount_amount'] if 'discount_amount' in request.json else 0.1
        referal_code = request.json[
            'referal_code'] if 'referal_code' in request.json else ''

        if quota:
            payloads = {
                'discount_amount': discount_amount,
                'quota': quota,
                'referal_code': referal_code
            }
        else:
            return BaseController.send_error_api({'payload_invalid': True},
                                                 'field is not complete')

        result = referalservice.update(payloads, id)

        if not result['error']:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
        else:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
Exemplo n.º 18
0
    def create(request, user):
        message = request.json['message'] if 'message' in request.json else None
        type = request.json['type'] if 'type' in request.json else None
        attachment = request.json[
            'attachment'] if 'attachment' in request.json else None
        receiver = request.json[
            'receiver'] if 'receiver' in request.json else None
        if message and type:
            payloads = {
                'message': message,
                'type': type,
                'attachment': attachment,
                'user': user,
                'receiver': receiver
            }
        else:
            return BaseController.send_error_api(None, 'field is not complete')

        result = notificationservice.create(payloads)

        if result['error']:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
        else:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
Exemplo n.º 19
0
 def update(request, user):
     code = request.json['code'] if 'code' in request.json else None
     if code is None:
         return BaseController.send_error_api(None, 'field is not complete')
     result = redeemcodeservice.update(code, user)
     if not result['error']:
         return BaseController.send_response_api(result['data'], result['message'], result['included'])
     else:
         return BaseController.send_error_api(result['data'], result['message'])
 def refresh_me(user):
     token, res_user = userservice.get_user_info(user)
     user = userservice.include_role_data(res_user)
     if token is None:
         BaseController.send_error_api(None, 'user not found')
     return BaseController.send_response_api(
         {
             'access_token': token['access_token'],
             'refresh_token': token['refresh_token']
         }, 'User data retrieved', res_user)
Exemplo n.º 21
0
 def verify(order_id):
     if order_id is None:
         return BaseController.send_error_api(None, 'invalid payload')
     payloads = {'order_id': order_id}
     result = hackatonproposalservice.verify(payloads)
     if result['error']:
         return BaseController.send_error_api(result['data'],
                                              result['message'])
     return BaseController.send_response_api(result['data'],
                                             result['message'])
Exemplo n.º 22
0
 def resend_certificate(user_id):
     if user_id is None:
         return BaseController.send_error_api(None, 'invalid payload')
     payloads = {'user_id': user_id}
     result = hackatonproposalservice.resend_certificate(payloads)
     if result['error']:
         return BaseController.send_error_api(result['data'],
                                              result['message'])
     return BaseController.send_response_api(result['data'],
                                             result['message'])
Exemplo n.º 23
0
    def check_in(request):
        user_ticket_id = request.json['user_ticket_id'] if 'user_ticket_id' in request.json else None
        if (user_ticket_id is None):
            BaseController.send_error_api({'payload_invalid': True}, 'payload is not valid')
        result = userticketservice.check_in(user_ticket_id)

        if 'error' in result and result['error']:
            return BaseController.send_error_api(result['data'], result['message'])

        return BaseController.send_response_api(result['data'], result['message'])
 def search_accounts(request):
     keyword = request.args.get('search')
     print(keyword)
     if keyword is None:
         return BaseController.send_error_api(None, 'invalid payloads')
     result = userservice.search_accounts(keyword)
     if result['error']:
         return BaseController.send_error_api(result['data'],
                                              result['message'])
     return BaseController.send_response_api(result['data'],
                                             result['message'])
    def updatefcmtoken(request, user):
        token = request.json['token'] if 'token' in request.json else None

        if token is None:
            return BaseController.send_error_api(None, 'token not provided')
        result = userservice.updatefcmtoken(token, user)
        if result['error']:
            return BaseController.send_error_api(result['message'],
                                                 result['message'])
        return BaseController.send_response_api(result['data'],
                                                result['message'])
Exemplo n.º 26
0
 def show(user):
     speaker = db.session.query(Speaker).filter_by(
         user_id=user['id']).first()
     if speaker is None:
         return BaseController.send_error_api(None, 'speaker not found')
     speaker = speaker.as_dict()
     _speaker_documents = speakerdocumentservice.show(speaker)
     if _speaker_documents['error']:
         return BaseController.send_error_api(_speaker_documents['data'],
                                              _speaker_documents['message'])
     return BaseController.send_response_api(_speaker_documents['data'],
                                             _speaker_documents['message'])
 def resend_order_email(request):
     order_id = request.json[
         'order_id'] if 'order_id' in request.json else None
     if order_id is None:
         return BaseController.send_error_api(None, 'invalid payload')
     payload = {'order_id': order_id}
     result = orderverificationservice.resend_order_email(payload)
     if result['error']:
         return BaseController.send_error_api(result['data'],
                                              result['error'])
     return BaseController.send_response_api(result['data'],
                                             result['message'])
    def update_mapping(request):
        version = request.json['version'] if 'version' in request.json else None
        if version is None:
            return BaseController.send_error_api(None, 'invalid payload')

        result = beaconservice.fetch_mapping(version)

        if result['error']:
            return BaseController.send_error_api(result['data'],
                                                 result['message'])
        return BaseController.send_response_api(result['data'],
                                                result['message'])
Exemplo n.º 29
0
	def post_answer(id, user, request):
		user_id = user.id
		answers = request.json['answers']
		if answers:
			payload = {
				'answers': answers
			}
			result = questionerservice.post_answer(id, user_id, payload)
			if result['error']:
				return BaseController.send_error_api(result['data'], 'error post answer')
			return BaseController.send_response_api(result, "answer successfully posted")
		else:
			return BaseController.send_error_api('payload not valid')
    def reward_point(request, user):
        major = request.json['major'] if 'major' in request.json else None
        minor = request.json['minor'] if 'minor' in request.json else None

        if major and minor:
            payloads = {'major': major, 'minor': minor}
        else:
            return BaseController.send_error_api(None, 'invalid payload')
        result = pointtransactionservice.reward_point(payloads, user)
        if result['error']:
            return BaseController.send_response_api(result['data'],
                                                    result['message'])
        return BaseController.send_error_api(result['data'], result['message'])