Base Project

This commit is contained in:
Tran Anh Tuan
2026-05-08 14:32:24 +07:00
parent 5a9249c9ea
commit 6a4a96e0ca
74 changed files with 6749 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package mapper
import (
"wm-backend/internal/models"
db "wm-backend/sqlc_gen"
"github.com/jackc/pgx/v5/pgtype"
)
// ToDomainRole maps a SQLC-generated Role to the domain Role model.
func ToDomainRole(r db.Role) *models.Role {
return &models.Role{
ID: r.ID.String(),
Name: r.Name,
Description: r.Description.String,
CreatedAt: r.CreatedAt.Time,
CreatedBy: r.CreatedBy.String,
}
}
// ToModelRole maps a domain Role model to the parameters needed for creating a Role in the database.
func ToModelRole(r *models.Role) *db.CreateRoleParams {
return &db.CreateRoleParams{
Name: r.Name,
Description: pgtype.Text{String: r.Description, Valid: r.Description != ""},
CreatedBy: pgtype.Text{String: r.CreatedBy, Valid: r.CreatedBy != ""},
}
}

View File

@@ -0,0 +1,21 @@
package mapper
import (
"wm-backend/internal/models"
db "wm-backend/sqlc_gen"
)
// toDomainUser maps a SQLC-generated User to the domain User model.
func ToDomainUser(u db.User) *models.User {
return &models.User{
ID: u.ID.String(),
Username: u.Username,
Email: u.Email,
FullName: u.FullName.String,
PasswordHash: u.PasswordHash,
IsActive: u.IsActive.Bool,
CreatedAt: u.CreatedAt.Time,
UpdatedAt: u.UpdatedAt.Time,
CreatedBy: u.CreatedBy.String,
}
}

View File

@@ -0,0 +1,51 @@
package mapper
import (
"wm-backend/internal/models"
db "wm-backend/sqlc_gen"
"github.com/jackc/pgx/v5/pgtype"
)
// ToDomainWarehouse maps a SQLC-generated Warehouse to the domain Warehouse model.
func ToDomainWarehouse(r db.Warehouse) *models.Warehouse {
return &models.Warehouse{
ID: r.ID,
Name: r.Name,
Description: r.Description.String,
Address: r.Address.String,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
}
}
func ToModelWarehouse(r *models.Warehouse) *db.CreateWarehouseParams {
return &db.CreateWarehouseParams{
Name: r.Name,
Description: pgtype.Text{
String: r.Description,
Valid: r.Description != "",
},
Address: pgtype.Text{
String: r.Address,
Valid: r.Address != "",
},
CreatedAt: r.CreatedAt,
}
}
func ToUpdateModelWarehouse(r *models.Warehouse) *db.UpdateWarehouseParams {
return &db.UpdateWarehouseParams{
Name: r.Name,
Description: pgtype.Text{
String: r.Description,
Valid: r.Description != "",
},
Address: pgtype.Text{
String: r.Address,
Valid: r.Address != "",
},
UpdatedAt: r.UpdatedAt,
ID: r.ID,
}
}