diff --git a/backend/biz/team/handler/http/v1/skill.go b/backend/biz/team/handler/http/v1/skill.go new file mode 100644 index 00000000..3e3b5993 --- /dev/null +++ b/backend/biz/team/handler/http/v1/skill.go @@ -0,0 +1,245 @@ +package v1 + +import ( + "encoding/json" + "fmt" + "io" + "mime/multipart" + + "github.com/GoYoko/web" + "github.com/google/uuid" + "github.com/samber/do" + + "github.com/chaitin/MonkeyCode/backend/config" + "github.com/chaitin/MonkeyCode/backend/domain" + "github.com/chaitin/MonkeyCode/backend/errcode" + "github.com/chaitin/MonkeyCode/backend/middleware" +) + +type TeamSkillHandler struct { + usecase domain.TeamSkillUsecase + cfg *config.Config +} + +func NewTeamSkillHandler(i *do.Injector) (*TeamSkillHandler, error) { + w := do.MustInvoke[*web.Web](i) + auth := do.MustInvoke[*middleware.AuthMiddleware](i) + audit := do.MustInvoke[*middleware.AuditMiddleware](i) + + h := &TeamSkillHandler{ + usecase: do.MustInvoke[domain.TeamSkillUsecase](i), + cfg: do.MustInvoke[*config.Config](i), + } + + g := w.Group("/api/v1/teams/skills") + g.Use(auth.TeamAuth()) + g.GET("", web.BaseHandler(h.List)) + g.POST("", web.BindHandler(h.Add), audit.Audit("add_team_skill")) + g.POST("/package", web.BindHandler(h.AddPackage), audit.Audit("add_team_skill_package")) + g.PUT("/:skill_id", web.BindHandler(h.Update), audit.Audit("update_team_skill")) + g.DELETE("/:skill_id", web.BindHandler(h.Delete), audit.Audit("delete_team_skill")) + + return h, nil +} + +type addTeamSkillPackageFormReq struct { + Name string `form:"name" validate:"required"` + Description string `form:"description" validate:"required"` + Tags string `form:"tags"` + Content string `form:"content" validate:"required"` + GroupIDs string `form:"group_ids"` + SourceType string `form:"source_type" validate:"required"` + SourceLabel string `form:"source_label" validate:"required"` + SkillMDPath string `form:"skill_md_path"` + File *multipart.FileHeader `form:"file" validate:"required"` +} + +// List 获取团队 Skill 列表 +// +// @Summary 获取团队 Skill 列表 +// @Description 获取团队 Skill 列表 +// @Tags 【Team 管理员】Skill 管理 +// @Accept json +// @Produce json +// @Security MonkeyCodeAITeamAuth +// @Success 200 {object} web.Resp{data=domain.ListTeamSkillsResp} "成功" +// @Failure 401 {object} web.Resp "未授权" +// @Failure 500 {object} web.Resp "服务器内部错误" +// @Router /api/v1/teams/skills [get] +func (h *TeamSkillHandler) List(c *web.Context) error { + teamUser := middleware.GetTeamUser(c) + resp, err := h.usecase.List(c.Request().Context(), teamUser) + if err != nil { + return err + } + return c.Success(resp) +} + +// Add 添加团队 Skill +// +// @Summary 添加团队 Skill +// @Description 添加团队 Skill +// @Tags 【Team 管理员】Skill 管理 +// @Accept json +// @Produce json +// @Security MonkeyCodeAITeamAuth +// @Param req body domain.AddTeamSkillReq true "请求参数" +// @Success 200 {object} web.Resp{data=domain.TeamSkill} "成功" +// @Failure 401 {object} web.Resp "未授权" +// @Failure 500 {object} web.Resp "服务器内部错误" +// @Router /api/v1/teams/skills [post] +func (h *TeamSkillHandler) Add(c *web.Context, req domain.AddTeamSkillReq) error { + teamUser := middleware.GetTeamUser(c) + resp, err := h.usecase.Add(c.Request().Context(), teamUser, &req) + if err != nil { + return err + } + return c.Success(resp) +} + +// AddPackage 上传团队 Skill zip 包 +// +// @Summary 上传团队 Skill zip 包 +// @Description 上传团队 Skill zip 包 +// @Tags 【Team 管理员】Skill 管理 +// @Accept multipart/form-data +// @Produce json +// @Security MonkeyCodeAITeamAuth +// @Param name formData string true "Skill 名称" +// @Param description formData string true "Skill 描述" +// @Param tags formData string false "JSON 字符串数组" +// @Param content formData string true "SKILL.md 原文" +// @Param group_ids formData string false "JSON 字符串数组" +// @Param source_type formData string true "来源类型" +// @Param source_label formData string true "来源标签" +// @Param skill_md_path formData string false "zip 内 SKILL.md 路径" +// @Param file formData file true "Skill zip 包" +// @Success 200 {object} web.Resp{data=domain.TeamSkill} "成功" +// @Failure 401 {object} web.Resp "未授权" +// @Failure 500 {object} web.Resp "服务器内部错误" +// @Router /api/v1/teams/skills/package [post] +func (h *TeamSkillHandler) AddPackage(c *web.Context, req addTeamSkillPackageFormReq) error { + teamUser := middleware.GetTeamUser(c) + data, err := h.readPackageFile(req.File) + if err != nil { + return err + } + tags, err := parseStringSlice(req.Tags) + if err != nil { + return err + } + groupIDs, err := parseUUIDSlice(req.GroupIDs) + if err != nil { + return err + } + resp, err := h.usecase.AddPackage(c.Request().Context(), teamUser, &domain.AddTeamSkillPackageReq{ + AddTeamSkillReq: domain.AddTeamSkillReq{ + Name: req.Name, + Description: req.Description, + Tags: tags, + Content: req.Content, + GroupIDs: groupIDs, + SourceType: req.SourceType, + SourceLabel: req.SourceLabel, + SkillMDPath: req.SkillMDPath, + }, + PackageFilename: req.File.Filename, + PackageData: data, + }) + if err != nil { + return err + } + return c.Success(resp) +} + +// Update 更新团队 Skill +// +// @Summary 更新团队 Skill +// @Description 更新团队 Skill +// @Tags 【Team 管理员】Skill 管理 +// @Accept json +// @Produce json +// @Security MonkeyCodeAITeamAuth +// @Param skill_id path string true "Skill ID" +// @Param req body domain.UpdateTeamSkillReq true "请求参数" +// @Success 200 {object} web.Resp{data=domain.TeamSkill} "成功" +// @Failure 401 {object} web.Resp "未授权" +// @Failure 500 {object} web.Resp "服务器内部错误" +// @Router /api/v1/teams/skills/{skill_id} [put] +func (h *TeamSkillHandler) Update(c *web.Context, req domain.UpdateTeamSkillReq) error { + teamUser := middleware.GetTeamUser(c) + resp, err := h.usecase.Update(c.Request().Context(), teamUser, &req) + if err != nil { + return err + } + return c.Success(resp) +} + +// Delete 删除团队 Skill +// +// @Summary 删除团队 Skill +// @Description 删除团队 Skill +// @Tags 【Team 管理员】Skill 管理 +// @Accept json +// @Produce json +// @Security MonkeyCodeAITeamAuth +// @Param skill_id path string true "Skill ID" +// @Success 200 {object} web.Resp{} "成功" +// @Failure 401 {object} web.Resp "未授权" +// @Failure 500 {object} web.Resp "服务器内部错误" +// @Router /api/v1/teams/skills/{skill_id} [delete] +func (h *TeamSkillHandler) Delete(c *web.Context, req domain.DeleteTeamSkillReq) error { + teamUser := middleware.GetTeamUser(c) + if err := h.usecase.Delete(c.Request().Context(), teamUser, &req); err != nil { + return err + } + return c.Success(nil) +} + +func (h *TeamSkillHandler) readPackageFile(fileHeader *multipart.FileHeader) ([]byte, error) { + if fileHeader == nil { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("file is required")) + } + maxSize := h.cfg.ObjectStorage.MaxSize + if maxSize <= 0 { + maxSize = 50 << 20 + } + if fileHeader.Size > maxSize { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("file exceeds limit")) + } + file, err := fileHeader.Open() + if err != nil { + return nil, err + } + defer file.Close() + data, err := io.ReadAll(io.LimitReader(file, maxSize+1)) + if err != nil { + return nil, err + } + if int64(len(data)) > maxSize { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("file exceeds limit")) + } + return data, nil +} + +func parseStringSlice(raw string) ([]string, error) { + if raw == "" { + return nil, nil + } + var values []string + if err := json.Unmarshal([]byte(raw), &values); err != nil { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("invalid string array")) + } + return values, nil +} + +func parseUUIDSlice(raw string) ([]uuid.UUID, error) { + if raw == "" { + return nil, nil + } + var values []uuid.UUID + if err := json.Unmarshal([]byte(raw), &values); err != nil { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("invalid uuid array")) + } + return values, nil +} diff --git a/backend/biz/team/register.go b/backend/biz/team/register.go index 08042b19..4df8a59d 100644 --- a/backend/biz/team/register.go +++ b/backend/biz/team/register.go @@ -24,6 +24,9 @@ func ProvideTeam(i *do.Injector) { do.Provide(i, repo.NewTeamImageRepo) do.Provide(i, usecase.NewTeamImageUsecase) do.Provide(i, v1.NewTeamImageHandler) + do.Provide(i, repo.NewTeamSkillRepo) + do.Provide(i, usecase.NewTeamSkillUsecase) + do.Provide(i, v1.NewTeamSkillHandler) do.Provide(i, repo.NewTeamHostRepo) do.Provide(i, usecase.NewTeamHostUsecase) do.Provide(i, v1.NewTeamHostHandler) @@ -47,6 +50,7 @@ func InvokeTeam(i *do.Injector) { do.MustInvoke[*v1.TeamDashboardHandler](i) do.MustInvoke[*v1.TeamModelHandler](i) do.MustInvoke[*v1.TeamImageHandler](i) + do.MustInvoke[*v1.TeamSkillHandler](i) do.MustInvoke[*v1.TeamHostHandler](i) do.MustInvoke[*v1.TeamPolicyHandler](i) do.MustInvoke[*v1.TeamOIDCHandler](i) diff --git a/backend/biz/team/repo/default_group_test.go b/backend/biz/team/repo/default_group_test.go index 4d60e95f..ee4a84bf 100644 --- a/backend/biz/team/repo/default_group_test.go +++ b/backend/biz/team/repo/default_group_test.go @@ -15,6 +15,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/teamgrouphost" "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/domain" "github.com/chaitin/MonkeyCode/backend/pkg/taskflow" ) @@ -184,6 +185,112 @@ func TestTeamHostUpsertUsesDefaultGroupForNewHost(t *testing.T) { } } +func TestTeamSkillCreateUsesDefaultGroupWhenGroupIDsEmpty(t *testing.T) { + ctx := context.Background() + client := newTeamRepoTestDB(t) + teamID := createTeamRepoTestTeam(t, client) + userID := createTeamRepoTestUser(t, client) + group := createTeamRepoDefaultGroup(t, client, teamID) + repo := &teamSkillRepo{ + db: client, + logger: slog.New(slog.NewTextHandler(io.Discard, nil)), + } + + skill, err := repo.Create(ctx, teamID, userID, &domain.AddTeamSkillReq{ + Name: "code-review", + Description: "Review code changes", + Content: "---\nname: code-review\ndescription: Review code changes\n---\n", + Tags: []string{"review", "go"}, + SourceType: "markdown", + SourceLabel: "SKILL.md", + }) + if err != nil { + t.Fatal(err) + } + + if exists := teamRepoSkillInGroup(t, client, group.ID, skill.ID); !exists { + t.Fatal("skill was not added to default group") + } +} + +func TestTeamSkillCreateKeepsExplicitGroup(t *testing.T) { + ctx := context.Background() + client := newTeamRepoTestDB(t) + teamID := createTeamRepoTestTeam(t, client) + userID := createTeamRepoTestUser(t, client) + defaultGroup := createTeamRepoDefaultGroup(t, client, teamID) + customGroup := createTeamRepoGroup(t, client, teamID, "Skill 分组") + repo := &teamSkillRepo{ + db: client, + logger: slog.New(slog.NewTextHandler(io.Discard, nil)), + } + + skill, err := repo.Create(ctx, teamID, userID, &domain.AddTeamSkillReq{ + Name: "frontend-polish", + Description: "Polish frontend UX", + Content: "---\nname: frontend-polish\ndescription: Polish frontend UX\n---\n", + GroupIDs: []uuid.UUID{customGroup.ID}, + SourceType: "markdown", + SourceLabel: "SKILL.md", + }) + if err != nil { + t.Fatal(err) + } + + if exists := teamRepoSkillInGroup(t, client, customGroup.ID, skill.ID); !exists { + t.Fatal("skill was not added to explicit group") + } + if exists := teamRepoSkillInGroup(t, client, defaultGroup.ID, skill.ID); exists { + t.Fatal("skill was added to default group despite explicit group") + } +} + +func TestTeamSkillUpdateReplacesGroups(t *testing.T) { + ctx := context.Background() + client := newTeamRepoTestDB(t) + teamID := createTeamRepoTestTeam(t, client) + userID := createTeamRepoTestUser(t, client) + oldGroup := createTeamRepoGroup(t, client, teamID, "旧分组") + newGroup := createTeamRepoGroup(t, client, teamID, "新分组") + repo := &teamSkillRepo{ + db: client, + logger: slog.New(slog.NewTextHandler(io.Discard, nil)), + } + + skill, err := repo.Create(ctx, teamID, userID, &domain.AddTeamSkillReq{ + Name: "plan-writer", + Description: "Write plans", + Content: "---\nname: plan-writer\ndescription: Write plans\n---\n", + GroupIDs: []uuid.UUID{oldGroup.ID}, + SourceType: "markdown", + SourceLabel: "SKILL.md", + }) + if err != nil { + t.Fatal(err) + } + + updated, err := repo.Update(ctx, teamID, &domain.UpdateTeamSkillReq{ + SkillID: skill.ID, + Name: "plan-writer-v2", + Description: "Write implementation plans", + Tags: []string{"planning"}, + GroupIDs: []uuid.UUID{newGroup.ID}, + }) + if err != nil { + t.Fatal(err) + } + + if updated.Name != "plan-writer-v2" { + t.Fatalf("skill name = %q, want plan-writer-v2", updated.Name) + } + if exists := teamRepoSkillInGroup(t, client, oldGroup.ID, skill.ID); exists { + t.Fatal("skill still belongs to old group") + } + if exists := teamRepoSkillInGroup(t, client, newGroup.ID, skill.ID); !exists { + t.Fatal("skill was not added to new group") + } +} + func createTeamRepoTestUser(t *testing.T, client *db.Client) uuid.UUID { t.Helper() userID := uuid.New() @@ -239,3 +346,14 @@ func teamRepoModelInGroup(t *testing.T, client *db.Client, groupID, modelID uuid } return exists } + +func teamRepoSkillInGroup(t *testing.T, client *db.Client, groupID, skillID uuid.UUID) bool { + t.Helper() + exists, err := client.TeamGroupSkill.Query(). + Where(teamgroupskill.GroupIDEQ(groupID), teamgroupskill.SkillIDEQ(skillID)). + Exist(context.Background()) + if err != nil { + t.Fatal(err) + } + return exists +} diff --git a/backend/biz/team/repo/skill.go b/backend/biz/team/repo/skill.go new file mode 100644 index 00000000..6c5d514e --- /dev/null +++ b/backend/biz/team/repo/skill.go @@ -0,0 +1,208 @@ +package repo + +import ( + "context" + "log/slog" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/samber/do" + + "github.com/chaitin/MonkeyCode/backend/db" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/chaitin/MonkeyCode/backend/domain" + "github.com/chaitin/MonkeyCode/backend/errcode" + "github.com/chaitin/MonkeyCode/backend/pkg/cvt" + "github.com/chaitin/MonkeyCode/backend/pkg/entx" +) + +type teamSkillRepo struct { + db *db.Client + logger *slog.Logger +} + +func NewTeamSkillRepo(i *do.Injector) (domain.TeamSkillRepo, error) { + return &teamSkillRepo{ + db: do.MustInvoke[*db.Client](i), + logger: do.MustInvoke[*slog.Logger](i), + }, nil +} + +func (r *teamSkillRepo) List(ctx context.Context, teamID uuid.UUID) ([]*db.Skill, error) { + tss, err := r.db.TeamSkill.Query(). + WithSkill(func(sq *db.SkillQuery) { + sq.WithGroups() + }). + Where(teamskill.TeamID(teamID)). + Order(teamskill.ByCreatedAt(sql.OrderDesc())). + All(ctx) + if err != nil { + return nil, errcode.ErrDatabaseQuery.Wrap(err) + } + return cvt.Iter(tss, func(_ int, ts *db.TeamSkill) *db.Skill { + return ts.Edges.Skill + }), nil +} + +func (r *teamSkillRepo) Create(ctx context.Context, teamID, userID uuid.UUID, req *domain.AddTeamSkillReq) (*db.Skill, error) { + var skillID uuid.UUID + err := entx.WithTx2(ctx, r.db, func(tx *db.Tx) error { + groupIDs, err := resolveTeamSkillGroupIDs(ctx, tx, teamID, req.GroupIDs) + if err != nil { + return err + } + + newSkill, err := tx.Skill.Create(). + SetID(uuid.New()). + SetUserID(userID). + SetName(req.Name). + SetDescription(req.Description). + SetTags(req.Tags). + SetContent(req.Content). + SetPackageObjectKey(req.PackageObjectKey). + SetPackageURL(req.PackageURL). + SetSourceType(req.SourceType). + SetSourceLabel(req.SourceLabel). + SetSkillMdPath(req.SkillMDPath). + Save(ctx) + if err != nil { + return err + } + skillID = newSkill.ID + + if err := tx.TeamSkill.Create(). + SetID(uuid.New()). + SetTeamID(teamID). + SetSkillID(newSkill.ID). + Exec(ctx); err != nil { + return err + } + + return replaceTeamSkillGroups(ctx, tx, newSkill.ID, groupIDs) + }) + if err != nil { + r.logger.Error("create team skill", "error", err) + return nil, errcode.ErrDatabaseOperation.Wrap(err) + } + return r.get(ctx, teamID, skillID) +} + +func (r *teamSkillRepo) Update(ctx context.Context, teamID uuid.UUID, req *domain.UpdateTeamSkillReq) (*db.Skill, error) { + err := entx.WithTx2(ctx, r.db, func(tx *db.Tx) error { + groupIDs, err := resolveTeamSkillGroupIDs(ctx, tx, teamID, req.GroupIDs) + if err != nil { + return err + } + + upt := tx.Skill.UpdateOneID(req.SkillID).Where(skill.HasTeamsWith(team.ID(teamID))) + if req.Name != "" { + upt.SetName(req.Name) + } + if req.Description != "" { + upt.SetDescription(req.Description) + } + if req.Tags != nil { + upt.SetTags(req.Tags) + } + if req.Content != "" { + upt.SetContent(req.Content) + } + if req.SourceType != "" { + upt.SetSourceType(req.SourceType) + } + if req.SourceLabel != "" { + upt.SetSourceLabel(req.SourceLabel) + } + if req.SkillMDPath != nil { + upt.SetSkillMdPath(*req.SkillMDPath) + } + if err := upt.Exec(ctx); err != nil { + return err + } + + if req.GroupIDs != nil { + return replaceTeamSkillGroups(ctx, tx, req.SkillID, groupIDs) + } + return nil + }) + if err != nil { + return nil, errcode.ErrDatabaseOperation.Wrap(err) + } + return r.get(ctx, teamID, req.SkillID) +} + +func (r *teamSkillRepo) Delete(ctx context.Context, teamID, skillID uuid.UUID) error { + err := entx.WithTx2(ctx, r.db, func(tx *db.Tx) error { + if err := tx.Skill.DeleteOneID(skillID).Where(skill.HasTeamsWith(team.ID(teamID))).Exec(ctx); err != nil { + return err + } + if _, err := tx.TeamSkill.Delete(). + Where(teamskill.TeamID(teamID)). + Where(teamskill.SkillID(skillID)). + Exec(ctx); err != nil { + return err + } + _, err := tx.TeamGroupSkill.Delete().Where(teamgroupskill.SkillIDEQ(skillID)).Exec(ctx) + return err + }) + if err != nil { + r.logger.Error("delete team skill", "error", err) + return errcode.ErrDatabaseOperation.Wrap(err) + } + return nil +} + +func (r *teamSkillRepo) get(ctx context.Context, teamID, skillID uuid.UUID) (*db.Skill, error) { + ts, err := r.db.TeamSkill.Query(). + WithSkill(func(sq *db.SkillQuery) { + sq.WithGroups() + }). + Where(teamskill.TeamID(teamID)). + Where(teamskill.SkillID(skillID)). + First(ctx) + if err != nil { + return nil, errcode.ErrDatabaseQuery.Wrap(err) + } + return ts.Edges.Skill, nil +} + +func resolveTeamSkillGroupIDs(ctx context.Context, tx *db.Tx, teamID uuid.UUID, reqGroupIDs []uuid.UUID) ([]uuid.UUID, error) { + useDefaultGroup := len(reqGroupIDs) == 0 + groups, err := tx.TeamGroup.Query(). + Where(teamgroup.TeamID(teamID)). + Where(teamgroup.IDIn(reqGroupIDs...)). + All(ctx) + if err != nil { + return nil, err + } + groupIDs := cvt.Iter(groups, func(_ int, group *db.TeamGroup) uuid.UUID { + return group.ID + }) + if useDefaultGroup { + return ensureDefaultGroupIDs(ctx, tx, teamID, groupIDs) + } + return groupIDs, nil +} + +func replaceTeamSkillGroups(ctx context.Context, tx *db.Tx, skillID uuid.UUID, groupIDs []uuid.UUID) error { + if _, err := tx.TeamGroupSkill.Delete().Where(teamgroupskill.SkillIDEQ(skillID)).Exec(ctx); err != nil { + return err + } + + builders := make([]*db.TeamGroupSkillCreate, 0, len(groupIDs)) + for _, groupID := range groupIDs { + builders = append(builders, tx.TeamGroupSkill.Create(). + SetID(uuid.New()). + SetGroupID(groupID). + SetSkillID(skillID)) + } + if len(builders) == 0 { + return nil + } + _, err := tx.TeamGroupSkill.CreateBulk(builders...).Save(ctx) + return err +} diff --git a/backend/biz/team/usecase/skill.go b/backend/biz/team/usecase/skill.go new file mode 100644 index 00000000..3af27190 --- /dev/null +++ b/backend/biz/team/usecase/skill.go @@ -0,0 +1,184 @@ +package usecase + +import ( + "archive/zip" + "bytes" + "context" + "fmt" + "log/slog" + "path/filepath" + "strings" + + "github.com/google/uuid" + "github.com/samber/do" + + "github.com/chaitin/MonkeyCode/backend/config" + "github.com/chaitin/MonkeyCode/backend/db" + "github.com/chaitin/MonkeyCode/backend/domain" + "github.com/chaitin/MonkeyCode/backend/errcode" + "github.com/chaitin/MonkeyCode/backend/pkg/cvt" + "github.com/chaitin/MonkeyCode/backend/pkg/oss" +) + +const skillPackagePrefix = "skills" + +type teamSkillUsecase struct { + repo domain.TeamSkillRepo + packageStore skillPackageStore + logger *slog.Logger +} + +func NewTeamSkillUsecase(i *do.Injector) (domain.TeamSkillUsecase, error) { + cfg := do.MustInvoke[*config.Config](i) + var store skillPackageStore + if cfg.ObjectStorage.Enabled { + client, err := oss.NewS3Compatible(context.Background(), cfg.ObjectStorage, oss.S3Option{ + ForcePathStyle: cfg.ObjectStorage.ForcePathStyle, + InitBucket: cfg.ObjectStorage.InitBucket, + }) + if err != nil { + return nil, err + } + store = &ossSkillPackageStore{client: client.WithAccessEndpoint(cfg.ObjectStorage.AccessEndpoint)} + } + return &teamSkillUsecase{ + repo: do.MustInvoke[domain.TeamSkillRepo](i), + packageStore: store, + logger: do.MustInvoke[*slog.Logger](i), + }, nil +} + +func (u *teamSkillUsecase) Add(ctx context.Context, teamUser *domain.TeamUser, req *domain.AddTeamSkillReq) (*domain.TeamSkill, error) { + if req.PackageObjectKey == "" { + if u.packageStore == nil { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("object storage is disabled")) + } + data, err := packageSkillMarkdownContent(req.Content) + if err != nil { + return nil, err + } + objectKey, url, err := u.packageStore.Put(ctx, skillPackageFilename(req.Name), data) + if err != nil { + return nil, err + } + req.PackageObjectKey = objectKey + req.PackageURL = url + } + + skill, err := u.repo.Create(ctx, teamUser.GetTeamID(), teamUser.User.ID, req) + if err != nil { + return nil, err + } + return cvt.From(skill, &domain.TeamSkill{}), nil +} + +func (u *teamSkillUsecase) AddPackage(ctx context.Context, teamUser *domain.TeamUser, req *domain.AddTeamSkillPackageReq) (*domain.TeamSkill, error) { + if u.packageStore == nil { + return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("object storage is disabled")) + } + if err := validateSkillZipPackage(req.PackageData); err != nil { + return nil, err + } + filename := skillPackageFilename(req.PackageFilename) + if strings.TrimSpace(req.Name) != "" { + filename = skillPackageFilename(req.Name) + } + objectKey, url, err := u.packageStore.Put(ctx, filename, req.PackageData) + if err != nil { + return nil, err + } + req.PackageObjectKey = objectKey + req.PackageURL = url + return u.Add(ctx, teamUser, &req.AddTeamSkillReq) +} + +func (u *teamSkillUsecase) List(ctx context.Context, teamUser *domain.TeamUser) (*domain.ListTeamSkillsResp, error) { + skills, err := u.repo.List(ctx, teamUser.GetTeamID()) + if err != nil { + return nil, err + } + return &domain.ListTeamSkillsResp{ + Skills: cvt.Iter(skills, func(_ int, skill *db.Skill) *domain.TeamSkill { + return cvt.From(skill, &domain.TeamSkill{}) + }), + }, nil +} + +func (u *teamSkillUsecase) Update(ctx context.Context, teamUser *domain.TeamUser, req *domain.UpdateTeamSkillReq) (*domain.TeamSkill, error) { + skill, err := u.repo.Update(ctx, teamUser.GetTeamID(), req) + if err != nil { + return nil, err + } + return cvt.From(skill, &domain.TeamSkill{}), nil +} + +func (u *teamSkillUsecase) Delete(ctx context.Context, teamUser *domain.TeamUser, req *domain.DeleteTeamSkillReq) error { + return u.repo.Delete(ctx, teamUser.GetTeamID(), req.SkillID) +} + +type skillPackageStore interface { + Put(ctx context.Context, filename string, data []byte) (objectKey string, url string, err error) +} + +type ossSkillPackageStore struct { + client *oss.Client +} + +func (s *ossSkillPackageStore) Put(ctx context.Context, filename string, data []byte) (string, string, error) { + if s == nil || s.client == nil { + return "", "", errcode.ErrBadRequest.Wrap(fmt.Errorf("object storage is disabled")) + } + if err := s.client.PutFile(ctx, skillPackagePrefix, filename, bytes.NewReader(data)); err != nil { + return "", "", err + } + objectKey := strings.Trim(filepath.ToSlash(filepath.Join(skillPackagePrefix, filepath.Base(filename))), "/") + return objectKey, s.client.GetURL(skillPackagePrefix, filename), nil +} + +func packageSkillMarkdownContent(content string) ([]byte, error) { + var buf bytes.Buffer + zw := zip.NewWriter(&buf) + w, err := zw.Create("SKILL.md") + if err != nil { + return nil, err + } + if _, err := w.Write([]byte(content)); err != nil { + _ = zw.Close() + return nil, err + } + if err := zw.Close(); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func validateSkillZipPackage(data []byte) error { + reader, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) + if err != nil { + return errcode.ErrBadRequest.Wrap(fmt.Errorf("invalid skill zip package")) + } + for _, file := range reader.File { + if file.FileInfo().IsDir() { + continue + } + if strings.EqualFold(filepath.Base(file.Name), "SKILL.md") { + return nil + } + } + return errcode.ErrBadRequest.Wrap(fmt.Errorf("zip package missing SKILL.md")) +} + +func skillPackageFilename(name string) string { + name = strings.TrimSpace(name) + if name == "" { + name = "skill" + } else if ext := filepath.Ext(name); strings.EqualFold(ext, ".zip") { + name = strings.TrimSuffix(name, ext) + } + replacer := strings.NewReplacer("/", "-", "\\", "-", ":", "-", " ", "-") + name = strings.Trim(replacer.Replace(name), ".-") + if name == "" { + name = "skill" + } + return fmt.Sprintf("%s-%s.zip", name, uuid.NewString()) +} diff --git a/backend/biz/team/usecase/skill_package_test.go b/backend/biz/team/usecase/skill_package_test.go new file mode 100644 index 00000000..3269e7aa --- /dev/null +++ b/backend/biz/team/usecase/skill_package_test.go @@ -0,0 +1,194 @@ +package usecase + +import ( + "archive/zip" + "bytes" + "context" + "io" + "log/slog" + "strings" + "testing" + + "github.com/google/uuid" + + "github.com/chaitin/MonkeyCode/backend/db" + "github.com/chaitin/MonkeyCode/backend/domain" +) + +func TestPackageSkillMarkdownContentCreatesRootSkillMarkdown(t *testing.T) { + content := "---\nname: reviewer\ndescription: Review code\n---\n" + data, err := packageSkillMarkdownContent(content) + if err != nil { + t.Fatal(err) + } + + got := readZipFile(t, data, "SKILL.md") + if got != content { + t.Fatalf("SKILL.md content = %q, want %q", got, content) + } +} + +func TestTeamSkillUsecaseAddUploadsPackageAndKeepsContent(t *testing.T) { + ctx := context.Background() + teamID := uuid.New() + userID := uuid.New() + repo := &teamSkillRepoStub{} + store := &skillPackageStoreStub{} + u := &teamSkillUsecase{ + repo: repo, + packageStore: store, + logger: slog.Default(), + } + + content := "---\nname: planner\ndescription: Write plans\n---\n" + _, err := u.Add(ctx, &domain.TeamUser{ + User: &domain.User{ID: userID}, + Team: &domain.Team{ID: teamID}, + }, &domain.AddTeamSkillReq{ + Name: "planner", + Description: "Write plans", + Content: content, + SourceType: "text", + SourceLabel: "粘贴文本", + }) + if err != nil { + t.Fatal(err) + } + + if repo.createdReq == nil { + t.Fatal("repo Create was not called") + } + if repo.createdReq.Content != content { + t.Fatalf("content = %q, want original content", repo.createdReq.Content) + } + if !strings.HasPrefix(repo.createdReq.PackageObjectKey, "skills/planner-") || !strings.HasSuffix(repo.createdReq.PackageObjectKey, ".zip") { + t.Fatalf("package object key = %q", repo.createdReq.PackageObjectKey) + } + if !strings.HasPrefix(repo.createdReq.PackageURL, "https://oss.example.com/skills/planner-") || !strings.HasSuffix(repo.createdReq.PackageURL, ".zip") { + t.Fatalf("package url = %q", repo.createdReq.PackageURL) + } + if got := readZipFile(t, store.data, "SKILL.md"); got != content { + t.Fatalf("uploaded SKILL.md content = %q, want %q", got, content) + } +} + +func TestTeamSkillUsecaseAddPackageUploadsOriginalZipAndKeepsContent(t *testing.T) { + ctx := context.Background() + teamID := uuid.New() + userID := uuid.New() + repo := &teamSkillRepoStub{} + store := &skillPackageStoreStub{} + u := &teamSkillUsecase{ + repo: repo, + packageStore: store, + logger: slog.Default(), + } + + content := "---\nname: packaged\ndescription: Packaged skill\n---\n" + zipData := makeSkillZip(t, content, "references/guide.md", "guide") + _, err := u.AddPackage(ctx, &domain.TeamUser{ + User: &domain.User{ID: userID}, + Team: &domain.Team{ID: teamID}, + }, &domain.AddTeamSkillPackageReq{ + AddTeamSkillReq: domain.AddTeamSkillReq{ + Name: "packaged", + Description: "Packaged skill", + Content: content, + SourceType: "zip", + SourceLabel: "packaged.zip", + }, + PackageFilename: "packaged.zip", + PackageData: zipData, + }) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(store.data, zipData) { + t.Fatal("uploaded data is not the original zip package") + } + if repo.createdReq.Content != content { + t.Fatalf("content = %q, want original SKILL.md content", repo.createdReq.Content) + } + if got := readZipFile(t, store.data, "references/guide.md"); got != "guide" { + t.Fatalf("zip reference file = %q, want guide", got) + } +} + +type teamSkillRepoStub struct { + domain.TeamSkillRepo + createdReq *domain.AddTeamSkillReq +} + +func makeSkillZip(t *testing.T, skillContent string, extraName string, extraContent string) []byte { + t.Helper() + var buf bytes.Buffer + zw := zip.NewWriter(&buf) + for name, content := range map[string]string{ + "SKILL.md": skillContent, + extraName: extraContent, + } { + w, err := zw.Create(name) + if err != nil { + t.Fatal(err) + } + if _, err := w.Write([]byte(content)); err != nil { + t.Fatal(err) + } + } + if err := zw.Close(); err != nil { + t.Fatal(err) + } + return buf.Bytes() +} + +func (r *teamSkillRepoStub) Create(ctx context.Context, teamID, userID uuid.UUID, req *domain.AddTeamSkillReq) (*db.Skill, error) { + r.createdReq = req + return &db.Skill{ + ID: uuid.New(), + UserID: userID, + Name: req.Name, + Description: req.Description, + Tags: req.Tags, + Content: req.Content, + SourceType: req.SourceType, + SourceLabel: req.SourceLabel, + SkillMdPath: req.SkillMDPath, + PackageObjectKey: req.PackageObjectKey, + PackageURL: req.PackageURL, + }, nil +} + +type skillPackageStoreStub struct { + data []byte +} + +func (s *skillPackageStoreStub) Put(ctx context.Context, filename string, data []byte) (string, string, error) { + s.data = append([]byte(nil), data...) + return "skills/" + filename, "https://oss.example.com/skills/" + filename, nil +} + +func readZipFile(t *testing.T, data []byte, name string) string { + t.Helper() + reader, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) + if err != nil { + t.Fatal(err) + } + for _, file := range reader.File { + if file.Name != name { + continue + } + rc, err := file.Open() + if err != nil { + t.Fatal(err) + } + defer rc.Close() + content, err := io.ReadAll(rc) + if err != nil { + t.Fatal(err) + } + return string(content) + } + t.Fatalf("%s not found in zip", name) + return "" +} diff --git a/backend/db/client.go b/backend/db/client.go index 5e3da272..f1d847e0 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -39,6 +39,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" "github.com/chaitin/MonkeyCode/backend/db/projecttask" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/taskusagestat" @@ -49,11 +50,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/teamhost" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" "github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/useridentity" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" @@ -112,6 +115,8 @@ type Client struct { ProjectIssueComment *ProjectIssueCommentClient // ProjectTask is the client for interacting with the ProjectTask builders. ProjectTask *ProjectTaskClient + // Skill is the client for interacting with the Skill builders. + Skill *SkillClient // Task is the client for interacting with the Task builders. Task *TaskClient // TaskModelSwitch is the client for interacting with the TaskModelSwitch builders. @@ -132,6 +137,8 @@ type Client struct { TeamGroupMember *TeamGroupMemberClient // TeamGroupModel is the client for interacting with the TeamGroupModel builders. TeamGroupModel *TeamGroupModelClient + // TeamGroupSkill is the client for interacting with the TeamGroupSkill builders. + TeamGroupSkill *TeamGroupSkillClient // TeamHost is the client for interacting with the TeamHost builders. TeamHost *TeamHostClient // TeamImage is the client for interacting with the TeamImage builders. @@ -142,6 +149,8 @@ type Client struct { TeamModel *TeamModelClient // TeamOIDCConfig is the client for interacting with the TeamOIDCConfig builders. TeamOIDCConfig *TeamOIDCConfigClient + // TeamSkill is the client for interacting with the TeamSkill builders. + TeamSkill *TeamSkillClient // User is the client for interacting with the User builders. User *UserClient // UserIdentity is the client for interacting with the UserIdentity builders. @@ -182,6 +191,7 @@ func (c *Client) init() { c.ProjectIssue = NewProjectIssueClient(c.config) c.ProjectIssueComment = NewProjectIssueCommentClient(c.config) c.ProjectTask = NewProjectTaskClient(c.config) + c.Skill = NewSkillClient(c.config) c.Task = NewTaskClient(c.config) c.TaskModelSwitch = NewTaskModelSwitchClient(c.config) c.TaskUsageStat = NewTaskUsageStatClient(c.config) @@ -192,11 +202,13 @@ func (c *Client) init() { c.TeamGroupImage = NewTeamGroupImageClient(c.config) c.TeamGroupMember = NewTeamGroupMemberClient(c.config) c.TeamGroupModel = NewTeamGroupModelClient(c.config) + c.TeamGroupSkill = NewTeamGroupSkillClient(c.config) c.TeamHost = NewTeamHostClient(c.config) c.TeamImage = NewTeamImageClient(c.config) c.TeamMember = NewTeamMemberClient(c.config) c.TeamModel = NewTeamModelClient(c.config) c.TeamOIDCConfig = NewTeamOIDCConfigClient(c.config) + c.TeamSkill = NewTeamSkillClient(c.config) c.User = NewUserClient(c.config) c.UserIdentity = NewUserIdentityClient(c.config) c.VirtualMachine = NewVirtualMachineClient(c.config) @@ -315,6 +327,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { ProjectIssue: NewProjectIssueClient(cfg), ProjectIssueComment: NewProjectIssueCommentClient(cfg), ProjectTask: NewProjectTaskClient(cfg), + Skill: NewSkillClient(cfg), Task: NewTaskClient(cfg), TaskModelSwitch: NewTaskModelSwitchClient(cfg), TaskUsageStat: NewTaskUsageStatClient(cfg), @@ -325,11 +338,13 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { TeamGroupImage: NewTeamGroupImageClient(cfg), TeamGroupMember: NewTeamGroupMemberClient(cfg), TeamGroupModel: NewTeamGroupModelClient(cfg), + TeamGroupSkill: NewTeamGroupSkillClient(cfg), TeamHost: NewTeamHostClient(cfg), TeamImage: NewTeamImageClient(cfg), TeamMember: NewTeamMemberClient(cfg), TeamModel: NewTeamModelClient(cfg), TeamOIDCConfig: NewTeamOIDCConfigClient(cfg), + TeamSkill: NewTeamSkillClient(cfg), User: NewUserClient(cfg), UserIdentity: NewUserIdentityClient(cfg), VirtualMachine: NewVirtualMachineClient(cfg), @@ -375,6 +390,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) ProjectIssue: NewProjectIssueClient(cfg), ProjectIssueComment: NewProjectIssueCommentClient(cfg), ProjectTask: NewProjectTaskClient(cfg), + Skill: NewSkillClient(cfg), Task: NewTaskClient(cfg), TaskModelSwitch: NewTaskModelSwitchClient(cfg), TaskUsageStat: NewTaskUsageStatClient(cfg), @@ -385,11 +401,13 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) TeamGroupImage: NewTeamGroupImageClient(cfg), TeamGroupMember: NewTeamGroupMemberClient(cfg), TeamGroupModel: NewTeamGroupModelClient(cfg), + TeamGroupSkill: NewTeamGroupSkillClient(cfg), TeamHost: NewTeamHostClient(cfg), TeamImage: NewTeamImageClient(cfg), TeamMember: NewTeamMemberClient(cfg), TeamModel: NewTeamModelClient(cfg), TeamOIDCConfig: NewTeamOIDCConfigClient(cfg), + TeamSkill: NewTeamSkillClient(cfg), User: NewUserClient(cfg), UserIdentity: NewUserIdentityClient(cfg), VirtualMachine: NewVirtualMachineClient(cfg), @@ -426,11 +444,11 @@ func (c *Client) Use(hooks ...Hook) { c.Image, c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model, c.ModelApiKey, c.ModelPricing, c.NotifyChannel, c.NotifySendLog, c.NotifySubscription, c.Project, c.ProjectCollaborator, c.ProjectGitBot, - c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Task, + c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Skill, c.Task, c.TaskModelSwitch, c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup, c.TeamGroupHost, c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel, - c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, c.TeamOIDCConfig, c.User, - c.UserIdentity, c.VirtualMachine, + c.TeamGroupSkill, c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, + c.TeamOIDCConfig, c.TeamSkill, c.User, c.UserIdentity, c.VirtualMachine, } { n.Use(hooks...) } @@ -444,11 +462,11 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.Image, c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model, c.ModelApiKey, c.ModelPricing, c.NotifyChannel, c.NotifySendLog, c.NotifySubscription, c.Project, c.ProjectCollaborator, c.ProjectGitBot, - c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Task, + c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Skill, c.Task, c.TaskModelSwitch, c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup, c.TeamGroupHost, c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel, - c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, c.TeamOIDCConfig, c.User, - c.UserIdentity, c.VirtualMachine, + c.TeamGroupSkill, c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, + c.TeamOIDCConfig, c.TeamSkill, c.User, c.UserIdentity, c.VirtualMachine, } { n.Intercept(interceptors...) } @@ -503,6 +521,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.ProjectIssueComment.mutate(ctx, m) case *ProjectTaskMutation: return c.ProjectTask.mutate(ctx, m) + case *SkillMutation: + return c.Skill.mutate(ctx, m) case *TaskMutation: return c.Task.mutate(ctx, m) case *TaskModelSwitchMutation: @@ -523,6 +543,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.TeamGroupMember.mutate(ctx, m) case *TeamGroupModelMutation: return c.TeamGroupModel.mutate(ctx, m) + case *TeamGroupSkillMutation: + return c.TeamGroupSkill.mutate(ctx, m) case *TeamHostMutation: return c.TeamHost.mutate(ctx, m) case *TeamImageMutation: @@ -533,6 +555,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.TeamModel.mutate(ctx, m) case *TeamOIDCConfigMutation: return c.TeamOIDCConfig.mutate(ctx, m) + case *TeamSkillMutation: + return c.TeamSkill.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) case *UserIdentityMutation: @@ -4799,6 +4823,221 @@ func (c *ProjectTaskClient) mutate(ctx context.Context, m *ProjectTaskMutation) } } +// SkillClient is a client for the Skill schema. +type SkillClient struct { + config +} + +// NewSkillClient returns a client for the Skill from the given config. +func NewSkillClient(c config) *SkillClient { + return &SkillClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `skill.Hooks(f(g(h())))`. +func (c *SkillClient) Use(hooks ...Hook) { + c.hooks.Skill = append(c.hooks.Skill, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `skill.Intercept(f(g(h())))`. +func (c *SkillClient) Intercept(interceptors ...Interceptor) { + c.inters.Skill = append(c.inters.Skill, interceptors...) +} + +// Create returns a builder for creating a Skill entity. +func (c *SkillClient) Create() *SkillCreate { + mutation := newSkillMutation(c.config, OpCreate) + return &SkillCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Skill entities. +func (c *SkillClient) CreateBulk(builders ...*SkillCreate) *SkillCreateBulk { + return &SkillCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SkillClient) MapCreateBulk(slice any, setFunc func(*SkillCreate, int)) *SkillCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SkillCreateBulk{err: fmt.Errorf("calling to SkillClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SkillCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SkillCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Skill. +func (c *SkillClient) Update() *SkillUpdate { + mutation := newSkillMutation(c.config, OpUpdate) + return &SkillUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SkillClient) UpdateOne(_m *Skill) *SkillUpdateOne { + mutation := newSkillMutation(c.config, OpUpdateOne, withSkill(_m)) + return &SkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SkillClient) UpdateOneID(id uuid.UUID) *SkillUpdateOne { + mutation := newSkillMutation(c.config, OpUpdateOne, withSkillID(id)) + return &SkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Skill. +func (c *SkillClient) Delete() *SkillDelete { + mutation := newSkillMutation(c.config, OpDelete) + return &SkillDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SkillClient) DeleteOne(_m *Skill) *SkillDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SkillClient) DeleteOneID(id uuid.UUID) *SkillDeleteOne { + builder := c.Delete().Where(skill.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SkillDeleteOne{builder} +} + +// Query returns a query builder for Skill. +func (c *SkillClient) Query() *SkillQuery { + return &SkillQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSkill}, + inters: c.Interceptors(), + } +} + +// Get returns a Skill entity by its id. +func (c *SkillClient) Get(ctx context.Context, id uuid.UUID) (*Skill, error) { + return c.Query().Where(skill.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SkillClient) GetX(ctx context.Context, id uuid.UUID) *Skill { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryUser queries the user edge of a Skill. +func (c *SkillClient) QueryUser(_m *Skill) *UserQuery { + query := (&UserClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, id), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, skill.UserTable, skill.UserColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryTeams queries the teams edge of a Skill. +func (c *SkillClient) QueryTeams(_m *Skill) *TeamQuery { + query := (&TeamClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, id), + sqlgraph.To(team.Table, team.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, skill.TeamsTable, skill.TeamsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryGroups queries the groups edge of a Skill. +func (c *SkillClient) QueryGroups(_m *Skill) *TeamGroupQuery { + query := (&TeamGroupClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, id), + sqlgraph.To(teamgroup.Table, teamgroup.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, skill.GroupsTable, skill.GroupsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryTeamSkills queries the team_skills edge of a Skill. +func (c *SkillClient) QueryTeamSkills(_m *Skill) *TeamSkillQuery { + query := (&TeamSkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, id), + sqlgraph.To(teamskill.Table, teamskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, skill.TeamSkillsTable, skill.TeamSkillsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryTeamGroupSkills queries the team_group_skills edge of a Skill. +func (c *SkillClient) QueryTeamGroupSkills(_m *Skill) *TeamGroupSkillQuery { + query := (&TeamGroupSkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, id), + sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, skill.TeamGroupSkillsTable, skill.TeamGroupSkillsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *SkillClient) Hooks() []Hook { + hooks := c.hooks.Skill + return append(hooks[:len(hooks):len(hooks)], skill.Hooks[:]...) +} + +// Interceptors returns the client interceptors. +func (c *SkillClient) Interceptors() []Interceptor { + inters := c.inters.Skill + return append(inters[:len(inters):len(inters)], skill.Interceptors[:]...) +} + +func (c *SkillClient) mutate(ctx context.Context, m *SkillMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SkillCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SkillUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SkillDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown Skill mutation op: %q", m.Op()) + } +} + // TaskClient is a client for the Task schema. type TaskClient struct { config @@ -5713,6 +5952,22 @@ func (c *TeamClient) QueryImages(_m *Team) *ImageQuery { return query } +// QuerySkills queries the skills edge of a Team. +func (c *TeamClient) QuerySkills(_m *Team) *SkillQuery { + query := (&SkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(team.Table, team.FieldID, id), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, team.SkillsTable, team.SkillsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryTeamMembers queries the team_members edge of a Team. func (c *TeamClient) QueryTeamMembers(_m *Team) *TeamMemberQuery { query := (&TeamMemberClient{config: c.config}).Query() @@ -5761,6 +6016,22 @@ func (c *TeamClient) QueryTeamImages(_m *Team) *TeamImageQuery { return query } +// QueryTeamSkills queries the team_skills edge of a Team. +func (c *TeamClient) QueryTeamSkills(_m *Team) *TeamSkillQuery { + query := (&TeamSkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(team.Table, team.FieldID, id), + sqlgraph.To(teamskill.Table, teamskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, team.TeamSkillsTable, team.TeamSkillsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *TeamClient) Hooks() []Hook { hooks := c.hooks.Team @@ -5976,6 +6247,22 @@ func (c *TeamGroupClient) QueryHosts(_m *TeamGroup) *HostQuery { return query } +// QuerySkills queries the skills edge of a TeamGroup. +func (c *TeamGroupClient) QuerySkills(_m *TeamGroup) *SkillQuery { + query := (&SkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamgroup.Table, teamgroup.FieldID, id), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, teamgroup.SkillsTable, teamgroup.SkillsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryTeamGroupMembers queries the team_group_members edge of a TeamGroup. func (c *TeamGroupClient) QueryTeamGroupMembers(_m *TeamGroup) *TeamGroupMemberQuery { query := (&TeamGroupMemberClient{config: c.config}).Query() @@ -6040,6 +6327,22 @@ func (c *TeamGroupClient) QueryTeamGroupHosts(_m *TeamGroup) *TeamGroupHostQuery return query } +// QueryTeamGroupSkills queries the team_group_skills edge of a TeamGroup. +func (c *TeamGroupClient) QueryTeamGroupSkills(_m *TeamGroup) *TeamGroupSkillQuery { + query := (&TeamGroupSkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamgroup.Table, teamgroup.FieldID, id), + sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, teamgroup.TeamGroupSkillsTable, teamgroup.TeamGroupSkillsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *TeamGroupClient) Hooks() []Hook { hooks := c.hooks.TeamGroup @@ -6727,6 +7030,171 @@ func (c *TeamGroupModelClient) mutate(ctx context.Context, m *TeamGroupModelMuta } } +// TeamGroupSkillClient is a client for the TeamGroupSkill schema. +type TeamGroupSkillClient struct { + config +} + +// NewTeamGroupSkillClient returns a client for the TeamGroupSkill from the given config. +func NewTeamGroupSkillClient(c config) *TeamGroupSkillClient { + return &TeamGroupSkillClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `teamgroupskill.Hooks(f(g(h())))`. +func (c *TeamGroupSkillClient) Use(hooks ...Hook) { + c.hooks.TeamGroupSkill = append(c.hooks.TeamGroupSkill, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `teamgroupskill.Intercept(f(g(h())))`. +func (c *TeamGroupSkillClient) Intercept(interceptors ...Interceptor) { + c.inters.TeamGroupSkill = append(c.inters.TeamGroupSkill, interceptors...) +} + +// Create returns a builder for creating a TeamGroupSkill entity. +func (c *TeamGroupSkillClient) Create() *TeamGroupSkillCreate { + mutation := newTeamGroupSkillMutation(c.config, OpCreate) + return &TeamGroupSkillCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of TeamGroupSkill entities. +func (c *TeamGroupSkillClient) CreateBulk(builders ...*TeamGroupSkillCreate) *TeamGroupSkillCreateBulk { + return &TeamGroupSkillCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TeamGroupSkillClient) MapCreateBulk(slice any, setFunc func(*TeamGroupSkillCreate, int)) *TeamGroupSkillCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TeamGroupSkillCreateBulk{err: fmt.Errorf("calling to TeamGroupSkillClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TeamGroupSkillCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TeamGroupSkillCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for TeamGroupSkill. +func (c *TeamGroupSkillClient) Update() *TeamGroupSkillUpdate { + mutation := newTeamGroupSkillMutation(c.config, OpUpdate) + return &TeamGroupSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *TeamGroupSkillClient) UpdateOne(_m *TeamGroupSkill) *TeamGroupSkillUpdateOne { + mutation := newTeamGroupSkillMutation(c.config, OpUpdateOne, withTeamGroupSkill(_m)) + return &TeamGroupSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *TeamGroupSkillClient) UpdateOneID(id uuid.UUID) *TeamGroupSkillUpdateOne { + mutation := newTeamGroupSkillMutation(c.config, OpUpdateOne, withTeamGroupSkillID(id)) + return &TeamGroupSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for TeamGroupSkill. +func (c *TeamGroupSkillClient) Delete() *TeamGroupSkillDelete { + mutation := newTeamGroupSkillMutation(c.config, OpDelete) + return &TeamGroupSkillDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *TeamGroupSkillClient) DeleteOne(_m *TeamGroupSkill) *TeamGroupSkillDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *TeamGroupSkillClient) DeleteOneID(id uuid.UUID) *TeamGroupSkillDeleteOne { + builder := c.Delete().Where(teamgroupskill.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &TeamGroupSkillDeleteOne{builder} +} + +// Query returns a query builder for TeamGroupSkill. +func (c *TeamGroupSkillClient) Query() *TeamGroupSkillQuery { + return &TeamGroupSkillQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeTeamGroupSkill}, + inters: c.Interceptors(), + } +} + +// Get returns a TeamGroupSkill entity by its id. +func (c *TeamGroupSkillClient) Get(ctx context.Context, id uuid.UUID) (*TeamGroupSkill, error) { + return c.Query().Where(teamgroupskill.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *TeamGroupSkillClient) GetX(ctx context.Context, id uuid.UUID) *TeamGroupSkill { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryGroup queries the group edge of a TeamGroupSkill. +func (c *TeamGroupSkillClient) QueryGroup(_m *TeamGroupSkill) *TeamGroupQuery { + query := (&TeamGroupClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, id), + sqlgraph.To(teamgroup.Table, teamgroup.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.GroupTable, teamgroupskill.GroupColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySkill queries the skill edge of a TeamGroupSkill. +func (c *TeamGroupSkillClient) QuerySkill(_m *TeamGroupSkill) *SkillQuery { + query := (&SkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, id), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.SkillTable, teamgroupskill.SkillColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *TeamGroupSkillClient) Hooks() []Hook { + return c.hooks.TeamGroupSkill +} + +// Interceptors returns the client interceptors. +func (c *TeamGroupSkillClient) Interceptors() []Interceptor { + return c.inters.TeamGroupSkill +} + +func (c *TeamGroupSkillClient) mutate(ctx context.Context, m *TeamGroupSkillMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TeamGroupSkillCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TeamGroupSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TeamGroupSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TeamGroupSkillDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown TeamGroupSkill mutation op: %q", m.Op()) + } +} + // TeamHostClient is a client for the TeamHost schema. type TeamHostClient struct { config @@ -7536,6 +8004,171 @@ func (c *TeamOIDCConfigClient) mutate(ctx context.Context, m *TeamOIDCConfigMuta } } +// TeamSkillClient is a client for the TeamSkill schema. +type TeamSkillClient struct { + config +} + +// NewTeamSkillClient returns a client for the TeamSkill from the given config. +func NewTeamSkillClient(c config) *TeamSkillClient { + return &TeamSkillClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `teamskill.Hooks(f(g(h())))`. +func (c *TeamSkillClient) Use(hooks ...Hook) { + c.hooks.TeamSkill = append(c.hooks.TeamSkill, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `teamskill.Intercept(f(g(h())))`. +func (c *TeamSkillClient) Intercept(interceptors ...Interceptor) { + c.inters.TeamSkill = append(c.inters.TeamSkill, interceptors...) +} + +// Create returns a builder for creating a TeamSkill entity. +func (c *TeamSkillClient) Create() *TeamSkillCreate { + mutation := newTeamSkillMutation(c.config, OpCreate) + return &TeamSkillCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of TeamSkill entities. +func (c *TeamSkillClient) CreateBulk(builders ...*TeamSkillCreate) *TeamSkillCreateBulk { + return &TeamSkillCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TeamSkillClient) MapCreateBulk(slice any, setFunc func(*TeamSkillCreate, int)) *TeamSkillCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TeamSkillCreateBulk{err: fmt.Errorf("calling to TeamSkillClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TeamSkillCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TeamSkillCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for TeamSkill. +func (c *TeamSkillClient) Update() *TeamSkillUpdate { + mutation := newTeamSkillMutation(c.config, OpUpdate) + return &TeamSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *TeamSkillClient) UpdateOne(_m *TeamSkill) *TeamSkillUpdateOne { + mutation := newTeamSkillMutation(c.config, OpUpdateOne, withTeamSkill(_m)) + return &TeamSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *TeamSkillClient) UpdateOneID(id uuid.UUID) *TeamSkillUpdateOne { + mutation := newTeamSkillMutation(c.config, OpUpdateOne, withTeamSkillID(id)) + return &TeamSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for TeamSkill. +func (c *TeamSkillClient) Delete() *TeamSkillDelete { + mutation := newTeamSkillMutation(c.config, OpDelete) + return &TeamSkillDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *TeamSkillClient) DeleteOne(_m *TeamSkill) *TeamSkillDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *TeamSkillClient) DeleteOneID(id uuid.UUID) *TeamSkillDeleteOne { + builder := c.Delete().Where(teamskill.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &TeamSkillDeleteOne{builder} +} + +// Query returns a query builder for TeamSkill. +func (c *TeamSkillClient) Query() *TeamSkillQuery { + return &TeamSkillQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeTeamSkill}, + inters: c.Interceptors(), + } +} + +// Get returns a TeamSkill entity by its id. +func (c *TeamSkillClient) Get(ctx context.Context, id uuid.UUID) (*TeamSkill, error) { + return c.Query().Where(teamskill.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *TeamSkillClient) GetX(ctx context.Context, id uuid.UUID) *TeamSkill { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryTeam queries the team edge of a TeamSkill. +func (c *TeamSkillClient) QueryTeam(_m *TeamSkill) *TeamQuery { + query := (&TeamClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamskill.Table, teamskill.FieldID, id), + sqlgraph.To(team.Table, team.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamskill.TeamTable, teamskill.TeamColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySkill queries the skill edge of a TeamSkill. +func (c *TeamSkillClient) QuerySkill(_m *TeamSkill) *SkillQuery { + query := (&SkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamskill.Table, teamskill.FieldID, id), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamskill.SkillTable, teamskill.SkillColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *TeamSkillClient) Hooks() []Hook { + return c.hooks.TeamSkill +} + +// Interceptors returns the client interceptors. +func (c *TeamSkillClient) Interceptors() []Interceptor { + return c.inters.TeamSkill +} + +func (c *TeamSkillClient) mutate(ctx context.Context, m *TeamSkillMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TeamSkillCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TeamSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TeamSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TeamSkillDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown TeamSkill mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -7740,6 +8373,22 @@ func (c *UserClient) QueryImages(_m *User) *ImageQuery { return query } +// QuerySkills queries the skills edge of a User. +func (c *UserClient) QuerySkills(_m *User) *SkillQuery { + query := (&SkillClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(user.Table, user.FieldID, id), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.SkillsTable, user.SkillsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryHosts queries the hosts edge of a User. func (c *UserClient) QueryHosts(_m *User) *HostQuery { query := (&HostClient{config: c.config}).Query() @@ -8395,21 +9044,21 @@ type ( Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, GitTask, Host, Image, MCPTool, MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing, NotifyChannel, NotifySendLog, NotifySubscription, Project, ProjectCollaborator, - ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Task, + ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Skill, Task, TaskModelSwitch, TaskUsageStat, TaskVirtualMachine, Team, TeamGroup, - TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamHost, - TeamImage, TeamMember, TeamModel, TeamOIDCConfig, User, UserIdentity, - VirtualMachine []ent.Hook + TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamGroupSkill, + TeamHost, TeamImage, TeamMember, TeamModel, TeamOIDCConfig, TeamSkill, User, + UserIdentity, VirtualMachine []ent.Hook } inters struct { Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, GitTask, Host, Image, MCPTool, MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing, NotifyChannel, NotifySendLog, NotifySubscription, Project, ProjectCollaborator, - ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Task, + ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Skill, Task, TaskModelSwitch, TaskUsageStat, TaskVirtualMachine, Team, TeamGroup, - TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamHost, - TeamImage, TeamMember, TeamModel, TeamOIDCConfig, User, UserIdentity, - VirtualMachine []ent.Interceptor + TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamGroupSkill, + TeamHost, TeamImage, TeamMember, TeamModel, TeamOIDCConfig, TeamSkill, User, + UserIdentity, VirtualMachine []ent.Interceptor } ) diff --git a/backend/db/cursor.go b/backend/db/cursor.go index c2ca17eb..5c53d7cf 100644 --- a/backend/db/cursor.go +++ b/backend/db/cursor.go @@ -22,10 +22,12 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/project" "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamgrouphost" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/google/uuid" ) @@ -618,6 +620,51 @@ func (q *ProjectIssueCommentQuery) After(ctx context.Context, cursor string, lim return nodes, res, nil } +func (q *SkillQuery) After(ctx context.Context, cursor string, limit int) ([]*Skill, *Cursor, error) { + i, err := unmarshalCreatedAt(cursor) + if err != nil { + return nil, nil, err + } + q.Order(skill.ByCreatedAt(sql.OrderDesc()), skill.ByID(sql.OrderDesc())) + q.Limit(limit + 1) + + if i != nil { + q.Where(func(s *sql.Selector) { + s.Where(sql.Or( + sql.LT(s.C("created_at"), i.CreatedAt), + sql.And( + sql.EQ(s.C("created_at"), i.CreatedAt), + sql.LT(s.C("id"), i.ID), + ), + )) + }) + } + nodes, err := q.All(ctx) + if err != nil { + return nil, nil, err + } + + res := &Cursor{} + if len(nodes) > limit { + res.HasNextPage = true + nodes = nodes[:limit] + } + + if len(nodes) > 0 { + last := nodes[len(nodes)-1] + i := &createdAtCursor{ + CreatedAt: last.CreatedAt, + ID: last.ID, + } + cursor, err := i.marshal() + if err != nil { + return nil, nil, err + } + res.Cursor = cursor + } + return nodes, res, nil +} + func (q *TaskQuery) After(ctx context.Context, cursor string, limit int) ([]*Task, *Cursor, error) { i, err := unmarshalCreatedAt(cursor) if err != nil { @@ -797,3 +844,48 @@ func (q *TeamGroupModelQuery) After(ctx context.Context, cursor string, limit in } return nodes, res, nil } + +func (q *TeamGroupSkillQuery) After(ctx context.Context, cursor string, limit int) ([]*TeamGroupSkill, *Cursor, error) { + i, err := unmarshalCreatedAt(cursor) + if err != nil { + return nil, nil, err + } + q.Order(teamgroupskill.ByCreatedAt(sql.OrderDesc()), teamgroupskill.ByID(sql.OrderDesc())) + q.Limit(limit + 1) + + if i != nil { + q.Where(func(s *sql.Selector) { + s.Where(sql.Or( + sql.LT(s.C("created_at"), i.CreatedAt), + sql.And( + sql.EQ(s.C("created_at"), i.CreatedAt), + sql.LT(s.C("id"), i.ID), + ), + )) + }) + } + nodes, err := q.All(ctx) + if err != nil { + return nil, nil, err + } + + res := &Cursor{} + if len(nodes) > limit { + res.HasNextPage = true + nodes = nodes[:limit] + } + + if len(nodes) > 0 { + last := nodes[len(nodes)-1] + i := &createdAtCursor{ + CreatedAt: last.CreatedAt, + ID: last.ID, + } + cursor, err := i.marshal() + if err != nil { + return nil, nil, err + } + res.Cursor = cursor + } + return nodes, res, nil +} diff --git a/backend/db/ent.go b/backend/db/ent.go index d4e57b21..2ed7ba1a 100644 --- a/backend/db/ent.go +++ b/backend/db/ent.go @@ -35,6 +35,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" "github.com/chaitin/MonkeyCode/backend/db/projecttask" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/taskusagestat" @@ -45,11 +46,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/teamhost" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" "github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/useridentity" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" @@ -136,6 +139,7 @@ func checkColumn(t, c string) error { projectissue.Table: projectissue.ValidColumn, projectissuecomment.Table: projectissuecomment.ValidColumn, projecttask.Table: projecttask.ValidColumn, + skill.Table: skill.ValidColumn, task.Table: task.ValidColumn, taskmodelswitch.Table: taskmodelswitch.ValidColumn, taskusagestat.Table: taskusagestat.ValidColumn, @@ -146,11 +150,13 @@ func checkColumn(t, c string) error { teamgroupimage.Table: teamgroupimage.ValidColumn, teamgroupmember.Table: teamgroupmember.ValidColumn, teamgroupmodel.Table: teamgroupmodel.ValidColumn, + teamgroupskill.Table: teamgroupskill.ValidColumn, teamhost.Table: teamhost.ValidColumn, teamimage.Table: teamimage.ValidColumn, teammember.Table: teammember.ValidColumn, teammodel.Table: teammodel.ValidColumn, teamoidcconfig.Table: teamoidcconfig.ValidColumn, + teamskill.Table: teamskill.ValidColumn, user.Table: user.ValidColumn, useridentity.Table: useridentity.ValidColumn, virtualmachine.Table: virtualmachine.ValidColumn, diff --git a/backend/db/hook/hook.go b/backend/db/hook/hook.go index 88c72cbb..feb67a63 100644 --- a/backend/db/hook/hook.go +++ b/backend/db/hook/hook.go @@ -285,6 +285,18 @@ func (f ProjectTaskFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, e return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ProjectTaskMutation", m) } +// The SkillFunc type is an adapter to allow the use of ordinary +// function as Skill mutator. +type SkillFunc func(context.Context, *db.SkillMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f SkillFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.SkillMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.SkillMutation", m) +} + // The TaskFunc type is an adapter to allow the use of ordinary // function as Task mutator. type TaskFunc func(context.Context, *db.TaskMutation) (db.Value, error) @@ -405,6 +417,18 @@ func (f TeamGroupModelFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamGroupModelMutation", m) } +// The TeamGroupSkillFunc type is an adapter to allow the use of ordinary +// function as TeamGroupSkill mutator. +type TeamGroupSkillFunc func(context.Context, *db.TeamGroupSkillMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f TeamGroupSkillFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.TeamGroupSkillMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamGroupSkillMutation", m) +} + // The TeamHostFunc type is an adapter to allow the use of ordinary // function as TeamHost mutator. type TeamHostFunc func(context.Context, *db.TeamHostMutation) (db.Value, error) @@ -465,6 +489,18 @@ func (f TeamOIDCConfigFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamOIDCConfigMutation", m) } +// The TeamSkillFunc type is an adapter to allow the use of ordinary +// function as TeamSkill mutator. +type TeamSkillFunc func(context.Context, *db.TeamSkillMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f TeamSkillFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.TeamSkillMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamSkillMutation", m) +} + // The UserFunc type is an adapter to allow the use of ordinary // function as User mutator. type UserFunc func(context.Context, *db.UserMutation) (db.Value, error) diff --git a/backend/db/intercept/intercept.go b/backend/db/intercept/intercept.go index cd073016..5b7af694 100644 --- a/backend/db/intercept/intercept.go +++ b/backend/db/intercept/intercept.go @@ -32,6 +32,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" "github.com/chaitin/MonkeyCode/backend/db/projecttask" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/taskusagestat" @@ -42,11 +43,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/teamhost" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" "github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/useridentity" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" @@ -729,6 +732,33 @@ func (f TraverseProjectTask) Traverse(ctx context.Context, q db.Query) error { return fmt.Errorf("unexpected query type %T. expect *db.ProjectTaskQuery", q) } +// The SkillFunc type is an adapter to allow the use of ordinary function as a Querier. +type SkillFunc func(context.Context, *db.SkillQuery) (db.Value, error) + +// Query calls f(ctx, q). +func (f SkillFunc) Query(ctx context.Context, q db.Query) (db.Value, error) { + if q, ok := q.(*db.SkillQuery); ok { + return f(ctx, q) + } + return nil, fmt.Errorf("unexpected query type %T. expect *db.SkillQuery", q) +} + +// The TraverseSkill type is an adapter to allow the use of ordinary function as Traverser. +type TraverseSkill func(context.Context, *db.SkillQuery) error + +// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. +func (f TraverseSkill) Intercept(next db.Querier) db.Querier { + return next +} + +// Traverse calls f(ctx, q). +func (f TraverseSkill) Traverse(ctx context.Context, q db.Query) error { + if q, ok := q.(*db.SkillQuery); ok { + return f(ctx, q) + } + return fmt.Errorf("unexpected query type %T. expect *db.SkillQuery", q) +} + // The TaskFunc type is an adapter to allow the use of ordinary function as a Querier. type TaskFunc func(context.Context, *db.TaskQuery) (db.Value, error) @@ -999,6 +1029,33 @@ func (f TraverseTeamGroupModel) Traverse(ctx context.Context, q db.Query) error return fmt.Errorf("unexpected query type %T. expect *db.TeamGroupModelQuery", q) } +// The TeamGroupSkillFunc type is an adapter to allow the use of ordinary function as a Querier. +type TeamGroupSkillFunc func(context.Context, *db.TeamGroupSkillQuery) (db.Value, error) + +// Query calls f(ctx, q). +func (f TeamGroupSkillFunc) Query(ctx context.Context, q db.Query) (db.Value, error) { + if q, ok := q.(*db.TeamGroupSkillQuery); ok { + return f(ctx, q) + } + return nil, fmt.Errorf("unexpected query type %T. expect *db.TeamGroupSkillQuery", q) +} + +// The TraverseTeamGroupSkill type is an adapter to allow the use of ordinary function as Traverser. +type TraverseTeamGroupSkill func(context.Context, *db.TeamGroupSkillQuery) error + +// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. +func (f TraverseTeamGroupSkill) Intercept(next db.Querier) db.Querier { + return next +} + +// Traverse calls f(ctx, q). +func (f TraverseTeamGroupSkill) Traverse(ctx context.Context, q db.Query) error { + if q, ok := q.(*db.TeamGroupSkillQuery); ok { + return f(ctx, q) + } + return fmt.Errorf("unexpected query type %T. expect *db.TeamGroupSkillQuery", q) +} + // The TeamHostFunc type is an adapter to allow the use of ordinary function as a Querier. type TeamHostFunc func(context.Context, *db.TeamHostQuery) (db.Value, error) @@ -1134,6 +1191,33 @@ func (f TraverseTeamOIDCConfig) Traverse(ctx context.Context, q db.Query) error return fmt.Errorf("unexpected query type %T. expect *db.TeamOIDCConfigQuery", q) } +// The TeamSkillFunc type is an adapter to allow the use of ordinary function as a Querier. +type TeamSkillFunc func(context.Context, *db.TeamSkillQuery) (db.Value, error) + +// Query calls f(ctx, q). +func (f TeamSkillFunc) Query(ctx context.Context, q db.Query) (db.Value, error) { + if q, ok := q.(*db.TeamSkillQuery); ok { + return f(ctx, q) + } + return nil, fmt.Errorf("unexpected query type %T. expect *db.TeamSkillQuery", q) +} + +// The TraverseTeamSkill type is an adapter to allow the use of ordinary function as Traverser. +type TraverseTeamSkill func(context.Context, *db.TeamSkillQuery) error + +// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. +func (f TraverseTeamSkill) Intercept(next db.Querier) db.Querier { + return next +} + +// Traverse calls f(ctx, q). +func (f TraverseTeamSkill) Traverse(ctx context.Context, q db.Query) error { + if q, ok := q.(*db.TeamSkillQuery); ok { + return f(ctx, q) + } + return fmt.Errorf("unexpected query type %T. expect *db.TeamSkillQuery", q) +} + // The UserFunc type is an adapter to allow the use of ordinary function as a Querier. type UserFunc func(context.Context, *db.UserQuery) (db.Value, error) @@ -1264,6 +1348,8 @@ func NewQuery(q db.Query) (Query, error) { return &query[*db.ProjectIssueCommentQuery, predicate.ProjectIssueComment, projectissuecomment.OrderOption]{typ: db.TypeProjectIssueComment, tq: q}, nil case *db.ProjectTaskQuery: return &query[*db.ProjectTaskQuery, predicate.ProjectTask, projecttask.OrderOption]{typ: db.TypeProjectTask, tq: q}, nil + case *db.SkillQuery: + return &query[*db.SkillQuery, predicate.Skill, skill.OrderOption]{typ: db.TypeSkill, tq: q}, nil case *db.TaskQuery: return &query[*db.TaskQuery, predicate.Task, task.OrderOption]{typ: db.TypeTask, tq: q}, nil case *db.TaskModelSwitchQuery: @@ -1284,6 +1370,8 @@ func NewQuery(q db.Query) (Query, error) { return &query[*db.TeamGroupMemberQuery, predicate.TeamGroupMember, teamgroupmember.OrderOption]{typ: db.TypeTeamGroupMember, tq: q}, nil case *db.TeamGroupModelQuery: return &query[*db.TeamGroupModelQuery, predicate.TeamGroupModel, teamgroupmodel.OrderOption]{typ: db.TypeTeamGroupModel, tq: q}, nil + case *db.TeamGroupSkillQuery: + return &query[*db.TeamGroupSkillQuery, predicate.TeamGroupSkill, teamgroupskill.OrderOption]{typ: db.TypeTeamGroupSkill, tq: q}, nil case *db.TeamHostQuery: return &query[*db.TeamHostQuery, predicate.TeamHost, teamhost.OrderOption]{typ: db.TypeTeamHost, tq: q}, nil case *db.TeamImageQuery: @@ -1294,6 +1382,8 @@ func NewQuery(q db.Query) (Query, error) { return &query[*db.TeamModelQuery, predicate.TeamModel, teammodel.OrderOption]{typ: db.TypeTeamModel, tq: q}, nil case *db.TeamOIDCConfigQuery: return &query[*db.TeamOIDCConfigQuery, predicate.TeamOIDCConfig, teamoidcconfig.OrderOption]{typ: db.TypeTeamOIDCConfig, tq: q}, nil + case *db.TeamSkillQuery: + return &query[*db.TeamSkillQuery, predicate.TeamSkill, teamskill.OrderOption]{typ: db.TypeTeamSkill, tq: q}, nil case *db.UserQuery: return &query[*db.UserQuery, predicate.User, user.OrderOption]{typ: db.TypeUser, tq: q}, nil case *db.UserIdentityQuery: diff --git a/backend/db/migrate/schema.go b/backend/db/migrate/schema.go index a72fe816..cf3fdacf 100644 --- a/backend/db/migrate/schema.go +++ b/backend/db/migrate/schema.go @@ -783,6 +783,37 @@ var ( }, }, } + // SkillsColumns holds the columns for the "skills" table. + SkillsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, + {Name: "name", Type: field.TypeString}, + {Name: "description", Type: field.TypeString, Size: 2147483647}, + {Name: "tags", Type: field.TypeJSON, Nullable: true}, + {Name: "content", Type: field.TypeString, Size: 2147483647}, + {Name: "package_object_key", Type: field.TypeString, Nullable: true}, + {Name: "package_url", Type: field.TypeString, Nullable: true}, + {Name: "source_type", Type: field.TypeString}, + {Name: "source_label", Type: field.TypeString}, + {Name: "skill_md_path", Type: field.TypeString, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "user_id", Type: field.TypeUUID}, + } + // SkillsTable holds the schema information for the "skills" table. + SkillsTable = &schema.Table{ + Name: "skills", + Columns: SkillsColumns, + PrimaryKey: []*schema.Column{SkillsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "skills_users_skills", + Columns: []*schema.Column{SkillsColumns[13]}, + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } // TasksColumns holds the columns for the "tasks" table. TasksColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -1114,6 +1145,40 @@ var ( }, }, } + // TeamGroupSkillsColumns holds the columns for the "team_group_skills" table. + TeamGroupSkillsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "group_id", Type: field.TypeUUID}, + {Name: "skill_id", Type: field.TypeUUID}, + } + // TeamGroupSkillsTable holds the schema information for the "team_group_skills" table. + TeamGroupSkillsTable = &schema.Table{ + Name: "team_group_skills", + Columns: TeamGroupSkillsColumns, + PrimaryKey: []*schema.Column{TeamGroupSkillsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "team_group_skills_team_groups_group", + Columns: []*schema.Column{TeamGroupSkillsColumns[2]}, + RefColumns: []*schema.Column{TeamGroupsColumns[0]}, + OnDelete: schema.NoAction, + }, + { + Symbol: "team_group_skills_skills_skill", + Columns: []*schema.Column{TeamGroupSkillsColumns[3]}, + RefColumns: []*schema.Column{SkillsColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + Indexes: []*schema.Index{ + { + Name: "teamgroupskill_group_id_skill_id", + Unique: true, + Columns: []*schema.Column{TeamGroupSkillsColumns[2], TeamGroupSkillsColumns[3]}, + }, + }, + } // TeamHostsColumns holds the columns for the "team_hosts" table. TeamHostsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, @@ -1281,6 +1346,40 @@ var ( }, }, } + // TeamSkillsColumns holds the columns for the "team_skills" table. + TeamSkillsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "team_id", Type: field.TypeUUID}, + {Name: "skill_id", Type: field.TypeUUID}, + } + // TeamSkillsTable holds the schema information for the "team_skills" table. + TeamSkillsTable = &schema.Table{ + Name: "team_skills", + Columns: TeamSkillsColumns, + PrimaryKey: []*schema.Column{TeamSkillsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "team_skills_teams_team", + Columns: []*schema.Column{TeamSkillsColumns[2]}, + RefColumns: []*schema.Column{TeamsColumns[0]}, + OnDelete: schema.NoAction, + }, + { + Symbol: "team_skills_skills_skill", + Columns: []*schema.Column{TeamSkillsColumns[3]}, + RefColumns: []*schema.Column{SkillsColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + Indexes: []*schema.Index{ + { + Name: "teamskill_team_id_skill_id", + Unique: true, + Columns: []*schema.Column{TeamSkillsColumns[2], TeamSkillsColumns[3]}, + }, + }, + } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, @@ -1415,6 +1514,7 @@ var ( ProjectIssuesTable, ProjectIssueCommentsTable, ProjectTasksTable, + SkillsTable, TasksTable, TaskModelSwitchesTable, TaskUsageStatsTable, @@ -1425,11 +1525,13 @@ var ( TeamGroupImagesTable, TeamGroupMembersTable, TeamGroupModelsTable, + TeamGroupSkillsTable, TeamHostsTable, TeamImagesTable, TeamMembersTable, TeamModelsTable, TeamOidcConfigsTable, + TeamSkillsTable, UsersTable, UserIdentitiesTable, VirtualmachinesTable, @@ -1541,6 +1643,10 @@ func init() { ProjectTasksTable.Annotation = &entsql.Annotation{ Table: "project_tasks", } + SkillsTable.ForeignKeys[0].RefTable = UsersTable + SkillsTable.Annotation = &entsql.Annotation{ + Table: "skills", + } TasksTable.ForeignKeys[0].RefTable = UsersTable TasksTable.Annotation = &entsql.Annotation{ Table: "tasks", @@ -1587,6 +1693,11 @@ func init() { TeamGroupModelsTable.Annotation = &entsql.Annotation{ Table: "team_group_models", } + TeamGroupSkillsTable.ForeignKeys[0].RefTable = TeamGroupsTable + TeamGroupSkillsTable.ForeignKeys[1].RefTable = SkillsTable + TeamGroupSkillsTable.Annotation = &entsql.Annotation{ + Table: "team_group_skills", + } TeamHostsTable.ForeignKeys[0].RefTable = TeamsTable TeamHostsTable.ForeignKeys[1].RefTable = HostsTable TeamHostsTable.Annotation = &entsql.Annotation{ @@ -1611,6 +1722,11 @@ func init() { TeamOidcConfigsTable.Annotation = &entsql.Annotation{ Table: "team_oidc_configs", } + TeamSkillsTable.ForeignKeys[0].RefTable = TeamsTable + TeamSkillsTable.ForeignKeys[1].RefTable = SkillsTable + TeamSkillsTable.Annotation = &entsql.Annotation{ + Table: "team_skills", + } UsersTable.Annotation = &entsql.Annotation{ Table: "users", } diff --git a/backend/db/mutation.go b/backend/db/mutation.go index bd8e42ce..d3161b3e 100644 --- a/backend/db/mutation.go +++ b/backend/db/mutation.go @@ -36,6 +36,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" "github.com/chaitin/MonkeyCode/backend/db/projecttask" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/taskusagestat" @@ -46,11 +47,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/teamhost" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" "github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/useridentity" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" @@ -90,6 +93,7 @@ const ( TypeProjectIssue = "ProjectIssue" TypeProjectIssueComment = "ProjectIssueComment" TypeProjectTask = "ProjectTask" + TypeSkill = "Skill" TypeTask = "Task" TypeTaskModelSwitch = "TaskModelSwitch" TypeTaskUsageStat = "TaskUsageStat" @@ -100,11 +104,13 @@ const ( TypeTeamGroupImage = "TeamGroupImage" TypeTeamGroupMember = "TeamGroupMember" TypeTeamGroupModel = "TeamGroupModel" + TypeTeamGroupSkill = "TeamGroupSkill" TypeTeamHost = "TeamHost" TypeTeamImage = "TeamImage" TypeTeamMember = "TeamMember" TypeTeamModel = "TeamModel" TypeTeamOIDCConfig = "TeamOIDCConfig" + TypeTeamSkill = "TeamSkill" TypeUser = "User" TypeUserIdentity = "UserIdentity" TypeVirtualMachine = "VirtualMachine" @@ -25215,6 +25221,1489 @@ func (m *ProjectTaskMutation) ResetEdge(name string) error { return fmt.Errorf("unknown ProjectTask edge %s", name) } +// SkillMutation represents an operation that mutates the Skill nodes in the graph. +type SkillMutation struct { + config + op Op + typ string + id *uuid.UUID + deleted_at *time.Time + name *string + description *string + tags *[]string + appendtags []string + content *string + package_object_key *string + package_url *string + source_type *string + source_label *string + skill_md_path *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + user *uuid.UUID + cleareduser bool + teams map[uuid.UUID]struct{} + removedteams map[uuid.UUID]struct{} + clearedteams bool + groups map[uuid.UUID]struct{} + removedgroups map[uuid.UUID]struct{} + clearedgroups bool + team_skills map[uuid.UUID]struct{} + removedteam_skills map[uuid.UUID]struct{} + clearedteam_skills bool + team_group_skills map[uuid.UUID]struct{} + removedteam_group_skills map[uuid.UUID]struct{} + clearedteam_group_skills bool + done bool + oldValue func(context.Context) (*Skill, error) + predicates []predicate.Skill +} + +var _ ent.Mutation = (*SkillMutation)(nil) + +// skillOption allows management of the mutation configuration using functional options. +type skillOption func(*SkillMutation) + +// newSkillMutation creates new mutation for the Skill entity. +func newSkillMutation(c config, op Op, opts ...skillOption) *SkillMutation { + m := &SkillMutation{ + config: c, + op: op, + typ: TypeSkill, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSkillID sets the ID field of the mutation. +func withSkillID(id uuid.UUID) skillOption { + return func(m *SkillMutation) { + var ( + err error + once sync.Once + value *Skill + ) + m.oldValue = func(ctx context.Context) (*Skill, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Skill.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSkill sets the old Skill of the mutation. +func withSkill(node *Skill) skillOption { + return func(m *SkillMutation) { + m.oldValue = func(context.Context) (*Skill, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SkillMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SkillMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("db: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Skill entities. +func (m *SkillMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SkillMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SkillMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Skill.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetDeletedAt sets the "deleted_at" field. +func (m *SkillMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t +} + +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *SkillMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at + if v == nil { + return + } + return *v, true +} + +// OldDeletedAt returns the old "deleted_at" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDeletedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) + } + return oldValue.DeletedAt, nil +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *SkillMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[skill.FieldDeletedAt] = struct{}{} +} + +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *SkillMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[skill.FieldDeletedAt] + return ok +} + +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *SkillMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, skill.FieldDeletedAt) +} + +// SetUserID sets the "user_id" field. +func (m *SkillMutation) SetUserID(u uuid.UUID) { + m.user = &u +} + +// UserID returns the value of the "user_id" field in the mutation. +func (m *SkillMutation) UserID() (r uuid.UUID, exists bool) { + v := m.user + if v == nil { + return + } + return *v, true +} + +// OldUserID returns the old "user_id" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUserID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUserID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUserID: %w", err) + } + return oldValue.UserID, nil +} + +// ResetUserID resets all changes to the "user_id" field. +func (m *SkillMutation) ResetUserID() { + m.user = nil +} + +// SetName sets the "name" field. +func (m *SkillMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *SkillMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *SkillMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *SkillMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *SkillMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ResetDescription resets all changes to the "description" field. +func (m *SkillMutation) ResetDescription() { + m.description = nil +} + +// SetTags sets the "tags" field. +func (m *SkillMutation) SetTags(s []string) { + m.tags = &s + m.appendtags = nil +} + +// Tags returns the value of the "tags" field in the mutation. +func (m *SkillMutation) Tags() (r []string, exists bool) { + v := m.tags + if v == nil { + return + } + return *v, true +} + +// OldTags returns the old "tags" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldTags(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTags is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTags requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTags: %w", err) + } + return oldValue.Tags, nil +} + +// AppendTags adds s to the "tags" field. +func (m *SkillMutation) AppendTags(s []string) { + m.appendtags = append(m.appendtags, s...) +} + +// AppendedTags returns the list of values that were appended to the "tags" field in this mutation. +func (m *SkillMutation) AppendedTags() ([]string, bool) { + if len(m.appendtags) == 0 { + return nil, false + } + return m.appendtags, true +} + +// ClearTags clears the value of the "tags" field. +func (m *SkillMutation) ClearTags() { + m.tags = nil + m.appendtags = nil + m.clearedFields[skill.FieldTags] = struct{}{} +} + +// TagsCleared returns if the "tags" field was cleared in this mutation. +func (m *SkillMutation) TagsCleared() bool { + _, ok := m.clearedFields[skill.FieldTags] + return ok +} + +// ResetTags resets all changes to the "tags" field. +func (m *SkillMutation) ResetTags() { + m.tags = nil + m.appendtags = nil + delete(m.clearedFields, skill.FieldTags) +} + +// SetContent sets the "content" field. +func (m *SkillMutation) SetContent(s string) { + m.content = &s +} + +// Content returns the value of the "content" field in the mutation. +func (m *SkillMutation) Content() (r string, exists bool) { + v := m.content + if v == nil { + return + } + return *v, true +} + +// OldContent returns the old "content" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldContent(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldContent is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldContent requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldContent: %w", err) + } + return oldValue.Content, nil +} + +// ResetContent resets all changes to the "content" field. +func (m *SkillMutation) ResetContent() { + m.content = nil +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (m *SkillMutation) SetPackageObjectKey(s string) { + m.package_object_key = &s +} + +// PackageObjectKey returns the value of the "package_object_key" field in the mutation. +func (m *SkillMutation) PackageObjectKey() (r string, exists bool) { + v := m.package_object_key + if v == nil { + return + } + return *v, true +} + +// OldPackageObjectKey returns the old "package_object_key" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldPackageObjectKey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPackageObjectKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPackageObjectKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPackageObjectKey: %w", err) + } + return oldValue.PackageObjectKey, nil +} + +// ClearPackageObjectKey clears the value of the "package_object_key" field. +func (m *SkillMutation) ClearPackageObjectKey() { + m.package_object_key = nil + m.clearedFields[skill.FieldPackageObjectKey] = struct{}{} +} + +// PackageObjectKeyCleared returns if the "package_object_key" field was cleared in this mutation. +func (m *SkillMutation) PackageObjectKeyCleared() bool { + _, ok := m.clearedFields[skill.FieldPackageObjectKey] + return ok +} + +// ResetPackageObjectKey resets all changes to the "package_object_key" field. +func (m *SkillMutation) ResetPackageObjectKey() { + m.package_object_key = nil + delete(m.clearedFields, skill.FieldPackageObjectKey) +} + +// SetPackageURL sets the "package_url" field. +func (m *SkillMutation) SetPackageURL(s string) { + m.package_url = &s +} + +// PackageURL returns the value of the "package_url" field in the mutation. +func (m *SkillMutation) PackageURL() (r string, exists bool) { + v := m.package_url + if v == nil { + return + } + return *v, true +} + +// OldPackageURL returns the old "package_url" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldPackageURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPackageURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPackageURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPackageURL: %w", err) + } + return oldValue.PackageURL, nil +} + +// ClearPackageURL clears the value of the "package_url" field. +func (m *SkillMutation) ClearPackageURL() { + m.package_url = nil + m.clearedFields[skill.FieldPackageURL] = struct{}{} +} + +// PackageURLCleared returns if the "package_url" field was cleared in this mutation. +func (m *SkillMutation) PackageURLCleared() bool { + _, ok := m.clearedFields[skill.FieldPackageURL] + return ok +} + +// ResetPackageURL resets all changes to the "package_url" field. +func (m *SkillMutation) ResetPackageURL() { + m.package_url = nil + delete(m.clearedFields, skill.FieldPackageURL) +} + +// SetSourceType sets the "source_type" field. +func (m *SkillMutation) SetSourceType(s string) { + m.source_type = &s +} + +// SourceType returns the value of the "source_type" field in the mutation. +func (m *SkillMutation) SourceType() (r string, exists bool) { + v := m.source_type + if v == nil { + return + } + return *v, true +} + +// OldSourceType returns the old "source_type" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldSourceType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSourceType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSourceType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSourceType: %w", err) + } + return oldValue.SourceType, nil +} + +// ResetSourceType resets all changes to the "source_type" field. +func (m *SkillMutation) ResetSourceType() { + m.source_type = nil +} + +// SetSourceLabel sets the "source_label" field. +func (m *SkillMutation) SetSourceLabel(s string) { + m.source_label = &s +} + +// SourceLabel returns the value of the "source_label" field in the mutation. +func (m *SkillMutation) SourceLabel() (r string, exists bool) { + v := m.source_label + if v == nil { + return + } + return *v, true +} + +// OldSourceLabel returns the old "source_label" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldSourceLabel(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSourceLabel is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSourceLabel requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSourceLabel: %w", err) + } + return oldValue.SourceLabel, nil +} + +// ResetSourceLabel resets all changes to the "source_label" field. +func (m *SkillMutation) ResetSourceLabel() { + m.source_label = nil +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (m *SkillMutation) SetSkillMdPath(s string) { + m.skill_md_path = &s +} + +// SkillMdPath returns the value of the "skill_md_path" field in the mutation. +func (m *SkillMutation) SkillMdPath() (r string, exists bool) { + v := m.skill_md_path + if v == nil { + return + } + return *v, true +} + +// OldSkillMdPath returns the old "skill_md_path" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldSkillMdPath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSkillMdPath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSkillMdPath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSkillMdPath: %w", err) + } + return oldValue.SkillMdPath, nil +} + +// ClearSkillMdPath clears the value of the "skill_md_path" field. +func (m *SkillMutation) ClearSkillMdPath() { + m.skill_md_path = nil + m.clearedFields[skill.FieldSkillMdPath] = struct{}{} +} + +// SkillMdPathCleared returns if the "skill_md_path" field was cleared in this mutation. +func (m *SkillMutation) SkillMdPathCleared() bool { + _, ok := m.clearedFields[skill.FieldSkillMdPath] + return ok +} + +// ResetSkillMdPath resets all changes to the "skill_md_path" field. +func (m *SkillMutation) ResetSkillMdPath() { + m.skill_md_path = nil + delete(m.clearedFields, skill.FieldSkillMdPath) +} + +// SetCreatedAt sets the "created_at" field. +func (m *SkillMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SkillMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SkillMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *SkillMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *SkillMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Skill entity. +// If the Skill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SkillMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *SkillMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearUser clears the "user" edge to the User entity. +func (m *SkillMutation) ClearUser() { + m.cleareduser = true + m.clearedFields[skill.FieldUserID] = struct{}{} +} + +// UserCleared reports if the "user" edge to the User entity was cleared. +func (m *SkillMutation) UserCleared() bool { + return m.cleareduser +} + +// UserIDs returns the "user" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// UserID instead. It exists only for internal usage by the builders. +func (m *SkillMutation) UserIDs() (ids []uuid.UUID) { + if id := m.user; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetUser resets all changes to the "user" edge. +func (m *SkillMutation) ResetUser() { + m.user = nil + m.cleareduser = false +} + +// AddTeamIDs adds the "teams" edge to the Team entity by ids. +func (m *SkillMutation) AddTeamIDs(ids ...uuid.UUID) { + if m.teams == nil { + m.teams = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.teams[ids[i]] = struct{}{} + } +} + +// ClearTeams clears the "teams" edge to the Team entity. +func (m *SkillMutation) ClearTeams() { + m.clearedteams = true +} + +// TeamsCleared reports if the "teams" edge to the Team entity was cleared. +func (m *SkillMutation) TeamsCleared() bool { + return m.clearedteams +} + +// RemoveTeamIDs removes the "teams" edge to the Team entity by IDs. +func (m *SkillMutation) RemoveTeamIDs(ids ...uuid.UUID) { + if m.removedteams == nil { + m.removedteams = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.teams, ids[i]) + m.removedteams[ids[i]] = struct{}{} + } +} + +// RemovedTeams returns the removed IDs of the "teams" edge to the Team entity. +func (m *SkillMutation) RemovedTeamsIDs() (ids []uuid.UUID) { + for id := range m.removedteams { + ids = append(ids, id) + } + return +} + +// TeamsIDs returns the "teams" edge IDs in the mutation. +func (m *SkillMutation) TeamsIDs() (ids []uuid.UUID) { + for id := range m.teams { + ids = append(ids, id) + } + return +} + +// ResetTeams resets all changes to the "teams" edge. +func (m *SkillMutation) ResetTeams() { + m.teams = nil + m.clearedteams = false + m.removedteams = nil +} + +// AddGroupIDs adds the "groups" edge to the TeamGroup entity by ids. +func (m *SkillMutation) AddGroupIDs(ids ...uuid.UUID) { + if m.groups == nil { + m.groups = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.groups[ids[i]] = struct{}{} + } +} + +// ClearGroups clears the "groups" edge to the TeamGroup entity. +func (m *SkillMutation) ClearGroups() { + m.clearedgroups = true +} + +// GroupsCleared reports if the "groups" edge to the TeamGroup entity was cleared. +func (m *SkillMutation) GroupsCleared() bool { + return m.clearedgroups +} + +// RemoveGroupIDs removes the "groups" edge to the TeamGroup entity by IDs. +func (m *SkillMutation) RemoveGroupIDs(ids ...uuid.UUID) { + if m.removedgroups == nil { + m.removedgroups = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.groups, ids[i]) + m.removedgroups[ids[i]] = struct{}{} + } +} + +// RemovedGroups returns the removed IDs of the "groups" edge to the TeamGroup entity. +func (m *SkillMutation) RemovedGroupsIDs() (ids []uuid.UUID) { + for id := range m.removedgroups { + ids = append(ids, id) + } + return +} + +// GroupsIDs returns the "groups" edge IDs in the mutation. +func (m *SkillMutation) GroupsIDs() (ids []uuid.UUID) { + for id := range m.groups { + ids = append(ids, id) + } + return +} + +// ResetGroups resets all changes to the "groups" edge. +func (m *SkillMutation) ResetGroups() { + m.groups = nil + m.clearedgroups = false + m.removedgroups = nil +} + +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by ids. +func (m *SkillMutation) AddTeamSkillIDs(ids ...uuid.UUID) { + if m.team_skills == nil { + m.team_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.team_skills[ids[i]] = struct{}{} + } +} + +// ClearTeamSkills clears the "team_skills" edge to the TeamSkill entity. +func (m *SkillMutation) ClearTeamSkills() { + m.clearedteam_skills = true +} + +// TeamSkillsCleared reports if the "team_skills" edge to the TeamSkill entity was cleared. +func (m *SkillMutation) TeamSkillsCleared() bool { + return m.clearedteam_skills +} + +// RemoveTeamSkillIDs removes the "team_skills" edge to the TeamSkill entity by IDs. +func (m *SkillMutation) RemoveTeamSkillIDs(ids ...uuid.UUID) { + if m.removedteam_skills == nil { + m.removedteam_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.team_skills, ids[i]) + m.removedteam_skills[ids[i]] = struct{}{} + } +} + +// RemovedTeamSkills returns the removed IDs of the "team_skills" edge to the TeamSkill entity. +func (m *SkillMutation) RemovedTeamSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedteam_skills { + ids = append(ids, id) + } + return +} + +// TeamSkillsIDs returns the "team_skills" edge IDs in the mutation. +func (m *SkillMutation) TeamSkillsIDs() (ids []uuid.UUID) { + for id := range m.team_skills { + ids = append(ids, id) + } + return +} + +// ResetTeamSkills resets all changes to the "team_skills" edge. +func (m *SkillMutation) ResetTeamSkills() { + m.team_skills = nil + m.clearedteam_skills = false + m.removedteam_skills = nil +} + +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by ids. +func (m *SkillMutation) AddTeamGroupSkillIDs(ids ...uuid.UUID) { + if m.team_group_skills == nil { + m.team_group_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.team_group_skills[ids[i]] = struct{}{} + } +} + +// ClearTeamGroupSkills clears the "team_group_skills" edge to the TeamGroupSkill entity. +func (m *SkillMutation) ClearTeamGroupSkills() { + m.clearedteam_group_skills = true +} + +// TeamGroupSkillsCleared reports if the "team_group_skills" edge to the TeamGroupSkill entity was cleared. +func (m *SkillMutation) TeamGroupSkillsCleared() bool { + return m.clearedteam_group_skills +} + +// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (m *SkillMutation) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) { + if m.removedteam_group_skills == nil { + m.removedteam_group_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.team_group_skills, ids[i]) + m.removedteam_group_skills[ids[i]] = struct{}{} + } +} + +// RemovedTeamGroupSkills returns the removed IDs of the "team_group_skills" edge to the TeamGroupSkill entity. +func (m *SkillMutation) RemovedTeamGroupSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedteam_group_skills { + ids = append(ids, id) + } + return +} + +// TeamGroupSkillsIDs returns the "team_group_skills" edge IDs in the mutation. +func (m *SkillMutation) TeamGroupSkillsIDs() (ids []uuid.UUID) { + for id := range m.team_group_skills { + ids = append(ids, id) + } + return +} + +// ResetTeamGroupSkills resets all changes to the "team_group_skills" edge. +func (m *SkillMutation) ResetTeamGroupSkills() { + m.team_group_skills = nil + m.clearedteam_group_skills = false + m.removedteam_group_skills = nil +} + +// Where appends a list predicates to the SkillMutation builder. +func (m *SkillMutation) Where(ps ...predicate.Skill) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SkillMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SkillMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Skill, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SkillMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SkillMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Skill). +func (m *SkillMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SkillMutation) Fields() []string { + fields := make([]string, 0, 13) + if m.deleted_at != nil { + fields = append(fields, skill.FieldDeletedAt) + } + if m.user != nil { + fields = append(fields, skill.FieldUserID) + } + if m.name != nil { + fields = append(fields, skill.FieldName) + } + if m.description != nil { + fields = append(fields, skill.FieldDescription) + } + if m.tags != nil { + fields = append(fields, skill.FieldTags) + } + if m.content != nil { + fields = append(fields, skill.FieldContent) + } + if m.package_object_key != nil { + fields = append(fields, skill.FieldPackageObjectKey) + } + if m.package_url != nil { + fields = append(fields, skill.FieldPackageURL) + } + if m.source_type != nil { + fields = append(fields, skill.FieldSourceType) + } + if m.source_label != nil { + fields = append(fields, skill.FieldSourceLabel) + } + if m.skill_md_path != nil { + fields = append(fields, skill.FieldSkillMdPath) + } + if m.created_at != nil { + fields = append(fields, skill.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, skill.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SkillMutation) Field(name string) (ent.Value, bool) { + switch name { + case skill.FieldDeletedAt: + return m.DeletedAt() + case skill.FieldUserID: + return m.UserID() + case skill.FieldName: + return m.Name() + case skill.FieldDescription: + return m.Description() + case skill.FieldTags: + return m.Tags() + case skill.FieldContent: + return m.Content() + case skill.FieldPackageObjectKey: + return m.PackageObjectKey() + case skill.FieldPackageURL: + return m.PackageURL() + case skill.FieldSourceType: + return m.SourceType() + case skill.FieldSourceLabel: + return m.SourceLabel() + case skill.FieldSkillMdPath: + return m.SkillMdPath() + case skill.FieldCreatedAt: + return m.CreatedAt() + case skill.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SkillMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case skill.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case skill.FieldUserID: + return m.OldUserID(ctx) + case skill.FieldName: + return m.OldName(ctx) + case skill.FieldDescription: + return m.OldDescription(ctx) + case skill.FieldTags: + return m.OldTags(ctx) + case skill.FieldContent: + return m.OldContent(ctx) + case skill.FieldPackageObjectKey: + return m.OldPackageObjectKey(ctx) + case skill.FieldPackageURL: + return m.OldPackageURL(ctx) + case skill.FieldSourceType: + return m.OldSourceType(ctx) + case skill.FieldSourceLabel: + return m.OldSourceLabel(ctx) + case skill.FieldSkillMdPath: + return m.OldSkillMdPath(ctx) + case skill.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case skill.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Skill field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SkillMutation) SetField(name string, value ent.Value) error { + switch name { + case skill.FieldDeletedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDeletedAt(v) + return nil + case skill.FieldUserID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserID(v) + return nil + case skill.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case skill.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case skill.FieldTags: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTags(v) + return nil + case skill.FieldContent: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetContent(v) + return nil + case skill.FieldPackageObjectKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPackageObjectKey(v) + return nil + case skill.FieldPackageURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPackageURL(v) + return nil + case skill.FieldSourceType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSourceType(v) + return nil + case skill.FieldSourceLabel: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSourceLabel(v) + return nil + case skill.FieldSkillMdPath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSkillMdPath(v) + return nil + case skill.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case skill.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Skill field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SkillMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SkillMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SkillMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Skill numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SkillMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(skill.FieldDeletedAt) { + fields = append(fields, skill.FieldDeletedAt) + } + if m.FieldCleared(skill.FieldTags) { + fields = append(fields, skill.FieldTags) + } + if m.FieldCleared(skill.FieldPackageObjectKey) { + fields = append(fields, skill.FieldPackageObjectKey) + } + if m.FieldCleared(skill.FieldPackageURL) { + fields = append(fields, skill.FieldPackageURL) + } + if m.FieldCleared(skill.FieldSkillMdPath) { + fields = append(fields, skill.FieldSkillMdPath) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SkillMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SkillMutation) ClearField(name string) error { + switch name { + case skill.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case skill.FieldTags: + m.ClearTags() + return nil + case skill.FieldPackageObjectKey: + m.ClearPackageObjectKey() + return nil + case skill.FieldPackageURL: + m.ClearPackageURL() + return nil + case skill.FieldSkillMdPath: + m.ClearSkillMdPath() + return nil + } + return fmt.Errorf("unknown Skill nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SkillMutation) ResetField(name string) error { + switch name { + case skill.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case skill.FieldUserID: + m.ResetUserID() + return nil + case skill.FieldName: + m.ResetName() + return nil + case skill.FieldDescription: + m.ResetDescription() + return nil + case skill.FieldTags: + m.ResetTags() + return nil + case skill.FieldContent: + m.ResetContent() + return nil + case skill.FieldPackageObjectKey: + m.ResetPackageObjectKey() + return nil + case skill.FieldPackageURL: + m.ResetPackageURL() + return nil + case skill.FieldSourceType: + m.ResetSourceType() + return nil + case skill.FieldSourceLabel: + m.ResetSourceLabel() + return nil + case skill.FieldSkillMdPath: + m.ResetSkillMdPath() + return nil + case skill.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case skill.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Skill field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SkillMutation) AddedEdges() []string { + edges := make([]string, 0, 5) + if m.user != nil { + edges = append(edges, skill.EdgeUser) + } + if m.teams != nil { + edges = append(edges, skill.EdgeTeams) + } + if m.groups != nil { + edges = append(edges, skill.EdgeGroups) + } + if m.team_skills != nil { + edges = append(edges, skill.EdgeTeamSkills) + } + if m.team_group_skills != nil { + edges = append(edges, skill.EdgeTeamGroupSkills) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SkillMutation) AddedIDs(name string) []ent.Value { + switch name { + case skill.EdgeUser: + if id := m.user; id != nil { + return []ent.Value{*id} + } + case skill.EdgeTeams: + ids := make([]ent.Value, 0, len(m.teams)) + for id := range m.teams { + ids = append(ids, id) + } + return ids + case skill.EdgeGroups: + ids := make([]ent.Value, 0, len(m.groups)) + for id := range m.groups { + ids = append(ids, id) + } + return ids + case skill.EdgeTeamSkills: + ids := make([]ent.Value, 0, len(m.team_skills)) + for id := range m.team_skills { + ids = append(ids, id) + } + return ids + case skill.EdgeTeamGroupSkills: + ids := make([]ent.Value, 0, len(m.team_group_skills)) + for id := range m.team_group_skills { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SkillMutation) RemovedEdges() []string { + edges := make([]string, 0, 5) + if m.removedteams != nil { + edges = append(edges, skill.EdgeTeams) + } + if m.removedgroups != nil { + edges = append(edges, skill.EdgeGroups) + } + if m.removedteam_skills != nil { + edges = append(edges, skill.EdgeTeamSkills) + } + if m.removedteam_group_skills != nil { + edges = append(edges, skill.EdgeTeamGroupSkills) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SkillMutation) RemovedIDs(name string) []ent.Value { + switch name { + case skill.EdgeTeams: + ids := make([]ent.Value, 0, len(m.removedteams)) + for id := range m.removedteams { + ids = append(ids, id) + } + return ids + case skill.EdgeGroups: + ids := make([]ent.Value, 0, len(m.removedgroups)) + for id := range m.removedgroups { + ids = append(ids, id) + } + return ids + case skill.EdgeTeamSkills: + ids := make([]ent.Value, 0, len(m.removedteam_skills)) + for id := range m.removedteam_skills { + ids = append(ids, id) + } + return ids + case skill.EdgeTeamGroupSkills: + ids := make([]ent.Value, 0, len(m.removedteam_group_skills)) + for id := range m.removedteam_group_skills { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SkillMutation) ClearedEdges() []string { + edges := make([]string, 0, 5) + if m.cleareduser { + edges = append(edges, skill.EdgeUser) + } + if m.clearedteams { + edges = append(edges, skill.EdgeTeams) + } + if m.clearedgroups { + edges = append(edges, skill.EdgeGroups) + } + if m.clearedteam_skills { + edges = append(edges, skill.EdgeTeamSkills) + } + if m.clearedteam_group_skills { + edges = append(edges, skill.EdgeTeamGroupSkills) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SkillMutation) EdgeCleared(name string) bool { + switch name { + case skill.EdgeUser: + return m.cleareduser + case skill.EdgeTeams: + return m.clearedteams + case skill.EdgeGroups: + return m.clearedgroups + case skill.EdgeTeamSkills: + return m.clearedteam_skills + case skill.EdgeTeamGroupSkills: + return m.clearedteam_group_skills + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SkillMutation) ClearEdge(name string) error { + switch name { + case skill.EdgeUser: + m.ClearUser() + return nil + } + return fmt.Errorf("unknown Skill unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SkillMutation) ResetEdge(name string) error { + switch name { + case skill.EdgeUser: + m.ResetUser() + return nil + case skill.EdgeTeams: + m.ResetTeams() + return nil + case skill.EdgeGroups: + m.ResetGroups() + return nil + case skill.EdgeTeamSkills: + m.ResetTeamSkills() + return nil + case skill.EdgeTeamGroupSkills: + m.ResetTeamGroupSkills() + return nil + } + return fmt.Errorf("unknown Skill edge %s", name) +} + // TaskMutation represents an operation that mutates the Task nodes in the graph. type TaskMutation struct { config @@ -29276,6 +30765,9 @@ type TeamMutation struct { images map[uuid.UUID]struct{} removedimages map[uuid.UUID]struct{} clearedimages bool + skills map[uuid.UUID]struct{} + removedskills map[uuid.UUID]struct{} + clearedskills bool team_members map[uuid.UUID]struct{} removedteam_members map[uuid.UUID]struct{} clearedteam_members bool @@ -29285,6 +30777,9 @@ type TeamMutation struct { team_images map[uuid.UUID]struct{} removedteam_images map[uuid.UUID]struct{} clearedteam_images bool + team_skills map[uuid.UUID]struct{} + removedteam_skills map[uuid.UUID]struct{} + clearedteam_skills bool done bool oldValue func(context.Context) (*Team, error) predicates []predicate.Team @@ -30007,6 +31502,60 @@ func (m *TeamMutation) ResetImages() { m.removedimages = nil } +// AddSkillIDs adds the "skills" edge to the Skill entity by ids. +func (m *TeamMutation) AddSkillIDs(ids ...uuid.UUID) { + if m.skills == nil { + m.skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.skills[ids[i]] = struct{}{} + } +} + +// ClearSkills clears the "skills" edge to the Skill entity. +func (m *TeamMutation) ClearSkills() { + m.clearedskills = true +} + +// SkillsCleared reports if the "skills" edge to the Skill entity was cleared. +func (m *TeamMutation) SkillsCleared() bool { + return m.clearedskills +} + +// RemoveSkillIDs removes the "skills" edge to the Skill entity by IDs. +func (m *TeamMutation) RemoveSkillIDs(ids ...uuid.UUID) { + if m.removedskills == nil { + m.removedskills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.skills, ids[i]) + m.removedskills[ids[i]] = struct{}{} + } +} + +// RemovedSkills returns the removed IDs of the "skills" edge to the Skill entity. +func (m *TeamMutation) RemovedSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedskills { + ids = append(ids, id) + } + return +} + +// SkillsIDs returns the "skills" edge IDs in the mutation. +func (m *TeamMutation) SkillsIDs() (ids []uuid.UUID) { + for id := range m.skills { + ids = append(ids, id) + } + return +} + +// ResetSkills resets all changes to the "skills" edge. +func (m *TeamMutation) ResetSkills() { + m.skills = nil + m.clearedskills = false + m.removedskills = nil +} + // AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by ids. func (m *TeamMutation) AddTeamMemberIDs(ids ...uuid.UUID) { if m.team_members == nil { @@ -30169,6 +31718,60 @@ func (m *TeamMutation) ResetTeamImages() { m.removedteam_images = nil } +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by ids. +func (m *TeamMutation) AddTeamSkillIDs(ids ...uuid.UUID) { + if m.team_skills == nil { + m.team_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.team_skills[ids[i]] = struct{}{} + } +} + +// ClearTeamSkills clears the "team_skills" edge to the TeamSkill entity. +func (m *TeamMutation) ClearTeamSkills() { + m.clearedteam_skills = true +} + +// TeamSkillsCleared reports if the "team_skills" edge to the TeamSkill entity was cleared. +func (m *TeamMutation) TeamSkillsCleared() bool { + return m.clearedteam_skills +} + +// RemoveTeamSkillIDs removes the "team_skills" edge to the TeamSkill entity by IDs. +func (m *TeamMutation) RemoveTeamSkillIDs(ids ...uuid.UUID) { + if m.removedteam_skills == nil { + m.removedteam_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.team_skills, ids[i]) + m.removedteam_skills[ids[i]] = struct{}{} + } +} + +// RemovedTeamSkills returns the removed IDs of the "team_skills" edge to the TeamSkill entity. +func (m *TeamMutation) RemovedTeamSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedteam_skills { + ids = append(ids, id) + } + return +} + +// TeamSkillsIDs returns the "team_skills" edge IDs in the mutation. +func (m *TeamMutation) TeamSkillsIDs() (ids []uuid.UUID) { + for id := range m.team_skills { + ids = append(ids, id) + } + return +} + +// ResetTeamSkills resets all changes to the "team_skills" edge. +func (m *TeamMutation) ResetTeamSkills() { + m.team_skills = nil + m.clearedteam_skills = false + m.removedteam_skills = nil +} + // Where appends a list predicates to the TeamMutation builder. func (m *TeamMutation) Where(ps ...predicate.Team) { m.predicates = append(m.predicates, ps...) @@ -30486,7 +32089,7 @@ func (m *TeamMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *TeamMutation) AddedEdges() []string { - edges := make([]string, 0, 7) + edges := make([]string, 0, 9) if m.groups != nil { edges = append(edges, team.EdgeGroups) } @@ -30499,6 +32102,9 @@ func (m *TeamMutation) AddedEdges() []string { if m.images != nil { edges = append(edges, team.EdgeImages) } + if m.skills != nil { + edges = append(edges, team.EdgeSkills) + } if m.team_members != nil { edges = append(edges, team.EdgeTeamMembers) } @@ -30508,6 +32114,9 @@ func (m *TeamMutation) AddedEdges() []string { if m.team_images != nil { edges = append(edges, team.EdgeTeamImages) } + if m.team_skills != nil { + edges = append(edges, team.EdgeTeamSkills) + } return edges } @@ -30539,6 +32148,12 @@ func (m *TeamMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case team.EdgeSkills: + ids := make([]ent.Value, 0, len(m.skills)) + for id := range m.skills { + ids = append(ids, id) + } + return ids case team.EdgeTeamMembers: ids := make([]ent.Value, 0, len(m.team_members)) for id := range m.team_members { @@ -30557,13 +32172,19 @@ func (m *TeamMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case team.EdgeTeamSkills: + ids := make([]ent.Value, 0, len(m.team_skills)) + for id := range m.team_skills { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *TeamMutation) RemovedEdges() []string { - edges := make([]string, 0, 7) + edges := make([]string, 0, 9) if m.removedgroups != nil { edges = append(edges, team.EdgeGroups) } @@ -30576,6 +32197,9 @@ func (m *TeamMutation) RemovedEdges() []string { if m.removedimages != nil { edges = append(edges, team.EdgeImages) } + if m.removedskills != nil { + edges = append(edges, team.EdgeSkills) + } if m.removedteam_members != nil { edges = append(edges, team.EdgeTeamMembers) } @@ -30585,6 +32209,9 @@ func (m *TeamMutation) RemovedEdges() []string { if m.removedteam_images != nil { edges = append(edges, team.EdgeTeamImages) } + if m.removedteam_skills != nil { + edges = append(edges, team.EdgeTeamSkills) + } return edges } @@ -30616,6 +32243,12 @@ func (m *TeamMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case team.EdgeSkills: + ids := make([]ent.Value, 0, len(m.removedskills)) + for id := range m.removedskills { + ids = append(ids, id) + } + return ids case team.EdgeTeamMembers: ids := make([]ent.Value, 0, len(m.removedteam_members)) for id := range m.removedteam_members { @@ -30634,13 +32267,19 @@ func (m *TeamMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case team.EdgeTeamSkills: + ids := make([]ent.Value, 0, len(m.removedteam_skills)) + for id := range m.removedteam_skills { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TeamMutation) ClearedEdges() []string { - edges := make([]string, 0, 7) + edges := make([]string, 0, 9) if m.clearedgroups { edges = append(edges, team.EdgeGroups) } @@ -30653,6 +32292,9 @@ func (m *TeamMutation) ClearedEdges() []string { if m.clearedimages { edges = append(edges, team.EdgeImages) } + if m.clearedskills { + edges = append(edges, team.EdgeSkills) + } if m.clearedteam_members { edges = append(edges, team.EdgeTeamMembers) } @@ -30662,6 +32304,9 @@ func (m *TeamMutation) ClearedEdges() []string { if m.clearedteam_images { edges = append(edges, team.EdgeTeamImages) } + if m.clearedteam_skills { + edges = append(edges, team.EdgeTeamSkills) + } return edges } @@ -30677,12 +32322,16 @@ func (m *TeamMutation) EdgeCleared(name string) bool { return m.clearedmodels case team.EdgeImages: return m.clearedimages + case team.EdgeSkills: + return m.clearedskills case team.EdgeTeamMembers: return m.clearedteam_members case team.EdgeTeamModels: return m.clearedteam_models case team.EdgeTeamImages: return m.clearedteam_images + case team.EdgeTeamSkills: + return m.clearedteam_skills } return false } @@ -30711,6 +32360,9 @@ func (m *TeamMutation) ResetEdge(name string) error { case team.EdgeImages: m.ResetImages() return nil + case team.EdgeSkills: + m.ResetSkills() + return nil case team.EdgeTeamMembers: m.ResetTeamMembers() return nil @@ -30720,6 +32372,9 @@ func (m *TeamMutation) ResetEdge(name string) error { case team.EdgeTeamImages: m.ResetTeamImages() return nil + case team.EdgeTeamSkills: + m.ResetTeamSkills() + return nil } return fmt.Errorf("unknown Team edge %s", name) } @@ -30749,6 +32404,9 @@ type TeamGroupMutation struct { hosts map[string]struct{} removedhosts map[string]struct{} clearedhosts bool + skills map[uuid.UUID]struct{} + removedskills map[uuid.UUID]struct{} + clearedskills bool team_group_members map[uuid.UUID]struct{} removedteam_group_members map[uuid.UUID]struct{} clearedteam_group_members bool @@ -30761,6 +32419,9 @@ type TeamGroupMutation struct { team_group_hosts map[uuid.UUID]struct{} removedteam_group_hosts map[uuid.UUID]struct{} clearedteam_group_hosts bool + team_group_skills map[uuid.UUID]struct{} + removedteam_group_skills map[uuid.UUID]struct{} + clearedteam_group_skills bool done bool oldValue func(context.Context) (*TeamGroup, error) predicates []predicate.TeamGroup @@ -31306,6 +32967,60 @@ func (m *TeamGroupMutation) ResetHosts() { m.removedhosts = nil } +// AddSkillIDs adds the "skills" edge to the Skill entity by ids. +func (m *TeamGroupMutation) AddSkillIDs(ids ...uuid.UUID) { + if m.skills == nil { + m.skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.skills[ids[i]] = struct{}{} + } +} + +// ClearSkills clears the "skills" edge to the Skill entity. +func (m *TeamGroupMutation) ClearSkills() { + m.clearedskills = true +} + +// SkillsCleared reports if the "skills" edge to the Skill entity was cleared. +func (m *TeamGroupMutation) SkillsCleared() bool { + return m.clearedskills +} + +// RemoveSkillIDs removes the "skills" edge to the Skill entity by IDs. +func (m *TeamGroupMutation) RemoveSkillIDs(ids ...uuid.UUID) { + if m.removedskills == nil { + m.removedskills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.skills, ids[i]) + m.removedskills[ids[i]] = struct{}{} + } +} + +// RemovedSkills returns the removed IDs of the "skills" edge to the Skill entity. +func (m *TeamGroupMutation) RemovedSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedskills { + ids = append(ids, id) + } + return +} + +// SkillsIDs returns the "skills" edge IDs in the mutation. +func (m *TeamGroupMutation) SkillsIDs() (ids []uuid.UUID) { + for id := range m.skills { + ids = append(ids, id) + } + return +} + +// ResetSkills resets all changes to the "skills" edge. +func (m *TeamGroupMutation) ResetSkills() { + m.skills = nil + m.clearedskills = false + m.removedskills = nil +} + // AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by ids. func (m *TeamGroupMutation) AddTeamGroupMemberIDs(ids ...uuid.UUID) { if m.team_group_members == nil { @@ -31522,6 +33237,60 @@ func (m *TeamGroupMutation) ResetTeamGroupHosts() { m.removedteam_group_hosts = nil } +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by ids. +func (m *TeamGroupMutation) AddTeamGroupSkillIDs(ids ...uuid.UUID) { + if m.team_group_skills == nil { + m.team_group_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.team_group_skills[ids[i]] = struct{}{} + } +} + +// ClearTeamGroupSkills clears the "team_group_skills" edge to the TeamGroupSkill entity. +func (m *TeamGroupMutation) ClearTeamGroupSkills() { + m.clearedteam_group_skills = true +} + +// TeamGroupSkillsCleared reports if the "team_group_skills" edge to the TeamGroupSkill entity was cleared. +func (m *TeamGroupMutation) TeamGroupSkillsCleared() bool { + return m.clearedteam_group_skills +} + +// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (m *TeamGroupMutation) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) { + if m.removedteam_group_skills == nil { + m.removedteam_group_skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.team_group_skills, ids[i]) + m.removedteam_group_skills[ids[i]] = struct{}{} + } +} + +// RemovedTeamGroupSkills returns the removed IDs of the "team_group_skills" edge to the TeamGroupSkill entity. +func (m *TeamGroupMutation) RemovedTeamGroupSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedteam_group_skills { + ids = append(ids, id) + } + return +} + +// TeamGroupSkillsIDs returns the "team_group_skills" edge IDs in the mutation. +func (m *TeamGroupMutation) TeamGroupSkillsIDs() (ids []uuid.UUID) { + for id := range m.team_group_skills { + ids = append(ids, id) + } + return +} + +// ResetTeamGroupSkills resets all changes to the "team_group_skills" edge. +func (m *TeamGroupMutation) ResetTeamGroupSkills() { + m.team_group_skills = nil + m.clearedteam_group_skills = false + m.removedteam_group_skills = nil +} + // Where appends a list predicates to the TeamGroupMutation builder. func (m *TeamGroupMutation) Where(ps ...predicate.TeamGroup) { m.predicates = append(m.predicates, ps...) @@ -31732,7 +33501,7 @@ func (m *TeamGroupMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *TeamGroupMutation) AddedEdges() []string { - edges := make([]string, 0, 9) + edges := make([]string, 0, 11) if m.members != nil { edges = append(edges, teamgroup.EdgeMembers) } @@ -31748,6 +33517,9 @@ func (m *TeamGroupMutation) AddedEdges() []string { if m.hosts != nil { edges = append(edges, teamgroup.EdgeHosts) } + if m.skills != nil { + edges = append(edges, teamgroup.EdgeSkills) + } if m.team_group_members != nil { edges = append(edges, teamgroup.EdgeTeamGroupMembers) } @@ -31760,6 +33532,9 @@ func (m *TeamGroupMutation) AddedEdges() []string { if m.team_group_hosts != nil { edges = append(edges, teamgroup.EdgeTeamGroupHosts) } + if m.team_group_skills != nil { + edges = append(edges, teamgroup.EdgeTeamGroupSkills) + } return edges } @@ -31795,6 +33570,12 @@ func (m *TeamGroupMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case teamgroup.EdgeSkills: + ids := make([]ent.Value, 0, len(m.skills)) + for id := range m.skills { + ids = append(ids, id) + } + return ids case teamgroup.EdgeTeamGroupMembers: ids := make([]ent.Value, 0, len(m.team_group_members)) for id := range m.team_group_members { @@ -31819,13 +33600,19 @@ func (m *TeamGroupMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case teamgroup.EdgeTeamGroupSkills: + ids := make([]ent.Value, 0, len(m.team_group_skills)) + for id := range m.team_group_skills { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *TeamGroupMutation) RemovedEdges() []string { - edges := make([]string, 0, 9) + edges := make([]string, 0, 11) if m.removedmembers != nil { edges = append(edges, teamgroup.EdgeMembers) } @@ -31838,6 +33625,9 @@ func (m *TeamGroupMutation) RemovedEdges() []string { if m.removedhosts != nil { edges = append(edges, teamgroup.EdgeHosts) } + if m.removedskills != nil { + edges = append(edges, teamgroup.EdgeSkills) + } if m.removedteam_group_members != nil { edges = append(edges, teamgroup.EdgeTeamGroupMembers) } @@ -31850,6 +33640,9 @@ func (m *TeamGroupMutation) RemovedEdges() []string { if m.removedteam_group_hosts != nil { edges = append(edges, teamgroup.EdgeTeamGroupHosts) } + if m.removedteam_group_skills != nil { + edges = append(edges, teamgroup.EdgeTeamGroupSkills) + } return edges } @@ -31881,6 +33674,12 @@ func (m *TeamGroupMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case teamgroup.EdgeSkills: + ids := make([]ent.Value, 0, len(m.removedskills)) + for id := range m.removedskills { + ids = append(ids, id) + } + return ids case teamgroup.EdgeTeamGroupMembers: ids := make([]ent.Value, 0, len(m.removedteam_group_members)) for id := range m.removedteam_group_members { @@ -31905,13 +33704,19 @@ func (m *TeamGroupMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case teamgroup.EdgeTeamGroupSkills: + ids := make([]ent.Value, 0, len(m.removedteam_group_skills)) + for id := range m.removedteam_group_skills { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TeamGroupMutation) ClearedEdges() []string { - edges := make([]string, 0, 9) + edges := make([]string, 0, 11) if m.clearedmembers { edges = append(edges, teamgroup.EdgeMembers) } @@ -31927,6 +33732,9 @@ func (m *TeamGroupMutation) ClearedEdges() []string { if m.clearedhosts { edges = append(edges, teamgroup.EdgeHosts) } + if m.clearedskills { + edges = append(edges, teamgroup.EdgeSkills) + } if m.clearedteam_group_members { edges = append(edges, teamgroup.EdgeTeamGroupMembers) } @@ -31939,6 +33747,9 @@ func (m *TeamGroupMutation) ClearedEdges() []string { if m.clearedteam_group_hosts { edges = append(edges, teamgroup.EdgeTeamGroupHosts) } + if m.clearedteam_group_skills { + edges = append(edges, teamgroup.EdgeTeamGroupSkills) + } return edges } @@ -31956,6 +33767,8 @@ func (m *TeamGroupMutation) EdgeCleared(name string) bool { return m.clearedimages case teamgroup.EdgeHosts: return m.clearedhosts + case teamgroup.EdgeSkills: + return m.clearedskills case teamgroup.EdgeTeamGroupMembers: return m.clearedteam_group_members case teamgroup.EdgeTeamGroupModels: @@ -31964,6 +33777,8 @@ func (m *TeamGroupMutation) EdgeCleared(name string) bool { return m.clearedteam_group_images case teamgroup.EdgeTeamGroupHosts: return m.clearedteam_group_hosts + case teamgroup.EdgeTeamGroupSkills: + return m.clearedteam_group_skills } return false } @@ -31998,6 +33813,9 @@ func (m *TeamGroupMutation) ResetEdge(name string) error { case teamgroup.EdgeHosts: m.ResetHosts() return nil + case teamgroup.EdgeSkills: + m.ResetSkills() + return nil case teamgroup.EdgeTeamGroupMembers: m.ResetTeamGroupMembers() return nil @@ -32010,6 +33828,9 @@ func (m *TeamGroupMutation) ResetEdge(name string) error { case teamgroup.EdgeTeamGroupHosts: m.ResetTeamGroupHosts() return nil + case teamgroup.EdgeTeamGroupSkills: + m.ResetTeamGroupSkills() + return nil } return fmt.Errorf("unknown TeamGroup edge %s", name) } @@ -34174,6 +35995,546 @@ func (m *TeamGroupModelMutation) ResetEdge(name string) error { return fmt.Errorf("unknown TeamGroupModel edge %s", name) } +// TeamGroupSkillMutation represents an operation that mutates the TeamGroupSkill nodes in the graph. +type TeamGroupSkillMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + clearedFields map[string]struct{} + group *uuid.UUID + clearedgroup bool + skill *uuid.UUID + clearedskill bool + done bool + oldValue func(context.Context) (*TeamGroupSkill, error) + predicates []predicate.TeamGroupSkill +} + +var _ ent.Mutation = (*TeamGroupSkillMutation)(nil) + +// teamgroupskillOption allows management of the mutation configuration using functional options. +type teamgroupskillOption func(*TeamGroupSkillMutation) + +// newTeamGroupSkillMutation creates new mutation for the TeamGroupSkill entity. +func newTeamGroupSkillMutation(c config, op Op, opts ...teamgroupskillOption) *TeamGroupSkillMutation { + m := &TeamGroupSkillMutation{ + config: c, + op: op, + typ: TypeTeamGroupSkill, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withTeamGroupSkillID sets the ID field of the mutation. +func withTeamGroupSkillID(id uuid.UUID) teamgroupskillOption { + return func(m *TeamGroupSkillMutation) { + var ( + err error + once sync.Once + value *TeamGroupSkill + ) + m.oldValue = func(ctx context.Context) (*TeamGroupSkill, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().TeamGroupSkill.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withTeamGroupSkill sets the old TeamGroupSkill of the mutation. +func withTeamGroupSkill(node *TeamGroupSkill) teamgroupskillOption { + return func(m *TeamGroupSkillMutation) { + m.oldValue = func(context.Context) (*TeamGroupSkill, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m TeamGroupSkillMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m TeamGroupSkillMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("db: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of TeamGroupSkill entities. +func (m *TeamGroupSkillMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *TeamGroupSkillMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *TeamGroupSkillMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().TeamGroupSkill.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetGroupID sets the "group_id" field. +func (m *TeamGroupSkillMutation) SetGroupID(u uuid.UUID) { + m.group = &u +} + +// GroupID returns the value of the "group_id" field in the mutation. +func (m *TeamGroupSkillMutation) GroupID() (r uuid.UUID, exists bool) { + v := m.group + if v == nil { + return + } + return *v, true +} + +// OldGroupID returns the old "group_id" field's value of the TeamGroupSkill entity. +// If the TeamGroupSkill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TeamGroupSkillMutation) OldGroupID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGroupID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGroupID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGroupID: %w", err) + } + return oldValue.GroupID, nil +} + +// ResetGroupID resets all changes to the "group_id" field. +func (m *TeamGroupSkillMutation) ResetGroupID() { + m.group = nil +} + +// SetSkillID sets the "skill_id" field. +func (m *TeamGroupSkillMutation) SetSkillID(u uuid.UUID) { + m.skill = &u +} + +// SkillID returns the value of the "skill_id" field in the mutation. +func (m *TeamGroupSkillMutation) SkillID() (r uuid.UUID, exists bool) { + v := m.skill + if v == nil { + return + } + return *v, true +} + +// OldSkillID returns the old "skill_id" field's value of the TeamGroupSkill entity. +// If the TeamGroupSkill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TeamGroupSkillMutation) OldSkillID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSkillID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSkillID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSkillID: %w", err) + } + return oldValue.SkillID, nil +} + +// ResetSkillID resets all changes to the "skill_id" field. +func (m *TeamGroupSkillMutation) ResetSkillID() { + m.skill = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *TeamGroupSkillMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *TeamGroupSkillMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the TeamGroupSkill entity. +// If the TeamGroupSkill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TeamGroupSkillMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *TeamGroupSkillMutation) ResetCreatedAt() { + m.created_at = nil +} + +// ClearGroup clears the "group" edge to the TeamGroup entity. +func (m *TeamGroupSkillMutation) ClearGroup() { + m.clearedgroup = true + m.clearedFields[teamgroupskill.FieldGroupID] = struct{}{} +} + +// GroupCleared reports if the "group" edge to the TeamGroup entity was cleared. +func (m *TeamGroupSkillMutation) GroupCleared() bool { + return m.clearedgroup +} + +// GroupIDs returns the "group" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// GroupID instead. It exists only for internal usage by the builders. +func (m *TeamGroupSkillMutation) GroupIDs() (ids []uuid.UUID) { + if id := m.group; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetGroup resets all changes to the "group" edge. +func (m *TeamGroupSkillMutation) ResetGroup() { + m.group = nil + m.clearedgroup = false +} + +// ClearSkill clears the "skill" edge to the Skill entity. +func (m *TeamGroupSkillMutation) ClearSkill() { + m.clearedskill = true + m.clearedFields[teamgroupskill.FieldSkillID] = struct{}{} +} + +// SkillCleared reports if the "skill" edge to the Skill entity was cleared. +func (m *TeamGroupSkillMutation) SkillCleared() bool { + return m.clearedskill +} + +// SkillIDs returns the "skill" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SkillID instead. It exists only for internal usage by the builders. +func (m *TeamGroupSkillMutation) SkillIDs() (ids []uuid.UUID) { + if id := m.skill; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSkill resets all changes to the "skill" edge. +func (m *TeamGroupSkillMutation) ResetSkill() { + m.skill = nil + m.clearedskill = false +} + +// Where appends a list predicates to the TeamGroupSkillMutation builder. +func (m *TeamGroupSkillMutation) Where(ps ...predicate.TeamGroupSkill) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the TeamGroupSkillMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TeamGroupSkillMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.TeamGroupSkill, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *TeamGroupSkillMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *TeamGroupSkillMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (TeamGroupSkill). +func (m *TeamGroupSkillMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *TeamGroupSkillMutation) Fields() []string { + fields := make([]string, 0, 3) + if m.group != nil { + fields = append(fields, teamgroupskill.FieldGroupID) + } + if m.skill != nil { + fields = append(fields, teamgroupskill.FieldSkillID) + } + if m.created_at != nil { + fields = append(fields, teamgroupskill.FieldCreatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *TeamGroupSkillMutation) Field(name string) (ent.Value, bool) { + switch name { + case teamgroupskill.FieldGroupID: + return m.GroupID() + case teamgroupskill.FieldSkillID: + return m.SkillID() + case teamgroupskill.FieldCreatedAt: + return m.CreatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *TeamGroupSkillMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case teamgroupskill.FieldGroupID: + return m.OldGroupID(ctx) + case teamgroupskill.FieldSkillID: + return m.OldSkillID(ctx) + case teamgroupskill.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown TeamGroupSkill field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TeamGroupSkillMutation) SetField(name string, value ent.Value) error { + switch name { + case teamgroupskill.FieldGroupID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGroupID(v) + return nil + case teamgroupskill.FieldSkillID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSkillID(v) + return nil + case teamgroupskill.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown TeamGroupSkill field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *TeamGroupSkillMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *TeamGroupSkillMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TeamGroupSkillMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown TeamGroupSkill numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *TeamGroupSkillMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *TeamGroupSkillMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *TeamGroupSkillMutation) ClearField(name string) error { + return fmt.Errorf("unknown TeamGroupSkill nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *TeamGroupSkillMutation) ResetField(name string) error { + switch name { + case teamgroupskill.FieldGroupID: + m.ResetGroupID() + return nil + case teamgroupskill.FieldSkillID: + m.ResetSkillID() + return nil + case teamgroupskill.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown TeamGroupSkill field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *TeamGroupSkillMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.group != nil { + edges = append(edges, teamgroupskill.EdgeGroup) + } + if m.skill != nil { + edges = append(edges, teamgroupskill.EdgeSkill) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *TeamGroupSkillMutation) AddedIDs(name string) []ent.Value { + switch name { + case teamgroupskill.EdgeGroup: + if id := m.group; id != nil { + return []ent.Value{*id} + } + case teamgroupskill.EdgeSkill: + if id := m.skill; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *TeamGroupSkillMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *TeamGroupSkillMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *TeamGroupSkillMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedgroup { + edges = append(edges, teamgroupskill.EdgeGroup) + } + if m.clearedskill { + edges = append(edges, teamgroupskill.EdgeSkill) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *TeamGroupSkillMutation) EdgeCleared(name string) bool { + switch name { + case teamgroupskill.EdgeGroup: + return m.clearedgroup + case teamgroupskill.EdgeSkill: + return m.clearedskill + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *TeamGroupSkillMutation) ClearEdge(name string) error { + switch name { + case teamgroupskill.EdgeGroup: + m.ClearGroup() + return nil + case teamgroupskill.EdgeSkill: + m.ClearSkill() + return nil + } + return fmt.Errorf("unknown TeamGroupSkill unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *TeamGroupSkillMutation) ResetEdge(name string) error { + switch name { + case teamgroupskill.EdgeGroup: + m.ResetGroup() + return nil + case teamgroupskill.EdgeSkill: + m.ResetSkill() + return nil + } + return fmt.Errorf("unknown TeamGroupSkill edge %s", name) +} + // TeamHostMutation represents an operation that mutates the TeamHost nodes in the graph. type TeamHostMutation struct { config @@ -37409,6 +39770,546 @@ func (m *TeamOIDCConfigMutation) ResetEdge(name string) error { return fmt.Errorf("unknown TeamOIDCConfig edge %s", name) } +// TeamSkillMutation represents an operation that mutates the TeamSkill nodes in the graph. +type TeamSkillMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + clearedFields map[string]struct{} + team *uuid.UUID + clearedteam bool + skill *uuid.UUID + clearedskill bool + done bool + oldValue func(context.Context) (*TeamSkill, error) + predicates []predicate.TeamSkill +} + +var _ ent.Mutation = (*TeamSkillMutation)(nil) + +// teamskillOption allows management of the mutation configuration using functional options. +type teamskillOption func(*TeamSkillMutation) + +// newTeamSkillMutation creates new mutation for the TeamSkill entity. +func newTeamSkillMutation(c config, op Op, opts ...teamskillOption) *TeamSkillMutation { + m := &TeamSkillMutation{ + config: c, + op: op, + typ: TypeTeamSkill, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withTeamSkillID sets the ID field of the mutation. +func withTeamSkillID(id uuid.UUID) teamskillOption { + return func(m *TeamSkillMutation) { + var ( + err error + once sync.Once + value *TeamSkill + ) + m.oldValue = func(ctx context.Context) (*TeamSkill, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().TeamSkill.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withTeamSkill sets the old TeamSkill of the mutation. +func withTeamSkill(node *TeamSkill) teamskillOption { + return func(m *TeamSkillMutation) { + m.oldValue = func(context.Context) (*TeamSkill, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m TeamSkillMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m TeamSkillMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("db: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of TeamSkill entities. +func (m *TeamSkillMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *TeamSkillMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *TeamSkillMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().TeamSkill.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetTeamID sets the "team_id" field. +func (m *TeamSkillMutation) SetTeamID(u uuid.UUID) { + m.team = &u +} + +// TeamID returns the value of the "team_id" field in the mutation. +func (m *TeamSkillMutation) TeamID() (r uuid.UUID, exists bool) { + v := m.team + if v == nil { + return + } + return *v, true +} + +// OldTeamID returns the old "team_id" field's value of the TeamSkill entity. +// If the TeamSkill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TeamSkillMutation) OldTeamID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTeamID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTeamID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTeamID: %w", err) + } + return oldValue.TeamID, nil +} + +// ResetTeamID resets all changes to the "team_id" field. +func (m *TeamSkillMutation) ResetTeamID() { + m.team = nil +} + +// SetSkillID sets the "skill_id" field. +func (m *TeamSkillMutation) SetSkillID(u uuid.UUID) { + m.skill = &u +} + +// SkillID returns the value of the "skill_id" field in the mutation. +func (m *TeamSkillMutation) SkillID() (r uuid.UUID, exists bool) { + v := m.skill + if v == nil { + return + } + return *v, true +} + +// OldSkillID returns the old "skill_id" field's value of the TeamSkill entity. +// If the TeamSkill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TeamSkillMutation) OldSkillID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSkillID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSkillID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSkillID: %w", err) + } + return oldValue.SkillID, nil +} + +// ResetSkillID resets all changes to the "skill_id" field. +func (m *TeamSkillMutation) ResetSkillID() { + m.skill = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *TeamSkillMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *TeamSkillMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the TeamSkill entity. +// If the TeamSkill object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TeamSkillMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *TeamSkillMutation) ResetCreatedAt() { + m.created_at = nil +} + +// ClearTeam clears the "team" edge to the Team entity. +func (m *TeamSkillMutation) ClearTeam() { + m.clearedteam = true + m.clearedFields[teamskill.FieldTeamID] = struct{}{} +} + +// TeamCleared reports if the "team" edge to the Team entity was cleared. +func (m *TeamSkillMutation) TeamCleared() bool { + return m.clearedteam +} + +// TeamIDs returns the "team" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// TeamID instead. It exists only for internal usage by the builders. +func (m *TeamSkillMutation) TeamIDs() (ids []uuid.UUID) { + if id := m.team; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetTeam resets all changes to the "team" edge. +func (m *TeamSkillMutation) ResetTeam() { + m.team = nil + m.clearedteam = false +} + +// ClearSkill clears the "skill" edge to the Skill entity. +func (m *TeamSkillMutation) ClearSkill() { + m.clearedskill = true + m.clearedFields[teamskill.FieldSkillID] = struct{}{} +} + +// SkillCleared reports if the "skill" edge to the Skill entity was cleared. +func (m *TeamSkillMutation) SkillCleared() bool { + return m.clearedskill +} + +// SkillIDs returns the "skill" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SkillID instead. It exists only for internal usage by the builders. +func (m *TeamSkillMutation) SkillIDs() (ids []uuid.UUID) { + if id := m.skill; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSkill resets all changes to the "skill" edge. +func (m *TeamSkillMutation) ResetSkill() { + m.skill = nil + m.clearedskill = false +} + +// Where appends a list predicates to the TeamSkillMutation builder. +func (m *TeamSkillMutation) Where(ps ...predicate.TeamSkill) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the TeamSkillMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TeamSkillMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.TeamSkill, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *TeamSkillMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *TeamSkillMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (TeamSkill). +func (m *TeamSkillMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *TeamSkillMutation) Fields() []string { + fields := make([]string, 0, 3) + if m.team != nil { + fields = append(fields, teamskill.FieldTeamID) + } + if m.skill != nil { + fields = append(fields, teamskill.FieldSkillID) + } + if m.created_at != nil { + fields = append(fields, teamskill.FieldCreatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *TeamSkillMutation) Field(name string) (ent.Value, bool) { + switch name { + case teamskill.FieldTeamID: + return m.TeamID() + case teamskill.FieldSkillID: + return m.SkillID() + case teamskill.FieldCreatedAt: + return m.CreatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *TeamSkillMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case teamskill.FieldTeamID: + return m.OldTeamID(ctx) + case teamskill.FieldSkillID: + return m.OldSkillID(ctx) + case teamskill.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown TeamSkill field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TeamSkillMutation) SetField(name string, value ent.Value) error { + switch name { + case teamskill.FieldTeamID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTeamID(v) + return nil + case teamskill.FieldSkillID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSkillID(v) + return nil + case teamskill.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown TeamSkill field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *TeamSkillMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *TeamSkillMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TeamSkillMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown TeamSkill numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *TeamSkillMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *TeamSkillMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *TeamSkillMutation) ClearField(name string) error { + return fmt.Errorf("unknown TeamSkill nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *TeamSkillMutation) ResetField(name string) error { + switch name { + case teamskill.FieldTeamID: + m.ResetTeamID() + return nil + case teamskill.FieldSkillID: + m.ResetSkillID() + return nil + case teamskill.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown TeamSkill field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *TeamSkillMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.team != nil { + edges = append(edges, teamskill.EdgeTeam) + } + if m.skill != nil { + edges = append(edges, teamskill.EdgeSkill) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *TeamSkillMutation) AddedIDs(name string) []ent.Value { + switch name { + case teamskill.EdgeTeam: + if id := m.team; id != nil { + return []ent.Value{*id} + } + case teamskill.EdgeSkill: + if id := m.skill; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *TeamSkillMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *TeamSkillMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *TeamSkillMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedteam { + edges = append(edges, teamskill.EdgeTeam) + } + if m.clearedskill { + edges = append(edges, teamskill.EdgeSkill) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *TeamSkillMutation) EdgeCleared(name string) bool { + switch name { + case teamskill.EdgeTeam: + return m.clearedteam + case teamskill.EdgeSkill: + return m.clearedskill + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *TeamSkillMutation) ClearEdge(name string) error { + switch name { + case teamskill.EdgeTeam: + m.ClearTeam() + return nil + case teamskill.EdgeSkill: + m.ClearSkill() + return nil + } + return fmt.Errorf("unknown TeamSkill unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *TeamSkillMutation) ResetEdge(name string) error { + switch name { + case teamskill.EdgeTeam: + m.ResetTeam() + return nil + case teamskill.EdgeSkill: + m.ResetSkill() + return nil + } + return fmt.Errorf("unknown TeamSkill edge %s", name) +} + // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config @@ -37445,6 +40346,9 @@ type UserMutation struct { images map[uuid.UUID]struct{} removedimages map[uuid.UUID]struct{} clearedimages bool + skills map[uuid.UUID]struct{} + removedskills map[uuid.UUID]struct{} + clearedskills bool hosts map[string]struct{} removedhosts map[string]struct{} clearedhosts bool @@ -38384,6 +41288,60 @@ func (m *UserMutation) ResetImages() { m.removedimages = nil } +// AddSkillIDs adds the "skills" edge to the Skill entity by ids. +func (m *UserMutation) AddSkillIDs(ids ...uuid.UUID) { + if m.skills == nil { + m.skills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.skills[ids[i]] = struct{}{} + } +} + +// ClearSkills clears the "skills" edge to the Skill entity. +func (m *UserMutation) ClearSkills() { + m.clearedskills = true +} + +// SkillsCleared reports if the "skills" edge to the Skill entity was cleared. +func (m *UserMutation) SkillsCleared() bool { + return m.clearedskills +} + +// RemoveSkillIDs removes the "skills" edge to the Skill entity by IDs. +func (m *UserMutation) RemoveSkillIDs(ids ...uuid.UUID) { + if m.removedskills == nil { + m.removedskills = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.skills, ids[i]) + m.removedskills[ids[i]] = struct{}{} + } +} + +// RemovedSkills returns the removed IDs of the "skills" edge to the Skill entity. +func (m *UserMutation) RemovedSkillsIDs() (ids []uuid.UUID) { + for id := range m.removedskills { + ids = append(ids, id) + } + return +} + +// SkillsIDs returns the "skills" edge IDs in the mutation. +func (m *UserMutation) SkillsIDs() (ids []uuid.UUID) { + for id := range m.skills { + ids = append(ids, id) + } + return +} + +// ResetSkills resets all changes to the "skills" edge. +func (m *UserMutation) ResetSkills() { + m.skills = nil + m.clearedskills = false + m.removedskills = nil +} + // AddHostIDs adds the "hosts" edge to the Host entity by ids. func (m *UserMutation) AddHostIDs(ids ...string) { if m.hosts == nil { @@ -39530,7 +42488,7 @@ func (m *UserMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMutation) AddedEdges() []string { - edges := make([]string, 0, 21) + edges := make([]string, 0, 22) if m.identities != nil { edges = append(edges, user.EdgeIdentities) } @@ -39549,6 +42507,9 @@ func (m *UserMutation) AddedEdges() []string { if m.images != nil { edges = append(edges, user.EdgeImages) } + if m.skills != nil { + edges = append(edges, user.EdgeSkills) + } if m.hosts != nil { edges = append(edges, user.EdgeHosts) } @@ -39637,6 +42598,12 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case user.EdgeSkills: + ids := make([]ent.Value, 0, len(m.skills)) + for id := range m.skills { + ids = append(ids, id) + } + return ids case user.EdgeHosts: ids := make([]ent.Value, 0, len(m.hosts)) for id := range m.hosts { @@ -39733,7 +42700,7 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { - edges := make([]string, 0, 21) + edges := make([]string, 0, 22) if m.removedidentities != nil { edges = append(edges, user.EdgeIdentities) } @@ -39752,6 +42719,9 @@ func (m *UserMutation) RemovedEdges() []string { if m.removedimages != nil { edges = append(edges, user.EdgeImages) } + if m.removedskills != nil { + edges = append(edges, user.EdgeSkills) + } if m.removedhosts != nil { edges = append(edges, user.EdgeHosts) } @@ -39840,6 +42810,12 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case user.EdgeSkills: + ids := make([]ent.Value, 0, len(m.removedskills)) + for id := range m.removedskills { + ids = append(ids, id) + } + return ids case user.EdgeHosts: ids := make([]ent.Value, 0, len(m.removedhosts)) for id := range m.removedhosts { @@ -39936,7 +42912,7 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { - edges := make([]string, 0, 21) + edges := make([]string, 0, 22) if m.clearedidentities { edges = append(edges, user.EdgeIdentities) } @@ -39955,6 +42931,9 @@ func (m *UserMutation) ClearedEdges() []string { if m.clearedimages { edges = append(edges, user.EdgeImages) } + if m.clearedskills { + edges = append(edges, user.EdgeSkills) + } if m.clearedhosts { edges = append(edges, user.EdgeHosts) } @@ -40019,6 +42998,8 @@ func (m *UserMutation) EdgeCleared(name string) bool { return m.clearedmodels case user.EdgeImages: return m.clearedimages + case user.EdgeSkills: + return m.clearedskills case user.EdgeHosts: return m.clearedhosts case user.EdgeVms: @@ -40083,6 +43064,9 @@ func (m *UserMutation) ResetEdge(name string) error { case user.EdgeImages: m.ResetImages() return nil + case user.EdgeSkills: + m.ResetSkills() + return nil case user.EdgeHosts: m.ResetHosts() return nil diff --git a/backend/db/page.go b/backend/db/page.go index a0f11c2a..79f7e57a 100644 --- a/backend/db/page.go +++ b/backend/db/page.go @@ -333,6 +333,20 @@ func (_m *ProjectTaskQuery) Page(ctx context.Context, page, size int) ([]*Projec return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil } +func (_m *SkillQuery) Page(ctx context.Context, page, size int) ([]*Skill, *PageInfo, error) { + cnt, err := _m.Count(ctx) + if err != nil { + return nil, nil, err + } + offset := size * (page - 1) + rs, err := _m.Offset(offset).Limit(size).All(ctx) + if err != nil { + return nil, nil, err + } + has := (page * size) < cnt + return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil +} + func (_m *TaskQuery) Page(ctx context.Context, page, size int) ([]*Task, *PageInfo, error) { cnt, err := _m.Count(ctx) if err != nil { @@ -473,6 +487,20 @@ func (_m *TeamGroupModelQuery) Page(ctx context.Context, page, size int) ([]*Tea return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil } +func (_m *TeamGroupSkillQuery) Page(ctx context.Context, page, size int) ([]*TeamGroupSkill, *PageInfo, error) { + cnt, err := _m.Count(ctx) + if err != nil { + return nil, nil, err + } + offset := size * (page - 1) + rs, err := _m.Offset(offset).Limit(size).All(ctx) + if err != nil { + return nil, nil, err + } + has := (page * size) < cnt + return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil +} + func (_m *TeamHostQuery) Page(ctx context.Context, page, size int) ([]*TeamHost, *PageInfo, error) { cnt, err := _m.Count(ctx) if err != nil { @@ -543,6 +571,20 @@ func (_m *TeamOIDCConfigQuery) Page(ctx context.Context, page, size int) ([]*Tea return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil } +func (_m *TeamSkillQuery) Page(ctx context.Context, page, size int) ([]*TeamSkill, *PageInfo, error) { + cnt, err := _m.Count(ctx) + if err != nil { + return nil, nil, err + } + offset := size * (page - 1) + rs, err := _m.Offset(offset).Limit(size).All(ctx) + if err != nil { + return nil, nil, err + } + has := (page * size) < cnt + return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil +} + func (_m *UserQuery) Page(ctx context.Context, page, size int) ([]*User, *PageInfo, error) { cnt, err := _m.Count(ctx) if err != nil { diff --git a/backend/db/predicate/predicate.go b/backend/db/predicate/predicate.go index b8e431ea..6f9efa7e 100644 --- a/backend/db/predicate/predicate.go +++ b/backend/db/predicate/predicate.go @@ -75,6 +75,9 @@ type ProjectIssueComment func(*sql.Selector) // ProjectTask is the predicate function for projecttask builders. type ProjectTask func(*sql.Selector) +// Skill is the predicate function for skill builders. +type Skill func(*sql.Selector) + // Task is the predicate function for task builders. type Task func(*sql.Selector) @@ -105,6 +108,9 @@ type TeamGroupMember func(*sql.Selector) // TeamGroupModel is the predicate function for teamgroupmodel builders. type TeamGroupModel func(*sql.Selector) +// TeamGroupSkill is the predicate function for teamgroupskill builders. +type TeamGroupSkill func(*sql.Selector) + // TeamHost is the predicate function for teamhost builders. type TeamHost func(*sql.Selector) @@ -120,6 +126,9 @@ type TeamModel func(*sql.Selector) // TeamOIDCConfig is the predicate function for teamoidcconfig builders. type TeamOIDCConfig func(*sql.Selector) +// TeamSkill is the predicate function for teamskill builders. +type TeamSkill func(*sql.Selector) + // User is the predicate function for user builders. type User func(*sql.Selector) diff --git a/backend/db/runtime/runtime.go b/backend/db/runtime/runtime.go index c242efb1..fa5ba35d 100644 --- a/backend/db/runtime/runtime.go +++ b/backend/db/runtime/runtime.go @@ -29,6 +29,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" "github.com/chaitin/MonkeyCode/backend/db/projecttask" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/taskusagestat" @@ -39,11 +40,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/teamhost" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" "github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/useridentity" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" @@ -657,6 +660,43 @@ func init() { projecttaskDescCreatedAt := projecttaskFields[11].Descriptor() // projecttask.DefaultCreatedAt holds the default value on creation for the created_at field. projecttask.DefaultCreatedAt = projecttaskDescCreatedAt.Default.(func() time.Time) + skillMixin := schema.Skill{}.Mixin() + skillMixinHooks0 := skillMixin[0].Hooks() + skill.Hooks[0] = skillMixinHooks0[0] + skillMixinInters0 := skillMixin[0].Interceptors() + skill.Interceptors[0] = skillMixinInters0[0] + skillFields := schema.Skill{}.Fields() + _ = skillFields + // skillDescName is the schema descriptor for name field. + skillDescName := skillFields[2].Descriptor() + // skill.NameValidator is a validator for the "name" field. It is called by the builders before save. + skill.NameValidator = skillDescName.Validators[0].(func(string) error) + // skillDescDescription is the schema descriptor for description field. + skillDescDescription := skillFields[3].Descriptor() + // skill.DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + skill.DescriptionValidator = skillDescDescription.Validators[0].(func(string) error) + // skillDescContent is the schema descriptor for content field. + skillDescContent := skillFields[5].Descriptor() + // skill.ContentValidator is a validator for the "content" field. It is called by the builders before save. + skill.ContentValidator = skillDescContent.Validators[0].(func(string) error) + // skillDescSourceType is the schema descriptor for source_type field. + skillDescSourceType := skillFields[8].Descriptor() + // skill.SourceTypeValidator is a validator for the "source_type" field. It is called by the builders before save. + skill.SourceTypeValidator = skillDescSourceType.Validators[0].(func(string) error) + // skillDescSourceLabel is the schema descriptor for source_label field. + skillDescSourceLabel := skillFields[9].Descriptor() + // skill.SourceLabelValidator is a validator for the "source_label" field. It is called by the builders before save. + skill.SourceLabelValidator = skillDescSourceLabel.Validators[0].(func(string) error) + // skillDescCreatedAt is the schema descriptor for created_at field. + skillDescCreatedAt := skillFields[11].Descriptor() + // skill.DefaultCreatedAt holds the default value on creation for the created_at field. + skill.DefaultCreatedAt = skillDescCreatedAt.Default.(func() time.Time) + // skillDescUpdatedAt is the schema descriptor for updated_at field. + skillDescUpdatedAt := skillFields[12].Descriptor() + // skill.DefaultUpdatedAt holds the default value on creation for the updated_at field. + skill.DefaultUpdatedAt = skillDescUpdatedAt.Default.(func() time.Time) + // skill.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + skill.UpdateDefaultUpdatedAt = skillDescUpdatedAt.UpdateDefault.(func() time.Time) taskMixin := schema.Task{}.Mixin() taskMixinHooks0 := taskMixin[0].Hooks() task.Hooks[0] = taskMixinHooks0[0] @@ -822,6 +862,12 @@ func init() { teamgroupmodelDescCreatedAt := teamgroupmodelFields[3].Descriptor() // teamgroupmodel.DefaultCreatedAt holds the default value on creation for the created_at field. teamgroupmodel.DefaultCreatedAt = teamgroupmodelDescCreatedAt.Default.(func() time.Time) + teamgroupskillFields := schema.TeamGroupSkill{}.Fields() + _ = teamgroupskillFields + // teamgroupskillDescCreatedAt is the schema descriptor for created_at field. + teamgroupskillDescCreatedAt := teamgroupskillFields[3].Descriptor() + // teamgroupskill.DefaultCreatedAt holds the default value on creation for the created_at field. + teamgroupskill.DefaultCreatedAt = teamgroupskillDescCreatedAt.Default.(func() time.Time) teamhostFields := schema.TeamHost{}.Fields() _ = teamhostFields // teamhostDescCreatedAt is the schema descriptor for created_at field. @@ -886,6 +932,12 @@ func init() { teamoidcconfig.DefaultUpdatedAt = teamoidcconfigDescUpdatedAt.Default.(func() time.Time) // teamoidcconfig.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. teamoidcconfig.UpdateDefaultUpdatedAt = teamoidcconfigDescUpdatedAt.UpdateDefault.(func() time.Time) + teamskillFields := schema.TeamSkill{}.Fields() + _ = teamskillFields + // teamskillDescCreatedAt is the schema descriptor for created_at field. + teamskillDescCreatedAt := teamskillFields[3].Descriptor() + // teamskill.DefaultCreatedAt holds the default value on creation for the created_at field. + teamskill.DefaultCreatedAt = teamskillDescCreatedAt.Default.(func() time.Time) userMixin := schema.User{}.Mixin() userMixinHooks0 := userMixin[0].Hooks() user.Hooks[0] = userMixinHooks0[0] diff --git a/backend/db/skill.go b/backend/db/skill.go new file mode 100644 index 00000000..ba15d8c9 --- /dev/null +++ b/backend/db/skill.go @@ -0,0 +1,337 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/user" + "github.com/google/uuid" +) + +// Skill is the model entity for the Skill schema. +type Skill struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // DeletedAt holds the value of the "deleted_at" field. + DeletedAt time.Time `json:"deleted_at,omitempty"` + // UserID holds the value of the "user_id" field. + UserID uuid.UUID `json:"user_id,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Description holds the value of the "description" field. + Description string `json:"description,omitempty"` + // Tags holds the value of the "tags" field. + Tags []string `json:"tags,omitempty"` + // Content holds the value of the "content" field. + Content string `json:"content,omitempty"` + // PackageObjectKey holds the value of the "package_object_key" field. + PackageObjectKey string `json:"package_object_key,omitempty"` + // PackageURL holds the value of the "package_url" field. + PackageURL string `json:"package_url,omitempty"` + // SourceType holds the value of the "source_type" field. + SourceType string `json:"source_type,omitempty"` + // SourceLabel holds the value of the "source_label" field. + SourceLabel string `json:"source_label,omitempty"` + // SkillMdPath holds the value of the "skill_md_path" field. + SkillMdPath string `json:"skill_md_path,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the SkillQuery when eager-loading is set. + Edges SkillEdges `json:"edges"` + selectValues sql.SelectValues +} + +// SkillEdges holds the relations/edges for other nodes in the graph. +type SkillEdges struct { + // User holds the value of the user edge. + User *User `json:"user,omitempty"` + // Teams holds the value of the teams edge. + Teams []*Team `json:"teams,omitempty"` + // Groups holds the value of the groups edge. + Groups []*TeamGroup `json:"groups,omitempty"` + // TeamSkills holds the value of the team_skills edge. + TeamSkills []*TeamSkill `json:"team_skills,omitempty"` + // TeamGroupSkills holds the value of the team_group_skills edge. + TeamGroupSkills []*TeamGroupSkill `json:"team_group_skills,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [5]bool +} + +// UserOrErr returns the User value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e SkillEdges) UserOrErr() (*User, error) { + if e.User != nil { + return e.User, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: user.Label} + } + return nil, &NotLoadedError{edge: "user"} +} + +// TeamsOrErr returns the Teams value or an error if the edge +// was not loaded in eager-loading. +func (e SkillEdges) TeamsOrErr() ([]*Team, error) { + if e.loadedTypes[1] { + return e.Teams, nil + } + return nil, &NotLoadedError{edge: "teams"} +} + +// GroupsOrErr returns the Groups value or an error if the edge +// was not loaded in eager-loading. +func (e SkillEdges) GroupsOrErr() ([]*TeamGroup, error) { + if e.loadedTypes[2] { + return e.Groups, nil + } + return nil, &NotLoadedError{edge: "groups"} +} + +// TeamSkillsOrErr returns the TeamSkills value or an error if the edge +// was not loaded in eager-loading. +func (e SkillEdges) TeamSkillsOrErr() ([]*TeamSkill, error) { + if e.loadedTypes[3] { + return e.TeamSkills, nil + } + return nil, &NotLoadedError{edge: "team_skills"} +} + +// TeamGroupSkillsOrErr returns the TeamGroupSkills value or an error if the edge +// was not loaded in eager-loading. +func (e SkillEdges) TeamGroupSkillsOrErr() ([]*TeamGroupSkill, error) { + if e.loadedTypes[4] { + return e.TeamGroupSkills, nil + } + return nil, &NotLoadedError{edge: "team_group_skills"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Skill) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case skill.FieldTags: + values[i] = new([]byte) + case skill.FieldName, skill.FieldDescription, skill.FieldContent, skill.FieldPackageObjectKey, skill.FieldPackageURL, skill.FieldSourceType, skill.FieldSourceLabel, skill.FieldSkillMdPath: + values[i] = new(sql.NullString) + case skill.FieldDeletedAt, skill.FieldCreatedAt, skill.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case skill.FieldID, skill.FieldUserID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Skill fields. +func (_m *Skill) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case skill.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case skill.FieldDeletedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field deleted_at", values[i]) + } else if value.Valid { + _m.DeletedAt = value.Time + } + case skill.FieldUserID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field user_id", values[i]) + } else if value != nil { + _m.UserID = *value + } + case skill.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case skill.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = value.String + } + case skill.FieldTags: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field tags", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Tags); err != nil { + return fmt.Errorf("unmarshal field tags: %w", err) + } + } + case skill.FieldContent: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field content", values[i]) + } else if value.Valid { + _m.Content = value.String + } + case skill.FieldPackageObjectKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field package_object_key", values[i]) + } else if value.Valid { + _m.PackageObjectKey = value.String + } + case skill.FieldPackageURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field package_url", values[i]) + } else if value.Valid { + _m.PackageURL = value.String + } + case skill.FieldSourceType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source_type", values[i]) + } else if value.Valid { + _m.SourceType = value.String + } + case skill.FieldSourceLabel: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source_label", values[i]) + } else if value.Valid { + _m.SourceLabel = value.String + } + case skill.FieldSkillMdPath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field skill_md_path", values[i]) + } else if value.Valid { + _m.SkillMdPath = value.String + } + case skill.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case skill.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Skill. +// This includes values selected through modifiers, order, etc. +func (_m *Skill) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryUser queries the "user" edge of the Skill entity. +func (_m *Skill) QueryUser() *UserQuery { + return NewSkillClient(_m.config).QueryUser(_m) +} + +// QueryTeams queries the "teams" edge of the Skill entity. +func (_m *Skill) QueryTeams() *TeamQuery { + return NewSkillClient(_m.config).QueryTeams(_m) +} + +// QueryGroups queries the "groups" edge of the Skill entity. +func (_m *Skill) QueryGroups() *TeamGroupQuery { + return NewSkillClient(_m.config).QueryGroups(_m) +} + +// QueryTeamSkills queries the "team_skills" edge of the Skill entity. +func (_m *Skill) QueryTeamSkills() *TeamSkillQuery { + return NewSkillClient(_m.config).QueryTeamSkills(_m) +} + +// QueryTeamGroupSkills queries the "team_group_skills" edge of the Skill entity. +func (_m *Skill) QueryTeamGroupSkills() *TeamGroupSkillQuery { + return NewSkillClient(_m.config).QueryTeamGroupSkills(_m) +} + +// Update returns a builder for updating this Skill. +// Note that you need to call Skill.Unwrap() before calling this method if this Skill +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Skill) Update() *SkillUpdateOne { + return NewSkillClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Skill entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *Skill) Unwrap() *Skill { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: Skill is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Skill) String() string { + var builder strings.Builder + builder.WriteString("Skill(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("deleted_at=") + builder.WriteString(_m.DeletedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("user_id=") + builder.WriteString(fmt.Sprintf("%v", _m.UserID)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("description=") + builder.WriteString(_m.Description) + builder.WriteString(", ") + builder.WriteString("tags=") + builder.WriteString(fmt.Sprintf("%v", _m.Tags)) + builder.WriteString(", ") + builder.WriteString("content=") + builder.WriteString(_m.Content) + builder.WriteString(", ") + builder.WriteString("package_object_key=") + builder.WriteString(_m.PackageObjectKey) + builder.WriteString(", ") + builder.WriteString("package_url=") + builder.WriteString(_m.PackageURL) + builder.WriteString(", ") + builder.WriteString("source_type=") + builder.WriteString(_m.SourceType) + builder.WriteString(", ") + builder.WriteString("source_label=") + builder.WriteString(_m.SourceLabel) + builder.WriteString(", ") + builder.WriteString("skill_md_path=") + builder.WriteString(_m.SkillMdPath) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// Skills is a parsable slice of Skill. +type Skills []*Skill diff --git a/backend/db/skill/skill.go b/backend/db/skill/skill.go new file mode 100644 index 00000000..22ba8fd9 --- /dev/null +++ b/backend/db/skill/skill.go @@ -0,0 +1,316 @@ +// Code generated by ent, DO NOT EDIT. + +package skill + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the skill type in the database. + Label = "skill" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldDeletedAt holds the string denoting the deleted_at field in the database. + FieldDeletedAt = "deleted_at" + // FieldUserID holds the string denoting the user_id field in the database. + FieldUserID = "user_id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldTags holds the string denoting the tags field in the database. + FieldTags = "tags" + // FieldContent holds the string denoting the content field in the database. + FieldContent = "content" + // FieldPackageObjectKey holds the string denoting the package_object_key field in the database. + FieldPackageObjectKey = "package_object_key" + // FieldPackageURL holds the string denoting the package_url field in the database. + FieldPackageURL = "package_url" + // FieldSourceType holds the string denoting the source_type field in the database. + FieldSourceType = "source_type" + // FieldSourceLabel holds the string denoting the source_label field in the database. + FieldSourceLabel = "source_label" + // FieldSkillMdPath holds the string denoting the skill_md_path field in the database. + FieldSkillMdPath = "skill_md_path" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeUser holds the string denoting the user edge name in mutations. + EdgeUser = "user" + // EdgeTeams holds the string denoting the teams edge name in mutations. + EdgeTeams = "teams" + // EdgeGroups holds the string denoting the groups edge name in mutations. + EdgeGroups = "groups" + // EdgeTeamSkills holds the string denoting the team_skills edge name in mutations. + EdgeTeamSkills = "team_skills" + // EdgeTeamGroupSkills holds the string denoting the team_group_skills edge name in mutations. + EdgeTeamGroupSkills = "team_group_skills" + // Table holds the table name of the skill in the database. + Table = "skills" + // UserTable is the table that holds the user relation/edge. + UserTable = "skills" + // UserInverseTable is the table name for the User entity. + // It exists in this package in order to avoid circular dependency with the "user" package. + UserInverseTable = "users" + // UserColumn is the table column denoting the user relation/edge. + UserColumn = "user_id" + // TeamsTable is the table that holds the teams relation/edge. The primary key declared below. + TeamsTable = "team_skills" + // TeamsInverseTable is the table name for the Team entity. + // It exists in this package in order to avoid circular dependency with the "team" package. + TeamsInverseTable = "teams" + // GroupsTable is the table that holds the groups relation/edge. The primary key declared below. + GroupsTable = "team_group_skills" + // GroupsInverseTable is the table name for the TeamGroup entity. + // It exists in this package in order to avoid circular dependency with the "teamgroup" package. + GroupsInverseTable = "team_groups" + // TeamSkillsTable is the table that holds the team_skills relation/edge. + TeamSkillsTable = "team_skills" + // TeamSkillsInverseTable is the table name for the TeamSkill entity. + // It exists in this package in order to avoid circular dependency with the "teamskill" package. + TeamSkillsInverseTable = "team_skills" + // TeamSkillsColumn is the table column denoting the team_skills relation/edge. + TeamSkillsColumn = "skill_id" + // TeamGroupSkillsTable is the table that holds the team_group_skills relation/edge. + TeamGroupSkillsTable = "team_group_skills" + // TeamGroupSkillsInverseTable is the table name for the TeamGroupSkill entity. + // It exists in this package in order to avoid circular dependency with the "teamgroupskill" package. + TeamGroupSkillsInverseTable = "team_group_skills" + // TeamGroupSkillsColumn is the table column denoting the team_group_skills relation/edge. + TeamGroupSkillsColumn = "skill_id" +) + +// Columns holds all SQL columns for skill fields. +var Columns = []string{ + FieldID, + FieldDeletedAt, + FieldUserID, + FieldName, + FieldDescription, + FieldTags, + FieldContent, + FieldPackageObjectKey, + FieldPackageURL, + FieldSourceType, + FieldSourceLabel, + FieldSkillMdPath, + FieldCreatedAt, + FieldUpdatedAt, +} + +var ( + // TeamsPrimaryKey and TeamsColumn2 are the table columns denoting the + // primary key for the teams relation (M2M). + TeamsPrimaryKey = []string{"team_id", "skill_id"} + // GroupsPrimaryKey and GroupsColumn2 are the table columns denoting the + // primary key for the groups relation (M2M). + GroupsPrimaryKey = []string{"group_id", "skill_id"} +) + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +// Note that the variables below are initialized by the runtime +// package on the initialization of the application. Therefore, +// it should be imported in the main as follows: +// +// import _ "github.com/chaitin/MonkeyCode/backend/db/runtime" +var ( + Hooks [1]ent.Hook + Interceptors [1]ent.Interceptor + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + DescriptionValidator func(string) error + // ContentValidator is a validator for the "content" field. It is called by the builders before save. + ContentValidator func(string) error + // SourceTypeValidator is a validator for the "source_type" field. It is called by the builders before save. + SourceTypeValidator func(string) error + // SourceLabelValidator is a validator for the "source_label" field. It is called by the builders before save. + SourceLabelValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time +) + +// OrderOption defines the ordering options for the Skill queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByUserID orders the results by the user_id field. +func ByUserID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUserID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByContent orders the results by the content field. +func ByContent(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldContent, opts...).ToFunc() +} + +// ByPackageObjectKey orders the results by the package_object_key field. +func ByPackageObjectKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPackageObjectKey, opts...).ToFunc() +} + +// ByPackageURL orders the results by the package_url field. +func ByPackageURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPackageURL, opts...).ToFunc() +} + +// BySourceType orders the results by the source_type field. +func BySourceType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSourceType, opts...).ToFunc() +} + +// BySourceLabel orders the results by the source_label field. +func BySourceLabel(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSourceLabel, opts...).ToFunc() +} + +// BySkillMdPath orders the results by the skill_md_path field. +func BySkillMdPath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSkillMdPath, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} + +// ByTeamsCount orders the results by teams count. +func ByTeamsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTeamsStep(), opts...) + } +} + +// ByTeams orders the results by teams terms. +func ByTeams(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByGroupsCount orders the results by groups count. +func ByGroupsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupsStep(), opts...) + } +} + +// ByGroups orders the results by groups terms. +func ByGroups(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTeamSkillsCount orders the results by team_skills count. +func ByTeamSkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTeamSkillsStep(), opts...) + } +} + +// ByTeamSkills orders the results by team_skills terms. +func ByTeamSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTeamGroupSkillsCount orders the results by team_group_skills count. +func ByTeamGroupSkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTeamGroupSkillsStep(), opts...) + } +} + +// ByTeamGroupSkills orders the results by team_group_skills terms. +func ByTeamGroupSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamGroupSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn), + ) +} +func newTeamsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TeamsTable, TeamsPrimaryKey...), + ) +} +func newGroupsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, GroupsTable, GroupsPrimaryKey...), + ) +} +func newTeamSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamSkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn), + ) +} +func newTeamGroupSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamGroupSkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn), + ) +} diff --git a/backend/db/skill/where.go b/backend/db/skill/where.go new file mode 100644 index 00000000..6f92c980 --- /dev/null +++ b/backend/db/skill/where.go @@ -0,0 +1,957 @@ +// Code generated by ent, DO NOT EDIT. + +package skill + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldID, id)) +} + +// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ. +func DeletedAt(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldDeletedAt, v)) +} + +// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. +func UserID(v uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldUserID, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldName, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldDescription, v)) +} + +// Content applies equality check predicate on the "content" field. It's identical to ContentEQ. +func Content(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldContent, v)) +} + +// PackageObjectKey applies equality check predicate on the "package_object_key" field. It's identical to PackageObjectKeyEQ. +func PackageObjectKey(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldPackageObjectKey, v)) +} + +// PackageURL applies equality check predicate on the "package_url" field. It's identical to PackageURLEQ. +func PackageURL(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldPackageURL, v)) +} + +// SourceType applies equality check predicate on the "source_type" field. It's identical to SourceTypeEQ. +func SourceType(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldSourceType, v)) +} + +// SourceLabel applies equality check predicate on the "source_label" field. It's identical to SourceLabelEQ. +func SourceLabel(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldSourceLabel, v)) +} + +// SkillMdPath applies equality check predicate on the "skill_md_path" field. It's identical to SkillMdPathEQ. +func SkillMdPath(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldSkillMdPath, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. +func DeletedAtEQ(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldDeletedAt, v)) +} + +// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. +func DeletedAtNEQ(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldDeletedAt, v)) +} + +// DeletedAtIn applies the In predicate on the "deleted_at" field. +func DeletedAtIn(vs ...time.Time) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldDeletedAt, vs...)) +} + +// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. +func DeletedAtNotIn(vs ...time.Time) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldDeletedAt, vs...)) +} + +// DeletedAtGT applies the GT predicate on the "deleted_at" field. +func DeletedAtGT(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldDeletedAt, v)) +} + +// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. +func DeletedAtGTE(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldDeletedAt, v)) +} + +// DeletedAtLT applies the LT predicate on the "deleted_at" field. +func DeletedAtLT(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldDeletedAt, v)) +} + +// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. +func DeletedAtLTE(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldDeletedAt, v)) +} + +// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. +func DeletedAtIsNil() predicate.Skill { + return predicate.Skill(sql.FieldIsNull(FieldDeletedAt)) +} + +// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. +func DeletedAtNotNil() predicate.Skill { + return predicate.Skill(sql.FieldNotNull(FieldDeletedAt)) +} + +// UserIDEQ applies the EQ predicate on the "user_id" field. +func UserIDEQ(v uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldUserID, v)) +} + +// UserIDNEQ applies the NEQ predicate on the "user_id" field. +func UserIDNEQ(v uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldUserID, v)) +} + +// UserIDIn applies the In predicate on the "user_id" field. +func UserIDIn(vs ...uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldUserID, vs...)) +} + +// UserIDNotIn applies the NotIn predicate on the "user_id" field. +func UserIDNotIn(vs ...uuid.UUID) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldUserID, vs...)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldName, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldDescription, v)) +} + +// TagsIsNil applies the IsNil predicate on the "tags" field. +func TagsIsNil() predicate.Skill { + return predicate.Skill(sql.FieldIsNull(FieldTags)) +} + +// TagsNotNil applies the NotNil predicate on the "tags" field. +func TagsNotNil() predicate.Skill { + return predicate.Skill(sql.FieldNotNull(FieldTags)) +} + +// ContentEQ applies the EQ predicate on the "content" field. +func ContentEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldContent, v)) +} + +// ContentNEQ applies the NEQ predicate on the "content" field. +func ContentNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldContent, v)) +} + +// ContentIn applies the In predicate on the "content" field. +func ContentIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldContent, vs...)) +} + +// ContentNotIn applies the NotIn predicate on the "content" field. +func ContentNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldContent, vs...)) +} + +// ContentGT applies the GT predicate on the "content" field. +func ContentGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldContent, v)) +} + +// ContentGTE applies the GTE predicate on the "content" field. +func ContentGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldContent, v)) +} + +// ContentLT applies the LT predicate on the "content" field. +func ContentLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldContent, v)) +} + +// ContentLTE applies the LTE predicate on the "content" field. +func ContentLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldContent, v)) +} + +// ContentContains applies the Contains predicate on the "content" field. +func ContentContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldContent, v)) +} + +// ContentHasPrefix applies the HasPrefix predicate on the "content" field. +func ContentHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldContent, v)) +} + +// ContentHasSuffix applies the HasSuffix predicate on the "content" field. +func ContentHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldContent, v)) +} + +// ContentEqualFold applies the EqualFold predicate on the "content" field. +func ContentEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldContent, v)) +} + +// ContentContainsFold applies the ContainsFold predicate on the "content" field. +func ContentContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldContent, v)) +} + +// PackageObjectKeyEQ applies the EQ predicate on the "package_object_key" field. +func PackageObjectKeyEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyNEQ applies the NEQ predicate on the "package_object_key" field. +func PackageObjectKeyNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyIn applies the In predicate on the "package_object_key" field. +func PackageObjectKeyIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldPackageObjectKey, vs...)) +} + +// PackageObjectKeyNotIn applies the NotIn predicate on the "package_object_key" field. +func PackageObjectKeyNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldPackageObjectKey, vs...)) +} + +// PackageObjectKeyGT applies the GT predicate on the "package_object_key" field. +func PackageObjectKeyGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyGTE applies the GTE predicate on the "package_object_key" field. +func PackageObjectKeyGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyLT applies the LT predicate on the "package_object_key" field. +func PackageObjectKeyLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyLTE applies the LTE predicate on the "package_object_key" field. +func PackageObjectKeyLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyContains applies the Contains predicate on the "package_object_key" field. +func PackageObjectKeyContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyHasPrefix applies the HasPrefix predicate on the "package_object_key" field. +func PackageObjectKeyHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyHasSuffix applies the HasSuffix predicate on the "package_object_key" field. +func PackageObjectKeyHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyIsNil applies the IsNil predicate on the "package_object_key" field. +func PackageObjectKeyIsNil() predicate.Skill { + return predicate.Skill(sql.FieldIsNull(FieldPackageObjectKey)) +} + +// PackageObjectKeyNotNil applies the NotNil predicate on the "package_object_key" field. +func PackageObjectKeyNotNil() predicate.Skill { + return predicate.Skill(sql.FieldNotNull(FieldPackageObjectKey)) +} + +// PackageObjectKeyEqualFold applies the EqualFold predicate on the "package_object_key" field. +func PackageObjectKeyEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldPackageObjectKey, v)) +} + +// PackageObjectKeyContainsFold applies the ContainsFold predicate on the "package_object_key" field. +func PackageObjectKeyContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldPackageObjectKey, v)) +} + +// PackageURLEQ applies the EQ predicate on the "package_url" field. +func PackageURLEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldPackageURL, v)) +} + +// PackageURLNEQ applies the NEQ predicate on the "package_url" field. +func PackageURLNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldPackageURL, v)) +} + +// PackageURLIn applies the In predicate on the "package_url" field. +func PackageURLIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldPackageURL, vs...)) +} + +// PackageURLNotIn applies the NotIn predicate on the "package_url" field. +func PackageURLNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldPackageURL, vs...)) +} + +// PackageURLGT applies the GT predicate on the "package_url" field. +func PackageURLGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldPackageURL, v)) +} + +// PackageURLGTE applies the GTE predicate on the "package_url" field. +func PackageURLGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldPackageURL, v)) +} + +// PackageURLLT applies the LT predicate on the "package_url" field. +func PackageURLLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldPackageURL, v)) +} + +// PackageURLLTE applies the LTE predicate on the "package_url" field. +func PackageURLLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldPackageURL, v)) +} + +// PackageURLContains applies the Contains predicate on the "package_url" field. +func PackageURLContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldPackageURL, v)) +} + +// PackageURLHasPrefix applies the HasPrefix predicate on the "package_url" field. +func PackageURLHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldPackageURL, v)) +} + +// PackageURLHasSuffix applies the HasSuffix predicate on the "package_url" field. +func PackageURLHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldPackageURL, v)) +} + +// PackageURLIsNil applies the IsNil predicate on the "package_url" field. +func PackageURLIsNil() predicate.Skill { + return predicate.Skill(sql.FieldIsNull(FieldPackageURL)) +} + +// PackageURLNotNil applies the NotNil predicate on the "package_url" field. +func PackageURLNotNil() predicate.Skill { + return predicate.Skill(sql.FieldNotNull(FieldPackageURL)) +} + +// PackageURLEqualFold applies the EqualFold predicate on the "package_url" field. +func PackageURLEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldPackageURL, v)) +} + +// PackageURLContainsFold applies the ContainsFold predicate on the "package_url" field. +func PackageURLContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldPackageURL, v)) +} + +// SourceTypeEQ applies the EQ predicate on the "source_type" field. +func SourceTypeEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldSourceType, v)) +} + +// SourceTypeNEQ applies the NEQ predicate on the "source_type" field. +func SourceTypeNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldSourceType, v)) +} + +// SourceTypeIn applies the In predicate on the "source_type" field. +func SourceTypeIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldSourceType, vs...)) +} + +// SourceTypeNotIn applies the NotIn predicate on the "source_type" field. +func SourceTypeNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldSourceType, vs...)) +} + +// SourceTypeGT applies the GT predicate on the "source_type" field. +func SourceTypeGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldSourceType, v)) +} + +// SourceTypeGTE applies the GTE predicate on the "source_type" field. +func SourceTypeGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldSourceType, v)) +} + +// SourceTypeLT applies the LT predicate on the "source_type" field. +func SourceTypeLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldSourceType, v)) +} + +// SourceTypeLTE applies the LTE predicate on the "source_type" field. +func SourceTypeLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldSourceType, v)) +} + +// SourceTypeContains applies the Contains predicate on the "source_type" field. +func SourceTypeContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldSourceType, v)) +} + +// SourceTypeHasPrefix applies the HasPrefix predicate on the "source_type" field. +func SourceTypeHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldSourceType, v)) +} + +// SourceTypeHasSuffix applies the HasSuffix predicate on the "source_type" field. +func SourceTypeHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldSourceType, v)) +} + +// SourceTypeEqualFold applies the EqualFold predicate on the "source_type" field. +func SourceTypeEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldSourceType, v)) +} + +// SourceTypeContainsFold applies the ContainsFold predicate on the "source_type" field. +func SourceTypeContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldSourceType, v)) +} + +// SourceLabelEQ applies the EQ predicate on the "source_label" field. +func SourceLabelEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldSourceLabel, v)) +} + +// SourceLabelNEQ applies the NEQ predicate on the "source_label" field. +func SourceLabelNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldSourceLabel, v)) +} + +// SourceLabelIn applies the In predicate on the "source_label" field. +func SourceLabelIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldSourceLabel, vs...)) +} + +// SourceLabelNotIn applies the NotIn predicate on the "source_label" field. +func SourceLabelNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldSourceLabel, vs...)) +} + +// SourceLabelGT applies the GT predicate on the "source_label" field. +func SourceLabelGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldSourceLabel, v)) +} + +// SourceLabelGTE applies the GTE predicate on the "source_label" field. +func SourceLabelGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldSourceLabel, v)) +} + +// SourceLabelLT applies the LT predicate on the "source_label" field. +func SourceLabelLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldSourceLabel, v)) +} + +// SourceLabelLTE applies the LTE predicate on the "source_label" field. +func SourceLabelLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldSourceLabel, v)) +} + +// SourceLabelContains applies the Contains predicate on the "source_label" field. +func SourceLabelContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldSourceLabel, v)) +} + +// SourceLabelHasPrefix applies the HasPrefix predicate on the "source_label" field. +func SourceLabelHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldSourceLabel, v)) +} + +// SourceLabelHasSuffix applies the HasSuffix predicate on the "source_label" field. +func SourceLabelHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldSourceLabel, v)) +} + +// SourceLabelEqualFold applies the EqualFold predicate on the "source_label" field. +func SourceLabelEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldSourceLabel, v)) +} + +// SourceLabelContainsFold applies the ContainsFold predicate on the "source_label" field. +func SourceLabelContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldSourceLabel, v)) +} + +// SkillMdPathEQ applies the EQ predicate on the "skill_md_path" field. +func SkillMdPathEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldSkillMdPath, v)) +} + +// SkillMdPathNEQ applies the NEQ predicate on the "skill_md_path" field. +func SkillMdPathNEQ(v string) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldSkillMdPath, v)) +} + +// SkillMdPathIn applies the In predicate on the "skill_md_path" field. +func SkillMdPathIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldSkillMdPath, vs...)) +} + +// SkillMdPathNotIn applies the NotIn predicate on the "skill_md_path" field. +func SkillMdPathNotIn(vs ...string) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldSkillMdPath, vs...)) +} + +// SkillMdPathGT applies the GT predicate on the "skill_md_path" field. +func SkillMdPathGT(v string) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldSkillMdPath, v)) +} + +// SkillMdPathGTE applies the GTE predicate on the "skill_md_path" field. +func SkillMdPathGTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldSkillMdPath, v)) +} + +// SkillMdPathLT applies the LT predicate on the "skill_md_path" field. +func SkillMdPathLT(v string) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldSkillMdPath, v)) +} + +// SkillMdPathLTE applies the LTE predicate on the "skill_md_path" field. +func SkillMdPathLTE(v string) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldSkillMdPath, v)) +} + +// SkillMdPathContains applies the Contains predicate on the "skill_md_path" field. +func SkillMdPathContains(v string) predicate.Skill { + return predicate.Skill(sql.FieldContains(FieldSkillMdPath, v)) +} + +// SkillMdPathHasPrefix applies the HasPrefix predicate on the "skill_md_path" field. +func SkillMdPathHasPrefix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasPrefix(FieldSkillMdPath, v)) +} + +// SkillMdPathHasSuffix applies the HasSuffix predicate on the "skill_md_path" field. +func SkillMdPathHasSuffix(v string) predicate.Skill { + return predicate.Skill(sql.FieldHasSuffix(FieldSkillMdPath, v)) +} + +// SkillMdPathIsNil applies the IsNil predicate on the "skill_md_path" field. +func SkillMdPathIsNil() predicate.Skill { + return predicate.Skill(sql.FieldIsNull(FieldSkillMdPath)) +} + +// SkillMdPathNotNil applies the NotNil predicate on the "skill_md_path" field. +func SkillMdPathNotNil() predicate.Skill { + return predicate.Skill(sql.FieldNotNull(FieldSkillMdPath)) +} + +// SkillMdPathEqualFold applies the EqualFold predicate on the "skill_md_path" field. +func SkillMdPathEqualFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldEqualFold(FieldSkillMdPath, v)) +} + +// SkillMdPathContainsFold applies the ContainsFold predicate on the "skill_md_path" field. +func SkillMdPathContainsFold(v string) predicate.Skill { + return predicate.Skill(sql.FieldContainsFold(FieldSkillMdPath, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Skill { + return predicate.Skill(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Skill { + return predicate.Skill(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Skill { + return predicate.Skill(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasUser applies the HasEdge predicate on the "user" edge. +func HasUser() predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). +func HasUserWith(preds ...predicate.User) predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := newUserStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasTeams applies the HasEdge predicate on the "teams" edge. +func HasTeams() predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TeamsTable, TeamsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamsWith applies the HasEdge predicate on the "teams" edge with a given conditions (other predicates). +func HasTeamsWith(preds ...predicate.Team) predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := newTeamsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasGroups applies the HasEdge predicate on the "groups" edge. +func HasGroups() predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, GroupsTable, GroupsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasGroupsWith applies the HasEdge predicate on the "groups" edge with a given conditions (other predicates). +func HasGroupsWith(preds ...predicate.TeamGroup) predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := newGroupsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasTeamSkills applies the HasEdge predicate on the "team_skills" edge. +func HasTeamSkills() predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamSkillsWith applies the HasEdge predicate on the "team_skills" edge with a given conditions (other predicates). +func HasTeamSkillsWith(preds ...predicate.TeamSkill) predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := newTeamSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasTeamGroupSkills applies the HasEdge predicate on the "team_group_skills" edge. +func HasTeamGroupSkills() predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamGroupSkillsWith applies the HasEdge predicate on the "team_group_skills" edge with a given conditions (other predicates). +func HasTeamGroupSkillsWith(preds ...predicate.TeamGroupSkill) predicate.Skill { + return predicate.Skill(func(s *sql.Selector) { + step := newTeamGroupSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Skill) predicate.Skill { + return predicate.Skill(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Skill) predicate.Skill { + return predicate.Skill(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Skill) predicate.Skill { + return predicate.Skill(sql.NotPredicates(p)) +} diff --git a/backend/db/skill_create.go b/backend/db/skill_create.go new file mode 100644 index 00000000..3039dd1f --- /dev/null +++ b/backend/db/skill_create.go @@ -0,0 +1,1466 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/chaitin/MonkeyCode/backend/db/user" + "github.com/google/uuid" +) + +// SkillCreate is the builder for creating a Skill entity. +type SkillCreate struct { + config + mutation *SkillMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetDeletedAt sets the "deleted_at" field. +func (_c *SkillCreate) SetDeletedAt(v time.Time) *SkillCreate { + _c.mutation.SetDeletedAt(v) + return _c +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_c *SkillCreate) SetNillableDeletedAt(v *time.Time) *SkillCreate { + if v != nil { + _c.SetDeletedAt(*v) + } + return _c +} + +// SetUserID sets the "user_id" field. +func (_c *SkillCreate) SetUserID(v uuid.UUID) *SkillCreate { + _c.mutation.SetUserID(v) + return _c +} + +// SetName sets the "name" field. +func (_c *SkillCreate) SetName(v string) *SkillCreate { + _c.mutation.SetName(v) + return _c +} + +// SetDescription sets the "description" field. +func (_c *SkillCreate) SetDescription(v string) *SkillCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetTags sets the "tags" field. +func (_c *SkillCreate) SetTags(v []string) *SkillCreate { + _c.mutation.SetTags(v) + return _c +} + +// SetContent sets the "content" field. +func (_c *SkillCreate) SetContent(v string) *SkillCreate { + _c.mutation.SetContent(v) + return _c +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (_c *SkillCreate) SetPackageObjectKey(v string) *SkillCreate { + _c.mutation.SetPackageObjectKey(v) + return _c +} + +// SetNillablePackageObjectKey sets the "package_object_key" field if the given value is not nil. +func (_c *SkillCreate) SetNillablePackageObjectKey(v *string) *SkillCreate { + if v != nil { + _c.SetPackageObjectKey(*v) + } + return _c +} + +// SetPackageURL sets the "package_url" field. +func (_c *SkillCreate) SetPackageURL(v string) *SkillCreate { + _c.mutation.SetPackageURL(v) + return _c +} + +// SetNillablePackageURL sets the "package_url" field if the given value is not nil. +func (_c *SkillCreate) SetNillablePackageURL(v *string) *SkillCreate { + if v != nil { + _c.SetPackageURL(*v) + } + return _c +} + +// SetSourceType sets the "source_type" field. +func (_c *SkillCreate) SetSourceType(v string) *SkillCreate { + _c.mutation.SetSourceType(v) + return _c +} + +// SetSourceLabel sets the "source_label" field. +func (_c *SkillCreate) SetSourceLabel(v string) *SkillCreate { + _c.mutation.SetSourceLabel(v) + return _c +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (_c *SkillCreate) SetSkillMdPath(v string) *SkillCreate { + _c.mutation.SetSkillMdPath(v) + return _c +} + +// SetNillableSkillMdPath sets the "skill_md_path" field if the given value is not nil. +func (_c *SkillCreate) SetNillableSkillMdPath(v *string) *SkillCreate { + if v != nil { + _c.SetSkillMdPath(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *SkillCreate) SetCreatedAt(v time.Time) *SkillCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *SkillCreate) SetNillableCreatedAt(v *time.Time) *SkillCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *SkillCreate) SetUpdatedAt(v time.Time) *SkillCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *SkillCreate) SetNillableUpdatedAt(v *time.Time) *SkillCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *SkillCreate) SetID(v uuid.UUID) *SkillCreate { + _c.mutation.SetID(v) + return _c +} + +// SetUser sets the "user" edge to the User entity. +func (_c *SkillCreate) SetUser(v *User) *SkillCreate { + return _c.SetUserID(v.ID) +} + +// AddTeamIDs adds the "teams" edge to the Team entity by IDs. +func (_c *SkillCreate) AddTeamIDs(ids ...uuid.UUID) *SkillCreate { + _c.mutation.AddTeamIDs(ids...) + return _c +} + +// AddTeams adds the "teams" edges to the Team entity. +func (_c *SkillCreate) AddTeams(v ...*Team) *SkillCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddTeamIDs(ids...) +} + +// AddGroupIDs adds the "groups" edge to the TeamGroup entity by IDs. +func (_c *SkillCreate) AddGroupIDs(ids ...uuid.UUID) *SkillCreate { + _c.mutation.AddGroupIDs(ids...) + return _c +} + +// AddGroups adds the "groups" edges to the TeamGroup entity. +func (_c *SkillCreate) AddGroups(v ...*TeamGroup) *SkillCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddGroupIDs(ids...) +} + +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs. +func (_c *SkillCreate) AddTeamSkillIDs(ids ...uuid.UUID) *SkillCreate { + _c.mutation.AddTeamSkillIDs(ids...) + return _c +} + +// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity. +func (_c *SkillCreate) AddTeamSkills(v ...*TeamSkill) *SkillCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddTeamSkillIDs(ids...) +} + +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (_c *SkillCreate) AddTeamGroupSkillIDs(ids ...uuid.UUID) *SkillCreate { + _c.mutation.AddTeamGroupSkillIDs(ids...) + return _c +} + +// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity. +func (_c *SkillCreate) AddTeamGroupSkills(v ...*TeamGroupSkill) *SkillCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddTeamGroupSkillIDs(ids...) +} + +// Mutation returns the SkillMutation object of the builder. +func (_c *SkillCreate) Mutation() *SkillMutation { + return _c.mutation +} + +// Save creates the Skill in the database. +func (_c *SkillCreate) Save(ctx context.Context) (*Skill, error) { + if err := _c.defaults(); err != nil { + return nil, err + } + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *SkillCreate) SaveX(ctx context.Context) *Skill { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *SkillCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *SkillCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *SkillCreate) defaults() error { + if _, ok := _c.mutation.CreatedAt(); !ok { + if skill.DefaultCreatedAt == nil { + return fmt.Errorf("db: uninitialized skill.DefaultCreatedAt (forgotten import db/runtime?)") + } + v := skill.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + if skill.DefaultUpdatedAt == nil { + return fmt.Errorf("db: uninitialized skill.DefaultUpdatedAt (forgotten import db/runtime?)") + } + v := skill.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + return nil +} + +// check runs all checks and user-defined validators on the builder. +func (_c *SkillCreate) check() error { + if _, ok := _c.mutation.UserID(); !ok { + return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "Skill.user_id"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`db: missing required field "Skill.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := skill.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Skill.name": %w`, err)} + } + } + if _, ok := _c.mutation.Description(); !ok { + return &ValidationError{Name: "description", err: errors.New(`db: missing required field "Skill.description"`)} + } + if v, ok := _c.mutation.Description(); ok { + if err := skill.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`db: validator failed for field "Skill.description": %w`, err)} + } + } + if _, ok := _c.mutation.Content(); !ok { + return &ValidationError{Name: "content", err: errors.New(`db: missing required field "Skill.content"`)} + } + if v, ok := _c.mutation.Content(); ok { + if err := skill.ContentValidator(v); err != nil { + return &ValidationError{Name: "content", err: fmt.Errorf(`db: validator failed for field "Skill.content": %w`, err)} + } + } + if _, ok := _c.mutation.SourceType(); !ok { + return &ValidationError{Name: "source_type", err: errors.New(`db: missing required field "Skill.source_type"`)} + } + if v, ok := _c.mutation.SourceType(); ok { + if err := skill.SourceTypeValidator(v); err != nil { + return &ValidationError{Name: "source_type", err: fmt.Errorf(`db: validator failed for field "Skill.source_type": %w`, err)} + } + } + if _, ok := _c.mutation.SourceLabel(); !ok { + return &ValidationError{Name: "source_label", err: errors.New(`db: missing required field "Skill.source_label"`)} + } + if v, ok := _c.mutation.SourceLabel(); ok { + if err := skill.SourceLabelValidator(v); err != nil { + return &ValidationError{Name: "source_label", err: fmt.Errorf(`db: validator failed for field "Skill.source_label": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Skill.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Skill.updated_at"`)} + } + if len(_c.mutation.UserIDs()) == 0 { + return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "Skill.user"`)} + } + return nil +} + +func (_c *SkillCreate) sqlSave(ctx context.Context) (*Skill, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *SkillCreate) createSpec() (*Skill, *sqlgraph.CreateSpec) { + var ( + _node = &Skill{config: _c.config} + _spec = sqlgraph.NewCreateSpec(skill.Table, sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = _c.conflict + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.DeletedAt(); ok { + _spec.SetField(skill.FieldDeletedAt, field.TypeTime, value) + _node.DeletedAt = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(skill.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(skill.FieldDescription, field.TypeString, value) + _node.Description = value + } + if value, ok := _c.mutation.Tags(); ok { + _spec.SetField(skill.FieldTags, field.TypeJSON, value) + _node.Tags = value + } + if value, ok := _c.mutation.Content(); ok { + _spec.SetField(skill.FieldContent, field.TypeString, value) + _node.Content = value + } + if value, ok := _c.mutation.PackageObjectKey(); ok { + _spec.SetField(skill.FieldPackageObjectKey, field.TypeString, value) + _node.PackageObjectKey = value + } + if value, ok := _c.mutation.PackageURL(); ok { + _spec.SetField(skill.FieldPackageURL, field.TypeString, value) + _node.PackageURL = value + } + if value, ok := _c.mutation.SourceType(); ok { + _spec.SetField(skill.FieldSourceType, field.TypeString, value) + _node.SourceType = value + } + if value, ok := _c.mutation.SourceLabel(); ok { + _spec.SetField(skill.FieldSourceLabel, field.TypeString, value) + _node.SourceLabel = value + } + if value, ok := _c.mutation.SkillMdPath(); ok { + _spec.SetField(skill.FieldSkillMdPath, field.TypeString, value) + _node.SkillMdPath = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(skill.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(skill.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.UserIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: skill.UserTable, + Columns: []string{skill.UserColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.UserID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.TeamsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _c.config, mutation: newTeamSkillMutation(_c.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.GroupsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _c.config, mutation: newTeamGroupSkillMutation(_c.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.TeamSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Skill.Create(). +// SetDeletedAt(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SkillUpsert) { +// SetDeletedAt(v+v). +// }). +// Exec(ctx) +func (_c *SkillCreate) OnConflict(opts ...sql.ConflictOption) *SkillUpsertOne { + _c.conflict = opts + return &SkillUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Skill.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *SkillCreate) OnConflictColumns(columns ...string) *SkillUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &SkillUpsertOne{ + create: _c, + } +} + +type ( + // SkillUpsertOne is the builder for "upsert"-ing + // one Skill node. + SkillUpsertOne struct { + create *SkillCreate + } + + // SkillUpsert is the "OnConflict" setter. + SkillUpsert struct { + *sql.UpdateSet + } +) + +// SetDeletedAt sets the "deleted_at" field. +func (u *SkillUpsert) SetDeletedAt(v time.Time) *SkillUpsert { + u.Set(skill.FieldDeletedAt, v) + return u +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *SkillUpsert) UpdateDeletedAt() *SkillUpsert { + u.SetExcluded(skill.FieldDeletedAt) + return u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *SkillUpsert) ClearDeletedAt() *SkillUpsert { + u.SetNull(skill.FieldDeletedAt) + return u +} + +// SetUserID sets the "user_id" field. +func (u *SkillUpsert) SetUserID(v uuid.UUID) *SkillUpsert { + u.Set(skill.FieldUserID, v) + return u +} + +// UpdateUserID sets the "user_id" field to the value that was provided on create. +func (u *SkillUpsert) UpdateUserID() *SkillUpsert { + u.SetExcluded(skill.FieldUserID) + return u +} + +// SetName sets the "name" field. +func (u *SkillUpsert) SetName(v string) *SkillUpsert { + u.Set(skill.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SkillUpsert) UpdateName() *SkillUpsert { + u.SetExcluded(skill.FieldName) + return u +} + +// SetDescription sets the "description" field. +func (u *SkillUpsert) SetDescription(v string) *SkillUpsert { + u.Set(skill.FieldDescription, v) + return u +} + +// UpdateDescription sets the "description" field to the value that was provided on create. +func (u *SkillUpsert) UpdateDescription() *SkillUpsert { + u.SetExcluded(skill.FieldDescription) + return u +} + +// SetTags sets the "tags" field. +func (u *SkillUpsert) SetTags(v []string) *SkillUpsert { + u.Set(skill.FieldTags, v) + return u +} + +// UpdateTags sets the "tags" field to the value that was provided on create. +func (u *SkillUpsert) UpdateTags() *SkillUpsert { + u.SetExcluded(skill.FieldTags) + return u +} + +// ClearTags clears the value of the "tags" field. +func (u *SkillUpsert) ClearTags() *SkillUpsert { + u.SetNull(skill.FieldTags) + return u +} + +// SetContent sets the "content" field. +func (u *SkillUpsert) SetContent(v string) *SkillUpsert { + u.Set(skill.FieldContent, v) + return u +} + +// UpdateContent sets the "content" field to the value that was provided on create. +func (u *SkillUpsert) UpdateContent() *SkillUpsert { + u.SetExcluded(skill.FieldContent) + return u +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (u *SkillUpsert) SetPackageObjectKey(v string) *SkillUpsert { + u.Set(skill.FieldPackageObjectKey, v) + return u +} + +// UpdatePackageObjectKey sets the "package_object_key" field to the value that was provided on create. +func (u *SkillUpsert) UpdatePackageObjectKey() *SkillUpsert { + u.SetExcluded(skill.FieldPackageObjectKey) + return u +} + +// ClearPackageObjectKey clears the value of the "package_object_key" field. +func (u *SkillUpsert) ClearPackageObjectKey() *SkillUpsert { + u.SetNull(skill.FieldPackageObjectKey) + return u +} + +// SetPackageURL sets the "package_url" field. +func (u *SkillUpsert) SetPackageURL(v string) *SkillUpsert { + u.Set(skill.FieldPackageURL, v) + return u +} + +// UpdatePackageURL sets the "package_url" field to the value that was provided on create. +func (u *SkillUpsert) UpdatePackageURL() *SkillUpsert { + u.SetExcluded(skill.FieldPackageURL) + return u +} + +// ClearPackageURL clears the value of the "package_url" field. +func (u *SkillUpsert) ClearPackageURL() *SkillUpsert { + u.SetNull(skill.FieldPackageURL) + return u +} + +// SetSourceType sets the "source_type" field. +func (u *SkillUpsert) SetSourceType(v string) *SkillUpsert { + u.Set(skill.FieldSourceType, v) + return u +} + +// UpdateSourceType sets the "source_type" field to the value that was provided on create. +func (u *SkillUpsert) UpdateSourceType() *SkillUpsert { + u.SetExcluded(skill.FieldSourceType) + return u +} + +// SetSourceLabel sets the "source_label" field. +func (u *SkillUpsert) SetSourceLabel(v string) *SkillUpsert { + u.Set(skill.FieldSourceLabel, v) + return u +} + +// UpdateSourceLabel sets the "source_label" field to the value that was provided on create. +func (u *SkillUpsert) UpdateSourceLabel() *SkillUpsert { + u.SetExcluded(skill.FieldSourceLabel) + return u +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (u *SkillUpsert) SetSkillMdPath(v string) *SkillUpsert { + u.Set(skill.FieldSkillMdPath, v) + return u +} + +// UpdateSkillMdPath sets the "skill_md_path" field to the value that was provided on create. +func (u *SkillUpsert) UpdateSkillMdPath() *SkillUpsert { + u.SetExcluded(skill.FieldSkillMdPath) + return u +} + +// ClearSkillMdPath clears the value of the "skill_md_path" field. +func (u *SkillUpsert) ClearSkillMdPath() *SkillUpsert { + u.SetNull(skill.FieldSkillMdPath) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *SkillUpsert) SetCreatedAt(v time.Time) *SkillUpsert { + u.Set(skill.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SkillUpsert) UpdateCreatedAt() *SkillUpsert { + u.SetExcluded(skill.FieldCreatedAt) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SkillUpsert) SetUpdatedAt(v time.Time) *SkillUpsert { + u.Set(skill.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SkillUpsert) UpdateUpdatedAt() *SkillUpsert { + u.SetExcluded(skill.FieldUpdatedAt) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.Skill.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(skill.FieldID) +// }), +// ). +// Exec(ctx) +func (u *SkillUpsertOne) UpdateNewValues() *SkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(skill.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Skill.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SkillUpsertOne) Ignore() *SkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SkillUpsertOne) DoNothing() *SkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SkillCreate.OnConflict +// documentation for more info. +func (u *SkillUpsertOne) Update(set func(*SkillUpsert)) *SkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SkillUpsert{UpdateSet: update}) + })) + return u +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *SkillUpsertOne) SetDeletedAt(v time.Time) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateDeletedAt() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *SkillUpsertOne) ClearDeletedAt() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.ClearDeletedAt() + }) +} + +// SetUserID sets the "user_id" field. +func (u *SkillUpsertOne) SetUserID(v uuid.UUID) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetUserID(v) + }) +} + +// UpdateUserID sets the "user_id" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateUserID() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateUserID() + }) +} + +// SetName sets the "name" field. +func (u *SkillUpsertOne) SetName(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateName() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateName() + }) +} + +// SetDescription sets the "description" field. +func (u *SkillUpsertOne) SetDescription(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetDescription(v) + }) +} + +// UpdateDescription sets the "description" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateDescription() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateDescription() + }) +} + +// SetTags sets the "tags" field. +func (u *SkillUpsertOne) SetTags(v []string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetTags(v) + }) +} + +// UpdateTags sets the "tags" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateTags() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateTags() + }) +} + +// ClearTags clears the value of the "tags" field. +func (u *SkillUpsertOne) ClearTags() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.ClearTags() + }) +} + +// SetContent sets the "content" field. +func (u *SkillUpsertOne) SetContent(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetContent(v) + }) +} + +// UpdateContent sets the "content" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateContent() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateContent() + }) +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (u *SkillUpsertOne) SetPackageObjectKey(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetPackageObjectKey(v) + }) +} + +// UpdatePackageObjectKey sets the "package_object_key" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdatePackageObjectKey() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdatePackageObjectKey() + }) +} + +// ClearPackageObjectKey clears the value of the "package_object_key" field. +func (u *SkillUpsertOne) ClearPackageObjectKey() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.ClearPackageObjectKey() + }) +} + +// SetPackageURL sets the "package_url" field. +func (u *SkillUpsertOne) SetPackageURL(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetPackageURL(v) + }) +} + +// UpdatePackageURL sets the "package_url" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdatePackageURL() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdatePackageURL() + }) +} + +// ClearPackageURL clears the value of the "package_url" field. +func (u *SkillUpsertOne) ClearPackageURL() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.ClearPackageURL() + }) +} + +// SetSourceType sets the "source_type" field. +func (u *SkillUpsertOne) SetSourceType(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetSourceType(v) + }) +} + +// UpdateSourceType sets the "source_type" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateSourceType() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateSourceType() + }) +} + +// SetSourceLabel sets the "source_label" field. +func (u *SkillUpsertOne) SetSourceLabel(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetSourceLabel(v) + }) +} + +// UpdateSourceLabel sets the "source_label" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateSourceLabel() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateSourceLabel() + }) +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (u *SkillUpsertOne) SetSkillMdPath(v string) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetSkillMdPath(v) + }) +} + +// UpdateSkillMdPath sets the "skill_md_path" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateSkillMdPath() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateSkillMdPath() + }) +} + +// ClearSkillMdPath clears the value of the "skill_md_path" field. +func (u *SkillUpsertOne) ClearSkillMdPath() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.ClearSkillMdPath() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SkillUpsertOne) SetCreatedAt(v time.Time) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateCreatedAt() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SkillUpsertOne) SetUpdatedAt(v time.Time) *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SkillUpsertOne) UpdateUpdatedAt() *SkillUpsertOne { + return u.Update(func(s *SkillUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *SkillUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for SkillCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SkillUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *SkillUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) { + if u.create.driver.Dialect() == dialect.MySQL { + // In case of "ON CONFLICT", there is no way to get back non-numeric ID + // fields from the database since MySQL does not support the RETURNING clause. + return id, errors.New("db: SkillUpsertOne.ID is not supported by MySQL driver. Use SkillUpsertOne.Exec instead") + } + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *SkillUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// SkillCreateBulk is the builder for creating many Skill entities in bulk. +type SkillCreateBulk struct { + config + err error + builders []*SkillCreate + conflict []sql.ConflictOption +} + +// Save creates the Skill entities in the database. +func (_c *SkillCreateBulk) Save(ctx context.Context) ([]*Skill, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Skill, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*SkillMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = _c.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *SkillCreateBulk) SaveX(ctx context.Context) []*Skill { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *SkillCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *SkillCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Skill.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SkillUpsert) { +// SetDeletedAt(v+v). +// }). +// Exec(ctx) +func (_c *SkillCreateBulk) OnConflict(opts ...sql.ConflictOption) *SkillUpsertBulk { + _c.conflict = opts + return &SkillUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Skill.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *SkillCreateBulk) OnConflictColumns(columns ...string) *SkillUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &SkillUpsertBulk{ + create: _c, + } +} + +// SkillUpsertBulk is the builder for "upsert"-ing +// a bulk of Skill nodes. +type SkillUpsertBulk struct { + create *SkillCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.Skill.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(skill.FieldID) +// }), +// ). +// Exec(ctx) +func (u *SkillUpsertBulk) UpdateNewValues() *SkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(skill.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Skill.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SkillUpsertBulk) Ignore() *SkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SkillUpsertBulk) DoNothing() *SkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SkillCreateBulk.OnConflict +// documentation for more info. +func (u *SkillUpsertBulk) Update(set func(*SkillUpsert)) *SkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SkillUpsert{UpdateSet: update}) + })) + return u +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *SkillUpsertBulk) SetDeletedAt(v time.Time) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateDeletedAt() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *SkillUpsertBulk) ClearDeletedAt() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.ClearDeletedAt() + }) +} + +// SetUserID sets the "user_id" field. +func (u *SkillUpsertBulk) SetUserID(v uuid.UUID) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetUserID(v) + }) +} + +// UpdateUserID sets the "user_id" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateUserID() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateUserID() + }) +} + +// SetName sets the "name" field. +func (u *SkillUpsertBulk) SetName(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateName() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateName() + }) +} + +// SetDescription sets the "description" field. +func (u *SkillUpsertBulk) SetDescription(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetDescription(v) + }) +} + +// UpdateDescription sets the "description" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateDescription() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateDescription() + }) +} + +// SetTags sets the "tags" field. +func (u *SkillUpsertBulk) SetTags(v []string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetTags(v) + }) +} + +// UpdateTags sets the "tags" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateTags() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateTags() + }) +} + +// ClearTags clears the value of the "tags" field. +func (u *SkillUpsertBulk) ClearTags() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.ClearTags() + }) +} + +// SetContent sets the "content" field. +func (u *SkillUpsertBulk) SetContent(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetContent(v) + }) +} + +// UpdateContent sets the "content" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateContent() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateContent() + }) +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (u *SkillUpsertBulk) SetPackageObjectKey(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetPackageObjectKey(v) + }) +} + +// UpdatePackageObjectKey sets the "package_object_key" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdatePackageObjectKey() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdatePackageObjectKey() + }) +} + +// ClearPackageObjectKey clears the value of the "package_object_key" field. +func (u *SkillUpsertBulk) ClearPackageObjectKey() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.ClearPackageObjectKey() + }) +} + +// SetPackageURL sets the "package_url" field. +func (u *SkillUpsertBulk) SetPackageURL(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetPackageURL(v) + }) +} + +// UpdatePackageURL sets the "package_url" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdatePackageURL() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdatePackageURL() + }) +} + +// ClearPackageURL clears the value of the "package_url" field. +func (u *SkillUpsertBulk) ClearPackageURL() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.ClearPackageURL() + }) +} + +// SetSourceType sets the "source_type" field. +func (u *SkillUpsertBulk) SetSourceType(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetSourceType(v) + }) +} + +// UpdateSourceType sets the "source_type" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateSourceType() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateSourceType() + }) +} + +// SetSourceLabel sets the "source_label" field. +func (u *SkillUpsertBulk) SetSourceLabel(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetSourceLabel(v) + }) +} + +// UpdateSourceLabel sets the "source_label" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateSourceLabel() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateSourceLabel() + }) +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (u *SkillUpsertBulk) SetSkillMdPath(v string) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetSkillMdPath(v) + }) +} + +// UpdateSkillMdPath sets the "skill_md_path" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateSkillMdPath() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateSkillMdPath() + }) +} + +// ClearSkillMdPath clears the value of the "skill_md_path" field. +func (u *SkillUpsertBulk) ClearSkillMdPath() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.ClearSkillMdPath() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SkillUpsertBulk) SetCreatedAt(v time.Time) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateCreatedAt() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SkillUpsertBulk) SetUpdatedAt(v time.Time) *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SkillUpsertBulk) UpdateUpdatedAt() *SkillUpsertBulk { + return u.Update(func(s *SkillUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *SkillUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the SkillCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for SkillCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SkillUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/skill_delete.go b/backend/db/skill_delete.go new file mode 100644 index 00000000..68880562 --- /dev/null +++ b/backend/db/skill_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" +) + +// SkillDelete is the builder for deleting a Skill entity. +type SkillDelete struct { + config + hooks []Hook + mutation *SkillMutation +} + +// Where appends a list predicates to the SkillDelete builder. +func (_d *SkillDelete) Where(ps ...predicate.Skill) *SkillDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *SkillDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *SkillDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *SkillDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(skill.Table, sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// SkillDeleteOne is the builder for deleting a single Skill entity. +type SkillDeleteOne struct { + _d *SkillDelete +} + +// Where appends a list predicates to the SkillDelete builder. +func (_d *SkillDeleteOne) Where(ps ...predicate.Skill) *SkillDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *SkillDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{skill.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *SkillDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/skill_query.go b/backend/db/skill_query.go new file mode 100644 index 00000000..88ae4d44 --- /dev/null +++ b/backend/db/skill_query.go @@ -0,0 +1,1016 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/chaitin/MonkeyCode/backend/db/user" + "github.com/google/uuid" +) + +// SkillQuery is the builder for querying Skill entities. +type SkillQuery struct { + config + ctx *QueryContext + order []skill.OrderOption + inters []Interceptor + predicates []predicate.Skill + withUser *UserQuery + withTeams *TeamQuery + withGroups *TeamGroupQuery + withTeamSkills *TeamSkillQuery + withTeamGroupSkills *TeamGroupSkillQuery + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the SkillQuery builder. +func (_q *SkillQuery) Where(ps ...predicate.Skill) *SkillQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *SkillQuery) Limit(limit int) *SkillQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *SkillQuery) Offset(offset int) *SkillQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *SkillQuery) Unique(unique bool) *SkillQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *SkillQuery) Order(o ...skill.OrderOption) *SkillQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryUser chains the current query on the "user" edge. +func (_q *SkillQuery) QueryUser() *UserQuery { + query := (&UserClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, selector), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, skill.UserTable, skill.UserColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryTeams chains the current query on the "teams" edge. +func (_q *SkillQuery) QueryTeams() *TeamQuery { + query := (&TeamClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, selector), + sqlgraph.To(team.Table, team.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, skill.TeamsTable, skill.TeamsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryGroups chains the current query on the "groups" edge. +func (_q *SkillQuery) QueryGroups() *TeamGroupQuery { + query := (&TeamGroupClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, selector), + sqlgraph.To(teamgroup.Table, teamgroup.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, skill.GroupsTable, skill.GroupsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryTeamSkills chains the current query on the "team_skills" edge. +func (_q *SkillQuery) QueryTeamSkills() *TeamSkillQuery { + query := (&TeamSkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, selector), + sqlgraph.To(teamskill.Table, teamskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, skill.TeamSkillsTable, skill.TeamSkillsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryTeamGroupSkills chains the current query on the "team_group_skills" edge. +func (_q *SkillQuery) QueryTeamGroupSkills() *TeamGroupSkillQuery { + query := (&TeamGroupSkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(skill.Table, skill.FieldID, selector), + sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, skill.TeamGroupSkillsTable, skill.TeamGroupSkillsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Skill entity from the query. +// Returns a *NotFoundError when no Skill was found. +func (_q *SkillQuery) First(ctx context.Context) (*Skill, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{skill.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *SkillQuery) FirstX(ctx context.Context) *Skill { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Skill ID from the query. +// Returns a *NotFoundError when no Skill ID was found. +func (_q *SkillQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{skill.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *SkillQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Skill entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Skill entity is found. +// Returns a *NotFoundError when no Skill entities are found. +func (_q *SkillQuery) Only(ctx context.Context) (*Skill, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{skill.Label} + default: + return nil, &NotSingularError{skill.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *SkillQuery) OnlyX(ctx context.Context) *Skill { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Skill ID in the query. +// Returns a *NotSingularError when more than one Skill ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *SkillQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{skill.Label} + default: + err = &NotSingularError{skill.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *SkillQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Skills. +func (_q *SkillQuery) All(ctx context.Context) ([]*Skill, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Skill, *SkillQuery]() + return withInterceptors[[]*Skill](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *SkillQuery) AllX(ctx context.Context) []*Skill { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Skill IDs. +func (_q *SkillQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(skill.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *SkillQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *SkillQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*SkillQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *SkillQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *SkillQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *SkillQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SkillQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *SkillQuery) Clone() *SkillQuery { + if _q == nil { + return nil + } + return &SkillQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]skill.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Skill{}, _q.predicates...), + withUser: _q.withUser.Clone(), + withTeams: _q.withTeams.Clone(), + withGroups: _q.withGroups.Clone(), + withTeamSkills: _q.withTeamSkills.Clone(), + withTeamGroupSkills: _q.withTeamGroupSkills.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// WithUser tells the query-builder to eager-load the nodes that are connected to +// the "user" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SkillQuery) WithUser(opts ...func(*UserQuery)) *SkillQuery { + query := (&UserClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withUser = query + return _q +} + +// WithTeams tells the query-builder to eager-load the nodes that are connected to +// the "teams" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SkillQuery) WithTeams(opts ...func(*TeamQuery)) *SkillQuery { + query := (&TeamClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeams = query + return _q +} + +// WithGroups tells the query-builder to eager-load the nodes that are connected to +// the "groups" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SkillQuery) WithGroups(opts ...func(*TeamGroupQuery)) *SkillQuery { + query := (&TeamGroupClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withGroups = query + return _q +} + +// WithTeamSkills tells the query-builder to eager-load the nodes that are connected to +// the "team_skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SkillQuery) WithTeamSkills(opts ...func(*TeamSkillQuery)) *SkillQuery { + query := (&TeamSkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeamSkills = query + return _q +} + +// WithTeamGroupSkills tells the query-builder to eager-load the nodes that are connected to +// the "team_group_skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SkillQuery) WithTeamGroupSkills(opts ...func(*TeamGroupSkillQuery)) *SkillQuery { + query := (&TeamGroupSkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeamGroupSkills = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// DeletedAt time.Time `json:"deleted_at,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Skill.Query(). +// GroupBy(skill.FieldDeletedAt). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *SkillQuery) GroupBy(field string, fields ...string) *SkillGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &SkillGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = skill.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// DeletedAt time.Time `json:"deleted_at,omitempty"` +// } +// +// client.Skill.Query(). +// Select(skill.FieldDeletedAt). +// Scan(ctx, &v) +func (_q *SkillQuery) Select(fields ...string) *SkillSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &SkillSelect{SkillQuery: _q} + sbuild.label = skill.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SkillSelect configured with the given aggregations. +func (_q *SkillQuery) Aggregate(fns ...AggregateFunc) *SkillSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *SkillQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !skill.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *SkillQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Skill, error) { + var ( + nodes = []*Skill{} + _spec = _q.querySpec() + loadedTypes = [5]bool{ + _q.withUser != nil, + _q.withTeams != nil, + _q.withGroups != nil, + _q.withTeamSkills != nil, + _q.withTeamGroupSkills != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Skill).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Skill{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withUser; query != nil { + if err := _q.loadUser(ctx, query, nodes, nil, + func(n *Skill, e *User) { n.Edges.User = e }); err != nil { + return nil, err + } + } + if query := _q.withTeams; query != nil { + if err := _q.loadTeams(ctx, query, nodes, + func(n *Skill) { n.Edges.Teams = []*Team{} }, + func(n *Skill, e *Team) { n.Edges.Teams = append(n.Edges.Teams, e) }); err != nil { + return nil, err + } + } + if query := _q.withGroups; query != nil { + if err := _q.loadGroups(ctx, query, nodes, + func(n *Skill) { n.Edges.Groups = []*TeamGroup{} }, + func(n *Skill, e *TeamGroup) { n.Edges.Groups = append(n.Edges.Groups, e) }); err != nil { + return nil, err + } + } + if query := _q.withTeamSkills; query != nil { + if err := _q.loadTeamSkills(ctx, query, nodes, + func(n *Skill) { n.Edges.TeamSkills = []*TeamSkill{} }, + func(n *Skill, e *TeamSkill) { n.Edges.TeamSkills = append(n.Edges.TeamSkills, e) }); err != nil { + return nil, err + } + } + if query := _q.withTeamGroupSkills; query != nil { + if err := _q.loadTeamGroupSkills(ctx, query, nodes, + func(n *Skill) { n.Edges.TeamGroupSkills = []*TeamGroupSkill{} }, + func(n *Skill, e *TeamGroupSkill) { n.Edges.TeamGroupSkills = append(n.Edges.TeamGroupSkills, e) }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *SkillQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Skill, init func(*Skill), assign func(*Skill, *User)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*Skill) + for i := range nodes { + fk := nodes[i].UserID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(user.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *SkillQuery) loadTeams(ctx context.Context, query *TeamQuery, nodes []*Skill, init func(*Skill), assign func(*Skill, *Team)) error { + edgeIDs := make([]driver.Value, len(nodes)) + byID := make(map[uuid.UUID]*Skill) + nids := make(map[uuid.UUID]map[*Skill]struct{}) + for i, node := range nodes { + edgeIDs[i] = node.ID + byID[node.ID] = node + if init != nil { + init(node) + } + } + query.Where(func(s *sql.Selector) { + joinT := sql.Table(skill.TeamsTable) + s.Join(joinT).On(s.C(team.FieldID), joinT.C(skill.TeamsPrimaryKey[0])) + s.Where(sql.InValues(joinT.C(skill.TeamsPrimaryKey[1]), edgeIDs...)) + columns := s.SelectedColumns() + s.Select(joinT.C(skill.TeamsPrimaryKey[1])) + s.AppendSelect(columns...) + s.SetDistinct(false) + }) + if err := query.prepareQuery(ctx); err != nil { + return err + } + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil + } + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*Skill]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil + } + }) + }) + neighbors, err := withInterceptors[[]*Team](ctx, query, qr, query.inters) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nids[n.ID] + if !ok { + return fmt.Errorf(`unexpected "teams" node returned %v`, n.ID) + } + for kn := range nodes { + assign(kn, n) + } + } + return nil +} +func (_q *SkillQuery) loadGroups(ctx context.Context, query *TeamGroupQuery, nodes []*Skill, init func(*Skill), assign func(*Skill, *TeamGroup)) error { + edgeIDs := make([]driver.Value, len(nodes)) + byID := make(map[uuid.UUID]*Skill) + nids := make(map[uuid.UUID]map[*Skill]struct{}) + for i, node := range nodes { + edgeIDs[i] = node.ID + byID[node.ID] = node + if init != nil { + init(node) + } + } + query.Where(func(s *sql.Selector) { + joinT := sql.Table(skill.GroupsTable) + s.Join(joinT).On(s.C(teamgroup.FieldID), joinT.C(skill.GroupsPrimaryKey[0])) + s.Where(sql.InValues(joinT.C(skill.GroupsPrimaryKey[1]), edgeIDs...)) + columns := s.SelectedColumns() + s.Select(joinT.C(skill.GroupsPrimaryKey[1])) + s.AppendSelect(columns...) + s.SetDistinct(false) + }) + if err := query.prepareQuery(ctx); err != nil { + return err + } + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil + } + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*Skill]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil + } + }) + }) + neighbors, err := withInterceptors[[]*TeamGroup](ctx, query, qr, query.inters) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nids[n.ID] + if !ok { + return fmt.Errorf(`unexpected "groups" node returned %v`, n.ID) + } + for kn := range nodes { + assign(kn, n) + } + } + return nil +} +func (_q *SkillQuery) loadTeamSkills(ctx context.Context, query *TeamSkillQuery, nodes []*Skill, init func(*Skill), assign func(*Skill, *TeamSkill)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Skill) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(teamskill.FieldSkillID) + } + query.Where(predicate.TeamSkill(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(skill.TeamSkillsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SkillID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "skill_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} +func (_q *SkillQuery) loadTeamGroupSkills(ctx context.Context, query *TeamGroupSkillQuery, nodes []*Skill, init func(*Skill), assign func(*Skill, *TeamGroupSkill)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Skill) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(teamgroupskill.FieldSkillID) + } + query.Where(predicate.TeamGroupSkill(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(skill.TeamGroupSkillsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SkillID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "skill_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (_q *SkillQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *SkillQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(skill.Table, skill.Columns, sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, skill.FieldID) + for i := range fields { + if fields[i] != skill.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withUser != nil { + _spec.Node.AddColumnOnce(skill.FieldUserID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *SkillQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(skill.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = skill.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ForUpdate locks the selected rows against concurrent updates, and prevent them from being +// updated, deleted or "selected ... for update" by other sessions, until the transaction is +// either committed or rolled-back. +func (_q *SkillQuery) ForUpdate(opts ...sql.LockOption) *SkillQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock +// on any rows that are read. Other sessions can read the rows, but cannot modify them +// until your transaction commits. +func (_q *SkillQuery) ForShare(opts ...sql.LockOption) *SkillQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_q *SkillQuery) Modify(modifiers ...func(s *sql.Selector)) *SkillSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// SkillGroupBy is the group-by builder for Skill entities. +type SkillGroupBy struct { + selector + build *SkillQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *SkillGroupBy) Aggregate(fns ...AggregateFunc) *SkillGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *SkillGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SkillQuery, *SkillGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *SkillGroupBy) sqlScan(ctx context.Context, root *SkillQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// SkillSelect is the builder for selecting fields of Skill entities. +type SkillSelect struct { + *SkillQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *SkillSelect) Aggregate(fns ...AggregateFunc) *SkillSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *SkillSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SkillQuery, *SkillSelect](ctx, _s.SkillQuery, _s, _s.inters, v) +} + +func (_s *SkillSelect) sqlScan(ctx context.Context, root *SkillQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_s *SkillSelect) Modify(modifiers ...func(s *sql.Selector)) *SkillSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/backend/db/skill_update.go b/backend/db/skill_update.go new file mode 100644 index 00000000..1b0af718 --- /dev/null +++ b/backend/db/skill_update.go @@ -0,0 +1,1593 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/chaitin/MonkeyCode/backend/db/user" + "github.com/google/uuid" +) + +// SkillUpdate is the builder for updating Skill entities. +type SkillUpdate struct { + config + hooks []Hook + mutation *SkillMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the SkillUpdate builder. +func (_u *SkillUpdate) Where(ps ...predicate.Skill) *SkillUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *SkillUpdate) SetDeletedAt(v time.Time) *SkillUpdate { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableDeletedAt(v *time.Time) *SkillUpdate { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *SkillUpdate) ClearDeletedAt() *SkillUpdate { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetUserID sets the "user_id" field. +func (_u *SkillUpdate) SetUserID(v uuid.UUID) *SkillUpdate { + _u.mutation.SetUserID(v) + return _u +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableUserID(v *uuid.UUID) *SkillUpdate { + if v != nil { + _u.SetUserID(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *SkillUpdate) SetName(v string) *SkillUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableName(v *string) *SkillUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *SkillUpdate) SetDescription(v string) *SkillUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableDescription(v *string) *SkillUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// SetTags sets the "tags" field. +func (_u *SkillUpdate) SetTags(v []string) *SkillUpdate { + _u.mutation.SetTags(v) + return _u +} + +// AppendTags appends value to the "tags" field. +func (_u *SkillUpdate) AppendTags(v []string) *SkillUpdate { + _u.mutation.AppendTags(v) + return _u +} + +// ClearTags clears the value of the "tags" field. +func (_u *SkillUpdate) ClearTags() *SkillUpdate { + _u.mutation.ClearTags() + return _u +} + +// SetContent sets the "content" field. +func (_u *SkillUpdate) SetContent(v string) *SkillUpdate { + _u.mutation.SetContent(v) + return _u +} + +// SetNillableContent sets the "content" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableContent(v *string) *SkillUpdate { + if v != nil { + _u.SetContent(*v) + } + return _u +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (_u *SkillUpdate) SetPackageObjectKey(v string) *SkillUpdate { + _u.mutation.SetPackageObjectKey(v) + return _u +} + +// SetNillablePackageObjectKey sets the "package_object_key" field if the given value is not nil. +func (_u *SkillUpdate) SetNillablePackageObjectKey(v *string) *SkillUpdate { + if v != nil { + _u.SetPackageObjectKey(*v) + } + return _u +} + +// ClearPackageObjectKey clears the value of the "package_object_key" field. +func (_u *SkillUpdate) ClearPackageObjectKey() *SkillUpdate { + _u.mutation.ClearPackageObjectKey() + return _u +} + +// SetPackageURL sets the "package_url" field. +func (_u *SkillUpdate) SetPackageURL(v string) *SkillUpdate { + _u.mutation.SetPackageURL(v) + return _u +} + +// SetNillablePackageURL sets the "package_url" field if the given value is not nil. +func (_u *SkillUpdate) SetNillablePackageURL(v *string) *SkillUpdate { + if v != nil { + _u.SetPackageURL(*v) + } + return _u +} + +// ClearPackageURL clears the value of the "package_url" field. +func (_u *SkillUpdate) ClearPackageURL() *SkillUpdate { + _u.mutation.ClearPackageURL() + return _u +} + +// SetSourceType sets the "source_type" field. +func (_u *SkillUpdate) SetSourceType(v string) *SkillUpdate { + _u.mutation.SetSourceType(v) + return _u +} + +// SetNillableSourceType sets the "source_type" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableSourceType(v *string) *SkillUpdate { + if v != nil { + _u.SetSourceType(*v) + } + return _u +} + +// SetSourceLabel sets the "source_label" field. +func (_u *SkillUpdate) SetSourceLabel(v string) *SkillUpdate { + _u.mutation.SetSourceLabel(v) + return _u +} + +// SetNillableSourceLabel sets the "source_label" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableSourceLabel(v *string) *SkillUpdate { + if v != nil { + _u.SetSourceLabel(*v) + } + return _u +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (_u *SkillUpdate) SetSkillMdPath(v string) *SkillUpdate { + _u.mutation.SetSkillMdPath(v) + return _u +} + +// SetNillableSkillMdPath sets the "skill_md_path" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableSkillMdPath(v *string) *SkillUpdate { + if v != nil { + _u.SetSkillMdPath(*v) + } + return _u +} + +// ClearSkillMdPath clears the value of the "skill_md_path" field. +func (_u *SkillUpdate) ClearSkillMdPath() *SkillUpdate { + _u.mutation.ClearSkillMdPath() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *SkillUpdate) SetCreatedAt(v time.Time) *SkillUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *SkillUpdate) SetNillableCreatedAt(v *time.Time) *SkillUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *SkillUpdate) SetUpdatedAt(v time.Time) *SkillUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetUser sets the "user" edge to the User entity. +func (_u *SkillUpdate) SetUser(v *User) *SkillUpdate { + return _u.SetUserID(v.ID) +} + +// AddTeamIDs adds the "teams" edge to the Team entity by IDs. +func (_u *SkillUpdate) AddTeamIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.AddTeamIDs(ids...) + return _u +} + +// AddTeams adds the "teams" edges to the Team entity. +func (_u *SkillUpdate) AddTeams(v ...*Team) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamIDs(ids...) +} + +// AddGroupIDs adds the "groups" edge to the TeamGroup entity by IDs. +func (_u *SkillUpdate) AddGroupIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.AddGroupIDs(ids...) + return _u +} + +// AddGroups adds the "groups" edges to the TeamGroup entity. +func (_u *SkillUpdate) AddGroups(v ...*TeamGroup) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddGroupIDs(ids...) +} + +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs. +func (_u *SkillUpdate) AddTeamSkillIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.AddTeamSkillIDs(ids...) + return _u +} + +// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity. +func (_u *SkillUpdate) AddTeamSkills(v ...*TeamSkill) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamSkillIDs(ids...) +} + +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (_u *SkillUpdate) AddTeamGroupSkillIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.AddTeamGroupSkillIDs(ids...) + return _u +} + +// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *SkillUpdate) AddTeamGroupSkills(v ...*TeamGroupSkill) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamGroupSkillIDs(ids...) +} + +// Mutation returns the SkillMutation object of the builder. +func (_u *SkillUpdate) Mutation() *SkillMutation { + return _u.mutation +} + +// ClearUser clears the "user" edge to the User entity. +func (_u *SkillUpdate) ClearUser() *SkillUpdate { + _u.mutation.ClearUser() + return _u +} + +// ClearTeams clears all "teams" edges to the Team entity. +func (_u *SkillUpdate) ClearTeams() *SkillUpdate { + _u.mutation.ClearTeams() + return _u +} + +// RemoveTeamIDs removes the "teams" edge to Team entities by IDs. +func (_u *SkillUpdate) RemoveTeamIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.RemoveTeamIDs(ids...) + return _u +} + +// RemoveTeams removes "teams" edges to Team entities. +func (_u *SkillUpdate) RemoveTeams(v ...*Team) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamIDs(ids...) +} + +// ClearGroups clears all "groups" edges to the TeamGroup entity. +func (_u *SkillUpdate) ClearGroups() *SkillUpdate { + _u.mutation.ClearGroups() + return _u +} + +// RemoveGroupIDs removes the "groups" edge to TeamGroup entities by IDs. +func (_u *SkillUpdate) RemoveGroupIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.RemoveGroupIDs(ids...) + return _u +} + +// RemoveGroups removes "groups" edges to TeamGroup entities. +func (_u *SkillUpdate) RemoveGroups(v ...*TeamGroup) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveGroupIDs(ids...) +} + +// ClearTeamSkills clears all "team_skills" edges to the TeamSkill entity. +func (_u *SkillUpdate) ClearTeamSkills() *SkillUpdate { + _u.mutation.ClearTeamSkills() + return _u +} + +// RemoveTeamSkillIDs removes the "team_skills" edge to TeamSkill entities by IDs. +func (_u *SkillUpdate) RemoveTeamSkillIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.RemoveTeamSkillIDs(ids...) + return _u +} + +// RemoveTeamSkills removes "team_skills" edges to TeamSkill entities. +func (_u *SkillUpdate) RemoveTeamSkills(v ...*TeamSkill) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamSkillIDs(ids...) +} + +// ClearTeamGroupSkills clears all "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *SkillUpdate) ClearTeamGroupSkills() *SkillUpdate { + _u.mutation.ClearTeamGroupSkills() + return _u +} + +// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to TeamGroupSkill entities by IDs. +func (_u *SkillUpdate) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) *SkillUpdate { + _u.mutation.RemoveTeamGroupSkillIDs(ids...) + return _u +} + +// RemoveTeamGroupSkills removes "team_group_skills" edges to TeamGroupSkill entities. +func (_u *SkillUpdate) RemoveTeamGroupSkills(v ...*TeamGroupSkill) *SkillUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamGroupSkillIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *SkillUpdate) Save(ctx context.Context) (int, error) { + if err := _u.defaults(); err != nil { + return 0, err + } + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *SkillUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *SkillUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *SkillUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *SkillUpdate) defaults() error { + if _, ok := _u.mutation.UpdatedAt(); !ok { + if skill.UpdateDefaultUpdatedAt == nil { + return fmt.Errorf("db: uninitialized skill.UpdateDefaultUpdatedAt (forgotten import db/runtime?)") + } + v := skill.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } + return nil +} + +// check runs all checks and user-defined validators on the builder. +func (_u *SkillUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := skill.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Skill.name": %w`, err)} + } + } + if v, ok := _u.mutation.Description(); ok { + if err := skill.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`db: validator failed for field "Skill.description": %w`, err)} + } + } + if v, ok := _u.mutation.Content(); ok { + if err := skill.ContentValidator(v); err != nil { + return &ValidationError{Name: "content", err: fmt.Errorf(`db: validator failed for field "Skill.content": %w`, err)} + } + } + if v, ok := _u.mutation.SourceType(); ok { + if err := skill.SourceTypeValidator(v); err != nil { + return &ValidationError{Name: "source_type", err: fmt.Errorf(`db: validator failed for field "Skill.source_type": %w`, err)} + } + } + if v, ok := _u.mutation.SourceLabel(); ok { + if err := skill.SourceLabelValidator(v); err != nil { + return &ValidationError{Name: "source_label", err: fmt.Errorf(`db: validator failed for field "Skill.source_label": %w`, err)} + } + } + if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "Skill.user"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *SkillUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SkillUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *SkillUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(skill.Table, skill.Columns, sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(skill.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(skill.FieldDeletedAt, field.TypeTime) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(skill.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(skill.FieldDescription, field.TypeString, value) + } + if value, ok := _u.mutation.Tags(); ok { + _spec.SetField(skill.FieldTags, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedTags(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, skill.FieldTags, value) + }) + } + if _u.mutation.TagsCleared() { + _spec.ClearField(skill.FieldTags, field.TypeJSON) + } + if value, ok := _u.mutation.Content(); ok { + _spec.SetField(skill.FieldContent, field.TypeString, value) + } + if value, ok := _u.mutation.PackageObjectKey(); ok { + _spec.SetField(skill.FieldPackageObjectKey, field.TypeString, value) + } + if _u.mutation.PackageObjectKeyCleared() { + _spec.ClearField(skill.FieldPackageObjectKey, field.TypeString) + } + if value, ok := _u.mutation.PackageURL(); ok { + _spec.SetField(skill.FieldPackageURL, field.TypeString, value) + } + if _u.mutation.PackageURLCleared() { + _spec.ClearField(skill.FieldPackageURL, field.TypeString) + } + if value, ok := _u.mutation.SourceType(); ok { + _spec.SetField(skill.FieldSourceType, field.TypeString, value) + } + if value, ok := _u.mutation.SourceLabel(); ok { + _spec.SetField(skill.FieldSourceLabel, field.TypeString, value) + } + if value, ok := _u.mutation.SkillMdPath(); ok { + _spec.SetField(skill.FieldSkillMdPath, field.TypeString, value) + } + if _u.mutation.SkillMdPathCleared() { + _spec.ClearField(skill.FieldSkillMdPath, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(skill.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(skill.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.UserCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: skill.UserTable, + Columns: []string{skill.UserColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.UserIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: skill.UserTable, + Columns: []string{skill.UserColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamsIDs(); len(nodes) > 0 && !_u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.GroupsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamGroupSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{skill.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// SkillUpdateOne is the builder for updating a single Skill entity. +type SkillUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SkillMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *SkillUpdateOne) SetDeletedAt(v time.Time) *SkillUpdateOne { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableDeletedAt(v *time.Time) *SkillUpdateOne { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *SkillUpdateOne) ClearDeletedAt() *SkillUpdateOne { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetUserID sets the "user_id" field. +func (_u *SkillUpdateOne) SetUserID(v uuid.UUID) *SkillUpdateOne { + _u.mutation.SetUserID(v) + return _u +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableUserID(v *uuid.UUID) *SkillUpdateOne { + if v != nil { + _u.SetUserID(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *SkillUpdateOne) SetName(v string) *SkillUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableName(v *string) *SkillUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *SkillUpdateOne) SetDescription(v string) *SkillUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableDescription(v *string) *SkillUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// SetTags sets the "tags" field. +func (_u *SkillUpdateOne) SetTags(v []string) *SkillUpdateOne { + _u.mutation.SetTags(v) + return _u +} + +// AppendTags appends value to the "tags" field. +func (_u *SkillUpdateOne) AppendTags(v []string) *SkillUpdateOne { + _u.mutation.AppendTags(v) + return _u +} + +// ClearTags clears the value of the "tags" field. +func (_u *SkillUpdateOne) ClearTags() *SkillUpdateOne { + _u.mutation.ClearTags() + return _u +} + +// SetContent sets the "content" field. +func (_u *SkillUpdateOne) SetContent(v string) *SkillUpdateOne { + _u.mutation.SetContent(v) + return _u +} + +// SetNillableContent sets the "content" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableContent(v *string) *SkillUpdateOne { + if v != nil { + _u.SetContent(*v) + } + return _u +} + +// SetPackageObjectKey sets the "package_object_key" field. +func (_u *SkillUpdateOne) SetPackageObjectKey(v string) *SkillUpdateOne { + _u.mutation.SetPackageObjectKey(v) + return _u +} + +// SetNillablePackageObjectKey sets the "package_object_key" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillablePackageObjectKey(v *string) *SkillUpdateOne { + if v != nil { + _u.SetPackageObjectKey(*v) + } + return _u +} + +// ClearPackageObjectKey clears the value of the "package_object_key" field. +func (_u *SkillUpdateOne) ClearPackageObjectKey() *SkillUpdateOne { + _u.mutation.ClearPackageObjectKey() + return _u +} + +// SetPackageURL sets the "package_url" field. +func (_u *SkillUpdateOne) SetPackageURL(v string) *SkillUpdateOne { + _u.mutation.SetPackageURL(v) + return _u +} + +// SetNillablePackageURL sets the "package_url" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillablePackageURL(v *string) *SkillUpdateOne { + if v != nil { + _u.SetPackageURL(*v) + } + return _u +} + +// ClearPackageURL clears the value of the "package_url" field. +func (_u *SkillUpdateOne) ClearPackageURL() *SkillUpdateOne { + _u.mutation.ClearPackageURL() + return _u +} + +// SetSourceType sets the "source_type" field. +func (_u *SkillUpdateOne) SetSourceType(v string) *SkillUpdateOne { + _u.mutation.SetSourceType(v) + return _u +} + +// SetNillableSourceType sets the "source_type" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableSourceType(v *string) *SkillUpdateOne { + if v != nil { + _u.SetSourceType(*v) + } + return _u +} + +// SetSourceLabel sets the "source_label" field. +func (_u *SkillUpdateOne) SetSourceLabel(v string) *SkillUpdateOne { + _u.mutation.SetSourceLabel(v) + return _u +} + +// SetNillableSourceLabel sets the "source_label" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableSourceLabel(v *string) *SkillUpdateOne { + if v != nil { + _u.SetSourceLabel(*v) + } + return _u +} + +// SetSkillMdPath sets the "skill_md_path" field. +func (_u *SkillUpdateOne) SetSkillMdPath(v string) *SkillUpdateOne { + _u.mutation.SetSkillMdPath(v) + return _u +} + +// SetNillableSkillMdPath sets the "skill_md_path" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableSkillMdPath(v *string) *SkillUpdateOne { + if v != nil { + _u.SetSkillMdPath(*v) + } + return _u +} + +// ClearSkillMdPath clears the value of the "skill_md_path" field. +func (_u *SkillUpdateOne) ClearSkillMdPath() *SkillUpdateOne { + _u.mutation.ClearSkillMdPath() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *SkillUpdateOne) SetCreatedAt(v time.Time) *SkillUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *SkillUpdateOne) SetNillableCreatedAt(v *time.Time) *SkillUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *SkillUpdateOne) SetUpdatedAt(v time.Time) *SkillUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetUser sets the "user" edge to the User entity. +func (_u *SkillUpdateOne) SetUser(v *User) *SkillUpdateOne { + return _u.SetUserID(v.ID) +} + +// AddTeamIDs adds the "teams" edge to the Team entity by IDs. +func (_u *SkillUpdateOne) AddTeamIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.AddTeamIDs(ids...) + return _u +} + +// AddTeams adds the "teams" edges to the Team entity. +func (_u *SkillUpdateOne) AddTeams(v ...*Team) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamIDs(ids...) +} + +// AddGroupIDs adds the "groups" edge to the TeamGroup entity by IDs. +func (_u *SkillUpdateOne) AddGroupIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.AddGroupIDs(ids...) + return _u +} + +// AddGroups adds the "groups" edges to the TeamGroup entity. +func (_u *SkillUpdateOne) AddGroups(v ...*TeamGroup) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddGroupIDs(ids...) +} + +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs. +func (_u *SkillUpdateOne) AddTeamSkillIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.AddTeamSkillIDs(ids...) + return _u +} + +// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity. +func (_u *SkillUpdateOne) AddTeamSkills(v ...*TeamSkill) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamSkillIDs(ids...) +} + +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (_u *SkillUpdateOne) AddTeamGroupSkillIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.AddTeamGroupSkillIDs(ids...) + return _u +} + +// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *SkillUpdateOne) AddTeamGroupSkills(v ...*TeamGroupSkill) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamGroupSkillIDs(ids...) +} + +// Mutation returns the SkillMutation object of the builder. +func (_u *SkillUpdateOne) Mutation() *SkillMutation { + return _u.mutation +} + +// ClearUser clears the "user" edge to the User entity. +func (_u *SkillUpdateOne) ClearUser() *SkillUpdateOne { + _u.mutation.ClearUser() + return _u +} + +// ClearTeams clears all "teams" edges to the Team entity. +func (_u *SkillUpdateOne) ClearTeams() *SkillUpdateOne { + _u.mutation.ClearTeams() + return _u +} + +// RemoveTeamIDs removes the "teams" edge to Team entities by IDs. +func (_u *SkillUpdateOne) RemoveTeamIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.RemoveTeamIDs(ids...) + return _u +} + +// RemoveTeams removes "teams" edges to Team entities. +func (_u *SkillUpdateOne) RemoveTeams(v ...*Team) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamIDs(ids...) +} + +// ClearGroups clears all "groups" edges to the TeamGroup entity. +func (_u *SkillUpdateOne) ClearGroups() *SkillUpdateOne { + _u.mutation.ClearGroups() + return _u +} + +// RemoveGroupIDs removes the "groups" edge to TeamGroup entities by IDs. +func (_u *SkillUpdateOne) RemoveGroupIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.RemoveGroupIDs(ids...) + return _u +} + +// RemoveGroups removes "groups" edges to TeamGroup entities. +func (_u *SkillUpdateOne) RemoveGroups(v ...*TeamGroup) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveGroupIDs(ids...) +} + +// ClearTeamSkills clears all "team_skills" edges to the TeamSkill entity. +func (_u *SkillUpdateOne) ClearTeamSkills() *SkillUpdateOne { + _u.mutation.ClearTeamSkills() + return _u +} + +// RemoveTeamSkillIDs removes the "team_skills" edge to TeamSkill entities by IDs. +func (_u *SkillUpdateOne) RemoveTeamSkillIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.RemoveTeamSkillIDs(ids...) + return _u +} + +// RemoveTeamSkills removes "team_skills" edges to TeamSkill entities. +func (_u *SkillUpdateOne) RemoveTeamSkills(v ...*TeamSkill) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamSkillIDs(ids...) +} + +// ClearTeamGroupSkills clears all "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *SkillUpdateOne) ClearTeamGroupSkills() *SkillUpdateOne { + _u.mutation.ClearTeamGroupSkills() + return _u +} + +// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to TeamGroupSkill entities by IDs. +func (_u *SkillUpdateOne) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) *SkillUpdateOne { + _u.mutation.RemoveTeamGroupSkillIDs(ids...) + return _u +} + +// RemoveTeamGroupSkills removes "team_group_skills" edges to TeamGroupSkill entities. +func (_u *SkillUpdateOne) RemoveTeamGroupSkills(v ...*TeamGroupSkill) *SkillUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamGroupSkillIDs(ids...) +} + +// Where appends a list predicates to the SkillUpdate builder. +func (_u *SkillUpdateOne) Where(ps ...predicate.Skill) *SkillUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *SkillUpdateOne) Select(field string, fields ...string) *SkillUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Skill entity. +func (_u *SkillUpdateOne) Save(ctx context.Context) (*Skill, error) { + if err := _u.defaults(); err != nil { + return nil, err + } + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *SkillUpdateOne) SaveX(ctx context.Context) *Skill { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *SkillUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *SkillUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *SkillUpdateOne) defaults() error { + if _, ok := _u.mutation.UpdatedAt(); !ok { + if skill.UpdateDefaultUpdatedAt == nil { + return fmt.Errorf("db: uninitialized skill.UpdateDefaultUpdatedAt (forgotten import db/runtime?)") + } + v := skill.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } + return nil +} + +// check runs all checks and user-defined validators on the builder. +func (_u *SkillUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := skill.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Skill.name": %w`, err)} + } + } + if v, ok := _u.mutation.Description(); ok { + if err := skill.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`db: validator failed for field "Skill.description": %w`, err)} + } + } + if v, ok := _u.mutation.Content(); ok { + if err := skill.ContentValidator(v); err != nil { + return &ValidationError{Name: "content", err: fmt.Errorf(`db: validator failed for field "Skill.content": %w`, err)} + } + } + if v, ok := _u.mutation.SourceType(); ok { + if err := skill.SourceTypeValidator(v); err != nil { + return &ValidationError{Name: "source_type", err: fmt.Errorf(`db: validator failed for field "Skill.source_type": %w`, err)} + } + } + if v, ok := _u.mutation.SourceLabel(); ok { + if err := skill.SourceLabelValidator(v); err != nil { + return &ValidationError{Name: "source_label", err: fmt.Errorf(`db: validator failed for field "Skill.source_label": %w`, err)} + } + } + if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "Skill.user"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *SkillUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SkillUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *SkillUpdateOne) sqlSave(ctx context.Context) (_node *Skill, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(skill.Table, skill.Columns, sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Skill.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, skill.FieldID) + for _, f := range fields { + if !skill.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != skill.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(skill.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(skill.FieldDeletedAt, field.TypeTime) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(skill.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(skill.FieldDescription, field.TypeString, value) + } + if value, ok := _u.mutation.Tags(); ok { + _spec.SetField(skill.FieldTags, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedTags(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, skill.FieldTags, value) + }) + } + if _u.mutation.TagsCleared() { + _spec.ClearField(skill.FieldTags, field.TypeJSON) + } + if value, ok := _u.mutation.Content(); ok { + _spec.SetField(skill.FieldContent, field.TypeString, value) + } + if value, ok := _u.mutation.PackageObjectKey(); ok { + _spec.SetField(skill.FieldPackageObjectKey, field.TypeString, value) + } + if _u.mutation.PackageObjectKeyCleared() { + _spec.ClearField(skill.FieldPackageObjectKey, field.TypeString) + } + if value, ok := _u.mutation.PackageURL(); ok { + _spec.SetField(skill.FieldPackageURL, field.TypeString, value) + } + if _u.mutation.PackageURLCleared() { + _spec.ClearField(skill.FieldPackageURL, field.TypeString) + } + if value, ok := _u.mutation.SourceType(); ok { + _spec.SetField(skill.FieldSourceType, field.TypeString, value) + } + if value, ok := _u.mutation.SourceLabel(); ok { + _spec.SetField(skill.FieldSourceLabel, field.TypeString, value) + } + if value, ok := _u.mutation.SkillMdPath(); ok { + _spec.SetField(skill.FieldSkillMdPath, field.TypeString, value) + } + if _u.mutation.SkillMdPathCleared() { + _spec.ClearField(skill.FieldSkillMdPath, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(skill.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(skill.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.UserCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: skill.UserTable, + Columns: []string{skill.UserColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.UserIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: skill.UserTable, + Columns: []string{skill.UserColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamsIDs(); len(nodes) > 0 && !_u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.TeamsTable, + Columns: skill.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.GroupsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: skill.GroupsTable, + Columns: skill.GroupsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamSkillsTable, + Columns: []string{skill.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamGroupSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: skill.TeamGroupSkillsTable, + Columns: []string{skill.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + _node = &Skill{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{skill.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/db/team.go b/backend/db/team.go index 709a9156..ba2de2f3 100644 --- a/backend/db/team.go +++ b/backend/db/team.go @@ -52,15 +52,19 @@ type TeamEdges struct { Models []*Model `json:"models,omitempty"` // Images holds the value of the images edge. Images []*Image `json:"images,omitempty"` + // Skills holds the value of the skills edge. + Skills []*Skill `json:"skills,omitempty"` // TeamMembers holds the value of the team_members edge. TeamMembers []*TeamMember `json:"team_members,omitempty"` // TeamModels holds the value of the team_models edge. TeamModels []*TeamModel `json:"team_models,omitempty"` // TeamImages holds the value of the team_images edge. TeamImages []*TeamImage `json:"team_images,omitempty"` + // TeamSkills holds the value of the team_skills edge. + TeamSkills []*TeamSkill `json:"team_skills,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [7]bool + loadedTypes [9]bool } // GroupsOrErr returns the Groups value or an error if the edge @@ -99,10 +103,19 @@ func (e TeamEdges) ImagesOrErr() ([]*Image, error) { return nil, &NotLoadedError{edge: "images"} } +// SkillsOrErr returns the Skills value or an error if the edge +// was not loaded in eager-loading. +func (e TeamEdges) SkillsOrErr() ([]*Skill, error) { + if e.loadedTypes[4] { + return e.Skills, nil + } + return nil, &NotLoadedError{edge: "skills"} +} + // TeamMembersOrErr returns the TeamMembers value or an error if the edge // was not loaded in eager-loading. func (e TeamEdges) TeamMembersOrErr() ([]*TeamMember, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.TeamMembers, nil } return nil, &NotLoadedError{edge: "team_members"} @@ -111,7 +124,7 @@ func (e TeamEdges) TeamMembersOrErr() ([]*TeamMember, error) { // TeamModelsOrErr returns the TeamModels value or an error if the edge // was not loaded in eager-loading. func (e TeamEdges) TeamModelsOrErr() ([]*TeamModel, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.TeamModels, nil } return nil, &NotLoadedError{edge: "team_models"} @@ -120,12 +133,21 @@ func (e TeamEdges) TeamModelsOrErr() ([]*TeamModel, error) { // TeamImagesOrErr returns the TeamImages value or an error if the edge // was not loaded in eager-loading. func (e TeamEdges) TeamImagesOrErr() ([]*TeamImage, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.TeamImages, nil } return nil, &NotLoadedError{edge: "team_images"} } +// TeamSkillsOrErr returns the TeamSkills value or an error if the edge +// was not loaded in eager-loading. +func (e TeamEdges) TeamSkillsOrErr() ([]*TeamSkill, error) { + if e.loadedTypes[8] { + return e.TeamSkills, nil + } + return nil, &NotLoadedError{edge: "team_skills"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*Team) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -249,6 +271,11 @@ func (_m *Team) QueryImages() *ImageQuery { return NewTeamClient(_m.config).QueryImages(_m) } +// QuerySkills queries the "skills" edge of the Team entity. +func (_m *Team) QuerySkills() *SkillQuery { + return NewTeamClient(_m.config).QuerySkills(_m) +} + // QueryTeamMembers queries the "team_members" edge of the Team entity. func (_m *Team) QueryTeamMembers() *TeamMemberQuery { return NewTeamClient(_m.config).QueryTeamMembers(_m) @@ -264,6 +291,11 @@ func (_m *Team) QueryTeamImages() *TeamImageQuery { return NewTeamClient(_m.config).QueryTeamImages(_m) } +// QueryTeamSkills queries the "team_skills" edge of the Team entity. +func (_m *Team) QueryTeamSkills() *TeamSkillQuery { + return NewTeamClient(_m.config).QueryTeamSkills(_m) +} + // Update returns a builder for updating this Team. // Note that you need to call Team.Unwrap() before calling this method if this Team // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/backend/db/team/team.go b/backend/db/team/team.go index c8b9a28d..6fb6686b 100644 --- a/backend/db/team/team.go +++ b/backend/db/team/team.go @@ -41,12 +41,16 @@ const ( EdgeModels = "models" // EdgeImages holds the string denoting the images edge name in mutations. EdgeImages = "images" + // EdgeSkills holds the string denoting the skills edge name in mutations. + EdgeSkills = "skills" // EdgeTeamMembers holds the string denoting the team_members edge name in mutations. EdgeTeamMembers = "team_members" // EdgeTeamModels holds the string denoting the team_models edge name in mutations. EdgeTeamModels = "team_models" // EdgeTeamImages holds the string denoting the team_images edge name in mutations. EdgeTeamImages = "team_images" + // EdgeTeamSkills holds the string denoting the team_skills edge name in mutations. + EdgeTeamSkills = "team_skills" // Table holds the table name of the team in the database. Table = "teams" // GroupsTable is the table that holds the groups relation/edge. @@ -71,6 +75,11 @@ const ( // ImagesInverseTable is the table name for the Image entity. // It exists in this package in order to avoid circular dependency with the "image" package. ImagesInverseTable = "images" + // SkillsTable is the table that holds the skills relation/edge. The primary key declared below. + SkillsTable = "team_skills" + // SkillsInverseTable is the table name for the Skill entity. + // It exists in this package in order to avoid circular dependency with the "skill" package. + SkillsInverseTable = "skills" // TeamMembersTable is the table that holds the team_members relation/edge. TeamMembersTable = "team_members" // TeamMembersInverseTable is the table name for the TeamMember entity. @@ -92,6 +101,13 @@ const ( TeamImagesInverseTable = "team_images" // TeamImagesColumn is the table column denoting the team_images relation/edge. TeamImagesColumn = "team_id" + // TeamSkillsTable is the table that holds the team_skills relation/edge. + TeamSkillsTable = "team_skills" + // TeamSkillsInverseTable is the table name for the TeamSkill entity. + // It exists in this package in order to avoid circular dependency with the "teamskill" package. + TeamSkillsInverseTable = "team_skills" + // TeamSkillsColumn is the table column denoting the team_skills relation/edge. + TeamSkillsColumn = "team_id" ) // Columns holds all SQL columns for team fields. @@ -118,6 +134,9 @@ var ( // ImagesPrimaryKey and ImagesColumn2 are the table columns denoting the // primary key for the images relation (M2M). ImagesPrimaryKey = []string{"team_id", "image_id"} + // SkillsPrimaryKey and SkillsColumn2 are the table columns denoting the + // primary key for the skills relation (M2M). + SkillsPrimaryKey = []string{"team_id", "skill_id"} ) // ValidColumn reports if the column name is valid (part of the table columns). @@ -263,6 +282,20 @@ func ByImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// BySkillsCount orders the results by skills count. +func BySkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newSkillsStep(), opts...) + } +} + +// BySkills orders the results by skills terms. +func BySkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByTeamMembersCount orders the results by team_members count. func ByTeamMembersCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -304,6 +337,20 @@ func ByTeamImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newTeamImagesStep(), append([]sql.OrderTerm{term}, terms...)...) } } + +// ByTeamSkillsCount orders the results by team_skills count. +func ByTeamSkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTeamSkillsStep(), opts...) + } +} + +// ByTeamSkills orders the results by team_skills terms. +func ByTeamSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} func newGroupsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -332,6 +379,13 @@ func newImagesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.M2M, false, ImagesTable, ImagesPrimaryKey...), ) } +func newSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...), + ) +} func newTeamMembersStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -353,3 +407,10 @@ func newTeamImagesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, true, TeamImagesTable, TeamImagesColumn), ) } +func newTeamSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamSkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn), + ) +} diff --git a/backend/db/team/where.go b/backend/db/team/where.go index e1488acc..f58ecde8 100644 --- a/backend/db/team/where.go +++ b/backend/db/team/where.go @@ -528,6 +528,29 @@ func HasImagesWith(preds ...predicate.Image) predicate.Team { }) } +// HasSkills applies the HasEdge predicate on the "skills" edge. +func HasSkills() predicate.Team { + return predicate.Team(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSkillsWith applies the HasEdge predicate on the "skills" edge with a given conditions (other predicates). +func HasSkillsWith(preds ...predicate.Skill) predicate.Team { + return predicate.Team(func(s *sql.Selector) { + step := newSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasTeamMembers applies the HasEdge predicate on the "team_members" edge. func HasTeamMembers() predicate.Team { return predicate.Team(func(s *sql.Selector) { @@ -597,6 +620,29 @@ func HasTeamImagesWith(preds ...predicate.TeamImage) predicate.Team { }) } +// HasTeamSkills applies the HasEdge predicate on the "team_skills" edge. +func HasTeamSkills() predicate.Team { + return predicate.Team(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamSkillsWith applies the HasEdge predicate on the "team_skills" edge with a given conditions (other predicates). +func HasTeamSkillsWith(preds ...predicate.TeamSkill) predicate.Team { + return predicate.Team(func(s *sql.Selector) { + step := newTeamSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Team) predicate.Team { return predicate.Team(sql.AndPredicates(predicates...)) diff --git a/backend/db/team_create.go b/backend/db/team_create.go index 26c3fc9d..7a4c7175 100644 --- a/backend/db/team_create.go +++ b/backend/db/team_create.go @@ -14,11 +14,13 @@ import ( "entgo.io/ent/schema/field" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) @@ -207,6 +209,21 @@ func (_c *TeamCreate) AddImages(v ...*Image) *TeamCreate { return _c.AddImageIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_c *TeamCreate) AddSkillIDs(ids ...uuid.UUID) *TeamCreate { + _c.mutation.AddSkillIDs(ids...) + return _c +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_c *TeamCreate) AddSkills(v ...*Skill) *TeamCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddSkillIDs(ids...) +} + // AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs. func (_c *TeamCreate) AddTeamMemberIDs(ids ...uuid.UUID) *TeamCreate { _c.mutation.AddTeamMemberIDs(ids...) @@ -252,6 +269,21 @@ func (_c *TeamCreate) AddTeamImages(v ...*TeamImage) *TeamCreate { return _c.AddTeamImageIDs(ids...) } +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs. +func (_c *TeamCreate) AddTeamSkillIDs(ids ...uuid.UUID) *TeamCreate { + _c.mutation.AddTeamSkillIDs(ids...) + return _c +} + +// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity. +func (_c *TeamCreate) AddTeamSkills(v ...*TeamSkill) *TeamCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddTeamSkillIDs(ids...) +} + // Mutation returns the TeamMutation object of the builder. func (_c *TeamCreate) Mutation() *TeamMutation { return _c.mutation @@ -501,6 +533,26 @@ func (_c *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) { edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _c.config, mutation: newTeamSkillMutation(_c.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.TeamMembersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -549,6 +601,22 @@ func (_c *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.TeamSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/backend/db/team_query.go b/backend/db/team_query.go index e9b5591e..2a8a124e 100644 --- a/backend/db/team_query.go +++ b/backend/db/team_query.go @@ -16,11 +16,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) @@ -36,9 +38,11 @@ type TeamQuery struct { withMembers *UserQuery withModels *ModelQuery withImages *ImageQuery + withSkills *SkillQuery withTeamMembers *TeamMemberQuery withTeamModels *TeamModelQuery withTeamImages *TeamImageQuery + withTeamSkills *TeamSkillQuery modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector @@ -164,6 +168,28 @@ func (_q *TeamQuery) QueryImages() *ImageQuery { return query } +// QuerySkills chains the current query on the "skills" edge. +func (_q *TeamQuery) QuerySkills() *SkillQuery { + query := (&SkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(team.Table, team.FieldID, selector), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, team.SkillsTable, team.SkillsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryTeamMembers chains the current query on the "team_members" edge. func (_q *TeamQuery) QueryTeamMembers() *TeamMemberQuery { query := (&TeamMemberClient{config: _q.config}).Query() @@ -230,6 +256,28 @@ func (_q *TeamQuery) QueryTeamImages() *TeamImageQuery { return query } +// QueryTeamSkills chains the current query on the "team_skills" edge. +func (_q *TeamQuery) QueryTeamSkills() *TeamSkillQuery { + query := (&TeamSkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(team.Table, team.FieldID, selector), + sqlgraph.To(teamskill.Table, teamskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, team.TeamSkillsTable, team.TeamSkillsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first Team entity from the query. // Returns a *NotFoundError when no Team was found. func (_q *TeamQuery) First(ctx context.Context) (*Team, error) { @@ -426,9 +474,11 @@ func (_q *TeamQuery) Clone() *TeamQuery { withMembers: _q.withMembers.Clone(), withModels: _q.withModels.Clone(), withImages: _q.withImages.Clone(), + withSkills: _q.withSkills.Clone(), withTeamMembers: _q.withTeamMembers.Clone(), withTeamModels: _q.withTeamModels.Clone(), withTeamImages: _q.withTeamImages.Clone(), + withTeamSkills: _q.withTeamSkills.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -480,6 +530,17 @@ func (_q *TeamQuery) WithImages(opts ...func(*ImageQuery)) *TeamQuery { return _q } +// WithSkills tells the query-builder to eager-load the nodes that are connected to +// the "skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamQuery) WithSkills(opts ...func(*SkillQuery)) *TeamQuery { + query := (&SkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSkills = query + return _q +} + // WithTeamMembers tells the query-builder to eager-load the nodes that are connected to // the "team_members" edge. The optional arguments are used to configure the query builder of the edge. func (_q *TeamQuery) WithTeamMembers(opts ...func(*TeamMemberQuery)) *TeamQuery { @@ -513,6 +574,17 @@ func (_q *TeamQuery) WithTeamImages(opts ...func(*TeamImageQuery)) *TeamQuery { return _q } +// WithTeamSkills tells the query-builder to eager-load the nodes that are connected to +// the "team_skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamQuery) WithTeamSkills(opts ...func(*TeamSkillQuery)) *TeamQuery { + query := (&TeamSkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeamSkills = query + return _q +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -591,14 +663,16 @@ func (_q *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, e var ( nodes = []*Team{} _spec = _q.querySpec() - loadedTypes = [7]bool{ + loadedTypes = [9]bool{ _q.withGroups != nil, _q.withMembers != nil, _q.withModels != nil, _q.withImages != nil, + _q.withSkills != nil, _q.withTeamMembers != nil, _q.withTeamModels != nil, _q.withTeamImages != nil, + _q.withTeamSkills != nil, } ) _spec.ScanValues = func(columns []string) ([]any, error) { @@ -650,6 +724,13 @@ func (_q *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, e return nil, err } } + if query := _q.withSkills; query != nil { + if err := _q.loadSkills(ctx, query, nodes, + func(n *Team) { n.Edges.Skills = []*Skill{} }, + func(n *Team, e *Skill) { n.Edges.Skills = append(n.Edges.Skills, e) }); err != nil { + return nil, err + } + } if query := _q.withTeamMembers; query != nil { if err := _q.loadTeamMembers(ctx, query, nodes, func(n *Team) { n.Edges.TeamMembers = []*TeamMember{} }, @@ -671,6 +752,13 @@ func (_q *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, e return nil, err } } + if query := _q.withTeamSkills; query != nil { + if err := _q.loadTeamSkills(ctx, query, nodes, + func(n *Team) { n.Edges.TeamSkills = []*TeamSkill{} }, + func(n *Team, e *TeamSkill) { n.Edges.TeamSkills = append(n.Edges.TeamSkills, e) }); err != nil { + return nil, err + } + } return nodes, nil } @@ -887,6 +975,67 @@ func (_q *TeamQuery) loadImages(ctx context.Context, query *ImageQuery, nodes [] } return nil } +func (_q *TeamQuery) loadSkills(ctx context.Context, query *SkillQuery, nodes []*Team, init func(*Team), assign func(*Team, *Skill)) error { + edgeIDs := make([]driver.Value, len(nodes)) + byID := make(map[uuid.UUID]*Team) + nids := make(map[uuid.UUID]map[*Team]struct{}) + for i, node := range nodes { + edgeIDs[i] = node.ID + byID[node.ID] = node + if init != nil { + init(node) + } + } + query.Where(func(s *sql.Selector) { + joinT := sql.Table(team.SkillsTable) + s.Join(joinT).On(s.C(skill.FieldID), joinT.C(team.SkillsPrimaryKey[1])) + s.Where(sql.InValues(joinT.C(team.SkillsPrimaryKey[0]), edgeIDs...)) + columns := s.SelectedColumns() + s.Select(joinT.C(team.SkillsPrimaryKey[0])) + s.AppendSelect(columns...) + s.SetDistinct(false) + }) + if err := query.prepareQuery(ctx); err != nil { + return err + } + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil + } + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*Team]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil + } + }) + }) + neighbors, err := withInterceptors[[]*Skill](ctx, query, qr, query.inters) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nids[n.ID] + if !ok { + return fmt.Errorf(`unexpected "skills" node returned %v`, n.ID) + } + for kn := range nodes { + assign(kn, n) + } + } + return nil +} func (_q *TeamQuery) loadTeamMembers(ctx context.Context, query *TeamMemberQuery, nodes []*Team, init func(*Team), assign func(*Team, *TeamMember)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[uuid.UUID]*Team) @@ -977,6 +1126,36 @@ func (_q *TeamQuery) loadTeamImages(ctx context.Context, query *TeamImageQuery, } return nil } +func (_q *TeamQuery) loadTeamSkills(ctx context.Context, query *TeamSkillQuery, nodes []*Team, init func(*Team), assign func(*Team, *TeamSkill)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Team) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(teamskill.FieldTeamID) + } + query.Where(predicate.TeamSkill(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(team.TeamSkillsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.TeamID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "team_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *TeamQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() diff --git a/backend/db/team_update.go b/backend/db/team_update.go index 3536d7ee..e3fa9143 100644 --- a/backend/db/team_update.go +++ b/backend/db/team_update.go @@ -14,11 +14,13 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamimage" "github.com/chaitin/MonkeyCode/backend/db/teammember" "github.com/chaitin/MonkeyCode/backend/db/teammodel" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) @@ -250,6 +252,21 @@ func (_u *TeamUpdate) AddImages(v ...*Image) *TeamUpdate { return _u.AddImageIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_u *TeamUpdate) AddSkillIDs(ids ...uuid.UUID) *TeamUpdate { + _u.mutation.AddSkillIDs(ids...) + return _u +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_u *TeamUpdate) AddSkills(v ...*Skill) *TeamUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddSkillIDs(ids...) +} + // AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs. func (_u *TeamUpdate) AddTeamMemberIDs(ids ...uuid.UUID) *TeamUpdate { _u.mutation.AddTeamMemberIDs(ids...) @@ -295,6 +312,21 @@ func (_u *TeamUpdate) AddTeamImages(v ...*TeamImage) *TeamUpdate { return _u.AddTeamImageIDs(ids...) } +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs. +func (_u *TeamUpdate) AddTeamSkillIDs(ids ...uuid.UUID) *TeamUpdate { + _u.mutation.AddTeamSkillIDs(ids...) + return _u +} + +// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity. +func (_u *TeamUpdate) AddTeamSkills(v ...*TeamSkill) *TeamUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamSkillIDs(ids...) +} + // Mutation returns the TeamMutation object of the builder. func (_u *TeamUpdate) Mutation() *TeamMutation { return _u.mutation @@ -384,6 +416,27 @@ func (_u *TeamUpdate) RemoveImages(v ...*Image) *TeamUpdate { return _u.RemoveImageIDs(ids...) } +// ClearSkills clears all "skills" edges to the Skill entity. +func (_u *TeamUpdate) ClearSkills() *TeamUpdate { + _u.mutation.ClearSkills() + return _u +} + +// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs. +func (_u *TeamUpdate) RemoveSkillIDs(ids ...uuid.UUID) *TeamUpdate { + _u.mutation.RemoveSkillIDs(ids...) + return _u +} + +// RemoveSkills removes "skills" edges to Skill entities. +func (_u *TeamUpdate) RemoveSkills(v ...*Skill) *TeamUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveSkillIDs(ids...) +} + // ClearTeamMembers clears all "team_members" edges to the TeamMember entity. func (_u *TeamUpdate) ClearTeamMembers() *TeamUpdate { _u.mutation.ClearTeamMembers() @@ -447,6 +500,27 @@ func (_u *TeamUpdate) RemoveTeamImages(v ...*TeamImage) *TeamUpdate { return _u.RemoveTeamImageIDs(ids...) } +// ClearTeamSkills clears all "team_skills" edges to the TeamSkill entity. +func (_u *TeamUpdate) ClearTeamSkills() *TeamUpdate { + _u.mutation.ClearTeamSkills() + return _u +} + +// RemoveTeamSkillIDs removes the "team_skills" edge to TeamSkill entities by IDs. +func (_u *TeamUpdate) RemoveTeamSkillIDs(ids ...uuid.UUID) *TeamUpdate { + _u.mutation.RemoveTeamSkillIDs(ids...) + return _u +} + +// RemoveTeamSkills removes "team_skills" edges to TeamSkill entities. +func (_u *TeamUpdate) RemoveTeamSkills(v ...*TeamSkill) *TeamUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamSkillIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (_u *TeamUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) @@ -757,6 +831,63 @@ func (_u *TeamUpdate) sqlSave(ctx context.Context) (_node int, err error) { edge.Target.Fields = specE.Fields _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.TeamMembersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -892,6 +1023,51 @@ func (_u *TeamUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -1127,6 +1303,21 @@ func (_u *TeamUpdateOne) AddImages(v ...*Image) *TeamUpdateOne { return _u.AddImageIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_u *TeamUpdateOne) AddSkillIDs(ids ...uuid.UUID) *TeamUpdateOne { + _u.mutation.AddSkillIDs(ids...) + return _u +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_u *TeamUpdateOne) AddSkills(v ...*Skill) *TeamUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddSkillIDs(ids...) +} + // AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs. func (_u *TeamUpdateOne) AddTeamMemberIDs(ids ...uuid.UUID) *TeamUpdateOne { _u.mutation.AddTeamMemberIDs(ids...) @@ -1172,6 +1363,21 @@ func (_u *TeamUpdateOne) AddTeamImages(v ...*TeamImage) *TeamUpdateOne { return _u.AddTeamImageIDs(ids...) } +// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs. +func (_u *TeamUpdateOne) AddTeamSkillIDs(ids ...uuid.UUID) *TeamUpdateOne { + _u.mutation.AddTeamSkillIDs(ids...) + return _u +} + +// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity. +func (_u *TeamUpdateOne) AddTeamSkills(v ...*TeamSkill) *TeamUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamSkillIDs(ids...) +} + // Mutation returns the TeamMutation object of the builder. func (_u *TeamUpdateOne) Mutation() *TeamMutation { return _u.mutation @@ -1261,6 +1467,27 @@ func (_u *TeamUpdateOne) RemoveImages(v ...*Image) *TeamUpdateOne { return _u.RemoveImageIDs(ids...) } +// ClearSkills clears all "skills" edges to the Skill entity. +func (_u *TeamUpdateOne) ClearSkills() *TeamUpdateOne { + _u.mutation.ClearSkills() + return _u +} + +// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs. +func (_u *TeamUpdateOne) RemoveSkillIDs(ids ...uuid.UUID) *TeamUpdateOne { + _u.mutation.RemoveSkillIDs(ids...) + return _u +} + +// RemoveSkills removes "skills" edges to Skill entities. +func (_u *TeamUpdateOne) RemoveSkills(v ...*Skill) *TeamUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveSkillIDs(ids...) +} + // ClearTeamMembers clears all "team_members" edges to the TeamMember entity. func (_u *TeamUpdateOne) ClearTeamMembers() *TeamUpdateOne { _u.mutation.ClearTeamMembers() @@ -1324,6 +1551,27 @@ func (_u *TeamUpdateOne) RemoveTeamImages(v ...*TeamImage) *TeamUpdateOne { return _u.RemoveTeamImageIDs(ids...) } +// ClearTeamSkills clears all "team_skills" edges to the TeamSkill entity. +func (_u *TeamUpdateOne) ClearTeamSkills() *TeamUpdateOne { + _u.mutation.ClearTeamSkills() + return _u +} + +// RemoveTeamSkillIDs removes the "team_skills" edge to TeamSkill entities by IDs. +func (_u *TeamUpdateOne) RemoveTeamSkillIDs(ids ...uuid.UUID) *TeamUpdateOne { + _u.mutation.RemoveTeamSkillIDs(ids...) + return _u +} + +// RemoveTeamSkills removes "team_skills" edges to TeamSkill entities. +func (_u *TeamUpdateOne) RemoveTeamSkills(v ...*TeamSkill) *TeamUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamSkillIDs(ids...) +} + // Where appends a list predicates to the TeamUpdate builder. func (_u *TeamUpdateOne) Where(ps ...predicate.Team) *TeamUpdateOne { _u.mutation.Where(ps...) @@ -1664,6 +1912,63 @@ func (_u *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) { edge.Target.Fields = specE.Fields _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: team.SkillsTable, + Columns: team.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.TeamMembersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -1799,6 +2104,51 @@ func (_u *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: team.TeamSkillsTable, + Columns: []string{team.TeamSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _spec.AddModifiers(_u.modifiers...) _node = &Team{config: _u.config} _spec.Assign = _node.assignValues diff --git a/backend/db/teamgroup.go b/backend/db/teamgroup.go index 8c7c21bd..b8b67492 100644 --- a/backend/db/teamgroup.go +++ b/backend/db/teamgroup.go @@ -47,6 +47,8 @@ type TeamGroupEdges struct { Images []*Image `json:"images,omitempty"` // Hosts holds the value of the hosts edge. Hosts []*Host `json:"hosts,omitempty"` + // Skills holds the value of the skills edge. + Skills []*Skill `json:"skills,omitempty"` // TeamGroupMembers holds the value of the team_group_members edge. TeamGroupMembers []*TeamGroupMember `json:"team_group_members,omitempty"` // TeamGroupModels holds the value of the team_group_models edge. @@ -55,9 +57,11 @@ type TeamGroupEdges struct { TeamGroupImages []*TeamGroupImage `json:"team_group_images,omitempty"` // TeamGroupHosts holds the value of the team_group_hosts edge. TeamGroupHosts []*TeamGroupHost `json:"team_group_hosts,omitempty"` + // TeamGroupSkills holds the value of the team_group_skills edge. + TeamGroupSkills []*TeamGroupSkill `json:"team_group_skills,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [9]bool + loadedTypes [11]bool } // MembersOrErr returns the Members value or an error if the edge @@ -107,10 +111,19 @@ func (e TeamGroupEdges) HostsOrErr() ([]*Host, error) { return nil, &NotLoadedError{edge: "hosts"} } +// SkillsOrErr returns the Skills value or an error if the edge +// was not loaded in eager-loading. +func (e TeamGroupEdges) SkillsOrErr() ([]*Skill, error) { + if e.loadedTypes[5] { + return e.Skills, nil + } + return nil, &NotLoadedError{edge: "skills"} +} + // TeamGroupMembersOrErr returns the TeamGroupMembers value or an error if the edge // was not loaded in eager-loading. func (e TeamGroupEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.TeamGroupMembers, nil } return nil, &NotLoadedError{edge: "team_group_members"} @@ -119,7 +132,7 @@ func (e TeamGroupEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) { // TeamGroupModelsOrErr returns the TeamGroupModels value or an error if the edge // was not loaded in eager-loading. func (e TeamGroupEdges) TeamGroupModelsOrErr() ([]*TeamGroupModel, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.TeamGroupModels, nil } return nil, &NotLoadedError{edge: "team_group_models"} @@ -128,7 +141,7 @@ func (e TeamGroupEdges) TeamGroupModelsOrErr() ([]*TeamGroupModel, error) { // TeamGroupImagesOrErr returns the TeamGroupImages value or an error if the edge // was not loaded in eager-loading. func (e TeamGroupEdges) TeamGroupImagesOrErr() ([]*TeamGroupImage, error) { - if e.loadedTypes[7] { + if e.loadedTypes[8] { return e.TeamGroupImages, nil } return nil, &NotLoadedError{edge: "team_group_images"} @@ -137,12 +150,21 @@ func (e TeamGroupEdges) TeamGroupImagesOrErr() ([]*TeamGroupImage, error) { // TeamGroupHostsOrErr returns the TeamGroupHosts value or an error if the edge // was not loaded in eager-loading. func (e TeamGroupEdges) TeamGroupHostsOrErr() ([]*TeamGroupHost, error) { - if e.loadedTypes[8] { + if e.loadedTypes[9] { return e.TeamGroupHosts, nil } return nil, &NotLoadedError{edge: "team_group_hosts"} } +// TeamGroupSkillsOrErr returns the TeamGroupSkills value or an error if the edge +// was not loaded in eager-loading. +func (e TeamGroupEdges) TeamGroupSkillsOrErr() ([]*TeamGroupSkill, error) { + if e.loadedTypes[10] { + return e.TeamGroupSkills, nil + } + return nil, &NotLoadedError{edge: "team_group_skills"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*TeamGroup) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -243,6 +265,11 @@ func (_m *TeamGroup) QueryHosts() *HostQuery { return NewTeamGroupClient(_m.config).QueryHosts(_m) } +// QuerySkills queries the "skills" edge of the TeamGroup entity. +func (_m *TeamGroup) QuerySkills() *SkillQuery { + return NewTeamGroupClient(_m.config).QuerySkills(_m) +} + // QueryTeamGroupMembers queries the "team_group_members" edge of the TeamGroup entity. func (_m *TeamGroup) QueryTeamGroupMembers() *TeamGroupMemberQuery { return NewTeamGroupClient(_m.config).QueryTeamGroupMembers(_m) @@ -263,6 +290,11 @@ func (_m *TeamGroup) QueryTeamGroupHosts() *TeamGroupHostQuery { return NewTeamGroupClient(_m.config).QueryTeamGroupHosts(_m) } +// QueryTeamGroupSkills queries the "team_group_skills" edge of the TeamGroup entity. +func (_m *TeamGroup) QueryTeamGroupSkills() *TeamGroupSkillQuery { + return NewTeamGroupClient(_m.config).QueryTeamGroupSkills(_m) +} + // Update returns a builder for updating this TeamGroup. // Note that you need to call TeamGroup.Unwrap() before calling this method if this TeamGroup // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/backend/db/teamgroup/teamgroup.go b/backend/db/teamgroup/teamgroup.go index d71ec41b..77707ea3 100644 --- a/backend/db/teamgroup/teamgroup.go +++ b/backend/db/teamgroup/teamgroup.go @@ -35,6 +35,8 @@ const ( EdgeImages = "images" // EdgeHosts holds the string denoting the hosts edge name in mutations. EdgeHosts = "hosts" + // EdgeSkills holds the string denoting the skills edge name in mutations. + EdgeSkills = "skills" // EdgeTeamGroupMembers holds the string denoting the team_group_members edge name in mutations. EdgeTeamGroupMembers = "team_group_members" // EdgeTeamGroupModels holds the string denoting the team_group_models edge name in mutations. @@ -43,6 +45,8 @@ const ( EdgeTeamGroupImages = "team_group_images" // EdgeTeamGroupHosts holds the string denoting the team_group_hosts edge name in mutations. EdgeTeamGroupHosts = "team_group_hosts" + // EdgeTeamGroupSkills holds the string denoting the team_group_skills edge name in mutations. + EdgeTeamGroupSkills = "team_group_skills" // Table holds the table name of the teamgroup in the database. Table = "team_groups" // MembersTable is the table that holds the members relation/edge. The primary key declared below. @@ -72,6 +76,11 @@ const ( // HostsInverseTable is the table name for the Host entity. // It exists in this package in order to avoid circular dependency with the "host" package. HostsInverseTable = "hosts" + // SkillsTable is the table that holds the skills relation/edge. The primary key declared below. + SkillsTable = "team_group_skills" + // SkillsInverseTable is the table name for the Skill entity. + // It exists in this package in order to avoid circular dependency with the "skill" package. + SkillsInverseTable = "skills" // TeamGroupMembersTable is the table that holds the team_group_members relation/edge. TeamGroupMembersTable = "team_group_members" // TeamGroupMembersInverseTable is the table name for the TeamGroupMember entity. @@ -100,6 +109,13 @@ const ( TeamGroupHostsInverseTable = "team_group_hosts" // TeamGroupHostsColumn is the table column denoting the team_group_hosts relation/edge. TeamGroupHostsColumn = "group_id" + // TeamGroupSkillsTable is the table that holds the team_group_skills relation/edge. + TeamGroupSkillsTable = "team_group_skills" + // TeamGroupSkillsInverseTable is the table name for the TeamGroupSkill entity. + // It exists in this package in order to avoid circular dependency with the "teamgroupskill" package. + TeamGroupSkillsInverseTable = "team_group_skills" + // TeamGroupSkillsColumn is the table column denoting the team_group_skills relation/edge. + TeamGroupSkillsColumn = "group_id" ) // Columns holds all SQL columns for teamgroup fields. @@ -125,6 +141,9 @@ var ( // HostsPrimaryKey and HostsColumn2 are the table columns denoting the // primary key for the hosts relation (M2M). HostsPrimaryKey = []string{"group_id", "host_id"} + // SkillsPrimaryKey and SkillsColumn2 are the table columns denoting the + // primary key for the skills relation (M2M). + SkillsPrimaryKey = []string{"group_id", "skill_id"} ) // ValidColumn reports if the column name is valid (part of the table columns). @@ -249,6 +268,20 @@ func ByHosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// BySkillsCount orders the results by skills count. +func BySkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newSkillsStep(), opts...) + } +} + +// BySkills orders the results by skills terms. +func BySkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByTeamGroupMembersCount orders the results by team_group_members count. func ByTeamGroupMembersCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -304,6 +337,20 @@ func ByTeamGroupHosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newTeamGroupHostsStep(), append([]sql.OrderTerm{term}, terms...)...) } } + +// ByTeamGroupSkillsCount orders the results by team_group_skills count. +func ByTeamGroupSkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTeamGroupSkillsStep(), opts...) + } +} + +// ByTeamGroupSkills orders the results by team_group_skills terms. +func ByTeamGroupSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamGroupSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} func newMembersStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -339,6 +386,13 @@ func newHostsStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.M2M, false, HostsTable, HostsPrimaryKey...), ) } +func newSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...), + ) +} func newTeamGroupMembersStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -367,3 +421,10 @@ func newTeamGroupHostsStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupHostsTable, TeamGroupHostsColumn), ) } +func newTeamGroupSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamGroupSkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn), + ) +} diff --git a/backend/db/teamgroup/where.go b/backend/db/teamgroup/where.go index 93e7954a..ef994886 100644 --- a/backend/db/teamgroup/where.go +++ b/backend/db/teamgroup/where.go @@ -411,6 +411,29 @@ func HasHostsWith(preds ...predicate.Host) predicate.TeamGroup { }) } +// HasSkills applies the HasEdge predicate on the "skills" edge. +func HasSkills() predicate.TeamGroup { + return predicate.TeamGroup(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSkillsWith applies the HasEdge predicate on the "skills" edge with a given conditions (other predicates). +func HasSkillsWith(preds ...predicate.Skill) predicate.TeamGroup { + return predicate.TeamGroup(func(s *sql.Selector) { + step := newSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasTeamGroupMembers applies the HasEdge predicate on the "team_group_members" edge. func HasTeamGroupMembers() predicate.TeamGroup { return predicate.TeamGroup(func(s *sql.Selector) { @@ -503,6 +526,29 @@ func HasTeamGroupHostsWith(preds ...predicate.TeamGroupHost) predicate.TeamGroup }) } +// HasTeamGroupSkills applies the HasEdge predicate on the "team_group_skills" edge. +func HasTeamGroupSkills() predicate.TeamGroup { + return predicate.TeamGroup(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamGroupSkillsWith applies the HasEdge predicate on the "team_group_skills" edge with a given conditions (other predicates). +func HasTeamGroupSkillsWith(preds ...predicate.TeamGroupSkill) predicate.TeamGroup { + return predicate.TeamGroup(func(s *sql.Selector) { + step := newTeamGroupSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.TeamGroup) predicate.TeamGroup { return predicate.TeamGroup(sql.AndPredicates(predicates...)) diff --git a/backend/db/teamgroup_create.go b/backend/db/teamgroup_create.go index 0adb5a5e..8fb6cdfd 100644 --- a/backend/db/teamgroup_create.go +++ b/backend/db/teamgroup_create.go @@ -15,12 +15,14 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamgrouphost" "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) @@ -158,6 +160,21 @@ func (_c *TeamGroupCreate) AddHosts(v ...*Host) *TeamGroupCreate { return _c.AddHostIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_c *TeamGroupCreate) AddSkillIDs(ids ...uuid.UUID) *TeamGroupCreate { + _c.mutation.AddSkillIDs(ids...) + return _c +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_c *TeamGroupCreate) AddSkills(v ...*Skill) *TeamGroupCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddSkillIDs(ids...) +} + // AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs. func (_c *TeamGroupCreate) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupCreate { _c.mutation.AddTeamGroupMemberIDs(ids...) @@ -218,6 +235,21 @@ func (_c *TeamGroupCreate) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupCrea return _c.AddTeamGroupHostIDs(ids...) } +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (_c *TeamGroupCreate) AddTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupCreate { + _c.mutation.AddTeamGroupSkillIDs(ids...) + return _c +} + +// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity. +func (_c *TeamGroupCreate) AddTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddTeamGroupSkillIDs(ids...) +} + // Mutation returns the TeamGroupMutation object of the builder. func (_c *TeamGroupCreate) Mutation() *TeamGroupMutation { return _c.mutation @@ -438,6 +470,26 @@ func (_c *TeamGroupCreate) createSpec() (*TeamGroup, *sqlgraph.CreateSpec) { edge.Target.Fields = specE.Fields _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _c.config, mutation: newTeamGroupSkillMutation(_c.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.TeamGroupMembersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -502,6 +554,22 @@ func (_c *TeamGroupCreate) createSpec() (*TeamGroup, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/backend/db/teamgroup_query.go b/backend/db/teamgroup_query.go index 794b1caf..5ec664b6 100644 --- a/backend/db/teamgroup_query.go +++ b/backend/db/teamgroup_query.go @@ -17,12 +17,14 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamgrouphost" "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) @@ -39,10 +41,12 @@ type TeamGroupQuery struct { withModels *ModelQuery withImages *ImageQuery withHosts *HostQuery + withSkills *SkillQuery withTeamGroupMembers *TeamGroupMemberQuery withTeamGroupModels *TeamGroupModelQuery withTeamGroupImages *TeamGroupImageQuery withTeamGroupHosts *TeamGroupHostQuery + withTeamGroupSkills *TeamGroupSkillQuery modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector @@ -190,6 +194,28 @@ func (_q *TeamGroupQuery) QueryHosts() *HostQuery { return query } +// QuerySkills chains the current query on the "skills" edge. +func (_q *TeamGroupQuery) QuerySkills() *SkillQuery { + query := (&SkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamgroup.Table, teamgroup.FieldID, selector), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, teamgroup.SkillsTable, teamgroup.SkillsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryTeamGroupMembers chains the current query on the "team_group_members" edge. func (_q *TeamGroupQuery) QueryTeamGroupMembers() *TeamGroupMemberQuery { query := (&TeamGroupMemberClient{config: _q.config}).Query() @@ -278,6 +304,28 @@ func (_q *TeamGroupQuery) QueryTeamGroupHosts() *TeamGroupHostQuery { return query } +// QueryTeamGroupSkills chains the current query on the "team_group_skills" edge. +func (_q *TeamGroupQuery) QueryTeamGroupSkills() *TeamGroupSkillQuery { + query := (&TeamGroupSkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamgroup.Table, teamgroup.FieldID, selector), + sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, teamgroup.TeamGroupSkillsTable, teamgroup.TeamGroupSkillsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first TeamGroup entity from the query. // Returns a *NotFoundError when no TeamGroup was found. func (_q *TeamGroupQuery) First(ctx context.Context) (*TeamGroup, error) { @@ -475,10 +523,12 @@ func (_q *TeamGroupQuery) Clone() *TeamGroupQuery { withModels: _q.withModels.Clone(), withImages: _q.withImages.Clone(), withHosts: _q.withHosts.Clone(), + withSkills: _q.withSkills.Clone(), withTeamGroupMembers: _q.withTeamGroupMembers.Clone(), withTeamGroupModels: _q.withTeamGroupModels.Clone(), withTeamGroupImages: _q.withTeamGroupImages.Clone(), withTeamGroupHosts: _q.withTeamGroupHosts.Clone(), + withTeamGroupSkills: _q.withTeamGroupSkills.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -541,6 +591,17 @@ func (_q *TeamGroupQuery) WithHosts(opts ...func(*HostQuery)) *TeamGroupQuery { return _q } +// WithSkills tells the query-builder to eager-load the nodes that are connected to +// the "skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamGroupQuery) WithSkills(opts ...func(*SkillQuery)) *TeamGroupQuery { + query := (&SkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSkills = query + return _q +} + // WithTeamGroupMembers tells the query-builder to eager-load the nodes that are connected to // the "team_group_members" edge. The optional arguments are used to configure the query builder of the edge. func (_q *TeamGroupQuery) WithTeamGroupMembers(opts ...func(*TeamGroupMemberQuery)) *TeamGroupQuery { @@ -585,6 +646,17 @@ func (_q *TeamGroupQuery) WithTeamGroupHosts(opts ...func(*TeamGroupHostQuery)) return _q } +// WithTeamGroupSkills tells the query-builder to eager-load the nodes that are connected to +// the "team_group_skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamGroupQuery) WithTeamGroupSkills(opts ...func(*TeamGroupSkillQuery)) *TeamGroupQuery { + query := (&TeamGroupSkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeamGroupSkills = query + return _q +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -663,16 +735,18 @@ func (_q *TeamGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Te var ( nodes = []*TeamGroup{} _spec = _q.querySpec() - loadedTypes = [9]bool{ + loadedTypes = [11]bool{ _q.withMembers != nil, _q.withTeam != nil, _q.withModels != nil, _q.withImages != nil, _q.withHosts != nil, + _q.withSkills != nil, _q.withTeamGroupMembers != nil, _q.withTeamGroupModels != nil, _q.withTeamGroupImages != nil, _q.withTeamGroupHosts != nil, + _q.withTeamGroupSkills != nil, } ) _spec.ScanValues = func(columns []string) ([]any, error) { @@ -730,6 +804,13 @@ func (_q *TeamGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Te return nil, err } } + if query := _q.withSkills; query != nil { + if err := _q.loadSkills(ctx, query, nodes, + func(n *TeamGroup) { n.Edges.Skills = []*Skill{} }, + func(n *TeamGroup, e *Skill) { n.Edges.Skills = append(n.Edges.Skills, e) }); err != nil { + return nil, err + } + } if query := _q.withTeamGroupMembers; query != nil { if err := _q.loadTeamGroupMembers(ctx, query, nodes, func(n *TeamGroup) { n.Edges.TeamGroupMembers = []*TeamGroupMember{} }, @@ -758,6 +839,13 @@ func (_q *TeamGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Te return nil, err } } + if query := _q.withTeamGroupSkills; query != nil { + if err := _q.loadTeamGroupSkills(ctx, query, nodes, + func(n *TeamGroup) { n.Edges.TeamGroupSkills = []*TeamGroupSkill{} }, + func(n *TeamGroup, e *TeamGroupSkill) { n.Edges.TeamGroupSkills = append(n.Edges.TeamGroupSkills, e) }); err != nil { + return nil, err + } + } return nodes, nil } @@ -1034,6 +1122,67 @@ func (_q *TeamGroupQuery) loadHosts(ctx context.Context, query *HostQuery, nodes } return nil } +func (_q *TeamGroupQuery) loadSkills(ctx context.Context, query *SkillQuery, nodes []*TeamGroup, init func(*TeamGroup), assign func(*TeamGroup, *Skill)) error { + edgeIDs := make([]driver.Value, len(nodes)) + byID := make(map[uuid.UUID]*TeamGroup) + nids := make(map[uuid.UUID]map[*TeamGroup]struct{}) + for i, node := range nodes { + edgeIDs[i] = node.ID + byID[node.ID] = node + if init != nil { + init(node) + } + } + query.Where(func(s *sql.Selector) { + joinT := sql.Table(teamgroup.SkillsTable) + s.Join(joinT).On(s.C(skill.FieldID), joinT.C(teamgroup.SkillsPrimaryKey[1])) + s.Where(sql.InValues(joinT.C(teamgroup.SkillsPrimaryKey[0]), edgeIDs...)) + columns := s.SelectedColumns() + s.Select(joinT.C(teamgroup.SkillsPrimaryKey[0])) + s.AppendSelect(columns...) + s.SetDistinct(false) + }) + if err := query.prepareQuery(ctx); err != nil { + return err + } + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil + } + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*TeamGroup]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil + } + }) + }) + neighbors, err := withInterceptors[[]*Skill](ctx, query, qr, query.inters) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nids[n.ID] + if !ok { + return fmt.Errorf(`unexpected "skills" node returned %v`, n.ID) + } + for kn := range nodes { + assign(kn, n) + } + } + return nil +} func (_q *TeamGroupQuery) loadTeamGroupMembers(ctx context.Context, query *TeamGroupMemberQuery, nodes []*TeamGroup, init func(*TeamGroup), assign func(*TeamGroup, *TeamGroupMember)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[uuid.UUID]*TeamGroup) @@ -1154,6 +1303,36 @@ func (_q *TeamGroupQuery) loadTeamGroupHosts(ctx context.Context, query *TeamGro } return nil } +func (_q *TeamGroupQuery) loadTeamGroupSkills(ctx context.Context, query *TeamGroupSkillQuery, nodes []*TeamGroup, init func(*TeamGroup), assign func(*TeamGroup, *TeamGroupSkill)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*TeamGroup) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(teamgroupskill.FieldGroupID) + } + query.Where(predicate.TeamGroupSkill(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(teamgroup.TeamGroupSkillsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.GroupID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "group_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *TeamGroupQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() diff --git a/backend/db/teamgroup_update.go b/backend/db/teamgroup_update.go index 85457c84..c29bf7f3 100644 --- a/backend/db/teamgroup_update.go +++ b/backend/db/teamgroup_update.go @@ -15,12 +15,14 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/team" "github.com/chaitin/MonkeyCode/backend/db/teamgroup" "github.com/chaitin/MonkeyCode/backend/db/teamgrouphost" "github.com/chaitin/MonkeyCode/backend/db/teamgroupimage" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmember" "github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) @@ -172,6 +174,21 @@ func (_u *TeamGroupUpdate) AddHosts(v ...*Host) *TeamGroupUpdate { return _u.AddHostIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_u *TeamGroupUpdate) AddSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate { + _u.mutation.AddSkillIDs(ids...) + return _u +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_u *TeamGroupUpdate) AddSkills(v ...*Skill) *TeamGroupUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddSkillIDs(ids...) +} + // AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs. func (_u *TeamGroupUpdate) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupUpdate { _u.mutation.AddTeamGroupMemberIDs(ids...) @@ -232,6 +249,21 @@ func (_u *TeamGroupUpdate) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupUpda return _u.AddTeamGroupHostIDs(ids...) } +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (_u *TeamGroupUpdate) AddTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate { + _u.mutation.AddTeamGroupSkillIDs(ids...) + return _u +} + +// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *TeamGroupUpdate) AddTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamGroupSkillIDs(ids...) +} + // Mutation returns the TeamGroupMutation object of the builder. func (_u *TeamGroupUpdate) Mutation() *TeamGroupMutation { return _u.mutation @@ -327,6 +359,27 @@ func (_u *TeamGroupUpdate) RemoveHosts(v ...*Host) *TeamGroupUpdate { return _u.RemoveHostIDs(ids...) } +// ClearSkills clears all "skills" edges to the Skill entity. +func (_u *TeamGroupUpdate) ClearSkills() *TeamGroupUpdate { + _u.mutation.ClearSkills() + return _u +} + +// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs. +func (_u *TeamGroupUpdate) RemoveSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate { + _u.mutation.RemoveSkillIDs(ids...) + return _u +} + +// RemoveSkills removes "skills" edges to Skill entities. +func (_u *TeamGroupUpdate) RemoveSkills(v ...*Skill) *TeamGroupUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveSkillIDs(ids...) +} + // ClearTeamGroupMembers clears all "team_group_members" edges to the TeamGroupMember entity. func (_u *TeamGroupUpdate) ClearTeamGroupMembers() *TeamGroupUpdate { _u.mutation.ClearTeamGroupMembers() @@ -411,6 +464,27 @@ func (_u *TeamGroupUpdate) RemoveTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupU return _u.RemoveTeamGroupHostIDs(ids...) } +// ClearTeamGroupSkills clears all "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *TeamGroupUpdate) ClearTeamGroupSkills() *TeamGroupUpdate { + _u.mutation.ClearTeamGroupSkills() + return _u +} + +// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to TeamGroupSkill entities by IDs. +func (_u *TeamGroupUpdate) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate { + _u.mutation.RemoveTeamGroupSkillIDs(ids...) + return _u +} + +// RemoveTeamGroupSkills removes "team_group_skills" edges to TeamGroupSkill entities. +func (_u *TeamGroupUpdate) RemoveTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamGroupSkillIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (_u *TeamGroupUpdate) Save(ctx context.Context) (int, error) { if err := _u.defaults(); err != nil { @@ -751,6 +825,63 @@ func (_u *TeamGroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { edge.Target.Fields = specE.Fields _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.TeamGroupMembersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -931,6 +1062,51 @@ func (_u *TeamGroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamGroupSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -1086,6 +1262,21 @@ func (_u *TeamGroupUpdateOne) AddHosts(v ...*Host) *TeamGroupUpdateOne { return _u.AddHostIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_u *TeamGroupUpdateOne) AddSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne { + _u.mutation.AddSkillIDs(ids...) + return _u +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_u *TeamGroupUpdateOne) AddSkills(v ...*Skill) *TeamGroupUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddSkillIDs(ids...) +} + // AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs. func (_u *TeamGroupUpdateOne) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupUpdateOne { _u.mutation.AddTeamGroupMemberIDs(ids...) @@ -1146,6 +1337,21 @@ func (_u *TeamGroupUpdateOne) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupU return _u.AddTeamGroupHostIDs(ids...) } +// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs. +func (_u *TeamGroupUpdateOne) AddTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne { + _u.mutation.AddTeamGroupSkillIDs(ids...) + return _u +} + +// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *TeamGroupUpdateOne) AddTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamGroupSkillIDs(ids...) +} + // Mutation returns the TeamGroupMutation object of the builder. func (_u *TeamGroupUpdateOne) Mutation() *TeamGroupMutation { return _u.mutation @@ -1241,6 +1447,27 @@ func (_u *TeamGroupUpdateOne) RemoveHosts(v ...*Host) *TeamGroupUpdateOne { return _u.RemoveHostIDs(ids...) } +// ClearSkills clears all "skills" edges to the Skill entity. +func (_u *TeamGroupUpdateOne) ClearSkills() *TeamGroupUpdateOne { + _u.mutation.ClearSkills() + return _u +} + +// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs. +func (_u *TeamGroupUpdateOne) RemoveSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne { + _u.mutation.RemoveSkillIDs(ids...) + return _u +} + +// RemoveSkills removes "skills" edges to Skill entities. +func (_u *TeamGroupUpdateOne) RemoveSkills(v ...*Skill) *TeamGroupUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveSkillIDs(ids...) +} + // ClearTeamGroupMembers clears all "team_group_members" edges to the TeamGroupMember entity. func (_u *TeamGroupUpdateOne) ClearTeamGroupMembers() *TeamGroupUpdateOne { _u.mutation.ClearTeamGroupMembers() @@ -1325,6 +1552,27 @@ func (_u *TeamGroupUpdateOne) RemoveTeamGroupHosts(v ...*TeamGroupHost) *TeamGro return _u.RemoveTeamGroupHostIDs(ids...) } +// ClearTeamGroupSkills clears all "team_group_skills" edges to the TeamGroupSkill entity. +func (_u *TeamGroupUpdateOne) ClearTeamGroupSkills() *TeamGroupUpdateOne { + _u.mutation.ClearTeamGroupSkills() + return _u +} + +// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to TeamGroupSkill entities by IDs. +func (_u *TeamGroupUpdateOne) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne { + _u.mutation.RemoveTeamGroupSkillIDs(ids...) + return _u +} + +// RemoveTeamGroupSkills removes "team_group_skills" edges to TeamGroupSkill entities. +func (_u *TeamGroupUpdateOne) RemoveTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamGroupSkillIDs(ids...) +} + // Where appends a list predicates to the TeamGroupUpdate builder. func (_u *TeamGroupUpdateOne) Where(ps ...predicate.TeamGroup) *TeamGroupUpdateOne { _u.mutation.Where(ps...) @@ -1695,6 +1943,63 @@ func (_u *TeamGroupUpdateOne) sqlSave(ctx context.Context) (_node *TeamGroup, er edge.Target.Fields = specE.Fields _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamgroup.SkillsTable, + Columns: teamgroup.SkillsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)} + createE.defaults() + _, specE := createE.createSpec() + edge.Target.Fields = specE.Fields + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.TeamGroupMembersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -1875,6 +2180,51 @@ func (_u *TeamGroupUpdateOne) sqlSave(ctx context.Context) (_node *TeamGroup, er } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamGroupSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamGroupSkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: teamgroup.TeamGroupSkillsTable, + Columns: []string{teamgroup.TeamGroupSkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _spec.AddModifiers(_u.modifiers...) _node = &TeamGroup{config: _u.config} _spec.Assign = _node.assignValues diff --git a/backend/db/teamgroupskill.go b/backend/db/teamgroupskill.go new file mode 100644 index 00000000..33e0fb07 --- /dev/null +++ b/backend/db/teamgroupskill.go @@ -0,0 +1,175 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/google/uuid" +) + +// TeamGroupSkill is the model entity for the TeamGroupSkill schema. +type TeamGroupSkill struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // GroupID holds the value of the "group_id" field. + GroupID uuid.UUID `json:"group_id,omitempty"` + // SkillID holds the value of the "skill_id" field. + SkillID uuid.UUID `json:"skill_id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the TeamGroupSkillQuery when eager-loading is set. + Edges TeamGroupSkillEdges `json:"edges"` + selectValues sql.SelectValues +} + +// TeamGroupSkillEdges holds the relations/edges for other nodes in the graph. +type TeamGroupSkillEdges struct { + // Group holds the value of the group edge. + Group *TeamGroup `json:"group,omitempty"` + // Skill holds the value of the skill edge. + Skill *Skill `json:"skill,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// GroupOrErr returns the Group value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e TeamGroupSkillEdges) GroupOrErr() (*TeamGroup, error) { + if e.Group != nil { + return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: teamgroup.Label} + } + return nil, &NotLoadedError{edge: "group"} +} + +// SkillOrErr returns the Skill value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e TeamGroupSkillEdges) SkillOrErr() (*Skill, error) { + if e.Skill != nil { + return e.Skill, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: skill.Label} + } + return nil, &NotLoadedError{edge: "skill"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*TeamGroupSkill) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case teamgroupskill.FieldCreatedAt: + values[i] = new(sql.NullTime) + case teamgroupskill.FieldID, teamgroupskill.FieldGroupID, teamgroupskill.FieldSkillID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the TeamGroupSkill fields. +func (_m *TeamGroupSkill) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case teamgroupskill.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case teamgroupskill.FieldGroupID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field group_id", values[i]) + } else if value != nil { + _m.GroupID = *value + } + case teamgroupskill.FieldSkillID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field skill_id", values[i]) + } else if value != nil { + _m.SkillID = *value + } + case teamgroupskill.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the TeamGroupSkill. +// This includes values selected through modifiers, order, etc. +func (_m *TeamGroupSkill) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryGroup queries the "group" edge of the TeamGroupSkill entity. +func (_m *TeamGroupSkill) QueryGroup() *TeamGroupQuery { + return NewTeamGroupSkillClient(_m.config).QueryGroup(_m) +} + +// QuerySkill queries the "skill" edge of the TeamGroupSkill entity. +func (_m *TeamGroupSkill) QuerySkill() *SkillQuery { + return NewTeamGroupSkillClient(_m.config).QuerySkill(_m) +} + +// Update returns a builder for updating this TeamGroupSkill. +// Note that you need to call TeamGroupSkill.Unwrap() before calling this method if this TeamGroupSkill +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *TeamGroupSkill) Update() *TeamGroupSkillUpdateOne { + return NewTeamGroupSkillClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the TeamGroupSkill entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *TeamGroupSkill) Unwrap() *TeamGroupSkill { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: TeamGroupSkill is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *TeamGroupSkill) String() string { + var builder strings.Builder + builder.WriteString("TeamGroupSkill(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("group_id=") + builder.WriteString(fmt.Sprintf("%v", _m.GroupID)) + builder.WriteString(", ") + builder.WriteString("skill_id=") + builder.WriteString(fmt.Sprintf("%v", _m.SkillID)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// TeamGroupSkills is a parsable slice of TeamGroupSkill. +type TeamGroupSkills []*TeamGroupSkill diff --git a/backend/db/teamgroupskill/teamgroupskill.go b/backend/db/teamgroupskill/teamgroupskill.go new file mode 100644 index 00000000..6b2b17fc --- /dev/null +++ b/backend/db/teamgroupskill/teamgroupskill.go @@ -0,0 +1,117 @@ +// Code generated by ent, DO NOT EDIT. + +package teamgroupskill + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the teamgroupskill type in the database. + Label = "team_group_skill" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldGroupID holds the string denoting the group_id field in the database. + FieldGroupID = "group_id" + // FieldSkillID holds the string denoting the skill_id field in the database. + FieldSkillID = "skill_id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // EdgeGroup holds the string denoting the group edge name in mutations. + EdgeGroup = "group" + // EdgeSkill holds the string denoting the skill edge name in mutations. + EdgeSkill = "skill" + // Table holds the table name of the teamgroupskill in the database. + Table = "team_group_skills" + // GroupTable is the table that holds the group relation/edge. + GroupTable = "team_group_skills" + // GroupInverseTable is the table name for the TeamGroup entity. + // It exists in this package in order to avoid circular dependency with the "teamgroup" package. + GroupInverseTable = "team_groups" + // GroupColumn is the table column denoting the group relation/edge. + GroupColumn = "group_id" + // SkillTable is the table that holds the skill relation/edge. + SkillTable = "team_group_skills" + // SkillInverseTable is the table name for the Skill entity. + // It exists in this package in order to avoid circular dependency with the "skill" package. + SkillInverseTable = "skills" + // SkillColumn is the table column denoting the skill relation/edge. + SkillColumn = "skill_id" +) + +// Columns holds all SQL columns for teamgroupskill fields. +var Columns = []string{ + FieldID, + FieldGroupID, + FieldSkillID, + FieldCreatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the TeamGroupSkill queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByGroupID orders the results by the group_id field. +func ByGroupID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldGroupID, opts...).ToFunc() +} + +// BySkillID orders the results by the skill_id field. +func BySkillID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSkillID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByGroupField orders the results by group field. +func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) + } +} + +// BySkillField orders the results by skill field. +func BySkillField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSkillStep(), sql.OrderByField(field, opts...)) + } +} +func newGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn), + ) +} +func newSkillStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SkillInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn), + ) +} diff --git a/backend/db/teamgroupskill/where.go b/backend/db/teamgroupskill/where.go new file mode 100644 index 00000000..1a989816 --- /dev/null +++ b/backend/db/teamgroupskill/where.go @@ -0,0 +1,213 @@ +// Code generated by ent, DO NOT EDIT. + +package teamgroupskill + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldLTE(FieldID, id)) +} + +// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ. +func GroupID(v uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldGroupID, v)) +} + +// SkillID applies equality check predicate on the "skill_id" field. It's identical to SkillIDEQ. +func SkillID(v uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldSkillID, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldCreatedAt, v)) +} + +// GroupIDEQ applies the EQ predicate on the "group_id" field. +func GroupIDEQ(v uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldGroupID, v)) +} + +// GroupIDNEQ applies the NEQ predicate on the "group_id" field. +func GroupIDNEQ(v uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNEQ(FieldGroupID, v)) +} + +// GroupIDIn applies the In predicate on the "group_id" field. +func GroupIDIn(vs ...uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldIn(FieldGroupID, vs...)) +} + +// GroupIDNotIn applies the NotIn predicate on the "group_id" field. +func GroupIDNotIn(vs ...uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNotIn(FieldGroupID, vs...)) +} + +// SkillIDEQ applies the EQ predicate on the "skill_id" field. +func SkillIDEQ(v uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldSkillID, v)) +} + +// SkillIDNEQ applies the NEQ predicate on the "skill_id" field. +func SkillIDNEQ(v uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNEQ(FieldSkillID, v)) +} + +// SkillIDIn applies the In predicate on the "skill_id" field. +func SkillIDIn(vs ...uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldIn(FieldSkillID, vs...)) +} + +// SkillIDNotIn applies the NotIn predicate on the "skill_id" field. +func SkillIDNotIn(vs ...uuid.UUID) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNotIn(FieldSkillID, vs...)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.FieldLTE(FieldCreatedAt, v)) +} + +// HasGroup applies the HasEdge predicate on the "group" edge. +func HasGroup() predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). +func HasGroupWith(preds ...predicate.TeamGroup) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(func(s *sql.Selector) { + step := newGroupStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSkill applies the HasEdge predicate on the "skill" edge. +func HasSkill() predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSkillWith applies the HasEdge predicate on the "skill" edge with a given conditions (other predicates). +func HasSkillWith(preds ...predicate.Skill) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(func(s *sql.Selector) { + step := newSkillStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.TeamGroupSkill) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.TeamGroupSkill) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.TeamGroupSkill) predicate.TeamGroupSkill { + return predicate.TeamGroupSkill(sql.NotPredicates(p)) +} diff --git a/backend/db/teamgroupskill_create.go b/backend/db/teamgroupskill_create.go new file mode 100644 index 00000000..13347fda --- /dev/null +++ b/backend/db/teamgroupskill_create.go @@ -0,0 +1,659 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/google/uuid" +) + +// TeamGroupSkillCreate is the builder for creating a TeamGroupSkill entity. +type TeamGroupSkillCreate struct { + config + mutation *TeamGroupSkillMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetGroupID sets the "group_id" field. +func (_c *TeamGroupSkillCreate) SetGroupID(v uuid.UUID) *TeamGroupSkillCreate { + _c.mutation.SetGroupID(v) + return _c +} + +// SetSkillID sets the "skill_id" field. +func (_c *TeamGroupSkillCreate) SetSkillID(v uuid.UUID) *TeamGroupSkillCreate { + _c.mutation.SetSkillID(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *TeamGroupSkillCreate) SetCreatedAt(v time.Time) *TeamGroupSkillCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *TeamGroupSkillCreate) SetNillableCreatedAt(v *time.Time) *TeamGroupSkillCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *TeamGroupSkillCreate) SetID(v uuid.UUID) *TeamGroupSkillCreate { + _c.mutation.SetID(v) + return _c +} + +// SetGroup sets the "group" edge to the TeamGroup entity. +func (_c *TeamGroupSkillCreate) SetGroup(v *TeamGroup) *TeamGroupSkillCreate { + return _c.SetGroupID(v.ID) +} + +// SetSkill sets the "skill" edge to the Skill entity. +func (_c *TeamGroupSkillCreate) SetSkill(v *Skill) *TeamGroupSkillCreate { + return _c.SetSkillID(v.ID) +} + +// Mutation returns the TeamGroupSkillMutation object of the builder. +func (_c *TeamGroupSkillCreate) Mutation() *TeamGroupSkillMutation { + return _c.mutation +} + +// Save creates the TeamGroupSkill in the database. +func (_c *TeamGroupSkillCreate) Save(ctx context.Context) (*TeamGroupSkill, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *TeamGroupSkillCreate) SaveX(ctx context.Context) *TeamGroupSkill { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TeamGroupSkillCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TeamGroupSkillCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *TeamGroupSkillCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := teamgroupskill.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *TeamGroupSkillCreate) check() error { + if _, ok := _c.mutation.GroupID(); !ok { + return &ValidationError{Name: "group_id", err: errors.New(`db: missing required field "TeamGroupSkill.group_id"`)} + } + if _, ok := _c.mutation.SkillID(); !ok { + return &ValidationError{Name: "skill_id", err: errors.New(`db: missing required field "TeamGroupSkill.skill_id"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamGroupSkill.created_at"`)} + } + if len(_c.mutation.GroupIDs()) == 0 { + return &ValidationError{Name: "group", err: errors.New(`db: missing required edge "TeamGroupSkill.group"`)} + } + if len(_c.mutation.SkillIDs()) == 0 { + return &ValidationError{Name: "skill", err: errors.New(`db: missing required edge "TeamGroupSkill.skill"`)} + } + return nil +} + +func (_c *TeamGroupSkillCreate) sqlSave(ctx context.Context) (*TeamGroupSkill, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *TeamGroupSkillCreate) createSpec() (*TeamGroupSkill, *sqlgraph.CreateSpec) { + var ( + _node = &TeamGroupSkill{config: _c.config} + _spec = sqlgraph.NewCreateSpec(teamgroupskill.Table, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = _c.conflict + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(teamgroupskill.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.GroupTable, + Columns: []string{teamgroupskill.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.GroupID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.SkillIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.SkillTable, + Columns: []string{teamgroupskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SkillID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.TeamGroupSkill.Create(). +// SetGroupID(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.TeamGroupSkillUpsert) { +// SetGroupID(v+v). +// }). +// Exec(ctx) +func (_c *TeamGroupSkillCreate) OnConflict(opts ...sql.ConflictOption) *TeamGroupSkillUpsertOne { + _c.conflict = opts + return &TeamGroupSkillUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.TeamGroupSkill.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *TeamGroupSkillCreate) OnConflictColumns(columns ...string) *TeamGroupSkillUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &TeamGroupSkillUpsertOne{ + create: _c, + } +} + +type ( + // TeamGroupSkillUpsertOne is the builder for "upsert"-ing + // one TeamGroupSkill node. + TeamGroupSkillUpsertOne struct { + create *TeamGroupSkillCreate + } + + // TeamGroupSkillUpsert is the "OnConflict" setter. + TeamGroupSkillUpsert struct { + *sql.UpdateSet + } +) + +// SetGroupID sets the "group_id" field. +func (u *TeamGroupSkillUpsert) SetGroupID(v uuid.UUID) *TeamGroupSkillUpsert { + u.Set(teamgroupskill.FieldGroupID, v) + return u +} + +// UpdateGroupID sets the "group_id" field to the value that was provided on create. +func (u *TeamGroupSkillUpsert) UpdateGroupID() *TeamGroupSkillUpsert { + u.SetExcluded(teamgroupskill.FieldGroupID) + return u +} + +// SetSkillID sets the "skill_id" field. +func (u *TeamGroupSkillUpsert) SetSkillID(v uuid.UUID) *TeamGroupSkillUpsert { + u.Set(teamgroupskill.FieldSkillID, v) + return u +} + +// UpdateSkillID sets the "skill_id" field to the value that was provided on create. +func (u *TeamGroupSkillUpsert) UpdateSkillID() *TeamGroupSkillUpsert { + u.SetExcluded(teamgroupskill.FieldSkillID) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *TeamGroupSkillUpsert) SetCreatedAt(v time.Time) *TeamGroupSkillUpsert { + u.Set(teamgroupskill.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *TeamGroupSkillUpsert) UpdateCreatedAt() *TeamGroupSkillUpsert { + u.SetExcluded(teamgroupskill.FieldCreatedAt) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.TeamGroupSkill.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(teamgroupskill.FieldID) +// }), +// ). +// Exec(ctx) +func (u *TeamGroupSkillUpsertOne) UpdateNewValues() *TeamGroupSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(teamgroupskill.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.TeamGroupSkill.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *TeamGroupSkillUpsertOne) Ignore() *TeamGroupSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *TeamGroupSkillUpsertOne) DoNothing() *TeamGroupSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the TeamGroupSkillCreate.OnConflict +// documentation for more info. +func (u *TeamGroupSkillUpsertOne) Update(set func(*TeamGroupSkillUpsert)) *TeamGroupSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&TeamGroupSkillUpsert{UpdateSet: update}) + })) + return u +} + +// SetGroupID sets the "group_id" field. +func (u *TeamGroupSkillUpsertOne) SetGroupID(v uuid.UUID) *TeamGroupSkillUpsertOne { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.SetGroupID(v) + }) +} + +// UpdateGroupID sets the "group_id" field to the value that was provided on create. +func (u *TeamGroupSkillUpsertOne) UpdateGroupID() *TeamGroupSkillUpsertOne { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.UpdateGroupID() + }) +} + +// SetSkillID sets the "skill_id" field. +func (u *TeamGroupSkillUpsertOne) SetSkillID(v uuid.UUID) *TeamGroupSkillUpsertOne { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.SetSkillID(v) + }) +} + +// UpdateSkillID sets the "skill_id" field to the value that was provided on create. +func (u *TeamGroupSkillUpsertOne) UpdateSkillID() *TeamGroupSkillUpsertOne { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.UpdateSkillID() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *TeamGroupSkillUpsertOne) SetCreatedAt(v time.Time) *TeamGroupSkillUpsertOne { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *TeamGroupSkillUpsertOne) UpdateCreatedAt() *TeamGroupSkillUpsertOne { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *TeamGroupSkillUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for TeamGroupSkillCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *TeamGroupSkillUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *TeamGroupSkillUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) { + if u.create.driver.Dialect() == dialect.MySQL { + // In case of "ON CONFLICT", there is no way to get back non-numeric ID + // fields from the database since MySQL does not support the RETURNING clause. + return id, errors.New("db: TeamGroupSkillUpsertOne.ID is not supported by MySQL driver. Use TeamGroupSkillUpsertOne.Exec instead") + } + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *TeamGroupSkillUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// TeamGroupSkillCreateBulk is the builder for creating many TeamGroupSkill entities in bulk. +type TeamGroupSkillCreateBulk struct { + config + err error + builders []*TeamGroupSkillCreate + conflict []sql.ConflictOption +} + +// Save creates the TeamGroupSkill entities in the database. +func (_c *TeamGroupSkillCreateBulk) Save(ctx context.Context) ([]*TeamGroupSkill, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*TeamGroupSkill, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*TeamGroupSkillMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = _c.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *TeamGroupSkillCreateBulk) SaveX(ctx context.Context) []*TeamGroupSkill { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TeamGroupSkillCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TeamGroupSkillCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.TeamGroupSkill.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.TeamGroupSkillUpsert) { +// SetGroupID(v+v). +// }). +// Exec(ctx) +func (_c *TeamGroupSkillCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamGroupSkillUpsertBulk { + _c.conflict = opts + return &TeamGroupSkillUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.TeamGroupSkill.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *TeamGroupSkillCreateBulk) OnConflictColumns(columns ...string) *TeamGroupSkillUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &TeamGroupSkillUpsertBulk{ + create: _c, + } +} + +// TeamGroupSkillUpsertBulk is the builder for "upsert"-ing +// a bulk of TeamGroupSkill nodes. +type TeamGroupSkillUpsertBulk struct { + create *TeamGroupSkillCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.TeamGroupSkill.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(teamgroupskill.FieldID) +// }), +// ). +// Exec(ctx) +func (u *TeamGroupSkillUpsertBulk) UpdateNewValues() *TeamGroupSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(teamgroupskill.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.TeamGroupSkill.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *TeamGroupSkillUpsertBulk) Ignore() *TeamGroupSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *TeamGroupSkillUpsertBulk) DoNothing() *TeamGroupSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the TeamGroupSkillCreateBulk.OnConflict +// documentation for more info. +func (u *TeamGroupSkillUpsertBulk) Update(set func(*TeamGroupSkillUpsert)) *TeamGroupSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&TeamGroupSkillUpsert{UpdateSet: update}) + })) + return u +} + +// SetGroupID sets the "group_id" field. +func (u *TeamGroupSkillUpsertBulk) SetGroupID(v uuid.UUID) *TeamGroupSkillUpsertBulk { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.SetGroupID(v) + }) +} + +// UpdateGroupID sets the "group_id" field to the value that was provided on create. +func (u *TeamGroupSkillUpsertBulk) UpdateGroupID() *TeamGroupSkillUpsertBulk { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.UpdateGroupID() + }) +} + +// SetSkillID sets the "skill_id" field. +func (u *TeamGroupSkillUpsertBulk) SetSkillID(v uuid.UUID) *TeamGroupSkillUpsertBulk { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.SetSkillID(v) + }) +} + +// UpdateSkillID sets the "skill_id" field to the value that was provided on create. +func (u *TeamGroupSkillUpsertBulk) UpdateSkillID() *TeamGroupSkillUpsertBulk { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.UpdateSkillID() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *TeamGroupSkillUpsertBulk) SetCreatedAt(v time.Time) *TeamGroupSkillUpsertBulk { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *TeamGroupSkillUpsertBulk) UpdateCreatedAt() *TeamGroupSkillUpsertBulk { + return u.Update(func(s *TeamGroupSkillUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *TeamGroupSkillUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the TeamGroupSkillCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for TeamGroupSkillCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *TeamGroupSkillUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/teamgroupskill_delete.go b/backend/db/teamgroupskill_delete.go new file mode 100644 index 00000000..d426033e --- /dev/null +++ b/backend/db/teamgroupskill_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" +) + +// TeamGroupSkillDelete is the builder for deleting a TeamGroupSkill entity. +type TeamGroupSkillDelete struct { + config + hooks []Hook + mutation *TeamGroupSkillMutation +} + +// Where appends a list predicates to the TeamGroupSkillDelete builder. +func (_d *TeamGroupSkillDelete) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *TeamGroupSkillDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TeamGroupSkillDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *TeamGroupSkillDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(teamgroupskill.Table, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// TeamGroupSkillDeleteOne is the builder for deleting a single TeamGroupSkill entity. +type TeamGroupSkillDeleteOne struct { + _d *TeamGroupSkillDelete +} + +// Where appends a list predicates to the TeamGroupSkillDelete builder. +func (_d *TeamGroupSkillDeleteOne) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *TeamGroupSkillDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{teamgroupskill.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TeamGroupSkillDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/teamgroupskill_query.go b/backend/db/teamgroupskill_query.go new file mode 100644 index 00000000..4f7b0b1a --- /dev/null +++ b/backend/db/teamgroupskill_query.go @@ -0,0 +1,732 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/google/uuid" +) + +// TeamGroupSkillQuery is the builder for querying TeamGroupSkill entities. +type TeamGroupSkillQuery struct { + config + ctx *QueryContext + order []teamgroupskill.OrderOption + inters []Interceptor + predicates []predicate.TeamGroupSkill + withGroup *TeamGroupQuery + withSkill *SkillQuery + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the TeamGroupSkillQuery builder. +func (_q *TeamGroupSkillQuery) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *TeamGroupSkillQuery) Limit(limit int) *TeamGroupSkillQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *TeamGroupSkillQuery) Offset(offset int) *TeamGroupSkillQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *TeamGroupSkillQuery) Unique(unique bool) *TeamGroupSkillQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *TeamGroupSkillQuery) Order(o ...teamgroupskill.OrderOption) *TeamGroupSkillQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryGroup chains the current query on the "group" edge. +func (_q *TeamGroupSkillQuery) QueryGroup() *TeamGroupQuery { + query := (&TeamGroupClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, selector), + sqlgraph.To(teamgroup.Table, teamgroup.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.GroupTable, teamgroupskill.GroupColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySkill chains the current query on the "skill" edge. +func (_q *TeamGroupSkillQuery) QuerySkill() *SkillQuery { + query := (&SkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, selector), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.SkillTable, teamgroupskill.SkillColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first TeamGroupSkill entity from the query. +// Returns a *NotFoundError when no TeamGroupSkill was found. +func (_q *TeamGroupSkillQuery) First(ctx context.Context) (*TeamGroupSkill, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{teamgroupskill.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) FirstX(ctx context.Context) *TeamGroupSkill { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first TeamGroupSkill ID from the query. +// Returns a *NotFoundError when no TeamGroupSkill ID was found. +func (_q *TeamGroupSkillQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{teamgroupskill.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single TeamGroupSkill entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one TeamGroupSkill entity is found. +// Returns a *NotFoundError when no TeamGroupSkill entities are found. +func (_q *TeamGroupSkillQuery) Only(ctx context.Context) (*TeamGroupSkill, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{teamgroupskill.Label} + default: + return nil, &NotSingularError{teamgroupskill.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) OnlyX(ctx context.Context) *TeamGroupSkill { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only TeamGroupSkill ID in the query. +// Returns a *NotSingularError when more than one TeamGroupSkill ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *TeamGroupSkillQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{teamgroupskill.Label} + default: + err = &NotSingularError{teamgroupskill.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of TeamGroupSkills. +func (_q *TeamGroupSkillQuery) All(ctx context.Context) ([]*TeamGroupSkill, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*TeamGroupSkill, *TeamGroupSkillQuery]() + return withInterceptors[[]*TeamGroupSkill](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) AllX(ctx context.Context) []*TeamGroupSkill { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of TeamGroupSkill IDs. +func (_q *TeamGroupSkillQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(teamgroupskill.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *TeamGroupSkillQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*TeamGroupSkillQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *TeamGroupSkillQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *TeamGroupSkillQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the TeamGroupSkillQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *TeamGroupSkillQuery) Clone() *TeamGroupSkillQuery { + if _q == nil { + return nil + } + return &TeamGroupSkillQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]teamgroupskill.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.TeamGroupSkill{}, _q.predicates...), + withGroup: _q.withGroup.Clone(), + withSkill: _q.withSkill.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// WithGroup tells the query-builder to eager-load the nodes that are connected to +// the "group" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamGroupSkillQuery) WithGroup(opts ...func(*TeamGroupQuery)) *TeamGroupSkillQuery { + query := (&TeamGroupClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withGroup = query + return _q +} + +// WithSkill tells the query-builder to eager-load the nodes that are connected to +// the "skill" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamGroupSkillQuery) WithSkill(opts ...func(*SkillQuery)) *TeamGroupSkillQuery { + query := (&SkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSkill = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// GroupID uuid.UUID `json:"group_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.TeamGroupSkill.Query(). +// GroupBy(teamgroupskill.FieldGroupID). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *TeamGroupSkillQuery) GroupBy(field string, fields ...string) *TeamGroupSkillGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &TeamGroupSkillGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = teamgroupskill.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// GroupID uuid.UUID `json:"group_id,omitempty"` +// } +// +// client.TeamGroupSkill.Query(). +// Select(teamgroupskill.FieldGroupID). +// Scan(ctx, &v) +func (_q *TeamGroupSkillQuery) Select(fields ...string) *TeamGroupSkillSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &TeamGroupSkillSelect{TeamGroupSkillQuery: _q} + sbuild.label = teamgroupskill.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a TeamGroupSkillSelect configured with the given aggregations. +func (_q *TeamGroupSkillQuery) Aggregate(fns ...AggregateFunc) *TeamGroupSkillSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *TeamGroupSkillQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !teamgroupskill.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *TeamGroupSkillQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TeamGroupSkill, error) { + var ( + nodes = []*TeamGroupSkill{} + _spec = _q.querySpec() + loadedTypes = [2]bool{ + _q.withGroup != nil, + _q.withSkill != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*TeamGroupSkill).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &TeamGroupSkill{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withGroup; query != nil { + if err := _q.loadGroup(ctx, query, nodes, nil, + func(n *TeamGroupSkill, e *TeamGroup) { n.Edges.Group = e }); err != nil { + return nil, err + } + } + if query := _q.withSkill; query != nil { + if err := _q.loadSkill(ctx, query, nodes, nil, + func(n *TeamGroupSkill, e *Skill) { n.Edges.Skill = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *TeamGroupSkillQuery) loadGroup(ctx context.Context, query *TeamGroupQuery, nodes []*TeamGroupSkill, init func(*TeamGroupSkill), assign func(*TeamGroupSkill, *TeamGroup)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*TeamGroupSkill) + for i := range nodes { + fk := nodes[i].GroupID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(teamgroup.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *TeamGroupSkillQuery) loadSkill(ctx context.Context, query *SkillQuery, nodes []*TeamGroupSkill, init func(*TeamGroupSkill), assign func(*TeamGroupSkill, *Skill)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*TeamGroupSkill) + for i := range nodes { + fk := nodes[i].SkillID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(skill.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "skill_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *TeamGroupSkillQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *TeamGroupSkillQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(teamgroupskill.Table, teamgroupskill.Columns, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, teamgroupskill.FieldID) + for i := range fields { + if fields[i] != teamgroupskill.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withGroup != nil { + _spec.Node.AddColumnOnce(teamgroupskill.FieldGroupID) + } + if _q.withSkill != nil { + _spec.Node.AddColumnOnce(teamgroupskill.FieldSkillID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *TeamGroupSkillQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(teamgroupskill.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = teamgroupskill.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ForUpdate locks the selected rows against concurrent updates, and prevent them from being +// updated, deleted or "selected ... for update" by other sessions, until the transaction is +// either committed or rolled-back. +func (_q *TeamGroupSkillQuery) ForUpdate(opts ...sql.LockOption) *TeamGroupSkillQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock +// on any rows that are read. Other sessions can read the rows, but cannot modify them +// until your transaction commits. +func (_q *TeamGroupSkillQuery) ForShare(opts ...sql.LockOption) *TeamGroupSkillQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_q *TeamGroupSkillQuery) Modify(modifiers ...func(s *sql.Selector)) *TeamGroupSkillSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// TeamGroupSkillGroupBy is the group-by builder for TeamGroupSkill entities. +type TeamGroupSkillGroupBy struct { + selector + build *TeamGroupSkillQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *TeamGroupSkillGroupBy) Aggregate(fns ...AggregateFunc) *TeamGroupSkillGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *TeamGroupSkillGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TeamGroupSkillQuery, *TeamGroupSkillGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *TeamGroupSkillGroupBy) sqlScan(ctx context.Context, root *TeamGroupSkillQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// TeamGroupSkillSelect is the builder for selecting fields of TeamGroupSkill entities. +type TeamGroupSkillSelect struct { + *TeamGroupSkillQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *TeamGroupSkillSelect) Aggregate(fns ...AggregateFunc) *TeamGroupSkillSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *TeamGroupSkillSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TeamGroupSkillQuery, *TeamGroupSkillSelect](ctx, _s.TeamGroupSkillQuery, _s, _s.inters, v) +} + +func (_s *TeamGroupSkillSelect) sqlScan(ctx context.Context, root *TeamGroupSkillQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_s *TeamGroupSkillSelect) Modify(modifiers ...func(s *sql.Selector)) *TeamGroupSkillSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/backend/db/teamgroupskill_update.go b/backend/db/teamgroupskill_update.go new file mode 100644 index 00000000..6efa4fb7 --- /dev/null +++ b/backend/db/teamgroupskill_update.go @@ -0,0 +1,473 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/teamgroup" + "github.com/chaitin/MonkeyCode/backend/db/teamgroupskill" + "github.com/google/uuid" +) + +// TeamGroupSkillUpdate is the builder for updating TeamGroupSkill entities. +type TeamGroupSkillUpdate struct { + config + hooks []Hook + mutation *TeamGroupSkillMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the TeamGroupSkillUpdate builder. +func (_u *TeamGroupSkillUpdate) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetGroupID sets the "group_id" field. +func (_u *TeamGroupSkillUpdate) SetGroupID(v uuid.UUID) *TeamGroupSkillUpdate { + _u.mutation.SetGroupID(v) + return _u +} + +// SetNillableGroupID sets the "group_id" field if the given value is not nil. +func (_u *TeamGroupSkillUpdate) SetNillableGroupID(v *uuid.UUID) *TeamGroupSkillUpdate { + if v != nil { + _u.SetGroupID(*v) + } + return _u +} + +// SetSkillID sets the "skill_id" field. +func (_u *TeamGroupSkillUpdate) SetSkillID(v uuid.UUID) *TeamGroupSkillUpdate { + _u.mutation.SetSkillID(v) + return _u +} + +// SetNillableSkillID sets the "skill_id" field if the given value is not nil. +func (_u *TeamGroupSkillUpdate) SetNillableSkillID(v *uuid.UUID) *TeamGroupSkillUpdate { + if v != nil { + _u.SetSkillID(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *TeamGroupSkillUpdate) SetCreatedAt(v time.Time) *TeamGroupSkillUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *TeamGroupSkillUpdate) SetNillableCreatedAt(v *time.Time) *TeamGroupSkillUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetGroup sets the "group" edge to the TeamGroup entity. +func (_u *TeamGroupSkillUpdate) SetGroup(v *TeamGroup) *TeamGroupSkillUpdate { + return _u.SetGroupID(v.ID) +} + +// SetSkill sets the "skill" edge to the Skill entity. +func (_u *TeamGroupSkillUpdate) SetSkill(v *Skill) *TeamGroupSkillUpdate { + return _u.SetSkillID(v.ID) +} + +// Mutation returns the TeamGroupSkillMutation object of the builder. +func (_u *TeamGroupSkillUpdate) Mutation() *TeamGroupSkillMutation { + return _u.mutation +} + +// ClearGroup clears the "group" edge to the TeamGroup entity. +func (_u *TeamGroupSkillUpdate) ClearGroup() *TeamGroupSkillUpdate { + _u.mutation.ClearGroup() + return _u +} + +// ClearSkill clears the "skill" edge to the Skill entity. +func (_u *TeamGroupSkillUpdate) ClearSkill() *TeamGroupSkillUpdate { + _u.mutation.ClearSkill() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *TeamGroupSkillUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TeamGroupSkillUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *TeamGroupSkillUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TeamGroupSkillUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TeamGroupSkillUpdate) check() error { + if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamGroupSkill.group"`) + } + if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamGroupSkill.skill"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *TeamGroupSkillUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamGroupSkillUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *TeamGroupSkillUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(teamgroupskill.Table, teamgroupskill.Columns, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(teamgroupskill.FieldCreatedAt, field.TypeTime, value) + } + if _u.mutation.GroupCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.GroupTable, + Columns: []string{teamgroupskill.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.GroupTable, + Columns: []string{teamgroupskill.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SkillCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.SkillTable, + Columns: []string{teamgroupskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.SkillTable, + Columns: []string{teamgroupskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{teamgroupskill.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// TeamGroupSkillUpdateOne is the builder for updating a single TeamGroupSkill entity. +type TeamGroupSkillUpdateOne struct { + config + fields []string + hooks []Hook + mutation *TeamGroupSkillMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetGroupID sets the "group_id" field. +func (_u *TeamGroupSkillUpdateOne) SetGroupID(v uuid.UUID) *TeamGroupSkillUpdateOne { + _u.mutation.SetGroupID(v) + return _u +} + +// SetNillableGroupID sets the "group_id" field if the given value is not nil. +func (_u *TeamGroupSkillUpdateOne) SetNillableGroupID(v *uuid.UUID) *TeamGroupSkillUpdateOne { + if v != nil { + _u.SetGroupID(*v) + } + return _u +} + +// SetSkillID sets the "skill_id" field. +func (_u *TeamGroupSkillUpdateOne) SetSkillID(v uuid.UUID) *TeamGroupSkillUpdateOne { + _u.mutation.SetSkillID(v) + return _u +} + +// SetNillableSkillID sets the "skill_id" field if the given value is not nil. +func (_u *TeamGroupSkillUpdateOne) SetNillableSkillID(v *uuid.UUID) *TeamGroupSkillUpdateOne { + if v != nil { + _u.SetSkillID(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *TeamGroupSkillUpdateOne) SetCreatedAt(v time.Time) *TeamGroupSkillUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *TeamGroupSkillUpdateOne) SetNillableCreatedAt(v *time.Time) *TeamGroupSkillUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetGroup sets the "group" edge to the TeamGroup entity. +func (_u *TeamGroupSkillUpdateOne) SetGroup(v *TeamGroup) *TeamGroupSkillUpdateOne { + return _u.SetGroupID(v.ID) +} + +// SetSkill sets the "skill" edge to the Skill entity. +func (_u *TeamGroupSkillUpdateOne) SetSkill(v *Skill) *TeamGroupSkillUpdateOne { + return _u.SetSkillID(v.ID) +} + +// Mutation returns the TeamGroupSkillMutation object of the builder. +func (_u *TeamGroupSkillUpdateOne) Mutation() *TeamGroupSkillMutation { + return _u.mutation +} + +// ClearGroup clears the "group" edge to the TeamGroup entity. +func (_u *TeamGroupSkillUpdateOne) ClearGroup() *TeamGroupSkillUpdateOne { + _u.mutation.ClearGroup() + return _u +} + +// ClearSkill clears the "skill" edge to the Skill entity. +func (_u *TeamGroupSkillUpdateOne) ClearSkill() *TeamGroupSkillUpdateOne { + _u.mutation.ClearSkill() + return _u +} + +// Where appends a list predicates to the TeamGroupSkillUpdate builder. +func (_u *TeamGroupSkillUpdateOne) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *TeamGroupSkillUpdateOne) Select(field string, fields ...string) *TeamGroupSkillUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated TeamGroupSkill entity. +func (_u *TeamGroupSkillUpdateOne) Save(ctx context.Context) (*TeamGroupSkill, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TeamGroupSkillUpdateOne) SaveX(ctx context.Context) *TeamGroupSkill { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *TeamGroupSkillUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TeamGroupSkillUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TeamGroupSkillUpdateOne) check() error { + if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamGroupSkill.group"`) + } + if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamGroupSkill.skill"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *TeamGroupSkillUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamGroupSkillUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *TeamGroupSkillUpdateOne) sqlSave(ctx context.Context) (_node *TeamGroupSkill, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(teamgroupskill.Table, teamgroupskill.Columns, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "TeamGroupSkill.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, teamgroupskill.FieldID) + for _, f := range fields { + if !teamgroupskill.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != teamgroupskill.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(teamgroupskill.FieldCreatedAt, field.TypeTime, value) + } + if _u.mutation.GroupCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.GroupTable, + Columns: []string{teamgroupskill.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.GroupTable, + Columns: []string{teamgroupskill.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SkillCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.SkillTable, + Columns: []string{teamgroupskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamgroupskill.SkillTable, + Columns: []string{teamgroupskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + _node = &TeamGroupSkill{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{teamgroupskill.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/db/teamskill.go b/backend/db/teamskill.go new file mode 100644 index 00000000..a2d36ca8 --- /dev/null +++ b/backend/db/teamskill.go @@ -0,0 +1,175 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/google/uuid" +) + +// TeamSkill is the model entity for the TeamSkill schema. +type TeamSkill struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // TeamID holds the value of the "team_id" field. + TeamID uuid.UUID `json:"team_id,omitempty"` + // SkillID holds the value of the "skill_id" field. + SkillID uuid.UUID `json:"skill_id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the TeamSkillQuery when eager-loading is set. + Edges TeamSkillEdges `json:"edges"` + selectValues sql.SelectValues +} + +// TeamSkillEdges holds the relations/edges for other nodes in the graph. +type TeamSkillEdges struct { + // Team holds the value of the team edge. + Team *Team `json:"team,omitempty"` + // Skill holds the value of the skill edge. + Skill *Skill `json:"skill,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// TeamOrErr returns the Team value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e TeamSkillEdges) TeamOrErr() (*Team, error) { + if e.Team != nil { + return e.Team, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: team.Label} + } + return nil, &NotLoadedError{edge: "team"} +} + +// SkillOrErr returns the Skill value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e TeamSkillEdges) SkillOrErr() (*Skill, error) { + if e.Skill != nil { + return e.Skill, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: skill.Label} + } + return nil, &NotLoadedError{edge: "skill"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*TeamSkill) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case teamskill.FieldCreatedAt: + values[i] = new(sql.NullTime) + case teamskill.FieldID, teamskill.FieldTeamID, teamskill.FieldSkillID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the TeamSkill fields. +func (_m *TeamSkill) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case teamskill.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case teamskill.FieldTeamID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field team_id", values[i]) + } else if value != nil { + _m.TeamID = *value + } + case teamskill.FieldSkillID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field skill_id", values[i]) + } else if value != nil { + _m.SkillID = *value + } + case teamskill.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the TeamSkill. +// This includes values selected through modifiers, order, etc. +func (_m *TeamSkill) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryTeam queries the "team" edge of the TeamSkill entity. +func (_m *TeamSkill) QueryTeam() *TeamQuery { + return NewTeamSkillClient(_m.config).QueryTeam(_m) +} + +// QuerySkill queries the "skill" edge of the TeamSkill entity. +func (_m *TeamSkill) QuerySkill() *SkillQuery { + return NewTeamSkillClient(_m.config).QuerySkill(_m) +} + +// Update returns a builder for updating this TeamSkill. +// Note that you need to call TeamSkill.Unwrap() before calling this method if this TeamSkill +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *TeamSkill) Update() *TeamSkillUpdateOne { + return NewTeamSkillClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the TeamSkill entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *TeamSkill) Unwrap() *TeamSkill { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: TeamSkill is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *TeamSkill) String() string { + var builder strings.Builder + builder.WriteString("TeamSkill(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("team_id=") + builder.WriteString(fmt.Sprintf("%v", _m.TeamID)) + builder.WriteString(", ") + builder.WriteString("skill_id=") + builder.WriteString(fmt.Sprintf("%v", _m.SkillID)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// TeamSkills is a parsable slice of TeamSkill. +type TeamSkills []*TeamSkill diff --git a/backend/db/teamskill/teamskill.go b/backend/db/teamskill/teamskill.go new file mode 100644 index 00000000..1f5d652c --- /dev/null +++ b/backend/db/teamskill/teamskill.go @@ -0,0 +1,117 @@ +// Code generated by ent, DO NOT EDIT. + +package teamskill + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the teamskill type in the database. + Label = "team_skill" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldTeamID holds the string denoting the team_id field in the database. + FieldTeamID = "team_id" + // FieldSkillID holds the string denoting the skill_id field in the database. + FieldSkillID = "skill_id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // EdgeTeam holds the string denoting the team edge name in mutations. + EdgeTeam = "team" + // EdgeSkill holds the string denoting the skill edge name in mutations. + EdgeSkill = "skill" + // Table holds the table name of the teamskill in the database. + Table = "team_skills" + // TeamTable is the table that holds the team relation/edge. + TeamTable = "team_skills" + // TeamInverseTable is the table name for the Team entity. + // It exists in this package in order to avoid circular dependency with the "team" package. + TeamInverseTable = "teams" + // TeamColumn is the table column denoting the team relation/edge. + TeamColumn = "team_id" + // SkillTable is the table that holds the skill relation/edge. + SkillTable = "team_skills" + // SkillInverseTable is the table name for the Skill entity. + // It exists in this package in order to avoid circular dependency with the "skill" package. + SkillInverseTable = "skills" + // SkillColumn is the table column denoting the skill relation/edge. + SkillColumn = "skill_id" +) + +// Columns holds all SQL columns for teamskill fields. +var Columns = []string{ + FieldID, + FieldTeamID, + FieldSkillID, + FieldCreatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the TeamSkill queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByTeamID orders the results by the team_id field. +func ByTeamID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTeamID, opts...).ToFunc() +} + +// BySkillID orders the results by the skill_id field. +func BySkillID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSkillID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByTeamField orders the results by team field. +func ByTeamField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamStep(), sql.OrderByField(field, opts...)) + } +} + +// BySkillField orders the results by skill field. +func BySkillField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSkillStep(), sql.OrderByField(field, opts...)) + } +} +func newTeamStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, TeamTable, TeamColumn), + ) +} +func newSkillStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SkillInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn), + ) +} diff --git a/backend/db/teamskill/where.go b/backend/db/teamskill/where.go new file mode 100644 index 00000000..5c6f4fe9 --- /dev/null +++ b/backend/db/teamskill/where.go @@ -0,0 +1,213 @@ +// Code generated by ent, DO NOT EDIT. + +package teamskill + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldLTE(FieldID, id)) +} + +// TeamID applies equality check predicate on the "team_id" field. It's identical to TeamIDEQ. +func TeamID(v uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldTeamID, v)) +} + +// SkillID applies equality check predicate on the "skill_id" field. It's identical to SkillIDEQ. +func SkillID(v uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldSkillID, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldCreatedAt, v)) +} + +// TeamIDEQ applies the EQ predicate on the "team_id" field. +func TeamIDEQ(v uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldTeamID, v)) +} + +// TeamIDNEQ applies the NEQ predicate on the "team_id" field. +func TeamIDNEQ(v uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNEQ(FieldTeamID, v)) +} + +// TeamIDIn applies the In predicate on the "team_id" field. +func TeamIDIn(vs ...uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldIn(FieldTeamID, vs...)) +} + +// TeamIDNotIn applies the NotIn predicate on the "team_id" field. +func TeamIDNotIn(vs ...uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNotIn(FieldTeamID, vs...)) +} + +// SkillIDEQ applies the EQ predicate on the "skill_id" field. +func SkillIDEQ(v uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldSkillID, v)) +} + +// SkillIDNEQ applies the NEQ predicate on the "skill_id" field. +func SkillIDNEQ(v uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNEQ(FieldSkillID, v)) +} + +// SkillIDIn applies the In predicate on the "skill_id" field. +func SkillIDIn(vs ...uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldIn(FieldSkillID, vs...)) +} + +// SkillIDNotIn applies the NotIn predicate on the "skill_id" field. +func SkillIDNotIn(vs ...uuid.UUID) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNotIn(FieldSkillID, vs...)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.TeamSkill { + return predicate.TeamSkill(sql.FieldLTE(FieldCreatedAt, v)) +} + +// HasTeam applies the HasEdge predicate on the "team" edge. +func HasTeam() predicate.TeamSkill { + return predicate.TeamSkill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, TeamTable, TeamColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamWith applies the HasEdge predicate on the "team" edge with a given conditions (other predicates). +func HasTeamWith(preds ...predicate.Team) predicate.TeamSkill { + return predicate.TeamSkill(func(s *sql.Selector) { + step := newTeamStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSkill applies the HasEdge predicate on the "skill" edge. +func HasSkill() predicate.TeamSkill { + return predicate.TeamSkill(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSkillWith applies the HasEdge predicate on the "skill" edge with a given conditions (other predicates). +func HasSkillWith(preds ...predicate.Skill) predicate.TeamSkill { + return predicate.TeamSkill(func(s *sql.Selector) { + step := newSkillStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.TeamSkill) predicate.TeamSkill { + return predicate.TeamSkill(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.TeamSkill) predicate.TeamSkill { + return predicate.TeamSkill(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.TeamSkill) predicate.TeamSkill { + return predicate.TeamSkill(sql.NotPredicates(p)) +} diff --git a/backend/db/teamskill_create.go b/backend/db/teamskill_create.go new file mode 100644 index 00000000..27d2a5f3 --- /dev/null +++ b/backend/db/teamskill_create.go @@ -0,0 +1,659 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/google/uuid" +) + +// TeamSkillCreate is the builder for creating a TeamSkill entity. +type TeamSkillCreate struct { + config + mutation *TeamSkillMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetTeamID sets the "team_id" field. +func (_c *TeamSkillCreate) SetTeamID(v uuid.UUID) *TeamSkillCreate { + _c.mutation.SetTeamID(v) + return _c +} + +// SetSkillID sets the "skill_id" field. +func (_c *TeamSkillCreate) SetSkillID(v uuid.UUID) *TeamSkillCreate { + _c.mutation.SetSkillID(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *TeamSkillCreate) SetCreatedAt(v time.Time) *TeamSkillCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *TeamSkillCreate) SetNillableCreatedAt(v *time.Time) *TeamSkillCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *TeamSkillCreate) SetID(v uuid.UUID) *TeamSkillCreate { + _c.mutation.SetID(v) + return _c +} + +// SetTeam sets the "team" edge to the Team entity. +func (_c *TeamSkillCreate) SetTeam(v *Team) *TeamSkillCreate { + return _c.SetTeamID(v.ID) +} + +// SetSkill sets the "skill" edge to the Skill entity. +func (_c *TeamSkillCreate) SetSkill(v *Skill) *TeamSkillCreate { + return _c.SetSkillID(v.ID) +} + +// Mutation returns the TeamSkillMutation object of the builder. +func (_c *TeamSkillCreate) Mutation() *TeamSkillMutation { + return _c.mutation +} + +// Save creates the TeamSkill in the database. +func (_c *TeamSkillCreate) Save(ctx context.Context) (*TeamSkill, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *TeamSkillCreate) SaveX(ctx context.Context) *TeamSkill { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TeamSkillCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TeamSkillCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *TeamSkillCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := teamskill.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *TeamSkillCreate) check() error { + if _, ok := _c.mutation.TeamID(); !ok { + return &ValidationError{Name: "team_id", err: errors.New(`db: missing required field "TeamSkill.team_id"`)} + } + if _, ok := _c.mutation.SkillID(); !ok { + return &ValidationError{Name: "skill_id", err: errors.New(`db: missing required field "TeamSkill.skill_id"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamSkill.created_at"`)} + } + if len(_c.mutation.TeamIDs()) == 0 { + return &ValidationError{Name: "team", err: errors.New(`db: missing required edge "TeamSkill.team"`)} + } + if len(_c.mutation.SkillIDs()) == 0 { + return &ValidationError{Name: "skill", err: errors.New(`db: missing required edge "TeamSkill.skill"`)} + } + return nil +} + +func (_c *TeamSkillCreate) sqlSave(ctx context.Context) (*TeamSkill, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *TeamSkillCreate) createSpec() (*TeamSkill, *sqlgraph.CreateSpec) { + var ( + _node = &TeamSkill{config: _c.config} + _spec = sqlgraph.NewCreateSpec(teamskill.Table, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = _c.conflict + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(teamskill.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if nodes := _c.mutation.TeamIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.TeamTable, + Columns: []string{teamskill.TeamColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.TeamID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.SkillIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.SkillTable, + Columns: []string{teamskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SkillID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.TeamSkill.Create(). +// SetTeamID(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.TeamSkillUpsert) { +// SetTeamID(v+v). +// }). +// Exec(ctx) +func (_c *TeamSkillCreate) OnConflict(opts ...sql.ConflictOption) *TeamSkillUpsertOne { + _c.conflict = opts + return &TeamSkillUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.TeamSkill.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *TeamSkillCreate) OnConflictColumns(columns ...string) *TeamSkillUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &TeamSkillUpsertOne{ + create: _c, + } +} + +type ( + // TeamSkillUpsertOne is the builder for "upsert"-ing + // one TeamSkill node. + TeamSkillUpsertOne struct { + create *TeamSkillCreate + } + + // TeamSkillUpsert is the "OnConflict" setter. + TeamSkillUpsert struct { + *sql.UpdateSet + } +) + +// SetTeamID sets the "team_id" field. +func (u *TeamSkillUpsert) SetTeamID(v uuid.UUID) *TeamSkillUpsert { + u.Set(teamskill.FieldTeamID, v) + return u +} + +// UpdateTeamID sets the "team_id" field to the value that was provided on create. +func (u *TeamSkillUpsert) UpdateTeamID() *TeamSkillUpsert { + u.SetExcluded(teamskill.FieldTeamID) + return u +} + +// SetSkillID sets the "skill_id" field. +func (u *TeamSkillUpsert) SetSkillID(v uuid.UUID) *TeamSkillUpsert { + u.Set(teamskill.FieldSkillID, v) + return u +} + +// UpdateSkillID sets the "skill_id" field to the value that was provided on create. +func (u *TeamSkillUpsert) UpdateSkillID() *TeamSkillUpsert { + u.SetExcluded(teamskill.FieldSkillID) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *TeamSkillUpsert) SetCreatedAt(v time.Time) *TeamSkillUpsert { + u.Set(teamskill.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *TeamSkillUpsert) UpdateCreatedAt() *TeamSkillUpsert { + u.SetExcluded(teamskill.FieldCreatedAt) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.TeamSkill.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(teamskill.FieldID) +// }), +// ). +// Exec(ctx) +func (u *TeamSkillUpsertOne) UpdateNewValues() *TeamSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(teamskill.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.TeamSkill.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *TeamSkillUpsertOne) Ignore() *TeamSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *TeamSkillUpsertOne) DoNothing() *TeamSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the TeamSkillCreate.OnConflict +// documentation for more info. +func (u *TeamSkillUpsertOne) Update(set func(*TeamSkillUpsert)) *TeamSkillUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&TeamSkillUpsert{UpdateSet: update}) + })) + return u +} + +// SetTeamID sets the "team_id" field. +func (u *TeamSkillUpsertOne) SetTeamID(v uuid.UUID) *TeamSkillUpsertOne { + return u.Update(func(s *TeamSkillUpsert) { + s.SetTeamID(v) + }) +} + +// UpdateTeamID sets the "team_id" field to the value that was provided on create. +func (u *TeamSkillUpsertOne) UpdateTeamID() *TeamSkillUpsertOne { + return u.Update(func(s *TeamSkillUpsert) { + s.UpdateTeamID() + }) +} + +// SetSkillID sets the "skill_id" field. +func (u *TeamSkillUpsertOne) SetSkillID(v uuid.UUID) *TeamSkillUpsertOne { + return u.Update(func(s *TeamSkillUpsert) { + s.SetSkillID(v) + }) +} + +// UpdateSkillID sets the "skill_id" field to the value that was provided on create. +func (u *TeamSkillUpsertOne) UpdateSkillID() *TeamSkillUpsertOne { + return u.Update(func(s *TeamSkillUpsert) { + s.UpdateSkillID() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *TeamSkillUpsertOne) SetCreatedAt(v time.Time) *TeamSkillUpsertOne { + return u.Update(func(s *TeamSkillUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *TeamSkillUpsertOne) UpdateCreatedAt() *TeamSkillUpsertOne { + return u.Update(func(s *TeamSkillUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *TeamSkillUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for TeamSkillCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *TeamSkillUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *TeamSkillUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) { + if u.create.driver.Dialect() == dialect.MySQL { + // In case of "ON CONFLICT", there is no way to get back non-numeric ID + // fields from the database since MySQL does not support the RETURNING clause. + return id, errors.New("db: TeamSkillUpsertOne.ID is not supported by MySQL driver. Use TeamSkillUpsertOne.Exec instead") + } + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *TeamSkillUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// TeamSkillCreateBulk is the builder for creating many TeamSkill entities in bulk. +type TeamSkillCreateBulk struct { + config + err error + builders []*TeamSkillCreate + conflict []sql.ConflictOption +} + +// Save creates the TeamSkill entities in the database. +func (_c *TeamSkillCreateBulk) Save(ctx context.Context) ([]*TeamSkill, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*TeamSkill, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*TeamSkillMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = _c.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *TeamSkillCreateBulk) SaveX(ctx context.Context) []*TeamSkill { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TeamSkillCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TeamSkillCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.TeamSkill.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.TeamSkillUpsert) { +// SetTeamID(v+v). +// }). +// Exec(ctx) +func (_c *TeamSkillCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamSkillUpsertBulk { + _c.conflict = opts + return &TeamSkillUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.TeamSkill.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *TeamSkillCreateBulk) OnConflictColumns(columns ...string) *TeamSkillUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &TeamSkillUpsertBulk{ + create: _c, + } +} + +// TeamSkillUpsertBulk is the builder for "upsert"-ing +// a bulk of TeamSkill nodes. +type TeamSkillUpsertBulk struct { + create *TeamSkillCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.TeamSkill.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(teamskill.FieldID) +// }), +// ). +// Exec(ctx) +func (u *TeamSkillUpsertBulk) UpdateNewValues() *TeamSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(teamskill.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.TeamSkill.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *TeamSkillUpsertBulk) Ignore() *TeamSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *TeamSkillUpsertBulk) DoNothing() *TeamSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the TeamSkillCreateBulk.OnConflict +// documentation for more info. +func (u *TeamSkillUpsertBulk) Update(set func(*TeamSkillUpsert)) *TeamSkillUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&TeamSkillUpsert{UpdateSet: update}) + })) + return u +} + +// SetTeamID sets the "team_id" field. +func (u *TeamSkillUpsertBulk) SetTeamID(v uuid.UUID) *TeamSkillUpsertBulk { + return u.Update(func(s *TeamSkillUpsert) { + s.SetTeamID(v) + }) +} + +// UpdateTeamID sets the "team_id" field to the value that was provided on create. +func (u *TeamSkillUpsertBulk) UpdateTeamID() *TeamSkillUpsertBulk { + return u.Update(func(s *TeamSkillUpsert) { + s.UpdateTeamID() + }) +} + +// SetSkillID sets the "skill_id" field. +func (u *TeamSkillUpsertBulk) SetSkillID(v uuid.UUID) *TeamSkillUpsertBulk { + return u.Update(func(s *TeamSkillUpsert) { + s.SetSkillID(v) + }) +} + +// UpdateSkillID sets the "skill_id" field to the value that was provided on create. +func (u *TeamSkillUpsertBulk) UpdateSkillID() *TeamSkillUpsertBulk { + return u.Update(func(s *TeamSkillUpsert) { + s.UpdateSkillID() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *TeamSkillUpsertBulk) SetCreatedAt(v time.Time) *TeamSkillUpsertBulk { + return u.Update(func(s *TeamSkillUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *TeamSkillUpsertBulk) UpdateCreatedAt() *TeamSkillUpsertBulk { + return u.Update(func(s *TeamSkillUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *TeamSkillUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the TeamSkillCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for TeamSkillCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *TeamSkillUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/teamskill_delete.go b/backend/db/teamskill_delete.go new file mode 100644 index 00000000..7c09d011 --- /dev/null +++ b/backend/db/teamskill_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" +) + +// TeamSkillDelete is the builder for deleting a TeamSkill entity. +type TeamSkillDelete struct { + config + hooks []Hook + mutation *TeamSkillMutation +} + +// Where appends a list predicates to the TeamSkillDelete builder. +func (_d *TeamSkillDelete) Where(ps ...predicate.TeamSkill) *TeamSkillDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *TeamSkillDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TeamSkillDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *TeamSkillDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(teamskill.Table, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// TeamSkillDeleteOne is the builder for deleting a single TeamSkill entity. +type TeamSkillDeleteOne struct { + _d *TeamSkillDelete +} + +// Where appends a list predicates to the TeamSkillDelete builder. +func (_d *TeamSkillDeleteOne) Where(ps ...predicate.TeamSkill) *TeamSkillDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *TeamSkillDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{teamskill.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TeamSkillDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/teamskill_query.go b/backend/db/teamskill_query.go new file mode 100644 index 00000000..875d0672 --- /dev/null +++ b/backend/db/teamskill_query.go @@ -0,0 +1,732 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/google/uuid" +) + +// TeamSkillQuery is the builder for querying TeamSkill entities. +type TeamSkillQuery struct { + config + ctx *QueryContext + order []teamskill.OrderOption + inters []Interceptor + predicates []predicate.TeamSkill + withTeam *TeamQuery + withSkill *SkillQuery + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the TeamSkillQuery builder. +func (_q *TeamSkillQuery) Where(ps ...predicate.TeamSkill) *TeamSkillQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *TeamSkillQuery) Limit(limit int) *TeamSkillQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *TeamSkillQuery) Offset(offset int) *TeamSkillQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *TeamSkillQuery) Unique(unique bool) *TeamSkillQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *TeamSkillQuery) Order(o ...teamskill.OrderOption) *TeamSkillQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryTeam chains the current query on the "team" edge. +func (_q *TeamSkillQuery) QueryTeam() *TeamQuery { + query := (&TeamClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamskill.Table, teamskill.FieldID, selector), + sqlgraph.To(team.Table, team.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamskill.TeamTable, teamskill.TeamColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySkill chains the current query on the "skill" edge. +func (_q *TeamSkillQuery) QuerySkill() *SkillQuery { + query := (&SkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamskill.Table, teamskill.FieldID, selector), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, teamskill.SkillTable, teamskill.SkillColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first TeamSkill entity from the query. +// Returns a *NotFoundError when no TeamSkill was found. +func (_q *TeamSkillQuery) First(ctx context.Context) (*TeamSkill, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{teamskill.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *TeamSkillQuery) FirstX(ctx context.Context) *TeamSkill { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first TeamSkill ID from the query. +// Returns a *NotFoundError when no TeamSkill ID was found. +func (_q *TeamSkillQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{teamskill.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *TeamSkillQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single TeamSkill entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one TeamSkill entity is found. +// Returns a *NotFoundError when no TeamSkill entities are found. +func (_q *TeamSkillQuery) Only(ctx context.Context) (*TeamSkill, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{teamskill.Label} + default: + return nil, &NotSingularError{teamskill.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *TeamSkillQuery) OnlyX(ctx context.Context) *TeamSkill { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only TeamSkill ID in the query. +// Returns a *NotSingularError when more than one TeamSkill ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *TeamSkillQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{teamskill.Label} + default: + err = &NotSingularError{teamskill.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *TeamSkillQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of TeamSkills. +func (_q *TeamSkillQuery) All(ctx context.Context) ([]*TeamSkill, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*TeamSkill, *TeamSkillQuery]() + return withInterceptors[[]*TeamSkill](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *TeamSkillQuery) AllX(ctx context.Context) []*TeamSkill { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of TeamSkill IDs. +func (_q *TeamSkillQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(teamskill.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *TeamSkillQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *TeamSkillQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*TeamSkillQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *TeamSkillQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *TeamSkillQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *TeamSkillQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the TeamSkillQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *TeamSkillQuery) Clone() *TeamSkillQuery { + if _q == nil { + return nil + } + return &TeamSkillQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]teamskill.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.TeamSkill{}, _q.predicates...), + withTeam: _q.withTeam.Clone(), + withSkill: _q.withSkill.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// WithTeam tells the query-builder to eager-load the nodes that are connected to +// the "team" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamSkillQuery) WithTeam(opts ...func(*TeamQuery)) *TeamSkillQuery { + query := (&TeamClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeam = query + return _q +} + +// WithSkill tells the query-builder to eager-load the nodes that are connected to +// the "skill" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamSkillQuery) WithSkill(opts ...func(*SkillQuery)) *TeamSkillQuery { + query := (&SkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSkill = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// TeamID uuid.UUID `json:"team_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.TeamSkill.Query(). +// GroupBy(teamskill.FieldTeamID). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *TeamSkillQuery) GroupBy(field string, fields ...string) *TeamSkillGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &TeamSkillGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = teamskill.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// TeamID uuid.UUID `json:"team_id,omitempty"` +// } +// +// client.TeamSkill.Query(). +// Select(teamskill.FieldTeamID). +// Scan(ctx, &v) +func (_q *TeamSkillQuery) Select(fields ...string) *TeamSkillSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &TeamSkillSelect{TeamSkillQuery: _q} + sbuild.label = teamskill.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a TeamSkillSelect configured with the given aggregations. +func (_q *TeamSkillQuery) Aggregate(fns ...AggregateFunc) *TeamSkillSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *TeamSkillQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !teamskill.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *TeamSkillQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TeamSkill, error) { + var ( + nodes = []*TeamSkill{} + _spec = _q.querySpec() + loadedTypes = [2]bool{ + _q.withTeam != nil, + _q.withSkill != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*TeamSkill).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &TeamSkill{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withTeam; query != nil { + if err := _q.loadTeam(ctx, query, nodes, nil, + func(n *TeamSkill, e *Team) { n.Edges.Team = e }); err != nil { + return nil, err + } + } + if query := _q.withSkill; query != nil { + if err := _q.loadSkill(ctx, query, nodes, nil, + func(n *TeamSkill, e *Skill) { n.Edges.Skill = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *TeamSkillQuery) loadTeam(ctx context.Context, query *TeamQuery, nodes []*TeamSkill, init func(*TeamSkill), assign func(*TeamSkill, *Team)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*TeamSkill) + for i := range nodes { + fk := nodes[i].TeamID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(team.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "team_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *TeamSkillQuery) loadSkill(ctx context.Context, query *SkillQuery, nodes []*TeamSkill, init func(*TeamSkill), assign func(*TeamSkill, *Skill)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*TeamSkill) + for i := range nodes { + fk := nodes[i].SkillID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(skill.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "skill_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *TeamSkillQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *TeamSkillQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(teamskill.Table, teamskill.Columns, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, teamskill.FieldID) + for i := range fields { + if fields[i] != teamskill.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withTeam != nil { + _spec.Node.AddColumnOnce(teamskill.FieldTeamID) + } + if _q.withSkill != nil { + _spec.Node.AddColumnOnce(teamskill.FieldSkillID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *TeamSkillQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(teamskill.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = teamskill.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ForUpdate locks the selected rows against concurrent updates, and prevent them from being +// updated, deleted or "selected ... for update" by other sessions, until the transaction is +// either committed or rolled-back. +func (_q *TeamSkillQuery) ForUpdate(opts ...sql.LockOption) *TeamSkillQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock +// on any rows that are read. Other sessions can read the rows, but cannot modify them +// until your transaction commits. +func (_q *TeamSkillQuery) ForShare(opts ...sql.LockOption) *TeamSkillQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_q *TeamSkillQuery) Modify(modifiers ...func(s *sql.Selector)) *TeamSkillSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// TeamSkillGroupBy is the group-by builder for TeamSkill entities. +type TeamSkillGroupBy struct { + selector + build *TeamSkillQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *TeamSkillGroupBy) Aggregate(fns ...AggregateFunc) *TeamSkillGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *TeamSkillGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TeamSkillQuery, *TeamSkillGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *TeamSkillGroupBy) sqlScan(ctx context.Context, root *TeamSkillQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// TeamSkillSelect is the builder for selecting fields of TeamSkill entities. +type TeamSkillSelect struct { + *TeamSkillQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *TeamSkillSelect) Aggregate(fns ...AggregateFunc) *TeamSkillSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *TeamSkillSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TeamSkillQuery, *TeamSkillSelect](ctx, _s.TeamSkillQuery, _s, _s.inters, v) +} + +func (_s *TeamSkillSelect) sqlScan(ctx context.Context, root *TeamSkillQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_s *TeamSkillSelect) Modify(modifiers ...func(s *sql.Selector)) *TeamSkillSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/backend/db/teamskill_update.go b/backend/db/teamskill_update.go new file mode 100644 index 00000000..d9a28374 --- /dev/null +++ b/backend/db/teamskill_update.go @@ -0,0 +1,473 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/skill" + "github.com/chaitin/MonkeyCode/backend/db/team" + "github.com/chaitin/MonkeyCode/backend/db/teamskill" + "github.com/google/uuid" +) + +// TeamSkillUpdate is the builder for updating TeamSkill entities. +type TeamSkillUpdate struct { + config + hooks []Hook + mutation *TeamSkillMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the TeamSkillUpdate builder. +func (_u *TeamSkillUpdate) Where(ps ...predicate.TeamSkill) *TeamSkillUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetTeamID sets the "team_id" field. +func (_u *TeamSkillUpdate) SetTeamID(v uuid.UUID) *TeamSkillUpdate { + _u.mutation.SetTeamID(v) + return _u +} + +// SetNillableTeamID sets the "team_id" field if the given value is not nil. +func (_u *TeamSkillUpdate) SetNillableTeamID(v *uuid.UUID) *TeamSkillUpdate { + if v != nil { + _u.SetTeamID(*v) + } + return _u +} + +// SetSkillID sets the "skill_id" field. +func (_u *TeamSkillUpdate) SetSkillID(v uuid.UUID) *TeamSkillUpdate { + _u.mutation.SetSkillID(v) + return _u +} + +// SetNillableSkillID sets the "skill_id" field if the given value is not nil. +func (_u *TeamSkillUpdate) SetNillableSkillID(v *uuid.UUID) *TeamSkillUpdate { + if v != nil { + _u.SetSkillID(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *TeamSkillUpdate) SetCreatedAt(v time.Time) *TeamSkillUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *TeamSkillUpdate) SetNillableCreatedAt(v *time.Time) *TeamSkillUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetTeam sets the "team" edge to the Team entity. +func (_u *TeamSkillUpdate) SetTeam(v *Team) *TeamSkillUpdate { + return _u.SetTeamID(v.ID) +} + +// SetSkill sets the "skill" edge to the Skill entity. +func (_u *TeamSkillUpdate) SetSkill(v *Skill) *TeamSkillUpdate { + return _u.SetSkillID(v.ID) +} + +// Mutation returns the TeamSkillMutation object of the builder. +func (_u *TeamSkillUpdate) Mutation() *TeamSkillMutation { + return _u.mutation +} + +// ClearTeam clears the "team" edge to the Team entity. +func (_u *TeamSkillUpdate) ClearTeam() *TeamSkillUpdate { + _u.mutation.ClearTeam() + return _u +} + +// ClearSkill clears the "skill" edge to the Skill entity. +func (_u *TeamSkillUpdate) ClearSkill() *TeamSkillUpdate { + _u.mutation.ClearSkill() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *TeamSkillUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TeamSkillUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *TeamSkillUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TeamSkillUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TeamSkillUpdate) check() error { + if _u.mutation.TeamCleared() && len(_u.mutation.TeamIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamSkill.team"`) + } + if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamSkill.skill"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *TeamSkillUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamSkillUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *TeamSkillUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(teamskill.Table, teamskill.Columns, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(teamskill.FieldCreatedAt, field.TypeTime, value) + } + if _u.mutation.TeamCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.TeamTable, + Columns: []string{teamskill.TeamColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.TeamTable, + Columns: []string{teamskill.TeamColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SkillCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.SkillTable, + Columns: []string{teamskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.SkillTable, + Columns: []string{teamskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{teamskill.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// TeamSkillUpdateOne is the builder for updating a single TeamSkill entity. +type TeamSkillUpdateOne struct { + config + fields []string + hooks []Hook + mutation *TeamSkillMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetTeamID sets the "team_id" field. +func (_u *TeamSkillUpdateOne) SetTeamID(v uuid.UUID) *TeamSkillUpdateOne { + _u.mutation.SetTeamID(v) + return _u +} + +// SetNillableTeamID sets the "team_id" field if the given value is not nil. +func (_u *TeamSkillUpdateOne) SetNillableTeamID(v *uuid.UUID) *TeamSkillUpdateOne { + if v != nil { + _u.SetTeamID(*v) + } + return _u +} + +// SetSkillID sets the "skill_id" field. +func (_u *TeamSkillUpdateOne) SetSkillID(v uuid.UUID) *TeamSkillUpdateOne { + _u.mutation.SetSkillID(v) + return _u +} + +// SetNillableSkillID sets the "skill_id" field if the given value is not nil. +func (_u *TeamSkillUpdateOne) SetNillableSkillID(v *uuid.UUID) *TeamSkillUpdateOne { + if v != nil { + _u.SetSkillID(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *TeamSkillUpdateOne) SetCreatedAt(v time.Time) *TeamSkillUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *TeamSkillUpdateOne) SetNillableCreatedAt(v *time.Time) *TeamSkillUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetTeam sets the "team" edge to the Team entity. +func (_u *TeamSkillUpdateOne) SetTeam(v *Team) *TeamSkillUpdateOne { + return _u.SetTeamID(v.ID) +} + +// SetSkill sets the "skill" edge to the Skill entity. +func (_u *TeamSkillUpdateOne) SetSkill(v *Skill) *TeamSkillUpdateOne { + return _u.SetSkillID(v.ID) +} + +// Mutation returns the TeamSkillMutation object of the builder. +func (_u *TeamSkillUpdateOne) Mutation() *TeamSkillMutation { + return _u.mutation +} + +// ClearTeam clears the "team" edge to the Team entity. +func (_u *TeamSkillUpdateOne) ClearTeam() *TeamSkillUpdateOne { + _u.mutation.ClearTeam() + return _u +} + +// ClearSkill clears the "skill" edge to the Skill entity. +func (_u *TeamSkillUpdateOne) ClearSkill() *TeamSkillUpdateOne { + _u.mutation.ClearSkill() + return _u +} + +// Where appends a list predicates to the TeamSkillUpdate builder. +func (_u *TeamSkillUpdateOne) Where(ps ...predicate.TeamSkill) *TeamSkillUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *TeamSkillUpdateOne) Select(field string, fields ...string) *TeamSkillUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated TeamSkill entity. +func (_u *TeamSkillUpdateOne) Save(ctx context.Context) (*TeamSkill, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TeamSkillUpdateOne) SaveX(ctx context.Context) *TeamSkill { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *TeamSkillUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TeamSkillUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TeamSkillUpdateOne) check() error { + if _u.mutation.TeamCleared() && len(_u.mutation.TeamIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamSkill.team"`) + } + if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "TeamSkill.skill"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *TeamSkillUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamSkillUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *TeamSkillUpdateOne) sqlSave(ctx context.Context) (_node *TeamSkill, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(teamskill.Table, teamskill.Columns, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "TeamSkill.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, teamskill.FieldID) + for _, f := range fields { + if !teamskill.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != teamskill.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(teamskill.FieldCreatedAt, field.TypeTime, value) + } + if _u.mutation.TeamCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.TeamTable, + Columns: []string{teamskill.TeamColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.TeamTable, + Columns: []string{teamskill.TeamColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SkillCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.SkillTable, + Columns: []string{teamskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: teamskill.SkillTable, + Columns: []string{teamskill.SkillColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + _node = &TeamSkill{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{teamskill.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/db/tx.go b/backend/db/tx.go index fc355144..b805a2a3 100644 --- a/backend/db/tx.go +++ b/backend/db/tx.go @@ -60,6 +60,8 @@ type Tx struct { ProjectIssueComment *ProjectIssueCommentClient // ProjectTask is the client for interacting with the ProjectTask builders. ProjectTask *ProjectTaskClient + // Skill is the client for interacting with the Skill builders. + Skill *SkillClient // Task is the client for interacting with the Task builders. Task *TaskClient // TaskModelSwitch is the client for interacting with the TaskModelSwitch builders. @@ -80,6 +82,8 @@ type Tx struct { TeamGroupMember *TeamGroupMemberClient // TeamGroupModel is the client for interacting with the TeamGroupModel builders. TeamGroupModel *TeamGroupModelClient + // TeamGroupSkill is the client for interacting with the TeamGroupSkill builders. + TeamGroupSkill *TeamGroupSkillClient // TeamHost is the client for interacting with the TeamHost builders. TeamHost *TeamHostClient // TeamImage is the client for interacting with the TeamImage builders. @@ -90,6 +94,8 @@ type Tx struct { TeamModel *TeamModelClient // TeamOIDCConfig is the client for interacting with the TeamOIDCConfig builders. TeamOIDCConfig *TeamOIDCConfigClient + // TeamSkill is the client for interacting with the TeamSkill builders. + TeamSkill *TeamSkillClient // User is the client for interacting with the User builders. User *UserClient // UserIdentity is the client for interacting with the UserIdentity builders. @@ -250,6 +256,7 @@ func (tx *Tx) init() { tx.ProjectIssue = NewProjectIssueClient(tx.config) tx.ProjectIssueComment = NewProjectIssueCommentClient(tx.config) tx.ProjectTask = NewProjectTaskClient(tx.config) + tx.Skill = NewSkillClient(tx.config) tx.Task = NewTaskClient(tx.config) tx.TaskModelSwitch = NewTaskModelSwitchClient(tx.config) tx.TaskUsageStat = NewTaskUsageStatClient(tx.config) @@ -260,11 +267,13 @@ func (tx *Tx) init() { tx.TeamGroupImage = NewTeamGroupImageClient(tx.config) tx.TeamGroupMember = NewTeamGroupMemberClient(tx.config) tx.TeamGroupModel = NewTeamGroupModelClient(tx.config) + tx.TeamGroupSkill = NewTeamGroupSkillClient(tx.config) tx.TeamHost = NewTeamHostClient(tx.config) tx.TeamImage = NewTeamImageClient(tx.config) tx.TeamMember = NewTeamMemberClient(tx.config) tx.TeamModel = NewTeamModelClient(tx.config) tx.TeamOIDCConfig = NewTeamOIDCConfigClient(tx.config) + tx.TeamSkill = NewTeamSkillClient(tx.config) tx.User = NewUserClient(tx.config) tx.UserIdentity = NewUserIdentityClient(tx.config) tx.VirtualMachine = NewVirtualMachineClient(tx.config) diff --git a/backend/db/user.go b/backend/db/user.go index 36dc2187..ae27db50 100644 --- a/backend/db/user.go +++ b/backend/db/user.go @@ -62,6 +62,8 @@ type UserEdges struct { Models []*Model `json:"models,omitempty"` // Images holds the value of the images edge. Images []*Image `json:"images,omitempty"` + // Skills holds the value of the skills edge. + Skills []*Skill `json:"skills,omitempty"` // Hosts holds the value of the hosts edge. Hosts []*Host `json:"hosts,omitempty"` // Vms holds the value of the vms edge. @@ -94,7 +96,7 @@ type UserEdges struct { GitBotUsers []*GitBotUser `json:"git_bot_users,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [21]bool + loadedTypes [22]bool } // IdentitiesOrErr returns the Identities value or an error if the edge @@ -151,10 +153,19 @@ func (e UserEdges) ImagesOrErr() ([]*Image, error) { return nil, &NotLoadedError{edge: "images"} } +// SkillsOrErr returns the Skills value or an error if the edge +// was not loaded in eager-loading. +func (e UserEdges) SkillsOrErr() ([]*Skill, error) { + if e.loadedTypes[6] { + return e.Skills, nil + } + return nil, &NotLoadedError{edge: "skills"} +} + // HostsOrErr returns the Hosts value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) HostsOrErr() ([]*Host, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.Hosts, nil } return nil, &NotLoadedError{edge: "hosts"} @@ -163,7 +174,7 @@ func (e UserEdges) HostsOrErr() ([]*Host, error) { // VmsOrErr returns the Vms value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) VmsOrErr() ([]*VirtualMachine, error) { - if e.loadedTypes[7] { + if e.loadedTypes[8] { return e.Vms, nil } return nil, &NotLoadedError{edge: "vms"} @@ -172,7 +183,7 @@ func (e UserEdges) VmsOrErr() ([]*VirtualMachine, error) { // TasksOrErr returns the Tasks value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) TasksOrErr() ([]*Task, error) { - if e.loadedTypes[8] { + if e.loadedTypes[9] { return e.Tasks, nil } return nil, &NotLoadedError{edge: "tasks"} @@ -181,7 +192,7 @@ func (e UserEdges) TasksOrErr() ([]*Task, error) { // TaskModelSwitchesOrErr returns the TaskModelSwitches value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) TaskModelSwitchesOrErr() ([]*TaskModelSwitch, error) { - if e.loadedTypes[9] { + if e.loadedTypes[10] { return e.TaskModelSwitches, nil } return nil, &NotLoadedError{edge: "task_model_switches"} @@ -190,7 +201,7 @@ func (e UserEdges) TaskModelSwitchesOrErr() ([]*TaskModelSwitch, error) { // GitIdentitiesOrErr returns the GitIdentities value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) GitIdentitiesOrErr() ([]*GitIdentity, error) { - if e.loadedTypes[10] { + if e.loadedTypes[11] { return e.GitIdentities, nil } return nil, &NotLoadedError{edge: "git_identities"} @@ -199,7 +210,7 @@ func (e UserEdges) GitIdentitiesOrErr() ([]*GitIdentity, error) { // ProjectsOrErr returns the Projects value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) ProjectsOrErr() ([]*Project, error) { - if e.loadedTypes[11] { + if e.loadedTypes[12] { return e.Projects, nil } return nil, &NotLoadedError{edge: "projects"} @@ -208,7 +219,7 @@ func (e UserEdges) ProjectsOrErr() ([]*Project, error) { // ProjectIssuesOrErr returns the ProjectIssues value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) ProjectIssuesOrErr() ([]*ProjectIssue, error) { - if e.loadedTypes[12] { + if e.loadedTypes[13] { return e.ProjectIssues, nil } return nil, &NotLoadedError{edge: "project_issues"} @@ -217,7 +228,7 @@ func (e UserEdges) ProjectIssuesOrErr() ([]*ProjectIssue, error) { // AssignedIssuesOrErr returns the AssignedIssues value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) AssignedIssuesOrErr() ([]*ProjectIssue, error) { - if e.loadedTypes[13] { + if e.loadedTypes[14] { return e.AssignedIssues, nil } return nil, &NotLoadedError{edge: "assigned_issues"} @@ -226,7 +237,7 @@ func (e UserEdges) AssignedIssuesOrErr() ([]*ProjectIssue, error) { // ProjectCollaboratorsOrErr returns the ProjectCollaborators value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) ProjectCollaboratorsOrErr() ([]*ProjectCollaborator, error) { - if e.loadedTypes[14] { + if e.loadedTypes[15] { return e.ProjectCollaborators, nil } return nil, &NotLoadedError{edge: "project_collaborators"} @@ -235,7 +246,7 @@ func (e UserEdges) ProjectCollaboratorsOrErr() ([]*ProjectCollaborator, error) { // ProjectIssueCommentsOrErr returns the ProjectIssueComments value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) ProjectIssueCommentsOrErr() ([]*ProjectIssueComment, error) { - if e.loadedTypes[15] { + if e.loadedTypes[16] { return e.ProjectIssueComments, nil } return nil, &NotLoadedError{edge: "project_issue_comments"} @@ -244,7 +255,7 @@ func (e UserEdges) ProjectIssueCommentsOrErr() ([]*ProjectIssueComment, error) { // GitBotsOrErr returns the GitBots value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) GitBotsOrErr() ([]*GitBot, error) { - if e.loadedTypes[16] { + if e.loadedTypes[17] { return e.GitBots, nil } return nil, &NotLoadedError{edge: "git_bots"} @@ -253,7 +264,7 @@ func (e UserEdges) GitBotsOrErr() ([]*GitBot, error) { // McpUpstreamsOrErr returns the McpUpstreams value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) McpUpstreamsOrErr() ([]*MCPUpstream, error) { - if e.loadedTypes[17] { + if e.loadedTypes[18] { return e.McpUpstreams, nil } return nil, &NotLoadedError{edge: "mcp_upstreams"} @@ -262,7 +273,7 @@ func (e UserEdges) McpUpstreamsOrErr() ([]*MCPUpstream, error) { // TeamMembersOrErr returns the TeamMembers value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) TeamMembersOrErr() ([]*TeamMember, error) { - if e.loadedTypes[18] { + if e.loadedTypes[19] { return e.TeamMembers, nil } return nil, &NotLoadedError{edge: "team_members"} @@ -271,7 +282,7 @@ func (e UserEdges) TeamMembersOrErr() ([]*TeamMember, error) { // TeamGroupMembersOrErr returns the TeamGroupMembers value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) { - if e.loadedTypes[19] { + if e.loadedTypes[20] { return e.TeamGroupMembers, nil } return nil, &NotLoadedError{edge: "team_group_members"} @@ -280,7 +291,7 @@ func (e UserEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) { // GitBotUsersOrErr returns the GitBotUsers value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) GitBotUsersOrErr() ([]*GitBotUser, error) { - if e.loadedTypes[20] { + if e.loadedTypes[21] { return e.GitBotUsers, nil } return nil, &NotLoadedError{edge: "git_bot_users"} @@ -433,6 +444,11 @@ func (_m *User) QueryImages() *ImageQuery { return NewUserClient(_m.config).QueryImages(_m) } +// QuerySkills queries the "skills" edge of the User entity. +func (_m *User) QuerySkills() *SkillQuery { + return NewUserClient(_m.config).QuerySkills(_m) +} + // QueryHosts queries the "hosts" edge of the User entity. func (_m *User) QueryHosts() *HostQuery { return NewUserClient(_m.config).QueryHosts(_m) diff --git a/backend/db/user/user.go b/backend/db/user/user.go index 0af0a2fc..fcd5af6d 100644 --- a/backend/db/user/user.go +++ b/backend/db/user/user.go @@ -49,6 +49,8 @@ const ( EdgeModels = "models" // EdgeImages holds the string denoting the images edge name in mutations. EdgeImages = "images" + // EdgeSkills holds the string denoting the skills edge name in mutations. + EdgeSkills = "skills" // EdgeHosts holds the string denoting the hosts edge name in mutations. EdgeHosts = "hosts" // EdgeVms holds the string denoting the vms edge name in mutations. @@ -119,6 +121,13 @@ const ( ImagesInverseTable = "images" // ImagesColumn is the table column denoting the images relation/edge. ImagesColumn = "user_id" + // SkillsTable is the table that holds the skills relation/edge. + SkillsTable = "skills" + // SkillsInverseTable is the table name for the Skill entity. + // It exists in this package in order to avoid circular dependency with the "skill" package. + SkillsInverseTable = "skills" + // SkillsColumn is the table column denoting the skills relation/edge. + SkillsColumn = "user_id" // HostsTable is the table that holds the hosts relation/edge. HostsTable = "hosts" // HostsInverseTable is the table name for the Host entity. @@ -424,6 +433,20 @@ func ByImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// BySkillsCount orders the results by skills count. +func BySkillsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newSkillsStep(), opts...) + } +} + +// BySkills orders the results by skills terms. +func BySkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSkillsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByHostsCount orders the results by hosts count. func ByHostsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -675,6 +698,13 @@ func newImagesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, ImagesTable, ImagesColumn), ) } +func newSkillsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SkillsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, SkillsTable, SkillsColumn), + ) +} func newHostsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/backend/db/user/where.go b/backend/db/user/where.go index 984ece12..943eb4f0 100644 --- a/backend/db/user/where.go +++ b/backend/db/user/where.go @@ -855,6 +855,29 @@ func HasImagesWith(preds ...predicate.Image) predicate.User { }) } +// HasSkills applies the HasEdge predicate on the "skills" edge. +func HasSkills() predicate.User { + return predicate.User(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, SkillsTable, SkillsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSkillsWith applies the HasEdge predicate on the "skills" edge with a given conditions (other predicates). +func HasSkillsWith(preds ...predicate.Skill) predicate.User { + return predicate.User(func(s *sql.Selector) { + step := newSkillsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasHosts applies the HasEdge predicate on the "hosts" edge. func HasHosts() predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/backend/db/user_create.go b/backend/db/user_create.go index f4a502c9..7c7d8d59 100644 --- a/backend/db/user_create.go +++ b/backend/db/user_create.go @@ -25,6 +25,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectcollaborator" "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/team" @@ -263,6 +264,21 @@ func (_c *UserCreate) AddImages(v ...*Image) *UserCreate { return _c.AddImageIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_c *UserCreate) AddSkillIDs(ids ...uuid.UUID) *UserCreate { + _c.mutation.AddSkillIDs(ids...) + return _c +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_c *UserCreate) AddSkills(v ...*Skill) *UserCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddSkillIDs(ids...) +} + // AddHostIDs adds the "hosts" edge to the Host entity by IDs. func (_c *UserCreate) AddHostIDs(ids ...string) *UserCreate { _c.mutation.AddHostIDs(ids...) @@ -755,6 +771,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.HostsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/backend/db/user_query.go b/backend/db/user_query.go index ec5367d1..9c5a47f4 100644 --- a/backend/db/user_query.go +++ b/backend/db/user_query.go @@ -26,6 +26,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectcollaborator" "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/team" @@ -51,6 +52,7 @@ type UserQuery struct { withGroups *TeamGroupQuery withModels *ModelQuery withImages *ImageQuery + withSkills *SkillQuery withHosts *HostQuery withVms *VirtualMachineQuery withTasks *TaskQuery @@ -235,6 +237,28 @@ func (_q *UserQuery) QueryImages() *ImageQuery { return query } +// QuerySkills chains the current query on the "skills" edge. +func (_q *UserQuery) QuerySkills() *SkillQuery { + query := (&SkillClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(user.Table, user.FieldID, selector), + sqlgraph.To(skill.Table, skill.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.SkillsTable, user.SkillsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryHosts chains the current query on the "hosts" edge. func (_q *UserQuery) QueryHosts() *HostQuery { query := (&HostClient{config: _q.config}).Query() @@ -763,6 +787,7 @@ func (_q *UserQuery) Clone() *UserQuery { withGroups: _q.withGroups.Clone(), withModels: _q.withModels.Clone(), withImages: _q.withImages.Clone(), + withSkills: _q.withSkills.Clone(), withHosts: _q.withHosts.Clone(), withVms: _q.withVms.Clone(), withTasks: _q.withTasks.Clone(), @@ -851,6 +876,17 @@ func (_q *UserQuery) WithImages(opts ...func(*ImageQuery)) *UserQuery { return _q } +// WithSkills tells the query-builder to eager-load the nodes that are connected to +// the "skills" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *UserQuery) WithSkills(opts ...func(*SkillQuery)) *UserQuery { + query := (&SkillClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSkills = query + return _q +} + // WithHosts tells the query-builder to eager-load the nodes that are connected to // the "hosts" edge. The optional arguments are used to configure the query builder of the edge. func (_q *UserQuery) WithHosts(opts ...func(*HostQuery)) *UserQuery { @@ -1094,13 +1130,14 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e var ( nodes = []*User{} _spec = _q.querySpec() - loadedTypes = [21]bool{ + loadedTypes = [22]bool{ _q.withIdentities != nil, _q.withAudits != nil, _q.withTeams != nil, _q.withGroups != nil, _q.withModels != nil, _q.withImages != nil, + _q.withSkills != nil, _q.withHosts != nil, _q.withVms != nil, _q.withTasks != nil, @@ -1181,6 +1218,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e return nil, err } } + if query := _q.withSkills; query != nil { + if err := _q.loadSkills(ctx, query, nodes, + func(n *User) { n.Edges.Skills = []*Skill{} }, + func(n *User, e *Skill) { n.Edges.Skills = append(n.Edges.Skills, e) }); err != nil { + return nil, err + } + } if query := _q.withHosts; query != nil { if err := _q.loadHosts(ctx, query, nodes, func(n *User) { n.Edges.Hosts = []*Host{} }, @@ -1535,6 +1579,36 @@ func (_q *UserQuery) loadImages(ctx context.Context, query *ImageQuery, nodes [] } return nil } +func (_q *UserQuery) loadSkills(ctx context.Context, query *SkillQuery, nodes []*User, init func(*User), assign func(*User, *Skill)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*User) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(skill.FieldUserID) + } + query.Where(predicate.Skill(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(user.SkillsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.UserID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *UserQuery) loadHosts(ctx context.Context, query *HostQuery, nodes []*User, init func(*User), assign func(*User, *Host)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[uuid.UUID]*User) diff --git a/backend/db/user_update.go b/backend/db/user_update.go index 3cc5121f..2e95d115 100644 --- a/backend/db/user_update.go +++ b/backend/db/user_update.go @@ -25,6 +25,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/projectcollaborator" "github.com/chaitin/MonkeyCode/backend/db/projectissue" "github.com/chaitin/MonkeyCode/backend/db/projectissuecomment" + "github.com/chaitin/MonkeyCode/backend/db/skill" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" "github.com/chaitin/MonkeyCode/backend/db/team" @@ -309,6 +310,21 @@ func (_u *UserUpdate) AddImages(v ...*Image) *UserUpdate { return _u.AddImageIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_u *UserUpdate) AddSkillIDs(ids ...uuid.UUID) *UserUpdate { + _u.mutation.AddSkillIDs(ids...) + return _u +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_u *UserUpdate) AddSkills(v ...*Skill) *UserUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddSkillIDs(ids...) +} + // AddHostIDs adds the "hosts" edge to the Host entity by IDs. func (_u *UserUpdate) AddHostIDs(ids ...string) *UserUpdate { _u.mutation.AddHostIDs(ids...) @@ -665,6 +681,27 @@ func (_u *UserUpdate) RemoveImages(v ...*Image) *UserUpdate { return _u.RemoveImageIDs(ids...) } +// ClearSkills clears all "skills" edges to the Skill entity. +func (_u *UserUpdate) ClearSkills() *UserUpdate { + _u.mutation.ClearSkills() + return _u +} + +// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs. +func (_u *UserUpdate) RemoveSkillIDs(ids ...uuid.UUID) *UserUpdate { + _u.mutation.RemoveSkillIDs(ids...) + return _u +} + +// RemoveSkills removes "skills" edges to Skill entities. +func (_u *UserUpdate) RemoveSkills(v ...*Skill) *UserUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveSkillIDs(ids...) +} + // ClearHosts clears all "hosts" edges to the Host entity. func (_u *UserUpdate) ClearHosts() *UserUpdate { _u.mutation.ClearHosts() @@ -1392,6 +1429,51 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.HostsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -2368,6 +2450,21 @@ func (_u *UserUpdateOne) AddImages(v ...*Image) *UserUpdateOne { return _u.AddImageIDs(ids...) } +// AddSkillIDs adds the "skills" edge to the Skill entity by IDs. +func (_u *UserUpdateOne) AddSkillIDs(ids ...uuid.UUID) *UserUpdateOne { + _u.mutation.AddSkillIDs(ids...) + return _u +} + +// AddSkills adds the "skills" edges to the Skill entity. +func (_u *UserUpdateOne) AddSkills(v ...*Skill) *UserUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddSkillIDs(ids...) +} + // AddHostIDs adds the "hosts" edge to the Host entity by IDs. func (_u *UserUpdateOne) AddHostIDs(ids ...string) *UserUpdateOne { _u.mutation.AddHostIDs(ids...) @@ -2724,6 +2821,27 @@ func (_u *UserUpdateOne) RemoveImages(v ...*Image) *UserUpdateOne { return _u.RemoveImageIDs(ids...) } +// ClearSkills clears all "skills" edges to the Skill entity. +func (_u *UserUpdateOne) ClearSkills() *UserUpdateOne { + _u.mutation.ClearSkills() + return _u +} + +// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs. +func (_u *UserUpdateOne) RemoveSkillIDs(ids ...uuid.UUID) *UserUpdateOne { + _u.mutation.RemoveSkillIDs(ids...) + return _u +} + +// RemoveSkills removes "skills" edges to Skill entities. +func (_u *UserUpdateOne) RemoveSkills(v ...*Skill) *UserUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveSkillIDs(ids...) +} + // ClearHosts clears all "hosts" edges to the Host entity. func (_u *UserUpdateOne) ClearHosts() *UserUpdateOne { _u.mutation.ClearHosts() @@ -3481,6 +3599,51 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.SkillsTable, + Columns: []string{user.SkillsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.HostsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index be5b4de9..0f05dfa2 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -2051,6 +2051,350 @@ } } }, + "/api/v1/teams/skills": { + "get": { + "security": [ + { + "MonkeyCodeAITeamAuth": [] + } + ], + "description": "获取团队 Skill 列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "【Team 管理员】Skill 管理" + ], + "summary": "获取团队 Skill 列表", + "responses": { + "200": { + "description": "成功", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.Resp" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/domain.ListTeamSkillsResp" + } + } + } + ] + } + }, + "401": { + "description": "未授权", + "schema": { + "$ref": "#/definitions/web.Resp" + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + }, + "post": { + "security": [ + { + "MonkeyCodeAITeamAuth": [] + } + ], + "description": "添加团队 Skill", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "【Team 管理员】Skill 管理" + ], + "summary": "添加团队 Skill", + "parameters": [ + { + "description": "请求参数", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.AddTeamSkillReq" + } + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.Resp" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/domain.TeamSkill" + } + } + } + ] + } + }, + "401": { + "description": "未授权", + "schema": { + "$ref": "#/definitions/web.Resp" + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + } + }, + "/api/v1/teams/skills/package": { + "post": { + "security": [ + { + "MonkeyCodeAITeamAuth": [] + } + ], + "description": "上传团队 Skill zip 包", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "【Team 管理员】Skill 管理" + ], + "summary": "上传团队 Skill zip 包", + "parameters": [ + { + "type": "string", + "description": "Skill 名称", + "name": "name", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "Skill 描述", + "name": "description", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "JSON 字符串数组", + "name": "tags", + "in": "formData" + }, + { + "type": "string", + "description": "SKILL.md 原文", + "name": "content", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "JSON 字符串数组", + "name": "group_ids", + "in": "formData" + }, + { + "type": "string", + "description": "来源类型", + "name": "source_type", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "来源标签", + "name": "source_label", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "zip 内 SKILL.md 路径", + "name": "skill_md_path", + "in": "formData" + }, + { + "type": "file", + "description": "Skill zip 包", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.Resp" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/domain.TeamSkill" + } + } + } + ] + } + }, + "401": { + "description": "未授权", + "schema": { + "$ref": "#/definitions/web.Resp" + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + } + }, + "/api/v1/teams/skills/{skill_id}": { + "put": { + "security": [ + { + "MonkeyCodeAITeamAuth": [] + } + ], + "description": "更新团队 Skill", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "【Team 管理员】Skill 管理" + ], + "summary": "更新团队 Skill", + "parameters": [ + { + "type": "string", + "description": "Skill ID", + "name": "skill_id", + "in": "path", + "required": true + }, + { + "description": "请求参数", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.UpdateTeamSkillReq" + } + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.Resp" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/domain.TeamSkill" + } + } + } + ] + } + }, + "401": { + "description": "未授权", + "schema": { + "$ref": "#/definitions/web.Resp" + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + }, + "delete": { + "security": [ + { + "MonkeyCodeAITeamAuth": [] + } + ], + "description": "删除团队 Skill", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "【Team 管理员】Skill 管理" + ], + "summary": "删除团队 Skill", + "parameters": [ + { + "type": "string", + "description": "Skill ID", + "name": "skill_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/web.Resp" + } + }, + "401": { + "description": "未授权", + "schema": { + "$ref": "#/definitions/web.Resp" + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + } + }, "/api/v1/teams/task-vm-idle-policy": { "get": { "security": [ @@ -9179,14 +9523,6 @@ "x-enum-comments": { "UserPlatformBaizhi": "百智云平台" }, - "x-enum-descriptions": [ - "百智云平台", - "", - "", - "", - "", - "" - ], "x-enum-varnames": [ "UserPlatformBaizhi", "UserPlatformGithub", @@ -9212,13 +9548,6 @@ "UserRoleIndividual": "个人用户", "UserRoleSubAccount": "企业子账户" }, - "x-enum-descriptions": [ - "个人用户", - "企业用户", - "企业子账户", - "MonkeyCode-AI 管理员账号,用来配置公共资源. 如公共宿主机等", - "全自动 git 任务插入的用户" - ], "x-enum-varnames": [ "UserRoleIndividual", "UserRoleEnterprise", @@ -9436,6 +9765,48 @@ } } }, + "domain.AddTeamSkillReq": { + "type": "object", + "required": [ + "content", + "description", + "name", + "source_label", + "source_type" + ], + "properties": { + "content": { + "type": "string" + }, + "description": { + "type": "string" + }, + "group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "name": { + "type": "string" + }, + "skill_md_path": { + "type": "string" + }, + "source_label": { + "type": "string" + }, + "source_type": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "domain.AddTeamUserReq": { "type": "object", "required": [ @@ -10525,6 +10896,17 @@ } } }, + "domain.ListTeamSkillsResp": { + "type": "object", + "properties": { + "skills": { + "type": "array", + "items": { + "$ref": "#/definitions/domain.TeamSkill" + } + } + } + }, "domain.ListUserMCPUpstreamsResp": { "type": "object", "properties": { @@ -12317,6 +12699,56 @@ } } }, + "domain.TeamSkill": { + "type": "object", + "properties": { + "content": { + "type": "string" + }, + "created_at": { + "type": "integer" + }, + "description": { + "type": "string" + }, + "groups": { + "type": "array", + "items": { + "$ref": "#/definitions/domain.TeamGroup" + } + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "package_object_key": { + "type": "string" + }, + "package_url": { + "type": "string" + }, + "skill_md_path": { + "type": "string" + }, + "source_label": { + "type": "string" + }, + "source_type": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "updated_at": { + "type": "integer" + } + } + }, "domain.TeamTaskItem": { "type": "object", "properties": { @@ -12772,6 +13204,41 @@ } } }, + "domain.UpdateTeamSkillReq": { + "type": "object", + "properties": { + "content": { + "type": "string" + }, + "description": { + "type": "string" + }, + "group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "name": { + "type": "string" + }, + "skill_md_path": { + "type": "string" + }, + "source_label": { + "type": "string" + }, + "source_type": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "domain.UpdateTeamTaskVMIdlePolicyReq": { "type": "object", "properties": { @@ -13209,7 +13676,6 @@ }, "types.ConditionStatus": { "type": "integer", - "format": "int32", "enum": [ 0, 1, diff --git a/backend/domain/team_skill.go b/backend/domain/team_skill.go new file mode 100644 index 00000000..23f91cf3 --- /dev/null +++ b/backend/domain/team_skill.go @@ -0,0 +1,103 @@ +package domain + +import ( + "context" + + "github.com/google/uuid" + + "github.com/chaitin/MonkeyCode/backend/db" + "github.com/chaitin/MonkeyCode/backend/pkg/cvt" +) + +type TeamSkillUsecase interface { + Add(ctx context.Context, teamUser *TeamUser, req *AddTeamSkillReq) (*TeamSkill, error) + AddPackage(ctx context.Context, teamUser *TeamUser, req *AddTeamSkillPackageReq) (*TeamSkill, error) + List(ctx context.Context, teamUser *TeamUser) (*ListTeamSkillsResp, error) + Update(ctx context.Context, teamUser *TeamUser, req *UpdateTeamSkillReq) (*TeamSkill, error) + Delete(ctx context.Context, teamUser *TeamUser, req *DeleteTeamSkillReq) error +} + +type TeamSkillRepo interface { + List(ctx context.Context, teamID uuid.UUID) ([]*db.Skill, error) + Create(ctx context.Context, teamID, userID uuid.UUID, req *AddTeamSkillReq) (*db.Skill, error) + Update(ctx context.Context, teamID uuid.UUID, req *UpdateTeamSkillReq) (*db.Skill, error) + Delete(ctx context.Context, teamID, skillID uuid.UUID) error +} + +type TeamSkill struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Tags []string `json:"tags"` + Content string `json:"content"` + PackageKey string `json:"package_object_key,omitempty"` + PackageURL string `json:"package_url,omitempty"` + Groups []*TeamGroup `json:"groups"` + SourceType string `json:"source_type"` + SourceLabel string `json:"source_label"` + SkillMDPath string `json:"skill_md_path,omitempty"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +func (t *TeamSkill) From(src *db.Skill) *TeamSkill { + if src == nil { + return t + } + + t.ID = src.ID + t.Name = src.Name + t.Description = src.Description + t.Tags = src.Tags + t.Content = src.Content + t.PackageKey = src.PackageObjectKey + t.PackageURL = src.PackageURL + t.SourceType = src.SourceType + t.SourceLabel = src.SourceLabel + t.SkillMDPath = src.SkillMdPath + t.Groups = cvt.Iter(src.Edges.Groups, func(_ int, g *db.TeamGroup) *TeamGroup { + return cvt.From(g, &TeamGroup{}) + }) + t.CreatedAt = src.CreatedAt.Unix() + t.UpdatedAt = src.UpdatedAt.Unix() + return t +} + +type AddTeamSkillReq struct { + Name string `json:"name" form:"name" validate:"required"` + Description string `json:"description" form:"description" validate:"required"` + Tags []string `json:"tags" validate:"omitempty"` + Content string `json:"content" form:"content" validate:"required"` + PackageObjectKey string `json:"package_object_key,omitempty" swaggerignore:"true"` + PackageURL string `json:"package_url,omitempty" swaggerignore:"true"` + GroupIDs []uuid.UUID `json:"group_ids" validate:"omitempty"` + SourceType string `json:"source_type" form:"source_type" validate:"required"` + SourceLabel string `json:"source_label" form:"source_label" validate:"required"` + SkillMDPath string `json:"skill_md_path" form:"skill_md_path" validate:"omitempty"` +} + +type AddTeamSkillPackageReq struct { + AddTeamSkillReq + PackageFilename string `json:"-" swaggerignore:"true"` + PackageData []byte `json:"-" swaggerignore:"true"` +} + +type ListTeamSkillsResp struct { + Skills []*TeamSkill `json:"skills"` +} + +type UpdateTeamSkillReq struct { + SkillID uuid.UUID `param:"skill_id" validate:"required" json:"-" swaggerignore:"true"` + Name string `json:"name" validate:"omitempty"` + Description string `json:"description" validate:"omitempty"` + Tags []string `json:"tags" validate:"omitempty"` + Content string `json:"content" validate:"omitempty"` + GroupIDs []uuid.UUID `json:"group_ids" validate:"omitempty"` + SourceType string `json:"source_type" validate:"omitempty"` + SourceLabel string `json:"source_label" validate:"omitempty"` + SkillMDPath *string `json:"skill_md_path,omitempty" validate:"omitempty"` +} + +type DeleteTeamSkillReq struct { + SkillID uuid.UUID `param:"skill_id" validate:"required" json:"-" swaggerignore:"true"` +} diff --git a/backend/ent/schema/skill.go b/backend/ent/schema/skill.go new file mode 100644 index 00000000..2a4729a5 --- /dev/null +++ b/backend/ent/schema/skill.go @@ -0,0 +1,57 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + + "github.com/chaitin/MonkeyCode/backend/pkg/entx" +) + +type Skill struct { + ent.Schema +} + +func (Skill) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Table("skills"), + entx.NewCursor(entx.CursorKindCreatedAt), + } +} + +func (Skill) Mixin() []ent.Mixin { + return []ent.Mixin{ + entx.SoftDeleteMixin2{}, + } +} + +func (Skill) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}).Unique(), + field.UUID("user_id", uuid.UUID{}), + field.String("name").NotEmpty(), + field.Text("description").NotEmpty(), + field.JSON("tags", []string{}).Optional(), + field.Text("content").NotEmpty(), + field.String("package_object_key").Optional(), + field.String("package_url").Optional(), + field.String("source_type").NotEmpty(), + field.String("source_label").NotEmpty(), + field.String("skill_md_path").Optional(), + field.Time("created_at").Default(time.Now), + field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), + } +} + +func (Skill) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("user", User.Type).Ref("skills").Field("user_id").Unique().Required(), + edge.From("teams", Team.Type).Ref("skills").Through("team_skills", TeamSkill.Type), + edge.From("groups", TeamGroup.Type).Ref("skills").Through("team_group_skills", TeamGroupSkill.Type), + } +} diff --git a/backend/ent/schema/team.go b/backend/ent/schema/team.go index 0c5d6e33..237c119e 100644 --- a/backend/ent/schema/team.go +++ b/backend/ent/schema/team.go @@ -52,5 +52,6 @@ func (Team) Edges() []ent.Edge { edge.From("members", User.Type).Ref("teams").Through("team_members", TeamMember.Type), edge.To("models", Model.Type).Through("team_models", TeamModel.Type), edge.To("images", Image.Type).Through("team_images", TeamImage.Type), + edge.To("skills", Skill.Type).Through("team_skills", TeamSkill.Type), } } diff --git a/backend/ent/schema/teamgroup.go b/backend/ent/schema/teamgroup.go index bb4a8f27..4a8722b1 100644 --- a/backend/ent/schema/teamgroup.go +++ b/backend/ent/schema/teamgroup.go @@ -50,5 +50,6 @@ func (TeamGroup) Edges() []ent.Edge { edge.To("models", Model.Type).Through("team_group_models", TeamGroupModel.Type), edge.To("images", Image.Type).Through("team_group_images", TeamGroupImage.Type), edge.To("hosts", Host.Type).Through("team_group_hosts", TeamGroupHost.Type), + edge.To("skills", Skill.Type).Through("team_group_skills", TeamGroupSkill.Type), } } diff --git a/backend/ent/schema/teamgroupskill.go b/backend/ent/schema/teamgroupskill.go new file mode 100644 index 00000000..1e8201bc --- /dev/null +++ b/backend/ent/schema/teamgroupskill.go @@ -0,0 +1,41 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + + "github.com/chaitin/MonkeyCode/backend/pkg/entx" +) + +type TeamGroupSkill struct { + ent.Schema +} + +func (TeamGroupSkill) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Table("team_group_skills"), + entx.NewCursor(entx.CursorKindCreatedAt), + } +} + +func (TeamGroupSkill) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}).Unique(), + field.UUID("group_id", uuid.UUID{}), + field.UUID("skill_id", uuid.UUID{}), + field.Time("created_at").Default(time.Now), + } +} + +func (TeamGroupSkill) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("group", TeamGroup.Type).Field("group_id").Unique().Required(), + edge.To("skill", Skill.Type).Field("skill_id").Unique().Required(), + } +} diff --git a/backend/ent/schema/teamskill.go b/backend/ent/schema/teamskill.go new file mode 100644 index 00000000..ed30a80b --- /dev/null +++ b/backend/ent/schema/teamskill.go @@ -0,0 +1,38 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +type TeamSkill struct { + ent.Schema +} + +func (TeamSkill) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Table("team_skills"), + } +} + +func (TeamSkill) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}), + field.UUID("team_id", uuid.UUID{}), + field.UUID("skill_id", uuid.UUID{}), + field.Time("created_at").Default(time.Now), + } +} + +func (TeamSkill) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("team", Team.Type).Field("team_id").Unique().Required(), + edge.To("skill", Skill.Type).Field("skill_id").Unique().Required(), + } +} diff --git a/backend/ent/schema/user.go b/backend/ent/schema/user.go index be079778..db66d99e 100644 --- a/backend/ent/schema/user.go +++ b/backend/ent/schema/user.go @@ -57,6 +57,7 @@ func (User) Edges() []ent.Edge { edge.To("groups", TeamGroup.Type).Through("team_group_members", TeamGroupMember.Type), edge.To("models", Model.Type), edge.To("images", Image.Type), + edge.To("skills", Skill.Type), edge.To("hosts", Host.Type), edge.To("vms", VirtualMachine.Type), edge.To("tasks", Task.Type), diff --git a/backend/migration/000016_team_skills.down.sql b/backend/migration/000016_team_skills.down.sql new file mode 100644 index 00000000..11c0b62d --- /dev/null +++ b/backend/migration/000016_team_skills.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS team_group_skills; +DROP TABLE IF EXISTS team_skills; +DROP TABLE IF EXISTS skills; diff --git a/backend/migration/000016_team_skills.up.sql b/backend/migration/000016_team_skills.up.sql new file mode 100644 index 00000000..17e83639 --- /dev/null +++ b/backend/migration/000016_team_skills.up.sql @@ -0,0 +1,38 @@ +CREATE TABLE IF NOT EXISTS skills ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + deleted_at timestamp with time zone, + user_id uuid NOT NULL, + name character varying NOT NULL, + description text NOT NULL, + tags jsonb, + content text NOT NULL, + package_object_key character varying, + package_url character varying, + source_type character varying NOT NULL, + source_label character varying NOT NULL, + skill_md_path character varying, + created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_skills_created_at_id ON skills USING btree (created_at, id); +CREATE INDEX IF NOT EXISTS idx_skills_user_id ON skills USING btree (user_id); + +CREATE TABLE IF NOT EXISTS team_skills ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + team_id uuid NOT NULL, + skill_id uuid NOT NULL, + created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS unique_idx_team_skills_team_skill ON team_skills USING btree (team_id, skill_id); + +CREATE TABLE IF NOT EXISTS team_group_skills ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + group_id uuid NOT NULL, + skill_id uuid NOT NULL, + created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_team_group_skills_created_at_id ON team_group_skills USING btree (created_at, id); +CREATE UNIQUE INDEX IF NOT EXISTS unique_idx_team_group_skills_group_skill ON team_group_skills USING btree (group_id, skill_id); diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts index 84d58f9f..9c504140 100644 --- a/frontend/src/api/Api.ts +++ b/frontend/src/api/Api.ts @@ -271,6 +271,29 @@ export interface DomainAddTeamImageReq { remark?: string; } +export interface DomainAddTeamSkillReq { + content: string; + description: string; + group_ids?: string[]; + name: string; + skill_md_path?: string; + source_label: string; + source_type: string; + tags?: string[]; +} + +export interface DomainAddTeamSkillPackageReq { + content: string; + description: string; + file: File; + group_ids?: string; + name: string; + skill_md_path?: string; + source_label: string; + source_type: string; + tags?: string; +} + export interface DomainAddTeamModelReq { api_key: string; base_url: string; @@ -837,6 +860,10 @@ export interface DomainListTeamImagesResp { images?: DomainTeamImage[]; } +export interface DomainListTeamSkillsResp { + skills?: DomainTeamSkill[]; +} + export interface DomainListTeamModelsResp { models?: DomainTeamModel[]; } @@ -1690,6 +1717,22 @@ export interface DomainTeamImage { updated_at?: number; } +export interface DomainTeamSkill { + content?: string; + created_at?: number; + description?: string; + groups?: DomainTeamGroup[]; + id?: string; + name?: string; + package_object_key?: string; + package_url?: string; + skill_md_path?: string; + source_label?: string; + source_type?: string; + tags?: string[]; + updated_at?: number; +} + export interface DomainTeamLoginReq { /** 验证码Token */ captcha_token: string; @@ -1898,6 +1941,17 @@ export interface DomainUpdateTeamImageReq { remark?: string; } +export interface DomainUpdateTeamSkillReq { + content?: string; + description?: string; + group_ids?: string[]; + name?: string; + skill_md_path?: string; + source_label?: string; + source_type?: string; + tags?: string[]; +} + export interface DomainUpdateTeamModelReq { api_key?: string; base_url?: string; @@ -3518,6 +3572,124 @@ export class Api extends HttpClient + this.request< + GithubComGoYokoWebResp & { + data?: DomainListTeamSkillsResp; + }, + GithubComGoYokoWebResp + >({ + path: `/api/v1/teams/skills`, + method: "GET", + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + + /** + * @description 添加团队 Skill + * + * @tags 【Team 管理员】Skill 管理 + * @name V1TeamsSkillsCreate + * @summary 添加团队 Skill + * @request POST:/api/v1/teams/skills + * @secure + */ + v1TeamsSkillsCreate: (req: DomainAddTeamSkillReq, params: RequestParams = {}) => + this.request< + GithubComGoYokoWebResp & { + data?: DomainTeamSkill; + }, + GithubComGoYokoWebResp + >({ + path: `/api/v1/teams/skills`, + method: "POST", + body: req, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + + /** + * @description 上传团队 Skill zip 包 + * + * @tags 【Team 管理员】Skill 管理 + * @name V1TeamsSkillsPackageCreate + * @summary 上传团队 Skill zip 包 + * @request POST:/api/v1/teams/skills/package + * @secure + */ + v1TeamsSkillsPackageCreate: (req: DomainAddTeamSkillPackageReq, params: RequestParams = {}) => + this.request< + GithubComGoYokoWebResp & { + data?: DomainTeamSkill; + }, + GithubComGoYokoWebResp + >({ + path: `/api/v1/teams/skills/package`, + method: "POST", + body: req, + secure: true, + type: ContentType.FormData, + format: "json", + ...params, + }), + + /** + * @description 更新团队 Skill + * + * @tags 【Team 管理员】Skill 管理 + * @name V1TeamsSkillsUpdate + * @summary 更新团队 Skill + * @request PUT:/api/v1/teams/skills/{skill_id} + * @secure + */ + v1TeamsSkillsUpdate: (skillId: string, req: DomainUpdateTeamSkillReq, params: RequestParams = {}) => + this.request< + GithubComGoYokoWebResp & { + data?: DomainTeamSkill; + }, + GithubComGoYokoWebResp + >({ + path: `/api/v1/teams/skills/${skillId}`, + method: "PUT", + body: req, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + + /** + * @description 删除团队 Skill + * + * @tags 【Team 管理员】Skill 管理 + * @name V1TeamsSkillsDelete + * @summary 删除团队 Skill + * @request DELETE:/api/v1/teams/skills/{skill_id} + * @secure + */ + v1TeamsSkillsDelete: (skillId: string, params: RequestParams = {}) => + this.request({ + path: `/api/v1/teams/skills/${skillId}`, + method: "DELETE", + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + /** * @description 获取当前团队企业登录 OIDC 配置 * diff --git a/frontend/src/pages/console/manager/skills.tsx b/frontend/src/pages/console/manager/skills.tsx index d5f8ad2e..74e7da39 100644 --- a/frontend/src/pages/console/manager/skills.tsx +++ b/frontend/src/pages/console/manager/skills.tsx @@ -11,7 +11,7 @@ import { import { IconPencil, IconTrash } from "@tabler/icons-react" import { toast } from "sonner" -import type { DomainTeamGroup } from "@/api/Api" +import { Api, type DomainTeamGroup, type DomainTeamSkill } from "@/api/Api" import { findSkillMarkdownPath, normalizeSkillTags, @@ -97,9 +97,26 @@ interface SkillSourceState { export default function TeamManagerSkills() { const [skills, setSkills] = useState([]) + const [loading, setLoading] = useState(true) const [addDialogOpen, setAddDialogOpen] = useState(false) const [editingSkill, setEditingSkill] = useState(null) + const fetchSkills = async () => { + setLoading(true) + await apiRequest("v1TeamsSkillsList", {}, [], (resp) => { + if (resp.code === 0) { + setSkills((resp.data?.skills || []).map(toManagedSkill)) + return + } + toast.error(resp.message || "获取 Skill 列表失败") + }) + setLoading(false) + } + + useEffect(() => { + void fetchSkills() + }, []) + const handleCreate = (skill: ManagedSkill) => { setSkills((prev) => [skill, ...prev]) } @@ -109,8 +126,14 @@ export default function TeamManagerSkills() { } const handleDelete = (skillID: string) => { - setSkills((prev) => prev.filter((skill) => skill.id !== skillID)) - toast.success("Skill 已删除") + void apiRequest("v1TeamsSkillsDelete", {}, [skillID], (resp) => { + if (resp.code === 0) { + setSkills((prev) => prev.filter((skill) => skill.id !== skillID)) + toast.success("Skill 已删除") + return + } + toast.error(resp.message || "删除 Skill 失败") + }) } return ( @@ -133,7 +156,16 @@ export default function TeamManagerSkills() { - {skills.length === 0 ? ( + {loading ? ( + + + + + + 正在加载 Skills + + + ) : skills.length === 0 ? ( @@ -260,6 +292,7 @@ function AddSkillDialog({ const [parsing, setParsing] = useState(false) const [parseError, setParseError] = useState("") const [pastedText, setPastedText] = useState("") + const [packageFile, setPackageFile] = useState(null) const [source, setSource] = useState(null) const [draft, setDraft] = useState(null) const [name, setName] = useState("") @@ -280,6 +313,7 @@ function AddSkillDialog({ setParsing(false) setParseError("") setPastedText("") + setPackageFile(null) setSource(null) setDraft(null) setName("") @@ -312,10 +346,12 @@ function AddSkillDialog({ setParsing(true) try { const parsedFile = await parseSkillFile(file) + setPackageFile(parsedFile.source.type === "zip" ? file : null) applyParsedSkill(parsedFile.parsed, parsedFile.source) } catch (error) { const message = error instanceof Error ? error.message : "Skill 文件解析失败" setDraft(null) + setPackageFile(null) setSource(null) setParseError(message) toast.error(message) @@ -329,12 +365,14 @@ function AddSkillDialog({ if (!value.trim()) { setDraft(null) + setPackageFile(null) setSource(null) setParseError("") return } try { + setPackageFile(null) applyParsedSkill(parseSkillMarkdown(value), { type: "text", label: "粘贴文本", @@ -362,22 +400,52 @@ function AddSkillDialog({ return } - const now = Math.floor(Date.now() / 1000) - onCreate({ - id: createLocalSkillID(), + const tags = normalizeSkillTags(tagsText) + if (source.type === "zip" && packageFile) { + const api = new Api() + void api.api.v1TeamsSkillsPackageCreate({ + name: name.trim(), + description: description.trim(), + tags: JSON.stringify(tags), + content: draft.content, + group_ids: JSON.stringify(selectedGroupIds), + source_type: source.type, + source_label: source.label, + skill_md_path: source.skillMdPath, + file: packageFile, + }).then((response) => { + const resp = response.data + if (resp.code === 0 && resp.data) { + onCreate(toManagedSkill(resp.data)) + toast.success("Skill 已添加") + handleOpenChange(false) + return + } + toast.error(resp.message || "添加 Skill 失败") + }).catch((error) => { + toast.error(error?.message || "添加 Skill 失败") + }) + return + } + + void apiRequest("v1TeamsSkillsCreate", { name: name.trim(), description: description.trim(), - tags: normalizeSkillTags(tagsText), - groups: resolveSelectedGroups(groups, selectedGroupIds), - sourceType: source.type, - sourceLabel: source.label, - skillMdPath: source.skillMdPath, - createdAt: now, - updatedAt: now, + tags, + content: draft.content, + group_ids: selectedGroupIds, + source_type: source.type, + source_label: source.label, + skill_md_path: source.skillMdPath, + }, [], (resp) => { + if (resp.code === 0 && resp.data) { + onCreate(toManagedSkill(resp.data)) + toast.success("Skill 已添加") + handleOpenChange(false) + return + } + toast.error(resp.message || "添加 Skill 失败") }) - - toast.success("Skill 已添加") - handleOpenChange(false) } return ( @@ -506,16 +574,20 @@ function EditSkillDialog({ return } - onUpdate({ - ...skill, + void apiRequest("v1TeamsSkillsUpdate", { name: name.trim(), description: description.trim(), tags: normalizeSkillTags(tagsText), - groups: resolveSelectedGroups(groups, selectedGroupIds), - updatedAt: Math.floor(Date.now() / 1000), + group_ids: selectedGroupIds, + }, [skill.id], (resp) => { + if (resp.code === 0 && resp.data) { + onUpdate(toManagedSkill(resp.data)) + toast.success("Skill 已修改") + onOpenChange(false) + return + } + toast.error(resp.message || "修改 Skill 失败") }) - toast.success("Skill 已修改") - onOpenChange(false) } return ( @@ -810,14 +882,24 @@ function fetchGroups(setGroups: (groups: DomainTeamGroup[]) => void) { }) } -function resolveSelectedGroups(groups: DomainTeamGroup[], selectedGroupIds: string[]): DomainTeamGroup[] { - const selected = new Set(selectedGroupIds) - return groups.filter((group) => group.id && selected.has(group.id)) +function toManagedSkill(skill: DomainTeamSkill): ManagedSkill { + return { + id: skill.id || "", + name: skill.name || "", + description: skill.description || "", + tags: skill.tags || [], + groups: skill.groups || [], + sourceType: toSkillSourceType(skill.source_type), + sourceLabel: skill.source_label || "SKILL.md", + skillMdPath: skill.skill_md_path, + createdAt: skill.created_at || 0, + updatedAt: skill.updated_at || 0, + } } -function createLocalSkillID() { - if (typeof crypto !== "undefined" && "randomUUID" in crypto) { - return crypto.randomUUID() +function toSkillSourceType(value: unknown): SkillSourceType { + if (value === "zip" || value === "markdown" || value === "text") { + return value } - return `skill-${Date.now()}` + return "markdown" }