diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs
index 1a07954..5494860 100644
--- a/misc/BreCalApi.cs
+++ b/misc/BreCalApi.cs
@@ -1,7 +1,7 @@
//----------------------
//
-// Generated REST API Client Code Generator v1.16.0.0 on 05.12.2024 18:21:44
+// Generated REST API Client Code Generator v1.16.0.0 on 10.12.2024 08:56:03
// Using the tool OpenAPI Generator v7.9.0
//
//----------------------
@@ -46,7 +46,7 @@ using System.Threading.Tasks;
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -850,7 +850,7 @@ namespace BreCalClient.misc.Api
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -1505,7 +1505,7 @@ namespace BreCalClient.misc.Api
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -2450,7 +2450,7 @@ namespace BreCalClient.misc.Api
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -3269,7 +3269,7 @@ namespace BreCalClient.misc.Api
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -3754,7 +3754,7 @@ namespace BreCalClient.misc.Api
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -4474,7 +4474,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -4534,7 +4534,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -4674,7 +4674,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -4898,7 +4898,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5357,7 +5357,7 @@ namespace BreCalClient.misc.Client
string report = "C# SDK (BreCalClient.misc) Debug Report:\n";
report += " OS: " + System.Environment.OSVersion + "\n";
report += " .NET Framework Version: " + System.Environment.Version + "\n";
- report += " Version of the API: 1.6.0\n";
+ report += " Version of the API: 1.7.0\n";
report += " SDK Package Version: 1.0.0\n";
return report;
}
@@ -5426,7 +5426,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5446,7 +5446,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5503,7 +5503,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5536,7 +5536,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5569,7 +5569,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5660,7 +5660,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5777,7 +5777,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -5861,7 +5861,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6120,7 +6120,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6148,7 +6148,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6218,7 +6218,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6245,7 +6245,7 @@ namespace BreCalClient.misc.Client
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6312,7 +6312,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6477,7 +6477,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6568,7 +6568,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6656,7 +6656,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6697,7 +6697,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6822,7 +6822,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6887,7 +6887,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -6915,7 +6915,7 @@ namespace BreCalClient.misc.Model
/// notifyPopup.
/// exp.
/// token.
- public LoginResult(int id = default(int), int participantId = default(int), string firstName = default(string), string lastName = default(string), string userName = default(string), string userPhone = default(string), string userEmail = default(string), bool notifyEmail = default(bool), bool notifyWhatsapp = default(bool), bool notifySignal = default(bool), bool notifyPopup = default(bool), float exp = default(float), string token = default(string))
+ public LoginResult(int id = default(int), int participantId = default(int), string firstName = default(string), string lastName = default(string), string userName = default(string), string userPhone = default(string), string userEmail = default(string), bool? notifyEmail = default(bool?), bool? notifyWhatsapp = default(bool?), bool? notifySignal = default(bool?), bool? notifyPopup = default(bool?), float exp = default(float), string token = default(string))
{
this.Id = id;
this.ParticipantId = participantId;
@@ -6994,7 +6994,7 @@ namespace BreCalClient.misc.Model
true
*/
[DataMember(Name = "notify_email", EmitDefaultValue = true)]
- public bool NotifyEmail { get; set; }
+ public bool? NotifyEmail { get; set; }
///
/// Gets or Sets NotifyWhatsapp
///
@@ -7002,7 +7002,7 @@ namespace BreCalClient.misc.Model
false
*/
[DataMember(Name = "notify_whatsapp", EmitDefaultValue = true)]
- public bool NotifyWhatsapp { get; set; }
+ public bool? NotifyWhatsapp { get; set; }
///
/// Gets or Sets NotifySignal
///
@@ -7010,7 +7010,7 @@ namespace BreCalClient.misc.Model
false
*/
[DataMember(Name = "notify_signal", EmitDefaultValue = true)]
- public bool NotifySignal { get; set; }
+ public bool? NotifySignal { get; set; }
///
/// Gets or Sets NotifyPopup
///
@@ -7018,7 +7018,7 @@ namespace BreCalClient.misc.Model
false
*/
[DataMember(Name = "notify_popup", EmitDefaultValue = true)]
- public bool NotifyPopup { get; set; }
+ public bool? NotifyPopup { get; set; }
///
/// Gets or Sets Exp
///
@@ -7084,7 +7084,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7203,7 +7203,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7235,7 +7235,12 @@ namespace BreCalClient.misc.Model
/// Enum TimeConflictResolved for value: time_conflict_resolved
///
[EnumMember(Value = "time_conflict_resolved")]
- TimeConflictResolved = 4
+ TimeConflictResolved = 4,
+ ///
+ /// Enum Unassigned for value: unassigned
+ ///
+ [EnumMember(Value = "unassigned")]
+ Unassigned = 5
}
}
@@ -7244,7 +7249,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7275,7 +7280,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7316,7 +7321,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7516,7 +7521,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7598,7 +7603,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7736,7 +7741,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -7948,7 +7953,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -8354,7 +8359,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -8395,7 +8400,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
@@ -8750,7 +8755,7 @@ namespace BreCalClient.misc.Model
*
* Administer DEBRE ship calls, times and notifications
*
- * The version of the OpenAPI document: 1.6.0
+ * The version of the OpenAPI document: 1.7.0
* Contact: info@textbausteine.net
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml
index e873d8f..a51bd29 100644
--- a/misc/BreCalApi.yaml
+++ b/misc/BreCalApi.yaml
@@ -1700,21 +1700,27 @@ components:
example: johndoe
user_phone:
type: string
+ nullable: true
example: '1234567890'
user_email:
type: string
+ nullable: true
example: no@where.com
notify_email:
type: boolean
+ nullable: true
example: true
notify_whatsapp:
type: boolean
+ nullable: true
example: false
notify_signal:
type: boolean
+ nullable: true
example: false
notify_popup:
type: boolean
+ nullable: true
example: false
exp:
type: number
@@ -1838,6 +1844,7 @@ components:
- next24h
- time_conflict
- time_conflict_resolved
+ - unassigned
example: time_conflict
EvaluationType:
description: Evaluation of the ship call
diff --git a/misc/notifications.md b/misc/notifications.md
new file mode 100644
index 0000000..fe45835
--- /dev/null
+++ b/misc/notifications.md
@@ -0,0 +1,103 @@
+# Benachrichtigungen
+
+___
+
+## Benachrichtigungs-Typen (Auslöser)
+
+### 1. Teilnehmer wird zugeordnet
+
+Ein Teilnehmer wird über die Anwendung einem Anlauf zugeordnet. Dies ist entweder die Agentur (durch BSMD zugeordnet) oder ein weiterer Teilnehmer außer dem Hafenamt, der durch die Agentur zugeordnet wird. Die Zuordnung des Hafenamts erfolgt automatisch bei Anlage des Anlaufs.
+
+### 2. Morgenrunde ist relevant
+
+Ein Teilnehmer ist einem Anlauf zugeordnet. Dieser Anlauf findet in den nächsten 24 Stunden statt und ist daher für die "Morgenrunde" relevant. Der Teilnehmer erhält dazu eine Benachrichtigung.
+
+### 3. Zeitlicher Konflikt ("Ampel")
+
+Durch unterschiedliche Zeitangaben der Teilnehmer wird die Ampel ausgelöst und stellt eine entsprechende Fehlermeldung dar. Die Benachrichtigung wird ausgelöst bei folgenden Ampel-Wechseln:
+
+* grün -> gelb
+* grün -> rot
+* gelb -> rot
+
+### 4. Auflösung zeitl. Konflikt
+
+* rot -> gelb
+* rot -> grün
+* gelb -> grün
+
+### 5. Abwählen eines Teilnehmer
+
+Der Teilnehmer ist nicht mehr länger dem Anlauf zugeordnet.
+
+## API
+
+```yaml
+ NotificationType:
+ type: string
+ description: Type of notification
+ enum:
+ - assignment
+ - next24h
+ - time_conflict
+ - time_conflict_resolved
+ - unassigned
+```
+
+## Entfernen von Benachrichtigungen
+
+Unter den folgenden Voraussetzungen werden Benachrichtigungen wieder aus dem System entfernt:
+
+* Die Benachrichtigung ist älter als 3 Tage (n.B.: Zeitraum definieren)
+* Ein Teilnehmer wird wieder abgewählt
+* Ein zeitlicher Konflikt wird aufgelöst
+
+## Ablauf der Benachrichtigungen
+
+Eine Benachrichtung enthält folgende Informationen:
+
+* Verweis auf den Anlauf (shipcall)
+* ein Erstell- und Änderungsdatum
+* einen Benachrichtigungs-Typ
+* einen Zustand ("level")
+
+Der Zustand steuert den Ablauf, wenn die Prüfungsfunktion die Anläufe durchsucht oder ein Anlauf gespeichert wird.
+
+Wird einer der Zustände 1-3 erkannt wird geprüft, ob bereits eine Benachrichtigung vorhanden ist. Ist dies nicht der Fall, wird eine Benachrichtigung neu erstellt im Zustand "0".
+
+Die Prüfungsfunktion durchläuft alle Benachrichtigungen. Abhängig vom Zustand (0-2) werden folgende Aktionen ausgeführt:
+
+* Ist die Benachrichtigung um Zustand "0" und sind mind. 10 Minuten vergangen, wird die Benachrichtigung in den Zustand "1" versetzt.
+
+* Ist die Benachrichtigung im Zustand "1" wird versucht, allen dafür eingetragenenen Benutzern eine E-Mail zu senden. Ist dies erfolgreich, wechselt die Benachrichtigung in den Zustand "2".
+
+* Ist die Benachrichtigung im Zustand "2" und sind mind. 3 Tage vergangen wird die Benachrichtigung gelöscht.
+
+```mermaid
+---
+title: Ablauf
+---
+stateDiagram-v2
+ state "Level 0" as lvl0
+ state "Level 1" as lvl1
+ state "Level 2" as lvl2
+ [*] --> lvl0: Zustand 1-3 erkannt
+ lvl0 --> lvl1: +10 min.
+ lvl1 --> lvl2: E-Mail Versand erfolgt
+ lvl2 --> [*]: +3 Tage ODER Zustand 1-3 nicht mehr relevant
+
+
+ lvl0 --> [*]: Zustand 1-3 nicht mehr relevant
+
+```
+
+## Bemerkungen
+
+Für die Zukunft sind ggf. auch Benachrichtigungen via Whatsapp/Signal geplant. Diese verhalten sich analog zu den E-Mail Benachrichtigungen und werden nur einmal versendet. Die Anzahl der Zustände wird dabei erhöht bzw. der Wechsel in den Endzustand ensprechend angepasst.
+
+## Benachrichtigungstext
+
+... TBD
+
+
+
diff --git a/misc/update_1.6_to_1.7.sql b/misc/update_1.6_to_1.7.sql
new file mode 100644
index 0000000..14834d3
--- /dev/null
+++ b/misc/update_1.6_to_1.7.sql
@@ -0,0 +1,10 @@
+ALTER TABLE `notification`
+ADD COLUMN `participant_id` INT UNSIGNED NULL DEFAULT NULL AFTER `shipcall_id`,
+ADD INDEX `FK_NOTIFICATION_PARTICIPANT_idx` (`participant_id` ASC) VISIBLE;
+;
+ALTER TABLE `notification`
+ADD CONSTRAINT `FK_NOTIFICATION_PARTICIPANT`
+ FOREIGN KEY (`participant_id`)
+ REFERENCES `participant` (`id`)
+ ON DELETE RESTRICT
+ ON UPDATE RESTRICT;
diff --git a/misc/weserport.md b/misc/weserport.md
new file mode 100644
index 0000000..45cb48a
--- /dev/null
+++ b/misc/weserport.md
@@ -0,0 +1,10 @@
+# Schnittstelle Weserport Anforderungen
+
+##
+
+Automatische Zuordnung:
+
+* Hafenamt
+* Festmacher
+* Lotsen (>120m l 13m br)
+
diff --git a/src/server/BreCal/database/sql_utils.py b/src/server/BreCal/database/sql_utils.py
index 7c9708d..c914986 100644
--- a/src/server/BreCal/database/sql_utils.py
+++ b/src/server/BreCal/database/sql_utils.py
@@ -1,4 +1,5 @@
from BreCal.database.sql_handler import execute_sql_query_standalone
+
import datetime
def get_user_data_for_id(user_id:int, expiration_time:int=90):
@@ -33,4 +34,10 @@ def get_port_ids_for_participant_id(participant_id:int):
"""helper function to load all port ids for a participant"""
query = "SELECT port_id FROM participant_port_map where participant_id = ?participant_id?"
pdata = execute_sql_query_standalone(query=query, param={"participant_id":participant_id})
+ return pdata
+
+def get_notification_for_shipcall_and_type(shipcall_id:int, notification_type:int):
+ """helper function to load a notification for a shipcall and a specific type"""
+ query = "SELECT * FROM notification where shipcall_id = ?shipcall_id? and type = ?type?"
+ pdata = execute_sql_query_standalone(query=query, param={"shipcall_id":shipcall_id, "type":notification_type}, command_type="query")
return pdata
\ No newline at end of file
diff --git a/src/server/BreCal/impl/notifications.py b/src/server/BreCal/impl/notifications.py
index 0fc39c7..57fe62c 100644
--- a/src/server/BreCal/impl/notifications.py
+++ b/src/server/BreCal/impl/notifications.py
@@ -19,7 +19,7 @@ def GetNotifications(options):
commands = pydapper.using(pooledConnection)
# query = SQLQuery.get_notifications()
# data = commands.query(query, model=model.Notification.from_query_row, param={"scid" : options["shipcall_id"]})
- data = commands.query("SELECT id, shipcall_id, level, type, message, created, modified FROM notification " +
+ data = commands.query("SELECT id, shipcall_id, participant_id, level, type, message, created, modified FROM notification " +
"WHERE shipcall_id = ?scid?", model=model.Notification.from_query_row, param={"scid" : options["shipcall_id"]})
pooledConnection.close()
diff --git a/src/server/BreCal/impl/shipcalls.py b/src/server/BreCal/impl/shipcalls.py
index 326d70c..3fe6c2c 100644
--- a/src/server/BreCal/impl/shipcalls.py
+++ b/src/server/BreCal/impl/shipcalls.py
@@ -8,6 +8,7 @@ from .. import local_db
from ..services.auth_guard import check_jwt
from BreCal.database.update_database import evaluate_shipcall_state
+from BreCal.database.sql_utils import get_notification_for_shipcall_and_type
from BreCal.database.sql_queries import create_sql_query_shipcall_get, create_sql_query_shipcall_post, create_sql_query_shipcall_put, create_sql_query_history_post, create_sql_query_history_put, SQLQuery
from marshmallow import Schema, fields, ValidationError
from BreCal.validators.validation_error import create_validation_error_response
@@ -137,9 +138,11 @@ def PostShipcalls(schemaModel):
if 'participants' in schemaModel:
# pquery = SQLQuery.get_shipcall_post_update_shipcall_participant_map()
pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
+ nquery = "INSERT INTO notification (shipcall_id, participant_id, level, type) VALUES (?shipcall_id?, ?participant_id?, 0, 1)" # type = 1 is assignment
+
for participant_assignment in schemaModel["participants"]:
commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
- # TODO: Create assignment notification for each participant
+ commands.execute(nquery, param={"shipcall_id" : new_id, "participant_id" : participant_assignment["participant_id"]})
# apply 'Traffic Light' evaluation to obtain 'GREEN', 'YELLOW' or 'RED' evaluation state. The function internally updates the mysql database
# evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=new_id) # new_id (last insert id) refers to the shipcall id
@@ -233,6 +236,8 @@ def PutShipcalls(schemaModel):
# loop across passed participant ids, creating entries for those not present in pdata
+ existing_notifications = get_notification_for_shipcall_and_type(schemaModel["id"], 1) # type = 1 is assignment
+
for participant_assignment in schemaModel["participants"]:
found_participant = False
for elem in pdata:
@@ -241,8 +246,18 @@ def PutShipcalls(schemaModel):
break
if not found_participant:
# nquery = SQLQuery.get_shipcall_post_update_shipcall_participant_map()
- nquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
- commands.execute(nquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
+ spquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
+ commands.execute(spquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
+
+ # create a notification but only if there is no existing notification in level 0
+ found_notification = False
+ for existing_notification in existing_notifications:
+ if existing_notification["participant_id"] == participant_assignment["participant_id"] and existing_notification["level"] == 1:
+ found_notification = True
+ break
+ if not found_notification:
+ nquery = "INSERT INTO notification (shipcall_id, participant_id, level, type) VALUES (?shipcall_id?, ?participant_id?, 0, 1)" # type = 1 is assignment
+ commands.execute(nquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : participant_assignment["participant_id"]})
# loop across existing pdata entries, deleting those not present in participant list
for elem in pdata:
@@ -250,14 +265,22 @@ def PutShipcalls(schemaModel):
for participant_assignment in schemaModel["participants"]:
if(participant_assignment["participant_id"] == elem["participant_id"] and participant_assignment["type"] == elem["type"]):
found_participant = True
- # TODO: Create assignment notification
-
break;
if not found_participant:
# dquery = SQLQuery.get_shipcall_participant_map_delete_by_id()
dquery = "DELETE FROM shipcall_participant_map WHERE id = ?existing_id?"
commands.execute(dquery, param={"existing_id" : elem["id"]})
- # TODO: Create un-assignment notification
+ # TODO: Create un-assignment notification but only if level > 0 else delete existing notification
+ for existing_notification in existing_notifications:
+ if existing_notification["participant_id"] == elem["participant_id"]:
+ if existing_notification["level"] == 0:
+ nquery = "DELETE FROM notification WHERE id = ?nid?"
+ commands.execute(nquery, param={"nid" : existing_notification["id"]})
+ else:
+ # create un-assignment notification
+ nquery = "INSERT INTO notification (shipcall_id, participant_id, level, type) VALUES (?shipcall_id?, ?participant_id?, 0, 5)"
+ commands.execute(nquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : elem["participant_id"]})
+ break
# save history data
# TODO: set ETA properly
diff --git a/src/server/BreCal/schemas/defs.py b/src/server/BreCal/schemas/defs.py
new file mode 100644
index 0000000..90a56b5
--- /dev/null
+++ b/src/server/BreCal/schemas/defs.py
@@ -0,0 +1,5 @@
+# Version: 1.7.0
+
+# Constants for the notification system
+NOTIFICATION_COOLDOWN = 600 # 10 minutes until a notification gets real
+NOTIFICATION_MAX_AGE_DAYS = 3 # 3 days until a notification gets deleted
\ No newline at end of file
diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py
index 29ab645..4ce7603 100644
--- a/src/server/BreCal/schemas/model.py
+++ b/src/server/BreCal/schemas/model.py
@@ -143,6 +143,7 @@ class Notification:
"""
id: int
shipcall_id: int # 'shipcall record that caused the notification'
+ participant_id: int # 'optional participant reference that needs to be specifically notified, if null all participants are notified'
level: int # 'severity of the notification'
type: NotificationType # 'type of the notification'
message: str # 'individual message'
@@ -161,8 +162,8 @@ class Notification:
}
@classmethod
- def from_query_row(self, id, shipcall_id, level, type, message, created, modified):
- return self(id, shipcall_id, level, NotificationType(type), message, created, modified)
+ def from_query_row(self, id, shipcall_id, participant_id, level, type, message, created, modified):
+ return self(id, shipcall_id, participant_id, level, NotificationType(type), message, created, modified)
@dataclass
class Participant(Schema):
diff --git a/src/server/BreCal/services/schedule_routines.py b/src/server/BreCal/services/schedule_routines.py
index 41241a7..33e19fa 100644
--- a/src/server/BreCal/services/schedule_routines.py
+++ b/src/server/BreCal/services/schedule_routines.py
@@ -55,11 +55,16 @@ def UpdateNotifications():
pooledConnection = getPoolConnection()
commands = pydapper.using(pooledConnection)
- query = "SELECT * FROM notification WHERE level = 0 AND created < DATE(NOW() - INTERVAL 10 MINUTES)"
+ query = "SELECT * FROM notification WHERE level = 0 AND created < DATE(NOW() - INTERVAL 10 MINUTE)"
data = commands.query(query, model=model.Notification)
for notification in data:
notification.level = 1
commands.update(notification)
+
+ # TODO
+ # send "real" notifications to user
+ # ... E-Mail, messenger
+
pooledConnection.close()
except Exception as ex:
logging.error(ex)
@@ -91,7 +96,7 @@ def setup_schedule(update_shipcalls_interval_in_minutes:int=60):
# placeholder: create/send notifications
# add_function_to_schedule__send_notifications(...)
-
+
return