From e714d6103df8c7406f5b3b296fafe23562f7ca38 Mon Sep 17 00:00:00 2001 From: Romain MATIAS Date: Tue, 5 Dec 2023 01:54:28 +0100 Subject: [PATCH 1/5] feat: add emprise_id to project --- sql/create-tables.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/create-tables.sql b/sql/create-tables.sql index 6612766..2a73981 100644 --- a/sql/create-tables.sql +++ b/sql/create-tables.sql @@ -83,6 +83,11 @@ CREATE TABLE base.projects ( ON DELETE NO ACTION, csv_id INTEGER NULL, FOREIGN KEY (csv_id) + REFERENCES base.documents (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION, + emprise_id INTEGER NULL, + FOREIGN KEY (emprise_id) REFERENCES base.documents (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION From 9b3d0ad0cf7514e20c57e315c584a34064c37917 Mon Sep 17 00:00:00 2001 From: Romain MATIAS Date: Tue, 5 Dec 2023 02:02:14 +0100 Subject: [PATCH 2/5] feat: add emprise_id in all file --- app/models.py | 4 ++++ app/modules/projects/views.py | 10 +++++++--- app/schemas.py | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models.py b/app/models.py index 4467816..095f5fb 100644 --- a/app/models.py +++ b/app/models.py @@ -112,11 +112,13 @@ class Projects(db.Model): user_id = db.Column(db.Integer, db.ForeignKey(schema + ".users.id")) model_id = db.Column(db.Integer, db.ForeignKey(schema + ".documents.id")) csv_id = db.Column(db.Integer, db.ForeignKey(schema + ".documents.id")) + emprise_id = db.Column(db.Integer, db.ForeignKey(schema + ".documents.id")) # Object links user = db.relationship("Users", foreign_keys=user_id) model = db.relationship("Documents", foreign_keys=model_id, viewonly=True) csv = db.relationship("Documents", foreign_keys=csv_id, viewonly=True) + emprise = db.relationship("Documents", foreign_keys=emprise_id, viewonly=True) def __str__(self): return ( @@ -140,6 +142,8 @@ def __str__(self): + str(self.model_id) + '" csv_id="' + str(self.csv_id) + + '" emprise_id="' + + str(self.emprise_id) + '">' ) diff --git a/app/modules/projects/views.py b/app/modules/projects/views.py index 288ad1e..ade07e7 100644 --- a/app/modules/projects/views.py +++ b/app/modules/projects/views.py @@ -133,10 +133,13 @@ def create(): description: ratio model_id: type: integer - description: ratio + description: model document csv_id: type: integer - description: ratio + description: csv document + emprise_id: + type: integer + description: emprise document responses: 200: description: OK @@ -165,7 +168,8 @@ def create(): nb_plaques_v=form['nb_plaques_v'], ratio=form['ratio'], model_id=form['model_id'], - csv_id=form['csv_id'] + csv_id=form['csv_id'], + emprise_id=form['emprise_id'] ) db.session.add(newproject) db.session.commit() diff --git a/app/schemas.py b/app/schemas.py index fd00aa1..ebf9e24 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -48,6 +48,7 @@ class ProjectsSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", only=("id",), many=False) model = ma.Nested("DocumentOnlySchema", only=("id",), many=False) csv = ma.Nested("DocumentOnlySchema", only=("id",), many=False) + emprise = ma.Nested("DocumentOnlySchema", only=("id",), many=False) class Meta: model = Projects From 4d7a225da88d395924d6c7feaeab5d433d56ddf3 Mon Sep 17 00:00:00 2001 From: Romain MATIAS Date: Tue, 5 Dec 2023 02:21:04 +0100 Subject: [PATCH 3/5] fix: varchar bbox --- sql/create-tables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/create-tables.sql b/sql/create-tables.sql index 2a73981..8a5c3ee 100644 --- a/sql/create-tables.sql +++ b/sql/create-tables.sql @@ -67,7 +67,7 @@ CREATE TABLE base.projects ( id serial PRIMARY KEY, date_create timestamp without time zone NOT NULL DEFAULT now(), name character varying(100) NOT NULL, - bbox character varying(100) NOT NULL, + bbox character varying(1000) NOT NULL, nb_plaques_h INT NOT NULL , nb_plaques_v INT NOT NULL , ratio INT NOT NULL, From ab4d561a11ce956b174b5923d11c0b2569b2e268 Mon Sep 17 00:00:00 2001 From: Romain MATIAS Date: Tue, 5 Dec 2023 02:43:48 +0100 Subject: [PATCH 4/5] fix: facultative _id in projects --- app/modules/projects/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/projects/views.py b/app/modules/projects/views.py index ade07e7..6a8c6ee 100644 --- a/app/modules/projects/views.py +++ b/app/modules/projects/views.py @@ -158,7 +158,7 @@ def create(): if currentUser: # Get Body of request form = request.json - if 'model_id' in form and 'csv_id' in form and 'name' in form and 'bbox' in form and 'nb_plaques_h' in form and 'nb_plaques_v' in form and 'ratio' in form: + if 'name' in form and 'bbox' in form and 'nb_plaques_h' in form and 'nb_plaques_v' in form and 'ratio' in form: newproject = Projects( date_create=datetime.datetime.utcnow(), user_id=currentUser['user_id'], From c91d323c1897a731859d6d75186c72c083ab9c2c Mon Sep 17 00:00:00 2001 From: Romain MATIAS Date: Tue, 5 Dec 2023 03:08:27 +0100 Subject: [PATCH 5/5] fix: again facultative id --- app/modules/projects/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/modules/projects/views.py b/app/modules/projects/views.py index 6a8c6ee..1f133de 100644 --- a/app/modules/projects/views.py +++ b/app/modules/projects/views.py @@ -167,9 +167,9 @@ def create(): nb_plaques_h=form['nb_plaques_h'], nb_plaques_v=form['nb_plaques_v'], ratio=form['ratio'], - model_id=form['model_id'], - csv_id=form['csv_id'], - emprise_id=form['emprise_id'] + model_id=form['model_id'] if 'model_id' in form else None, + csv_id=form['csv_id'] if 'csv_id' in form else None, + emprise_id=form['emprise_id'] if 'emprise_id' in form else None ) db.session.add(newproject) db.session.commit()