Webservices
This commit is contained in:
74
services/db_schema/db_sql_schema.sql
Normal file
74
services/db_schema/db_sql_schema.sql
Normal file
@@ -0,0 +1,74 @@
|
||||
-- Run this query to create the OpenWeddingApp db
|
||||
|
||||
--
|
||||
-- Table structure for table `gallery`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `gallery`;
|
||||
CREATE TABLE `gallery` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`image_url` varchar(100) NOT NULL,
|
||||
`image_thumb_url` varchar(100) NOT NULL,
|
||||
`description` varchar(100) DEFAULT NULL,
|
||||
`author` int(11) NOT NULL,
|
||||
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `gallery_like`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `gallery_like`;
|
||||
CREATE TABLE `gallery_like` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`gallery_id` int(11) DEFAULT NULL,
|
||||
`user_id` int(11) DEFAULT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `presence`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `presence`;
|
||||
CREATE TABLE `presence` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) DEFAULT NULL,
|
||||
`will_be_present` tinyint(1) DEFAULT NULL,
|
||||
`notes` text DEFAULT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `token`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `token`;
|
||||
CREATE TABLE `token` (
|
||||
`token` varchar(255) NOT NULL,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
`expires` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (`token`)
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `user`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`surname` varchar(255) NOT NULL,
|
||||
`code` varchar(255) NOT NULL,
|
||||
`picture` text DEFAULT NULL,
|
||||
`admin` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`table` varchar(100) NOT NULL,
|
||||
`witness` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`invited_by` varchar(50) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
8
services/db_schema/tests and queries/test_suite.sql
Normal file
8
services/db_schema/tests and queries/test_suite.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
-- Wedding app test suite: creates posts for all users
|
||||
|
||||
insert into gallery (image_url, image_thumb_url,author)
|
||||
select
|
||||
CONCAT('https://picsum.photos/id/', id, '/2000/3000'),
|
||||
CONCAT('https://picsum.photos/id/', id, '/200/300'),
|
||||
id
|
||||
from `user`
|
||||
43
services/db_schema/tests and queries/useful_queries.sql
Normal file
43
services/db_schema/tests and queries/useful_queries.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
-- Useful queries
|
||||
|
||||
-- User presence
|
||||
SELECT
|
||||
u.name,
|
||||
u.surname,
|
||||
CASE WHEN p.will_be_present THEN 'Yes' ELSE 'No' END as will_be_present,
|
||||
p.notes,
|
||||
p.created as when_user_answered
|
||||
FROM presence p
|
||||
LEFT JOIN `user` u
|
||||
ON p.user_id = u.id
|
||||
|
||||
-- User started app
|
||||
SELECT
|
||||
u.name,
|
||||
u.surname,
|
||||
t.created AS logged_in
|
||||
FROM token t
|
||||
LEFT JOIN `user` u
|
||||
ON u.id = t.user_id
|
||||
ORDER BY logged_in ASC
|
||||
|
||||
-- Report
|
||||
SELECT
|
||||
u.name,
|
||||
u.surname,
|
||||
(SELECT t.created FROM token t WHERE t.user_id = u.id ORDER BY t.created ASC LIMIT 1) AS started_app,
|
||||
CASE WHEN p.will_be_present IS NULL THEN '⏳' ELSE (
|
||||
CASE WHEN p.will_be_present THEN '✅' ELSE '❌' END
|
||||
) END as will_be_present,
|
||||
p.created as when_user_answered,
|
||||
p.notes
|
||||
FROM `user` u
|
||||
LEFT JOIN presence p
|
||||
ON p.user_id = u.id
|
||||
GROUP BY u.id
|
||||
ORDER BY when_user_answered DESC, started_app DESC
|
||||
|
||||
-- Clear user token
|
||||
DELETE FROM token WHERE user_id = 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user