Compare commits
4 Commits
c1e3e8939a
...
f68e9ee218
| Author | SHA1 | Date | |
|---|---|---|---|
| f68e9ee218 | |||
| 18f6d53998 | |||
| 4b8e878735 | |||
| 3f7da82ea6 |
@ -658,12 +658,12 @@ paths:
|
||||
- notification
|
||||
operationId: notificationsGet
|
||||
parameters:
|
||||
- name: shipcall_id
|
||||
- name: participant_id
|
||||
in: query
|
||||
required: false
|
||||
description: '**Id of ship call**. *Example: 52*. Id given in ship call list'
|
||||
description: '**Id of participant**. *Example: 7*. Id of logged in participant.'
|
||||
schema:
|
||||
$ref: '#/components/schemas/shipcallId'
|
||||
$ref: '#/components/schemas/participant_id'
|
||||
responses:
|
||||
'200':
|
||||
description: notification list
|
||||
|
||||
153
misc/Readme.md
153
misc/Readme.md
@ -48,3 +48,156 @@ DROP TABLE IF EXISTS `shipcall`;
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
```
|
||||
|
||||
## Schema
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
participant {
|
||||
INT id PK
|
||||
VARCHAR name
|
||||
VARCHAR street
|
||||
VARCHAR postal_code
|
||||
VARCHAR city
|
||||
INT type
|
||||
INT flags
|
||||
}
|
||||
port {
|
||||
INT id PK
|
||||
VARCHAR name
|
||||
CHAR locode
|
||||
}
|
||||
berth {
|
||||
INT id PK
|
||||
VARCHAR name
|
||||
BIT lock
|
||||
INT owner_id FK
|
||||
INT authority_id FK
|
||||
INT port_id FK
|
||||
BIT deleted
|
||||
}
|
||||
ship {
|
||||
INT id PK
|
||||
VARCHAR name
|
||||
INT imo
|
||||
VARCHAR callsign
|
||||
INT participant_id FK
|
||||
FLOAT length
|
||||
FLOAT width
|
||||
BIT is_tug
|
||||
INT bollard_pull
|
||||
INT eni
|
||||
BIT deleted
|
||||
}
|
||||
shipcall {
|
||||
INT id PK
|
||||
INT ship_id FK
|
||||
TINYINT type
|
||||
DATETIME eta
|
||||
DATETIME etd
|
||||
INT arrival_berth_id FK
|
||||
INT departure_berth_id FK
|
||||
INT port_id FK
|
||||
INT flags
|
||||
BIT tug_required
|
||||
BIT pilot_required
|
||||
}
|
||||
times {
|
||||
INT id PK
|
||||
INT shipcall_id FK
|
||||
INT participant_id FK
|
||||
INT berth_id FK
|
||||
INT participant_type
|
||||
DATETIME eta_berth
|
||||
DATETIME etd_berth
|
||||
DATETIME lock_time
|
||||
DATETIME zone_entry
|
||||
}
|
||||
notification {
|
||||
INT id PK
|
||||
INT shipcall_id FK
|
||||
INT participant_id FK
|
||||
TINYINT level
|
||||
TINYINT type
|
||||
}
|
||||
history {
|
||||
INT id PK
|
||||
INT participant_id FK
|
||||
INT user_id FK
|
||||
INT shipcall_id FK
|
||||
DATETIME timestamp
|
||||
DATETIME eta
|
||||
INT type
|
||||
INT operation
|
||||
}
|
||||
shipcall_participant_map {
|
||||
INT id PK
|
||||
INT shipcall_id FK
|
||||
INT participant_id FK
|
||||
INT type
|
||||
}
|
||||
shipcall_tug_map {
|
||||
INT id PK
|
||||
INT shipcall_id FK
|
||||
INT ship_id FK
|
||||
}
|
||||
participant_port_map {
|
||||
INT id PK
|
||||
INT participant_id FK
|
||||
INT port_id FK
|
||||
}
|
||||
user {
|
||||
INT id PK
|
||||
INT participant_id FK
|
||||
VARCHAR first_name
|
||||
VARCHAR last_name
|
||||
VARCHAR user_name
|
||||
VARCHAR user_email
|
||||
}
|
||||
role {
|
||||
INT id PK
|
||||
VARCHAR name
|
||||
VARCHAR description
|
||||
}
|
||||
securable {
|
||||
INT id PK
|
||||
VARCHAR name
|
||||
}
|
||||
role_securable_map {
|
||||
INT id PK
|
||||
INT role_id FK
|
||||
INT securable_id FK
|
||||
}
|
||||
user_role_map {
|
||||
INT id PK
|
||||
INT user_id FK
|
||||
INT role_id FK
|
||||
}
|
||||
|
||||
participant ||--o{ berth : owner_id
|
||||
participant ||--o{ berth : authority_id
|
||||
port ||--o{ berth : port_id
|
||||
participant ||--o{ ship : participant_id
|
||||
ship ||--o{ shipcall : ship_id
|
||||
berth ||--o{ shipcall : arrival_berth_id
|
||||
berth ||--o{ shipcall : departure_berth_id
|
||||
port ||--o{ shipcall : port_id
|
||||
shipcall ||--|| times : shipcall_id
|
||||
participant ||--|| times : participant_id
|
||||
berth ||--o{ times : berth_id
|
||||
shipcall ||--o{ notification : shipcall_id
|
||||
participant ||--o{ notification : participant_id
|
||||
participant ||--o{ history : participant_id
|
||||
user ||--o{ history : user_id
|
||||
shipcall ||--o{ history : shipcall_id
|
||||
shipcall ||--o{ shipcall_participant_map : shipcall_id
|
||||
participant ||--o{ shipcall_participant_map : participant_id
|
||||
shipcall ||--o{ shipcall_tug_map : shipcall_id
|
||||
ship ||--o{ shipcall_tug_map : ship_id
|
||||
participant ||--o{ participant_port_map : participant_id
|
||||
port ||--o{ participant_port_map : port_id
|
||||
participant ||--o{ user : participant_id
|
||||
user ||--o{ user_role_map : user_id
|
||||
role ||--o{ user_role_map : role_id
|
||||
role ||--o{ role_securable_map : role_id
|
||||
securable ||--o{ role_securable_map : securable_id
|
||||
```
|
||||
|
||||
46
misc/check_clear_double_times_entries.sql
Normal file
46
misc/check_clear_double_times_entries.sql
Normal file
@ -0,0 +1,46 @@
|
||||
-- Inspect duplicates first
|
||||
WITH duplicate_participants AS (
|
||||
SELECT
|
||||
shipcall_id,
|
||||
participant_type,
|
||||
COUNT(*) AS cnt
|
||||
FROM times
|
||||
GROUP BY shipcall_id, participant_type
|
||||
HAVING COUNT(*) > 1
|
||||
)
|
||||
SELECT
|
||||
t.*
|
||||
FROM times AS t
|
||||
JOIN duplicate_participants AS d
|
||||
ON d.shipcall_id = t.shipcall_id
|
||||
AND (d.participant_type <=> t.participant_type)
|
||||
ORDER BY t.shipcall_id, t.participant_type, t.id;
|
||||
|
||||
-- Delete all but the highest-id entry per (shipcall_id, participant_type)
|
||||
WITH ordered_times AS (
|
||||
SELECT
|
||||
id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY shipcall_id, participant_type
|
||||
ORDER BY id DESC
|
||||
) AS rn
|
||||
FROM times
|
||||
)
|
||||
DELETE FROM times
|
||||
WHERE id IN (
|
||||
SELECT id
|
||||
FROM ordered_times
|
||||
WHERE rn > 1
|
||||
);
|
||||
|
||||
-- Optional: re-check that no duplicates remain
|
||||
WITH duplicate_participants AS (
|
||||
SELECT
|
||||
shipcall_id,
|
||||
participant_type,
|
||||
COUNT(*) AS cnt
|
||||
FROM times
|
||||
GROUP BY shipcall_id, participant_type
|
||||
HAVING COUNT(*) > 1
|
||||
)
|
||||
SELECT COUNT(*) AS remaining_duplicates FROM duplicate_participants;
|
||||
@ -1,8 +1,8 @@
|
||||
-- MySQL dump 10.13 Distrib 8.0.33, for Win64 (x86_64)
|
||||
-- MySQL dump 10.13 Distrib 8.0.43, for Win64 (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: bremen_calling_test
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 8.0.34-0ubuntu0.22.04.1
|
||||
-- Server version 8.0.42-0ubuntu0.24.10.1
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
@ -28,15 +28,44 @@ CREATE TABLE `berth` (
|
||||
`lock` bit(1) DEFAULT NULL COMMENT 'The lock must be used',
|
||||
`owner_id` int unsigned DEFAULT NULL,
|
||||
`authority_id` int unsigned DEFAULT NULL,
|
||||
`port_id` int unsigned DEFAULT NULL,
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) DEFAULT b'0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_OWNER_PART_idx` (`owner_id`),
|
||||
KEY `FK_AUTHORITY_PART_idx` (`authority_id`),
|
||||
KEY `FK_AUTHORITY_PART_idx` (`authority_id`) /*!80000 INVISIBLE */,
|
||||
KEY `FK_PORT_PART_idx` (`port_id`),
|
||||
CONSTRAINT `FK_AUTHORITY_PART` FOREIGN KEY (`authority_id`) REFERENCES `participant` (`id`),
|
||||
CONSTRAINT `FK_OWNER_PART` FOREIGN KEY (`owner_id`) REFERENCES `participant` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=195 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Berth of ship for a ship call';
|
||||
CONSTRAINT `FK_OWNER_PART` FOREIGN KEY (`owner_id`) REFERENCES `participant` (`id`),
|
||||
CONSTRAINT `FK_PORT` FOREIGN KEY (`port_id`) REFERENCES `port` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=205 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Berth of ship for a ship call';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `history`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `history`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `history` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`participant_id` int unsigned NOT NULL,
|
||||
`user_id` int unsigned DEFAULT NULL,
|
||||
`shipcall_id` int unsigned NOT NULL,
|
||||
`timestamp` datetime NOT NULL COMMENT 'Time of saving',
|
||||
`eta` datetime DEFAULT NULL COMMENT 'Current ETA / ETD value (depends if shipcall or times were saved)',
|
||||
`type` int NOT NULL COMMENT 'shipcall or times',
|
||||
`operation` int NOT NULL COMMENT 'insert, update or delete',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_HISTORY_PARTICIPANT_idx` (`participant_id`),
|
||||
KEY `FK_HISTORY_SHIPCALL_idx` (`shipcall_id`),
|
||||
KEY `FK_HISTORY_USER` (`user_id`),
|
||||
CONSTRAINT `FK_HISTORY_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`),
|
||||
CONSTRAINT `FK_HISTORY_SHIPCALL` FOREIGN KEY (`shipcall_id`) REFERENCES `shipcall` (`id`),
|
||||
CONSTRAINT `FK_HISTORY_USER` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=23537 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='This table stores a history of changes made to shipcalls so that everyone can see who changed what and when';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
CREATE TABLE `history` (
|
||||
@ -67,20 +96,19 @@ DROP TABLE IF EXISTS `notification`;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `notification` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`times_id` int unsigned NOT NULL COMMENT 'times record that caused the notification',
|
||||
`participant_id` int unsigned NOT NULL COMMENT 'participant ref',
|
||||
`acknowledged` bit(1) DEFAULT b'0' COMMENT 'true if UI acknowledged',
|
||||
`shipcall_id` int unsigned DEFAULT NULL,
|
||||
`participant_id` int unsigned DEFAULT NULL,
|
||||
`level` tinyint DEFAULT NULL COMMENT 'severity of the notification',
|
||||
`type` tinyint DEFAULT NULL COMMENT 'Email/UI/Other',
|
||||
`message` varchar(256) DEFAULT NULL COMMENT 'individual message',
|
||||
`message` varchar(512) DEFAULT NULL COMMENT 'individual message',
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_NOT_TIMES` (`times_id`),
|
||||
KEY `FK_NOT_PART` (`participant_id`),
|
||||
CONSTRAINT `FK_NOT_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`),
|
||||
CONSTRAINT `FK_NOT_TIMES` FOREIGN KEY (`times_id`) REFERENCES `times` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='An entry corresponds to an alarm given by a violated rule during times update';
|
||||
KEY `FK_NOTIFICATION_SHIPCALL_idx` (`shipcall_id`),
|
||||
KEY `FK_NOTIFICATION_PARTICIPANT_idx` (`participant_id`),
|
||||
CONSTRAINT `FK_NOTIFICATION_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `FK_NOTIFICATION_SHIPCALL` FOREIGN KEY (`shipcall_id`) REFERENCES `shipcall` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10398 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='An entry corresponds to an alarm given by a violated rule during times update';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -102,7 +130,46 @@ CREATE TABLE `participant` (
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) DEFAULT b'0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='An organization taking part';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=160 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='An organization taking part';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `participant_port_map`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `participant_port_map`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `participant_port_map` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`participant_id` int unsigned NOT NULL COMMENT 'Ref to participant',
|
||||
`port_id` int unsigned NOT NULL COMMENT 'Ref to port',
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_PP_PARTICIPANT` (`participant_id`),
|
||||
KEY `FK_PP_PORT` (`port_id`),
|
||||
CONSTRAINT `FK_PP_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`),
|
||||
CONSTRAINT `FK_PP_PORT` FOREIGN KEY (`port_id`) REFERENCES `port` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=86 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Mapping table that assigns participants to a port';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `port`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `port`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `port` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(128) NOT NULL COMMENT 'Name of port',
|
||||
`locode` char(5) DEFAULT NULL COMMENT 'UNECE locode',
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) DEFAULT b'0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Port as reference for shipcalls and berths';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -185,7 +252,7 @@ CREATE TABLE `ship` (
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_SHIP_PARTICIPANT` (`participant_id`),
|
||||
CONSTRAINT `FK_SHIP_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=485 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -221,16 +288,25 @@ CREATE TABLE `shipcall` (
|
||||
`canceled` bit(1) DEFAULT NULL,
|
||||
`evaluation` int unsigned DEFAULT NULL,
|
||||
`evaluation_message` varchar(512) DEFAULT NULL,
|
||||
`evaluation_time` datetime DEFAULT NULL,
|
||||
`evaluation_notifications_sent` bit(1) DEFAULT NULL,
|
||||
`port_id` int unsigned NOT NULL DEFAULT '1' COMMENT 'Selected port for this shipcall',
|
||||
`time_ref_point` int DEFAULT '0' COMMENT 'Index of a location which is the reference point for all time value entries, e.g. berth or Geeste',
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_SHIPCALL_SHIP` (`ship_id`),
|
||||
KEY `FK_SHIPCALL_BERTH_ARRIVAL` (`arrival_berth_id`),
|
||||
KEY `FK_SHIPCALL_BERTH_DEPARTURE` (`departure_berth_id`),
|
||||
KEY `idx_shipcall_type` (`type`),
|
||||
KEY `idx_shipcall_eta` (`eta`),
|
||||
KEY `idx_shipcall_etd` (`etd`),
|
||||
KEY `FK_SHIPCALL_PORT_idx` (`port_id`),
|
||||
CONSTRAINT `FK_SHIPCALL_BERTH_ARRIVAL` FOREIGN KEY (`arrival_berth_id`) REFERENCES `berth` (`id`),
|
||||
CONSTRAINT `FK_SHIPCALL_BERTH_DEPARTURE` FOREIGN KEY (`departure_berth_id`) REFERENCES `berth` (`id`),
|
||||
CONSTRAINT `FK_SHIPCALL_PORT` FOREIGN KEY (`port_id`) REFERENCES `port` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `FK_SHIPCALL_SHIP` FOREIGN KEY (`ship_id`) REFERENCES `ship` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Incoming, outgoing or moving to another berth';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2789 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Incoming, outgoing or moving to another berth';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -244,15 +320,15 @@ CREATE TABLE `shipcall_participant_map` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`shipcall_id` int unsigned DEFAULT NULL,
|
||||
`participant_id` int unsigned DEFAULT NULL,
|
||||
`type` int unsigned DEFAULT NULL COMMENT 'Type of participant role',
|
||||
`type` int unsigned DEFAULT NULL,
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_MAP_PARTICIPANT_SHIPCALL` (`shipcall_id`),
|
||||
KEY `FK_MAP_SHIPCALL_PARTICIPANT` (`participant_id`),
|
||||
CONSTRAINT `FK_MAP_PARTICIPANT_SHIPCALL` FOREIGN KEY (`shipcall_id`) REFERENCES `shipcall` (`id`),
|
||||
CONSTRAINT `FK_MAP_PARTICIPANT_SHIPCALL` FOREIGN KEY (`shipcall_id`) REFERENCES `shipcall` (`id`) ON DELETE SET NULL,
|
||||
CONSTRAINT `FK_MAP_SHIPCALL_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=128 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Associates a participant with a shipcall';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=8933 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Associates a participant with a shipcall';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -304,13 +380,20 @@ CREATE TABLE `times` (
|
||||
`berth_info` varchar(512) DEFAULT NULL,
|
||||
`pier_side` bit(1) DEFAULT NULL,
|
||||
`participant_type` int unsigned DEFAULT NULL,
|
||||
`ata` datetime DEFAULT NULL COMMENT 'Relevant only for mooring, this field can be used to record actual ATA',
|
||||
`atd` datetime DEFAULT NULL COMMENT 'Relevant only for mooring, this field can be used to record actual ATD',
|
||||
`eta_interval_end` datetime DEFAULT NULL COMMENT 'If this value is set the times are given as interval instead of a single point in time. The start time value depends on the participant type.',
|
||||
`etd_interval_end` datetime DEFAULT NULL COMMENT 'If this value is set the times are given as interval instead of a single point in time. The start time value depends on the participant type.',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_shipcall_participant` (`shipcall_id`,`participant_type`),
|
||||
KEY `FK_TIME_SHIPCALL` (`shipcall_id`),
|
||||
KEY `FK_TIME_PART` (`participant_id`) /*!80000 INVISIBLE */,
|
||||
KEY `FK_TIME_BERTH` (`berth_id`) /*!80000 INVISIBLE */,
|
||||
KEY `idx_times_eta_berth` (`eta_berth`),
|
||||
KEY `idx_times_etd_berth` (`etd_berth`),
|
||||
CONSTRAINT `FK_TIME_BERTH` FOREIGN KEY (`berth_id`) REFERENCES `berth` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `FK_TIME_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='the planned time for the participants work';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=7863 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='the planned time for the participants work';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -322,7 +405,7 @@ DROP TABLE IF EXISTS `user`;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `user` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`participant_id` int unsigned DEFAULT NULL,
|
||||
`participant_id` int unsigned NOT NULL,
|
||||
`first_name` varchar(45) DEFAULT NULL,
|
||||
`last_name` varchar(45) DEFAULT NULL,
|
||||
`user_name` varchar(45) DEFAULT NULL,
|
||||
@ -330,12 +413,17 @@ CREATE TABLE `user` (
|
||||
`user_phone` varchar(128) DEFAULT NULL,
|
||||
`password_hash` varchar(128) DEFAULT NULL,
|
||||
`api_key` varchar(256) DEFAULT NULL,
|
||||
`notify_email` bit(1) DEFAULT NULL,
|
||||
`notify_whatsapp` bit(1) DEFAULT NULL,
|
||||
`notify_signal` bit(1) DEFAULT NULL,
|
||||
`notify_popup` bit(1) DEFAULT NULL,
|
||||
`notify_event` int DEFAULT NULL COMMENT 'Bitflag of selected notification event types that the user wants to be notified of',
|
||||
`created` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_USER_PART` (`participant_id`),
|
||||
CONSTRAINT `FK_USER_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='member of a participant';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='member of a participant';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -358,6 +446,57 @@ CREATE TABLE `user_role_map` (
|
||||
CONSTRAINT `FK_USER_ROLE` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Assigns a user to a role';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping routines for database 'bremen_calling_test'
|
||||
--
|
||||
/*!50003 DROP PROCEDURE IF EXISTS `delete_data` */;
|
||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
|
||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
|
||||
DELIMITER ;;
|
||||
CREATE DEFINER=`ds`@`localhost` PROCEDURE `delete_data`()
|
||||
BEGIN
|
||||
DECLARE shipcall_id_var int;
|
||||
DECLARE done INT DEFAULT FALSE;
|
||||
|
||||
DECLARE shipcall_iter CURSOR FOR
|
||||
SELECT shipcall.id FROM shipcall
|
||||
LEFT JOIN times ON
|
||||
times.shipcall_id = shipcall.id AND times.participant_type = 8
|
||||
WHERE
|
||||
-- ARRIVAL
|
||||
(type = 1 AND GREATEST(shipcall.eta, COALESCE(times.eta_berth, 0)) <= CURRENT_DATE() - INTERVAL 1 MONTH) OR
|
||||
-- DEPARTURE / SHIFTING
|
||||
(type != 1 AND GREATEST(shipcall.etd, COALESCE(times.etd_berth, 0)) <= CURRENT_DATE() - INTERVAL 1 MONTH);
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
||||
|
||||
OPEN shipcall_iter;
|
||||
|
||||
delete_loop: LOOP
|
||||
FETCH shipcall_iter INTO shipcall_id_var;
|
||||
IF done THEN
|
||||
LEAVE delete_loop;
|
||||
END IF;
|
||||
DELETE FROM shipcall_participant_map WHERE shipcall_id = shipcall_id_var;
|
||||
DELETE FROM shipcall_tug_map WHERE shipcall_id = shipcall_id_var;
|
||||
DELETE FROM times WHERE shipcall_id = shipcall_id_var;
|
||||
DELETE FROM history WHERE shipcall_id = shipcall_id_var;
|
||||
DELETE FROM shipcall WHERE id = shipcall_id_var;
|
||||
END LOOP;
|
||||
CLOSE shipcall_iter;
|
||||
END ;;
|
||||
DELIMITER ;
|
||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
@ -368,4 +507,4 @@ CREATE TABLE `user_role_map` (
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2023-10-06 14:52:04
|
||||
-- Dump completed on 2025-11-17 8:26:36
|
||||
|
||||
@ -14,7 +14,14 @@ def GetNotifications():
|
||||
try:
|
||||
if 'Authorization' in request.headers:
|
||||
token = request.headers.get('Authorization')
|
||||
return impl.notifications.GetNotifications(token)
|
||||
participant_id = None
|
||||
if 'participant_id' in request.args:
|
||||
try:
|
||||
participant_id = int(request.args.get('participant_id'))
|
||||
except (TypeError, ValueError):
|
||||
return create_dynamic_exception_response(ex=None, status_code=400, message="participant_id must be an integer")
|
||||
|
||||
return impl.notifications.GetNotifications(token, participant_id=participant_id)
|
||||
else:
|
||||
return create_dynamic_exception_response(ex=None, status_code=403, message="not authenticated")
|
||||
|
||||
|
||||
@ -7,12 +7,17 @@ from marshmallow import ValidationError
|
||||
from . import verify_if_request_is_json
|
||||
from BreCal.validators.validation_error import create_dynamic_exception_response, create_validation_error_response
|
||||
|
||||
import json
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
bp = Blueprint('user', __name__)
|
||||
|
||||
@bp.route('/user', methods=['put'])
|
||||
@auth_guard() # no restriction by role
|
||||
def PutUser():
|
||||
|
||||
content = None
|
||||
try:
|
||||
verify_if_request_is_json(request)
|
||||
|
||||
@ -21,9 +26,11 @@ def PutUser():
|
||||
return impl.user.PutUser(loadedModel)
|
||||
|
||||
except ValidationError as ex:
|
||||
logging.warning("UserSchema validation failed. Payload=%s", json.dumps(content, default=str))
|
||||
return create_validation_error_response(ex=ex, status_code=400)
|
||||
|
||||
except Exception as ex:
|
||||
logging.error("UserSchema load failed. Payload=%s\n%s", json.dumps(content, default=str), traceback.format_exc())
|
||||
return create_dynamic_exception_response(ex=None, status_code=400, message="bad format")
|
||||
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ def GetUser(options):
|
||||
"notify_whatsapp": data[0].notify_whatsapp,
|
||||
"notify_signal": data[0].notify_signal,
|
||||
"notify_popup": data[0].notify_popup,
|
||||
"notify_on": model.bitflag_to_list(data[0].notify_event)
|
||||
"notify_on": model.notification_types_to_names(model.bitflag_to_list(data[0].notify_event))
|
||||
}
|
||||
token = jwt_handler.generate_jwt(payload=result, lifetime=120) # generate token valid 60 mins
|
||||
result["token"] = token # add token to user data
|
||||
|
||||
@ -6,17 +6,22 @@ from ..schemas import model
|
||||
from .. import local_db
|
||||
from BreCal.database.sql_queries import SQLQuery
|
||||
|
||||
def GetNotifications(token):
|
||||
def GetNotifications(token, participant_id=None):
|
||||
"""
|
||||
No parameters, gets all entries
|
||||
Optional filtering by participant_id. Returns delivered (level=2) notifications.
|
||||
"""
|
||||
|
||||
pooledConnection = None
|
||||
try:
|
||||
pooledConnection = local_db.getPoolConnection()
|
||||
commands = pydapper.using(pooledConnection)
|
||||
data = commands.query("SELECT id, shipcall_id, participant_id, level, type, message, created, modified FROM notification " +
|
||||
"WHERE level = 2", model=model.Notification.from_query_row)
|
||||
query = "SELECT id, shipcall_id, participant_id, level, type, message, created, modified FROM notification WHERE level = 2"
|
||||
params = {}
|
||||
if participant_id is not None:
|
||||
query += " AND participant_id = ?participant_id?"
|
||||
params["participant_id"] = participant_id
|
||||
|
||||
data = commands.query(query, model=model.Notification.from_query_row, param=params if params else None)
|
||||
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
|
||||
@ -5,7 +5,7 @@ from marshmallow_enum import EnumField
|
||||
from enum import IntEnum
|
||||
|
||||
from marshmallow_dataclass import dataclass
|
||||
from typing import List
|
||||
from typing import Iterable, List
|
||||
|
||||
import json
|
||||
import re
|
||||
@ -85,19 +85,31 @@ class NotificationType(IntEnum):
|
||||
def _missing_(cls, value):
|
||||
return cls.undefined
|
||||
|
||||
def bitflag_to_list(bitflag: int) -> list[NotificationType]:
|
||||
def bitflag_to_list(bitflag: int | None) -> list[NotificationType]:
|
||||
"""Converts an integer bitflag to a list of NotificationType enums."""
|
||||
if bitflag is None:
|
||||
return []
|
||||
"""Converts an integer bitflag to a list of NotificationType enums."""
|
||||
return [nt for nt in NotificationType if bitflag & (1 << (nt.value - 1))]
|
||||
|
||||
def list_to_bitflag(notifications: fields.List) -> int:
|
||||
"""Converts a list of NotificationType enums to an integer bitflag."""
|
||||
try:
|
||||
iter(notifications)
|
||||
return sum(1 << (nt.value - 1) for nt in notifications)
|
||||
except TypeError as te:
|
||||
def list_to_bitflag(notifications: Iterable[NotificationType | str | int] | None) -> int:
|
||||
"""Converts a list of NotificationType enums (or their names/values) to an integer bitflag."""
|
||||
if not notifications:
|
||||
return 0
|
||||
bitflag = 0
|
||||
for nt in notifications:
|
||||
enum_val = None
|
||||
if isinstance(nt, NotificationType):
|
||||
enum_val = nt
|
||||
elif isinstance(nt, str):
|
||||
enum_val = NotificationType[nt]
|
||||
else:
|
||||
enum_val = NotificationType(nt)
|
||||
bitflag |= 1 << (enum_val.value - 1)
|
||||
return bitflag
|
||||
|
||||
def notification_types_to_names(notifications: Iterable[NotificationType]) -> list[str]:
|
||||
"""Render NotificationType values as their names for API responses."""
|
||||
return [nt.name for nt in notifications]
|
||||
|
||||
|
||||
class ShipcallType(IntEnum):
|
||||
@ -573,8 +585,7 @@ class User:
|
||||
notify_popup: bool
|
||||
created: datetime
|
||||
modified: datetime
|
||||
ports: List[NotificationType] = field(default_factory=list)
|
||||
notify_event: List[NotificationType] = field(default_factory=list)
|
||||
notify_event: int | None = 0
|
||||
|
||||
def __hash__(self):
|
||||
return hash(id)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user