summaryrefslogtreecommitdiff
path: root/src/database/dbsearch.py
blob: 3089bf1e768e17a8607b49a6979a5ca915007edd (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
############################################################################
#                                                                          #
# Description: Ensemble de méthodes pour étendre dbmain afin               #
#              d'effectuer des recherches dans la bdd                      #
#                                                                          #
############################################################################

# Infos pour les """join""":
# https:#www.freecodecamp.org/news/sql-joins-tutorial/

# Import de dbmain
from src.database import dbmain


# Extension de cette classe avec dbmain
class DbSearch(dbmain.DbMain):
    # ****************************************************************************
    # RECUPERATION DES INFORMATIONS RELATIVES AUX UTILISATEURS
    # ****************************************************************************
    # Récupération des infos d'un compte par son id
    def get_user_account_by_userid(self, userId: int) -> list:
        reqSearchUser = """
            SELECT 
                userId, email, inscriptionDate, userStatus
            FROM 
                """ + self.TABLEUSERACCOUNT + """
            WHERE 
                userId = %s"""
        self.exec_cmd(reqSearchUser, [userId])
        return self.cur.fetchall()

    # Récupération des infos d'un utilisateur par son id
    def get_user_info_by_userid(self, userId: int) -> list:
        reqGetUserInfo = """
            SELECT 
                userId, lastname, firstname, degree, 
                capability, description, phoneNumber,
                adress, zipCode, city 
            FROM 
                """ + self.TABLEUSERINFO + """ 
            WHERE 
                userId = %s"""
        self.exec_cmd(reqGetUserInfo, [userId])
        return self.cur.fetchall()

    # ****************************************************************************
    # RECUPERATION DES INFORMATIONS RELATIVES AUX PROS
    # ****************************************************************************
    def get_all_pro_by_jobid(self, jobId):
        reqSearchConsultant = """
            SELECT 
                """ + self.TABLEUSERINFO + """.userId, 
                lastname, firstname, capability 
            FROM 
                """ + self.TABLEUSERINFO + """
            INNER JOIN
                """ + self.TABLEUSERJOB + """
            ON
                """ + self.TABLEUSERINFO + """.userId = """ + self.TABLEUSERJOB + """.userId
            WHERE 
                jobCategoryId = %s"""
        self.exec_cmd(reqSearchConsultant, [jobId])
        return self.cur.fetchall()

    # Récupération des infos d'un pro par son nom
    def get_pro_info_by_lastname(self, lastname):
        reqSearchConsultant = """
            SELECT 
                """ + self.TABLEUSERINFO + """.userId, 
                lastname, firstname, capability 
            FROM 
                """ + self.TABLEUSERINFO + """
            INNER JOIN 
                """ + self.TABLEUSERACCOUNT + """ 
            ON 
                """ + self.TABLEUSERINFO + """.userId = """ + self.TABLEUSERACCOUNT + """.userId
            WHERE 
                userStatus = '1' 
            AND 
                lastname LIKE CONCAT('%', %s, '%')"""
        self.exec_cmd(reqSearchConsultant, [lastname])
        return self.cur.fetchall()

    # Récupération des emploies associés à un pro
    def get_pro_job_by_proid(self, proId):
        reqGetAll = """
            SELECT 
                """ + self.TABLEUSERJOB + """.jobCategoryId, 
                jobCategoryNameEn, jobCategoryNameFr 
            FROM 
                """ + self.TABLEUSERJOB + """
            INNER JOIN 
                """ + self.TABLEJOBCATEGORY + """
            ON 
                """ + self.TABLEUSERJOB + """.jobCategoryId = """ + self.TABLEJOBCATEGORY + """.jobCategoryId
            WHERE 
                userId = %s"""
        self.exec_cmd(reqGetAll, [proId])
        return self.cur.fetchall()

    # Récupération des notes d'un consultant par son nom
    def get_pro_note_by_proid(self, proId):
        reqCountMission = """
            SELECT 
                note 
            FROM 
                """ + self.TABLEMISSION + """
            INNER JOIN 
                """ + self.TABLEUSERINFO + """ 
            ON 
                """ + self.TABLEMISSION + """.proId = """ + self.TABLEUSERINFO + """.userId
            WHERE 
                proId = %s"""
        self.exec_cmd(reqCountMission, [proId])
        return self.cur.fetchall()

    # ****************************************************************************
    # RECUPERATION DES INFORMATIONS RELATIVES AUX EMPLOIS
    # ****************************************************************************
    # Récupérer toutes les infos de la table jobCategory
    def get_job_all(self) -> list:
        reqGetAllJobs = """
            SELECT 
                * 
            FROM 
                """ + self.TABLEJOBCATEGORY
        self.exec_cmd(reqGetAllJobs)
        return self.cur.fetchall()

    # Récupérer toutes les infos de la table jobCategory
    def get_job_by_jobid(self, jobId: int) -> list:
        reqGetJobinfo = """
            SELECT 
                * 
            FROM 
                """ + self.TABLEJOBCATEGORY + """
            WHERE
                jobCategoryId = %s"""
        self.exec_cmd(reqGetJobinfo, [jobId])
        return self.cur.fetchall()