File size: 2,010 Bytes
b39c0ba
 
 
 
 
 
 
69beac6
 
b39c0ba
 
69beac6
 
b39c0ba
 
 
 
 
 
 
 
69beac6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b39c0ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69beac6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from db.models import Category, Metadata
from db.query.base_query import BaseQuery

class CategoryQuery(BaseQuery):
    def __init__(self, user):
        super().__init__(user)

    def add_category(self, db, category_name):
        new_category = Category(category=category_name)
        return self.add(db, new_category)

    def update_category(self, db, category_id, category_name):
        update_data = {"category": category_name}
        self.update(db, Category, category_id, update_data)

    def delete_category(self, db, category_id):
        self.delete(db, Category, category_id)

    def get_category(self, db, category_id):
        columns = [Category.category]
        model = Category
        results = self.get_columns(db,model=model, columns=columns, id=category_id)
        return results
    
    def get_existing_category(self, db, category_name):
        columns = [Category.category]
        model = Category
        filter_condition = [Category.category == category_name]
        results = self.get_columns(db, columns=columns, model=model, filter_conditions=filter_condition)
        return results
    
    def get_category_by_id(self, db, category_id):
        model = Category
        filter_conditions = [Category.id == category_id]
        results = self.get(db, model=model, filter_conditions=filter_conditions)
        
        return results

    def get_current_category(self, db, metadata_id):
        columns = [Category.category]
        join_models = [Metadata]
        where_conditions = [Metadata.id == metadata_id]

        result = self.get_with_joins(
            db,
            join_models=join_models,
            filter_conditions=where_conditions,
            columns=columns,
            multiple=False  # Assuming you want a single result
        )
        
        return result

    def get_all_categories(self, db):
        results = self.get(db, Category, multiple=True)
        categories = [category[0] for category in results]
        return categories