Skip to content

add#1

Open
trungtranvn wants to merge 1 commit intocesc1802:masterfrom
trungtranvn:trungtran
Open

add#1
trungtranvn wants to merge 1 commit intocesc1802:masterfrom
trungtranvn:trungtran

Conversation

@trungtranvn
Copy link
Copy Markdown

No description provided.

"github.com/jinzhu/gorm"
)

func GetDB() *gorm.DB {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sau khi khởi tạo connect đến cơ sở dữ liệu, thì mình nên lưu lại cái connect đó để tái sử dụng. Không nên mỗi lần có request từ client thì tạo một connect mới

// return resp
//}

GetDB().Create(task)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mỗi lần GetDB() được gọi sẽ khởi tạo một connection mới tới db, nên rất tốn tài nguyên. Cần lưu ý cách sử dụng này

}

//contact.UserId = user
resp := task.Create()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ở chỗ này chưa có kiểm tra lỗi khi không tạo được task

}


func GetTasks() ([]*Task) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theo convention chuẩn của Go, thì 1 function nên trả về kết quả và error. Ví dụ func GetTasks() ([]*Task, error)

test string `json:"test"`
}

func GetUsers() ([]*Users) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chỗ này cũng tương tự, nên trả về kết quả và error

@cesc1802
Copy link
Copy Markdown
Owner

Những chức năng còn thiếu:

  • Chức năng login
  • Chức năng kiểm tra giới hạn số lượng task người dùng được phép tạo trong một ngày

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants