package dao import ( "errors" ) type UserRepository struct { //TODO: should contain db connection. Only a mockup for now } func NewUserRepository() *UserRepository { return &UserRepository{} } func (r *UserRepository) GetUserById(id string) (User, error) { for i := 0; i < len(usersList); i++ { if usersList[i].Id == id { return usersList[i], nil } } //TODO: create a more robust error type for handling user errors return User{}, errors.New("could not find user") } func (r *UserRepository) GetUserByUsername(username string) (User, error) { for i := 0; i < len(usersList); i++ { if usersList[i].Username == username { return usersList[i], nil } } //TODO: create a more robust error type for handling user errors return User{}, errors.New("could not find user") } func (r *UserRepository) AddUser(username string, password string) string { newUser := User{Id: "2", Username: username, PasswordHash: password} usersList = append(usersList, newUser) return newUser.Id } func (r *UserRepository) GetAllUsers() ([]User, error) { return usersList, nil } // mock user type User struct { Id string Username string PasswordHash string } var usersList = []User{ { Id: "1", Username: "cmtedouglas", PasswordHash: "$2a$14$xEOuOEjuA48ko4IFBjcmoOrtY0dWXMQOPhp0sfcWkUXEw.ABsNkfu", }, }