frontend and backend base setup
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DatabaseURL string
|
||||
Port string
|
||||
}
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
viper.AddConfigPath(path)
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Config{
|
||||
DatabaseURL: viper.GetString("database.url"),
|
||||
Port: viper.GetString("server.port"),
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"actatempus_backend/internal/domain/entities"
|
||||
"actatempus_backend/internal/domain/repositories"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type PostgresUserRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewPostgresUserRepository(db *sql.DB) repositories.UserRepository {
|
||||
return &PostgresUserRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *PostgresUserRepository) Create(user *entities.User) error {
|
||||
_, err := r.db.Exec("INSERT INTO users (id, name, email, password) VALUES ($1, $2, $3, $4)",
|
||||
user.ID, user.Name, user.Email, user.Password)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *PostgresUserRepository) FindByEmail(email string) (*entities.User, error) {
|
||||
var user entities.User
|
||||
err := r.db.QueryRow("SELECT id, name, email, password FROM users WHERE email = $1", email).
|
||||
Scan(&user.ID, &user.Name, &user.Email, &user.Password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (r *PostgresUserRepository) FindByID(id string) (*entities.User, error) {
|
||||
var user entities.User
|
||||
err := r.db.QueryRow("SELECT id, name, email, password FROM users WHERE id = $1", id).
|
||||
Scan(&user.ID, &user.Name, &user.Email, &user.Password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
Reference in New Issue
Block a user