Go workspace (go.work) with 5 microservices + shared library: - gateway (8080), auth-service (8081), purchaser-service (8082) - textile-service (8083), washing-service (8084) - shared: proto definitions, common packages Infrastructure: docker-compose for local dev, K8s manifests for K3s cluster deployment (mysql/redis/etcd + traefik ingress). Frontend (iloom-flatten) added as git submodule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"github.com/muyuqingfeng/iloom/purchaser-service/internal/model"
|
|
)
|
|
|
|
type FactoryRepo struct {
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewFactoryRepo(db *sql.DB) *FactoryRepo {
|
|
return &FactoryRepo{db: db}
|
|
}
|
|
|
|
func (r *FactoryRepo) ListRelationships(ctx context.Context, companyID string) ([]model.CompanyRelationship, error) {
|
|
query := `SELECT cr.id, cr.purchaser_company_id, cr.factory_company_id,
|
|
cr.factory_type, cr.status, cr.created_at, cr.updated_at,
|
|
COALESCE(c.name, '') as factory_name
|
|
FROM ilm_company_relationship cr
|
|
LEFT JOIN ilm_company c ON c.id = cr.factory_company_id
|
|
WHERE cr.purchaser_company_id = ? AND cr.status = 'active'
|
|
ORDER BY cr.created_at DESC`
|
|
|
|
rows, err := r.db.QueryContext(ctx, query, companyID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list relationships: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var rels []model.CompanyRelationship
|
|
for rows.Next() {
|
|
var rel model.CompanyRelationship
|
|
if err := rows.Scan(
|
|
&rel.ID, &rel.PurchaserCompanyID, &rel.FactoryCompanyID,
|
|
&rel.FactoryType, &rel.Status, &rel.CreatedAt, &rel.UpdatedAt,
|
|
&rel.FactoryName,
|
|
); err != nil {
|
|
return nil, fmt.Errorf("scan relationship: %w", err)
|
|
}
|
|
rels = append(rels, rel)
|
|
}
|
|
return rels, nil
|
|
}
|