CRUD với GORM và Tests
Lập trìnhImplement CRUD operations và viết tests
Hướng dẫn
Lời giải
Implement UserRepository với: - Create, FindByID, FindAll, Update, Delete - Viết unit tests sử dụng in-memory SQLite - Test các edge cases
Code mẫu
package repository
import "gorm.io/gorm"
type User struct {
ID uint
Name string
Email string
}
type UserRepository struct {
db *gorm.DB
}
func NewUserRepository(db *gorm.DB) *UserRepository {
return &UserRepository{db: db}
}
// Viết các methods ở đây