feat(app): wire project module and integration test for pm closed loop

This commit is contained in:
2026-05-01 10:36:37 +08:00
parent 1567f21a82
commit a0087d2c25
2 changed files with 122 additions and 0 deletions
+20
View File
@@ -26,11 +26,13 @@ import (
"net/http"
"time"
"github.com/google/uuid"
"github.com/yan1h/agent-coding-workflow/internal/audit"
"github.com/yan1h/agent-coding-workflow/internal/config"
"github.com/yan1h/agent-coding-workflow/internal/infra/db"
"github.com/yan1h/agent-coding-workflow/internal/infra/logger"
"github.com/yan1h/agent-coding-workflow/internal/infra/notify"
"github.com/yan1h/agent-coding-workflow/internal/project"
httpx "github.com/yan1h/agent-coding-workflow/internal/transport/http"
"github.com/yan1h/agent-coding-workflow/internal/transport/http/middleware"
"github.com/yan1h/agent-coding-workflow/internal/user"
@@ -66,6 +68,11 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) {
userRepo := user.NewPostgresRepository(pool)
userSvc := user.NewService(userRepo, auditRec)
projectRepo := project.NewPostgresRepository(pool)
projectSvc := project.NewProjectService(projectRepo, auditRec)
requirementSvc := project.NewRequirementService(projectRepo, auditRec)
issueSvc := project.NewIssueService(projectRepo, auditRec)
notifyRepo := notify.NewPostgresRepository(pool)
notifyDispatcher := notify.NewDispatcher(notifyRepo, log)
notifyDispatcher.Register(notify.NewDummyNotifier(log))
@@ -94,6 +101,7 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) {
// userSvc 直接满足 middleware.SessionResolver(ResolveSession 同名同签名)。
user.NewHandler(userSvc).Mount(r)
notify.NewHandler(notifyRepo, userSvc).Mount(r)
project.NewHandler(projectSvc, requirementSvc, issueSvc, userSvc, userAdminAdapter{svc: userSvc}).Mount(r)
if cfg.Bootstrap.AdminEmail != "" && cfg.Bootstrap.AdminPassword != "" {
if u, err := userSvc.Bootstrap(ctx, cfg.Bootstrap.AdminEmail, cfg.Bootstrap.AdminPassword); err != nil {
@@ -149,3 +157,15 @@ func (a *App) Run(ctx context.Context) error {
return err
}
}
// userAdminAdapter 把 user.Service 适配为 project.AdminLookup(窄接口)。
// 复用 user.Service.Get:返回的 *User 直接读 IsAdmin。
type userAdminAdapter struct{ svc user.Service }
func (a userAdminAdapter) IsAdmin(ctx context.Context, id uuid.UUID) (bool, error) {
u, err := a.svc.Get(ctx, id)
if err != nil {
return false, err
}
return u.IsAdmin, nil
}