Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/240909 users #10

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ENV GO111MODULE=on \
WORKDIR /app

COPY ./server ./server
COPY ./middleware ./middleware
COPY go.mod .
COPY go.sum .

Expand All @@ -28,3 +29,4 @@ COPY .env .
EXPOSE 22250

ENTRYPOINT ["/bin/sh", "-c" , "./build/server"]

85 changes: 33 additions & 52 deletions db/init_db.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
-- dep.ADMIN definition
CREATE TABLE Users (
user_id INT NOT NULL AUTO_INCREMENT,
user_name VARCHAR(10) NOT NULL,
user_email VARCHAR(40) NOT NULL,
PRIMARY KEY (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;


CREATE TABLE ADMIN (
id INT NOT NULL AUTO_INCREMENT,
email varchar(255) NOT NULL,
Expand All @@ -9,62 +16,36 @@ CREATE TABLE ADMIN (
UNIQUE KEY ADMIN_unique (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

INSERT INTO ADMIN (email,passcode,admin_type,brand_id) VALUES
('[email protected]','$2a$12$cqXwxUhyP5bkcdoz7Tge1.6DgDeN9h4mqfTqMycCdm01K8rsKwbVG','SUPER',NULL);
-- INSERT INTO ADMIN (email,passcode,admin_type,brand_id) VALUES
-- ('[email protected]','$2a$12$cqXwxUhyP5bkcdoz7Tge1.6DgDeN9h4mqfTqMycCdm01K8rsKwbVG','SUPER',NULL);

CREATE TABLE Users (
user_id SERIAL PRIMARY KEY, --SERIAL: 자동으로 증가하는 정수 타입
--password_hash VARCHAR(255) NOT NULL,
user_name VARCHAR(10) NOT NULL,
--preferences JSONB
);

-- 카테고리 별 누적 시간 미포함
CREATE TABLE Categories (
categories_id SERIAL PRIMARY KEY,
user_id INT REFERENCES Users(user_id),
id INT NOT NULL AUTO_INCREMENT,
category_user_id INT,
color VARCHAR(7),
--start_time TIMESTAMP NOT NULL,
--end_time TIMESTAMP NOT NULL,
categories_title VARCHAR(20) NOT NULL,
categories_total_time INT NOT NULL DEFAULT 0,
);
title VARCHAR(20) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (category_user_id) REFERENCES Users(user_id) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

CREATE TABLE Blocks (
block_id SERIAL PRIMARY KEY,
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP NOT NULL,
duration time.Duration NOT NULL,
color VARCHAR(7) REFERENCES Categories(categories_id) ON DELETE CASCADE ON UPDATE NO ACTION,
background_image_url TEXT,
block_memo TEXT,
block_pin BOOLEAN NOT NULL,
);


-- CREATE TABLE CategoriesBlocks (
-- categories_id INT REFERENCES categories(categories_id),
-- block_id INT REFERENCES Blocks(block_id),
-- PRIMARY KEY(categories_id, block_id)
-- );

/* CREATE TABLE Tags (
tag_id SERIAL PRIMARY KEY,
tag_name VARCHAR(100) UNIQUE NOT NULL
);--? */

/* CREATE TABLE CategoriesTags (
categories_id INT REFERENCES categories(categories_id),
tag_id INT REFERENCES Tags(tag_id),
PRIMARY KEY(categories_id, tag_id)
); */
block_id INT NOT NULL AUTO_INCREMENT,
category_id INT,
start_time INT NOT NULL,
end_time INT NOT NULL,
duration INT NOT NULL,
color VARCHAR(7),
background_image_url VARCHAR(50),
block_memo VARCHAR(100),
PRIMARY KEY(block_id),
FOREIGN KEY (category_id) REFERENCES Categories(id) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

CREATE TABLE Calendar (
date DATE PRIMARY KEY,
representative_block_id INT REFERENCES Blocks(block_id),
);

-- CREATE TABLE CalendarBlocks (
-- date DATE REFERENCES Calendar(date),
-- block_id INT REFERENCES Blocks(block_id),
-- PRIMARY KEY(date, block_id)
-- );
date_id INT NOT NULL AUTO_INCREMENT,
representative_block_id INT,
PRIMARY KEY(date_id),
FOREIGN KEY (representative_block_id) REFERENCES Blocks(block_id) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
18 changes: 1 addition & 17 deletions docker-compose-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,4 @@ services:
- ./db/mysql:/var/lib/mysql/
- ./db/init_db.sql:/docker-entrypoint-initdb.d/init_1.sql

swagger-ui:
image: swaggerapi/swagger-ui
ports:
- "22251:8080"
volumes:
- ./swagger:/foo
environment:
- SWAGGER_JSON=/foo/api_dep.yaml

go-backend:
build: .
environment:
TZ: "Asia/Seoul"
ports:
- "22250:22250"
volumes:
- ./log:/app/log

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/go-sql-driver/mysql v1.8.1
github.com/gofiber/fiber/v2 v2.52.5
github.com/google/wire v0.6.0
github.com/jmoiron/sqlx v1.4.0
github.com/joho/godotenv v1.5.1
)

Expand All @@ -17,7 +18,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand All @@ -40,6 +41,7 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "taskbuddy",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.4",
"vue": "^3.4.37",
"vue-router": "4.4.3",
"vue3-cookies": "1.0.6"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.1.2",
"vite": "5.4.2"
}
}
File renamed without changes.
22 changes: 22 additions & 0 deletions server/controller/categoryController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package controller

import (
"lifelogger/server/di"
"lifelogger/server/domain/categories/dto"
"lifelogger/server/util/httpHelper"

"github.com/gofiber/fiber/v2"
)

type CategoryController struct{}

func (a *CategoryController) CreateCategory(c *fiber.Ctx) error {
reqDto := new(dto.CreateCategoryReqDto)
httpHelper.ParseBody(c, reqDto)

createCategoryService, cleanup := di.InjectCreateCategoryService()
defer cleanup()
createCategoryService.CreateCategory(*reqDto)

return c.SendStatus(200)
}
22 changes: 21 additions & 1 deletion server/controller/loginController.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package controller

import (
"lifelogger/server/di"
"lifelogger/server/domain/users/dto"
"lifelogger/server/service/users"
"lifelogger/server/util"
"lifelogger/server/util/cookies"

"github.com/gofiber/fiber/v2"
)

type LoginController struct{}
type LoginController struct {
UserService users.CreateUserService
}

func NewLoginController(userService users.CreateUserService) *LoginController {
return &LoginController{UserService: userService}
}

func (a *LoginController) Login(c *fiber.Ctx) error {
code := c.Query("code")
Expand All @@ -17,6 +26,17 @@ func (a *LoginController) Login(c *fiber.Ctx) error {
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Faild to retrieve user info")
}
//
// Users 테이블에 사용자 정보 저장
createUserService, cleanup := di.InjectCreateUserService()
defer cleanup()

// CreateUser에 사용자 이메일과 닉네임을 전달
createUserService.CreateUser(dto.CreateUserReqDto{
UserEmail: email,
UserName: nickname,
})
//
c.Cookie(cookies.MakeCookies("refreshToken", refreshToken)) // Refresh Token을 쿠키에 저장
c.Cookie(cookies.MakeCookies("accessToken", accessToken)) // Access Token을 쿠키에 저장
return c.SendString("hi, " + nickname + "!! \nYour email: " + email + "\nYour refreshToken: " + refreshToken)
Expand Down
22 changes: 22 additions & 0 deletions server/controller/userController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package controller

import (
"lifelogger/server/di"
"lifelogger/server/domain/users/dto"
"lifelogger/server/util/httpHelper"

"github.com/gofiber/fiber/v2"
)

type UserController struct{}

func (a *UserController) CreateUser(c *fiber.Ctx) error {
reqDto := new(dto.CreateUserReqDto)
httpHelper.ParseBody(c, reqDto)

createUserService, cleanup := di.InjectCreateUserService()
defer cleanup()
createUserService.CreateUser(*reqDto)

return c.SendStatus(200)
}
19 changes: 15 additions & 4 deletions server/di/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import (

"github.com/google/wire"

helloService "lifelogger/service/hello"
helloService "lifelogger/server/service/hello"

"lifelogger/config"
"lifelogger/config/domainEvent"
"lifelogger/util/mattermost"
categoriesModel "lifelogger/server/domain/categories/model"
categoryService "lifelogger/server/service/categories"

"lifelogger/server/config"
"lifelogger/server/config/domainEvent"
"lifelogger/server/util/mattermost"
)

var (
Expand Down Expand Up @@ -94,3 +97,11 @@ func InjectGetHelloService() helloService.GetHelloService {
)
return nil
}

func InjectCreateCategoryService() (categoryService.CreateCategoryService, func()) {
panic(wire.Build(
superSet,
categoriesModel.NewCategoriesRepository,
categoryService.NewCreateCategoryService,
))
}
26 changes: 25 additions & 1 deletion server/di/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading