Commit 09334a60 authored by Dimitri Nicolas's avatar Dimitri Nicolas
Browse files

Views inserted + repartition emprunts + liste prets

parent 98f232ed
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="src.cogs.stats.stream_voice_channel.client" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ai23-projet.iml" filepath="$PROJECT_DIR$/.idea/ai23-projet.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -14,7 +14,18 @@ class AdherentDataMapper(DataMapper):
print(err)
finally:
conn.close()
def getPrets(self, login):
connection = self.connect()
try:
cursor : psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"SELECT COUNT(exemplairepret.pret) AS nb_articles,pret.pretid, pret.date, pret.adherent "
f"FROM pret JOIN exemplairepret ON pret.pretid = exemplairepret.pret "
f"WHERE pret.adherent = '{login}' GROUP BY pret.pretid")
return cursor.fetchall()
except Exception as err:
print(err)
finally:
conn.close()
datamapper = AdherentDataMapper()
datamapper.selectAdherents()
\ No newline at end of file
......@@ -5,16 +5,26 @@ from DataMapper import DataMapper
class RessourceDataMapper(DataMapper):
def getAvailableExemplaires(self) ->list[Tuple[str, str]]:
def getAvailableExemplaires(self):
connection = self.connect()
try:
cursor: psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"SELECT DISTINCT(codeunique), titre, editeur, genre FROM ressource JOIN exemplaire ON exemplaire.ressource = ressource.codeunique WHERE disponible = TRUE")
cursor.execute("SELECT Exemplaires_Disponibles")
return cursor.fetchall()
except Exception as err:
print(err)
finally:
connection.close()
def getRepartitionEmprunts(self):
connection = self.connect()
try:
cursor: psycopg2.extensions.cursor = connection.cursor()
cursor.execute("SELECT Repartition_Emprunts")
return cursor.fetchall()
except Exception as err:
print(err)
finally:
connection.close()
datamapper = RessourceDataMapper()
print(datamapper.getAvailableExemplaires())
\ No newline at end of file
......@@ -161,92 +161,20 @@ CREATE TABLE IF NOT EXISTS ExemplairePret (
FOREIGN KEY (pret) REFERENCES Pret(pretID),
PRIMARY KEY (ref, pret)
);
/* ****** TRIGGERS ******
-- REPRESENTATION DES ASSOCIATIONS EXCLUSIVES, UN CONTRIBUTEUR NE PEUT AVOIR QU'UN SEUL RÔLE POUR CHAQUE RESSOURCE
-- PAS FONCTIONNEL, A DEBUG
CREATE OR REPLACE FUNCTION check_exclusivite_realisateur()
RETURNS trigger AS
$$
BEGIN
DECLARE var INTEGER;
SELECT acteur INTO var FROM Acteur WHERE acteur = NEW.realisateur AND film = NEW.film;
RAISE Erreur_exclu;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN Erreur_exclu THEN
RAISE_APPLICATION_ERROR(-20001, 'Erreur : ce contributeur existe déjà dans la table Auteur');
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
CREATE TRIGGER T_EXCUSIVITE_REALISATEUR BEFORE INSERT ON Realisateur
FOR EACH ROW
EXECUTE PROCEDURE check_exclusivite_realisateur();
CREATE OR REPLACE FUNCTION check_exclusivite_acteur()
RETURNS trigger AS
$$
BEGIN
DECLARE var INTEGER;
SELECT realisateur INTO var FROM Realisateur WHERE realisateur = NEW.auteur AND film = NEW.film;
RAISE Erreur_exclu;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN Erreur_exclu THEN
RAISE_APPLICATION_ERROR(-20001, 'Erreur : ce contributeur existe déjà dans la table Realisateur');
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
CREATE TRIGGER T_EXCUSIVITE_ACTEUR BEFORE INSERT OR UPDATE ON Acteur
FOR EACH ROW
EXECUTE PROCEDURE check_exclusivite_acteur();
CREATE OR REPLACE FUNCTION check_exclusivite_compositeur()
RETURNS trigger AS
$$
BEGIN
DECLARE var INTEGER;
SELECT interprete INTO var FROM Interprete WHERE interprete = NEW.compositeur AND oeuvreMusicale = NEW.oeuvreMusicale;
RAISE Erreur_exclu;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN Erreur_exclu THEN
RAISE_APPLICATION_ERROR(-20001, 'Erreur : ce contributeur existe déjà dans la table Interprete');
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
CREATE TRIGGER T_EXCUSIVITE_COMPOSITEUR BEFORE INSERT OR UPDATE ON Compositeur
FOR EACH ROW
EXECUTE PROCEDURE check_exclusivite_compositeur();
CREATE OR REPLACE FUNCTION check_exclusivite_interprete()
RETURNS trigger AS
$$
BEGIN
DECLARE var INTEGER;
SELECT compositeur INTO var FROM Compositeur WHERE compositeur = NEW.interprete AND oeuvreMusicale = NEW.oeuvreMusicale;
RAISE Erreur_exclu;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN Erreur_exclu THEN
RAISE_APPLICATION_ERROR(-20001, 'Erreur : ce contributeur existe déjà dans la table Compositeur');
END;
$$
LANGUAGE 'plpgsql';
CREATE TRIGGER T_EXCUSIVITE_INTERPRETE BEFORE INSERT OR UPDATE ON Interprete
FOR EACH ROW
EXECUTE PROCEDURE check_exclusivite_interprete();
*/
\ No newline at end of file
/*--------------------------------- VIEWS -----------------------------------------------*/
CREATE VIEW Exemplaires_Disponibles AS
SELECT DISTINCT(codeunique), titre, editeur, genre
FROM ressource
JOIN exemplaire ON exemplaire.ressource = ressource.codeunique
WHERE disponible = TRUE;
CREATE VIEW Repartition_Emprunts AS
SELECT
CASE
WHEN exemplaire.ressource IN (SELECT codeunique FROM livre) THEN 'livre'
WHEN exemplaire.ressource IN (SELECT codeunique FROM film) THEN 'film'
WHEN exemplaire.ressource IN (SELECT codeunique FROM oeuvremusicale) THEN 'oeuvre musicale'
END AS "category", COUNT(exemplaire.ressource) AS "nb_ressources", (COUNT(exemplaire.ressource)/SUM(COUNT(exemplaire.ressource)) OVER()) * 100 AS "part"
FROM exemplaire
JOIN exemplairepret ON exemplaire.ref = exemplairepret.ref
GROUP BY "category";
\ No newline at end of file
......@@ -16,4 +16,6 @@ DROP TABLE IF EXISTS remboursement CASCADE;
DROP TABLE IF EXISTS ressource CASCADE;
DROP TABLE IF EXISTS sanction CASCADE;
DROP TABLE IF EXISTS suspension CASCADE;
DROP TABLE IF EXISTS utilisateur CASCADE;
\ No newline at end of file
DROP TABLE IF EXISTS utilisateur CASCADE;
DROP VIEW IF EXISTS Exemplaires_Disponibles;
DROP VIEW IF EXISTS Repartition_Emprunts;
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment