Example #1
0
    def add_template(self,
                     user_id,
                     name,
                     price,
                     description,
                     category,
                     tags=[]):
        try:
            item = insert(self.database, 'Items',
                          [('user_id', user_id), ('category_id', category),
                           ('name', name), ('price', price),
                           ('created_at', datetime.datetime.now().isoformat()),
                           ('description', description)])

            item_id = item.lastrowid

            template = insert(self.database, 'Templates',
                              [('item_id', item_id), ('file_path', '')])

            self.database.commit()

            return item_id
        except:
            self.database.rollback()
            raise
    def create_order(self, user_id, card_payment, items):
        try:
            transaction = insert(
                self.database, 'Transactions',
                [('user_id', user_id),
                 ('created_at', datetime.datetime.now().isoformat()),
                 ('card_number', card_payment.number),
                 ('card_name', card_payment.name),
                 ('card_expiration', card_payment.expiration.isoformat()),
                 ('card_cvc', card_payment.cvc)])

            transaction_id = transaction.lastrowid

            for item_id in items:
                insert(self.database, 'Transaction_Items',
                       [('transaction_id', transaction_id),
                        ('item_id', item_id)])

            self.database.commit()

            return transaction_id

        except:
            self.database.rollback()
            raise
Example #3
0
    def create_order(self, user_id, card_payment, items):
        try:
            transaction = insert(self.database, 'Transactions', [
                ('user_id', user_id),
                ('created_at', datetime.datetime.now().isoformat()),
                ('card_number', card_payment.number),
                ('card_name', card_payment.name),
                ('card_expiration', card_payment.expiration.isoformat()),
                ('card_cvc', card_payment.cvc)
            ])

            transaction_id = transaction.lastrowid

            for item_id in items:
                insert(self.database, 'Transaction_Items', [
                    ('transaction_id', transaction_id),
                    ('item_id', item_id)
                ])

            self.database.commit()

            return transaction_id

        except:
            self.database.rollback()
            raise
Example #4
0
    def add_tags_to_item(self, tags, item_id):
        for tag in tags:
            try:
                insert(self.database, 'Item_Tags', [('item_id', item_id),
                                                    ('tag_id', tag)])

                self.database.commit()
            except Exception as e:
                print(e)
                self.database.rollback()
Example #5
0
    def add_tags_to_item(self, tags, item_id):
        for tag in tags:
            try:
                insert(self.database, 'Item_Tags', [
                    ('item_id', item_id),
                    ('tag_id', tag)
                ])

                self.database.commit()
            except Exception as e:
                print(e)
                self.database.rollback()
Example #6
0
    def create_custom_tags_for_item(self, tags, item_id):
        for tag in tags:
            try:
                existing_tag = self.get_by_name(tag)
                if existing_tag is None:
                    # Insert the new tag, then insert into Item_tags using the lastinsertid
                    result = insert(self.database, 'Tags', [('name', tag)])

                    new_tag_id = result.lastrowid
                else:
                    new_tag_id = existing_tag.tag_id

                insert(self.database, 'Item_Tags', [('item_id', item_id),
                                                    ('tag_id', new_tag_id)])

                self.database.commit()

            except Exception as e:
                print(e)
                self.database.rollback()
Example #7
0
 def add_rating(self, template_id, user_id, amount):
     try:
         transaction = insert(self.database, 'Ratings', [
             ('template_id', template_id),
             ('user_id', user_id),
             ('amount', amount),
             ('created_at', datetime.datetime.now().isoformat())
         ])
         self.database.commit()
     except:
         self.database.rollback()
Example #8
0
    def add_service(self, user_id, name, start_price, description, duration):
        try:
            item = insert(self.database, 'Items',
                          [('user_id', user_id), ('name', name),
                           ('price', start_price),
                           ('created_at', datetime.datetime.now().isoformat()),
                           ('description', description)])

            item_id = item.lastrowid
            end_date = datetime.datetime.now() + datetime.timedelta(
                days=duration)

            service = insert(self.database, 'Services',
                             [('item_id', item_id),
                              ('end_date', end_date.isoformat())])

            self.database.commit()

            return item_id
        except:
            self.database.rollback()
            raise
Example #9
0
    def add_service(self, user_id, name, start_price, description, duration):
        try:
            item = insert(self.database, 'Items', [
                ('user_id', user_id),
                ('name', name),
                ('price', start_price),
                ('created_at', datetime.datetime.now().isoformat()),
                ('description', description)
            ])

            item_id = item.lastrowid
            end_date = datetime.datetime.now() + datetime.timedelta(days=duration)

            service = insert(self.database, 'Services', [
                ('item_id', item_id),
                ('end_date', end_date.isoformat())
            ])

            self.database.commit()

            return item_id
        except:
            self.database.rollback()
            raise
Example #10
0
    def add_template(self, user_id, name, price, description, category, tags=[]):
        try:
            item = insert(self.database, 'Items', [
                ('user_id', user_id),
                ('category_id', category),
                ('name', name),
                ('price', price),
                ('created_at', datetime.datetime.now().isoformat()),
                ('description', description)
            ])

            item_id = item.lastrowid

            template = insert(self.database, 'Templates', [
                ('item_id', item_id),
                ('file_path', '')
            ])

            self.database.commit()

            return item_id
        except:
            self.database.rollback()
            raise
Example #11
0
    def create_custom_tags_for_item(self, tags, item_id):
        for tag in tags:
            try:
                existing_tag = self.get_by_name(tag)
                if existing_tag is None:
                    # Insert the new tag, then insert into Item_tags using the lastinsertid
                    result = insert(self.database, 'Tags', [
                        ('name', tag)
                    ])

                    new_tag_id = result.lastrowid
                else:
                    new_tag_id = existing_tag.tag_id

                insert(self.database, 'Item_Tags', [
                    ('item_id', item_id),
                    ('tag_id', new_tag_id)
                ])

                self.database.commit()

            except Exception as e:
                print(e)
                self.database.rollback()
Example #12
0
 def add_rating(self, template_id, user_id, amount):
     try:
         transaction = insert(
             self.database,
             "Ratings",
             [
                 ("template_id", template_id),
                 ("user_id", user_id),
                 ("amount", amount),
                 ("created_at", datetime.datetime.now().isoformat()),
             ],
         )
         self.database.commit()
     except:
         self.database.rollback()
Example #13
0
    def place_bid(self, service_id, user_id, amount):

        try:
            bid = insert(self.database, 'Bids', [
                ('service_id', service_id),
                ('user_id', user_id),
                ('amount', amount),
                ('created_at', datetime.now().isoformat())
            ])

            self.database.commit()

            return bid
        except:
            self.database.rollback()
            raise