fix: cast vpn_cidr to text in gateway repository queries
Add explicit ::text cast to vpn_cidr column in List, FirstActive, and Update queries to ensure proper type handling when scanning CIDR values from PostgreSQL.
This commit is contained in:
@@ -27,7 +27,7 @@ func NewPGRepository(db *pgxpool.Pool) *PGRepository {
|
|||||||
|
|
||||||
func (r *PGRepository) List(ctx context.Context) ([]Gateway, error) {
|
func (r *PGRepository) List(ctx context.Context) ([]Gateway, error) {
|
||||||
rows, err := r.db.Query(ctx, `
|
rows, err := r.db.Query(ctx, `
|
||||||
select id, name, endpoint, public_key, listen_port, vpn_cidr, dns_servers, is_active
|
select id, name, endpoint, public_key, listen_port, vpn_cidr::text, dns_servers, is_active
|
||||||
from gateways
|
from gateways
|
||||||
where deleted_at is null
|
where deleted_at is null
|
||||||
order by created_at desc
|
order by created_at desc
|
||||||
@@ -50,7 +50,7 @@ func (r *PGRepository) List(ctx context.Context) ([]Gateway, error) {
|
|||||||
|
|
||||||
func (r *PGRepository) FirstActive(ctx context.Context) (Gateway, error) {
|
func (r *PGRepository) FirstActive(ctx context.Context) (Gateway, error) {
|
||||||
row := r.db.QueryRow(ctx, `
|
row := r.db.QueryRow(ctx, `
|
||||||
select id, name, endpoint, public_key, listen_port, vpn_cidr, dns_servers, is_active
|
select id, name, endpoint, public_key, listen_port, vpn_cidr::text, dns_servers, is_active
|
||||||
from gateways
|
from gateways
|
||||||
where deleted_at is null and is_active = true
|
where deleted_at is null and is_active = true
|
||||||
order by created_at asc
|
order by created_at asc
|
||||||
@@ -128,7 +128,7 @@ func (r *PGRepository) Update(ctx context.Context, gatewayID uuid.UUID, input Up
|
|||||||
is_active = $7,
|
is_active = $7,
|
||||||
updated_at = now()
|
updated_at = now()
|
||||||
where id = $1
|
where id = $1
|
||||||
returning id, name, endpoint, public_key, listen_port, vpn_cidr, dns_servers, is_active
|
returning id, name, endpoint, public_key, listen_port, vpn_cidr::text, dns_servers, is_active
|
||||||
`, gatewayID, input.Endpoint, input.PublicKey, input.ListenPort, input.VPNCIDR, input.DNSServers, input.IsActive)
|
`, gatewayID, input.Endpoint, input.PublicKey, input.ListenPort, input.VPNCIDR, input.DNSServers, input.IsActive)
|
||||||
|
|
||||||
var item Gateway
|
var item Gateway
|
||||||
|
|||||||
Reference in New Issue
Block a user