Chever John 9c39c8cbd7
init: iloom WMS monorepo with K8s deployment manifests
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>
2026-06-14 11:33:31 +08:00

75 lines
2.2 KiB
Go

package repository
import (
"context"
"database/sql"
"fmt"
"github.com/muyuqingfeng/iloom/auth-service/internal/model"
)
type ProfileRepo struct {
db *sql.DB
}
func NewProfileRepo(db *sql.DB) *ProfileRepo {
return &ProfileRepo{db: db}
}
func (r *ProfileRepo) GetByID(ctx context.Context, userID string) (*model.Profile, error) {
query := `SELECT user_id, username, real_name, phone, email, avatar, status, created_at
FROM sys_user WHERE user_id = ? AND deleted_at IS NULL`
p := &model.Profile{}
err := r.db.QueryRowContext(ctx, query, userID).Scan(
&p.ID, &p.Username, &p.RealName, &p.Phone, &p.Email,
&p.Avatar, &p.Status, &p.CreatedAt,
)
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, fmt.Errorf("get profile by id: %w", err)
}
return p, nil
}
func (r *ProfileRepo) GetByUsername(ctx context.Context, username string) (*model.Profile, error) {
query := `SELECT user_id, username, real_name, phone, email, avatar, status, created_at
FROM sys_user WHERE username = ? AND deleted_at IS NULL`
p := &model.Profile{}
err := r.db.QueryRowContext(ctx, query, username).Scan(
&p.ID, &p.Username, &p.RealName, &p.Phone, &p.Email,
&p.Avatar, &p.Status, &p.CreatedAt,
)
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, fmt.Errorf("get profile by username: %w", err)
}
return p, nil
}
func (r *ProfileRepo) GetWithCompany(ctx context.Context, userID string) (*model.Profile, error) {
query := `SELECT su.user_id, su.username, su.real_name, su.phone, su.email, su.avatar, su.status, su.created_at,
COALESCE(cm.company_id, ''), COALESCE(c.name, ''), COALESCE(c.type, ''), COALESCE(cm.is_master, 0)
FROM sys_user su
LEFT JOIN ilm_company_member cm ON cm.user_id = su.user_id
LEFT JOIN ilm_company c ON c.id = cm.company_id
WHERE su.user_id = ? AND su.deleted_at IS NULL
LIMIT 1`
p := &model.Profile{}
err := r.db.QueryRowContext(ctx, query, userID).Scan(
&p.ID, &p.Username, &p.RealName, &p.Phone, &p.Email,
&p.Avatar, &p.Status, &p.CreatedAt,
&p.CompanyID, &p.CompanyName, &p.Role, &p.IsMaster,
)
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, fmt.Errorf("get profile with company: %w", err)
}
return p, nil
}