diff --git a/service/planner/db/config.json b/service/planner/db/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d6ad9c80de30d4ef0e36a67aa3c3b648a8c6a78a --- /dev/null +++ b/service/planner/db/config.json @@ -0,0 +1,6 @@ +{ + "addr": ":3306", + "dbName": "planner", + "user": "root", + "passwd": "secret" +} \ No newline at end of file diff --git a/service/planner/db/init.sql b/service/planner/db/init.sql new file mode 100644 index 0000000000000000000000000000000000000000..7259ad373a8f60ce8a2d7711911f2278f00943bc --- /dev/null +++ b/service/planner/db/init.sql @@ -0,0 +1,50 @@ +CREATE DATABASE IF NOT EXISTS planner; +USE planner; + +CREATE TABLE IF NOT EXISTS `userAccount` ( + `id` int NOT NULL AUTO_INCREMENT, + `mail` varchar(255) NOT NULL, + `firstName` varchar(255) NOT NULL, + `lastName` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE IF NOT EXISTS `userGroup` ( + `id` int NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +); + +CREATE TABLE IF NOT EXISTS `userMeal` ( + `id` int NOT NULL AUTO_INCREMENT, + `userId` int NOT NULL, + `mealId` int NOT NULL, + `date` DATE NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`userId`) REFERENCES userAccount(`id`) +); + +CREATE TABLE IF NOT EXISTS `groupMeal` ( + `id` int NOT NULL AUTO_INCREMENT, + `groupId` int NOT NULL, + `mealId` int NOT NULL, + `date` DATE NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`groupId`) REFERENCES userGroup(`id`) +); + +CREATE TABLE IF NOT EXISTS `shoppingDate` ( + `id` int NOT NULL AUTO_INCREMENT, + `userId` int NOT NULL, + `date` DATE NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`userId`) REFERENCES userAccount(`id`) +); + +CREATE TABLE IF NOT EXISTS `userGroupRelation` ( + `id` int NOT NULL AUTO_INCREMENT, + `groupId` int NOT NULL, + `userId` int NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`groupId`) REFERENCES userGroup(`id`), + FOREIGN KEY (`userId`) REFERENCES userAccount(`id`) +); \ No newline at end of file diff --git a/service/planner/model/group.go b/service/planner/model/group.go index 593f78ac438a1b40165c9c229e26d69ab1dd3bb9..4a4d419b6d8f4908b2c0fcf6388a76893aab1a8a 100644 --- a/service/planner/model/group.go +++ b/service/planner/model/group.go @@ -1,7 +1,7 @@ package model type Group struct { - ID uint `json:"id"` - UserIDs []uint `json:"userIds"` - Meals []MealGroup `json:"meals"` + ID int `json:"id"` + UserIDs []int `json:"userIds"` + Meals []GroupMeal `json:"meals"` } diff --git a/service/planner/model/meal.go b/service/planner/model/meal.go index 003f5004fc96e4cbbc130d4fc79679d151d4ddb8..4f615657a5c46f2e6f11e05939652bc95f10f748 100644 --- a/service/planner/model/meal.go +++ b/service/planner/model/meal.go @@ -1,16 +1,13 @@ package model -type Meal struct { +type UserMeal struct { + UserID int `json:"userId"` MealID int `json:"mealId"` Date string `json:"date"` } -type MealUser struct { - UserID uint `json:"userId"` - Meal -} - -type MealGroup struct { - GroupID uint `json:"groupId"` - Meal +type GroupMeal struct { + GroupID int `json:"groupId"` + MealID int `json:"mealId"` + Date string `json:"date"` } diff --git a/service/planner/model/shopping.go b/service/planner/model/shopping.go index a87ec8341760e0214f7a4600ed043bbf6933bf6a..23b3aad963d9ea8262744f35530204fa85853d54 100644 --- a/service/planner/model/shopping.go +++ b/service/planner/model/shopping.go @@ -1,6 +1,6 @@ package model type ShoppingDate struct { - UserID uint `json:"userId"` + UserID int `json:"userId"` Date string `json:"date"` } diff --git a/service/planner/model/user.go b/service/planner/model/user.go index 8b2fc831db90ae653bede4e76b11fe2e49fb8eb6..134adff7d93b241a55bac23c4e8b9c991c3c162b 100644 --- a/service/planner/model/user.go +++ b/service/planner/model/user.go @@ -1,10 +1,10 @@ package model type User struct { - ID uint `json:"id"` + ID int `json:"id"` Mail string `json:"mail"` FirstName string `json:"firstName"` LastName string `json:"lastName"` - Meals []MealUser `json:"meals"` + Meals []UserMeal `json:"meals"` ShoppingDates []ShoppingDate `json:"shoppingDates"` }