From 3c0e64bee953995d583b2dc76f8ab4201ec8ea73 Mon Sep 17 00:00:00 2001
From: Sercan Yesildal <sercan.yesildal@gmail.com>
Date: Mon, 10 Jul 2023 00:20:29 +0200
Subject: [PATCH] db added

---
 service/planner/db/config.json    |  6 ++++
 service/planner/db/init.sql       | 50 +++++++++++++++++++++++++++++++
 service/planner/model/group.go    |  6 ++--
 service/planner/model/meal.go     | 15 ++++------
 service/planner/model/shopping.go |  2 +-
 service/planner/model/user.go     |  4 +--
 6 files changed, 68 insertions(+), 15 deletions(-)
 create mode 100644 service/planner/db/config.json
 create mode 100644 service/planner/db/init.sql

diff --git a/service/planner/db/config.json b/service/planner/db/config.json
new file mode 100644
index 0000000..d6ad9c8
--- /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 0000000..7259ad3
--- /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 593f78a..4a4d419 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 003f500..4f61565 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 a87ec83..23b3aad 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 8b2fc83..134adff 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"`
 }
-- 
GitLab