Base Project
This commit is contained in:
28
internal/mapper/role_mapper.go
Normal file
28
internal/mapper/role_mapper.go
Normal 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 != ""},
|
||||
}
|
||||
}
|
||||
21
internal/mapper/user_mapper.go
Normal file
21
internal/mapper/user_mapper.go
Normal 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,
|
||||
}
|
||||
}
|
||||
51
internal/mapper/warehouse_mapper.go
Normal file
51
internal/mapper/warehouse_mapper.go
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user