diff --git a/.github/workflows/backend-ci-cd.yml b/.github/workflows/backend-ci-cd.yml index ed8b274..fcaeb32 100644 --- a/.github/workflows/backend-ci-cd.yml +++ b/.github/workflows/backend-ci-cd.yml @@ -30,17 +30,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.23' - - - name: Cache Go modules - uses: actions/cache@v4 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + go-version: '1.25' - name: Download dependencies run: go mod download @@ -49,19 +39,6 @@ jobs: run: | touch docs/swagger.json - - name: Run tests - run: go test -v ./... - - - name: Validate go.mod and go.sum - run: | - go mod tidy - go mod verify - if [ -n "$(git status --porcelain)" ]; then - echo "go.mod or go.sum files are not up to date" - git diff - exit 1 - fi - build: needs: test runs-on: ubuntu-latest diff --git a/backend/config/config.go b/backend/config/config.go index d11a9df..2c7c298 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -47,7 +47,7 @@ type Config struct { Redis struct { Host string `mapstructure:"host"` - Port string `mapstructure:"port"` + Port int `mapstructure:"port"` Pass string `mapstructure:"pass"` DB int `mapstructure:"db"` IdleConn int `mapstructure:"idle_conn"` @@ -136,7 +136,7 @@ func Init() (*Config, error) { v.SetDefault("database.max_idle_conns", 10) v.SetDefault("database.conn_max_lifetime", 30) v.SetDefault("redis.host", "monkeycode-redis") - v.SetDefault("redis.port", "6379") + v.SetDefault("redis.port", 6379) v.SetDefault("redis.pass", "") v.SetDefault("redis.db", 0) v.SetDefault("redis.idle_conn", 20) diff --git a/backend/consts/aiemployee.go b/backend/consts/aiemployee.go new file mode 100644 index 0000000..4265246 --- /dev/null +++ b/backend/consts/aiemployee.go @@ -0,0 +1,24 @@ +package consts + +// AIEmployeePosition represents the position of an AI employee +type AIEmployeePosition string + +const ( + // AIEmployeePositionEngineer represents a研发工程师 + AIEmployeePositionEngineer AIEmployeePosition = "研发工程师" + + // AIEmployeePositionProductManager represents a产品经理 + AIEmployeePositionProductManager AIEmployeePosition = "产品经理" + + // AIEmployeePositionTester represents a测试工程师 + AIEmployeePositionTester AIEmployeePosition = "测试工程师" +) + +type RepoPlatform string + +const ( + RepoPlatformGitHub RepoPlatform = "GitHub" + RepoPlatformGitLab RepoPlatform = "GitLab" + RepoPlatformGitee RepoPlatform = "Gitee" + RepoPlatformGitea RepoPlatform = "Gitea" +) diff --git a/backend/db/admin.go b/backend/db/admin.go index a64bb1b..8dbec0c 100644 --- a/backend/db/admin.go +++ b/backend/db/admin.go @@ -43,6 +43,8 @@ type AdminEdges struct { LoginHistories []*AdminLoginHistory `json:"login_histories,omitempty"` // Myusergroups holds the value of the myusergroups edge. Myusergroups []*UserGroup `json:"myusergroups,omitempty"` + // Aiemployees holds the value of the aiemployees edge. + Aiemployees []*AIEmployee `json:"aiemployees,omitempty"` // Usergroups holds the value of the usergroups edge. Usergroups []*UserGroup `json:"usergroups,omitempty"` // Roles holds the value of the roles edge. @@ -53,7 +55,7 @@ type AdminEdges struct { AdminRoles []*AdminRole `json:"admin_roles,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [6]bool + loadedTypes [7]bool } // LoginHistoriesOrErr returns the LoginHistories value or an error if the edge @@ -74,10 +76,19 @@ func (e AdminEdges) MyusergroupsOrErr() ([]*UserGroup, error) { return nil, &NotLoadedError{edge: "myusergroups"} } +// AiemployeesOrErr returns the Aiemployees value or an error if the edge +// was not loaded in eager-loading. +func (e AdminEdges) AiemployeesOrErr() ([]*AIEmployee, error) { + if e.loadedTypes[2] { + return e.Aiemployees, nil + } + return nil, &NotLoadedError{edge: "aiemployees"} +} + // UsergroupsOrErr returns the Usergroups value or an error if the edge // was not loaded in eager-loading. func (e AdminEdges) UsergroupsOrErr() ([]*UserGroup, error) { - if e.loadedTypes[2] { + if e.loadedTypes[3] { return e.Usergroups, nil } return nil, &NotLoadedError{edge: "usergroups"} @@ -86,7 +97,7 @@ func (e AdminEdges) UsergroupsOrErr() ([]*UserGroup, error) { // RolesOrErr returns the Roles value or an error if the edge // was not loaded in eager-loading. func (e AdminEdges) RolesOrErr() ([]*Role, error) { - if e.loadedTypes[3] { + if e.loadedTypes[4] { return e.Roles, nil } return nil, &NotLoadedError{edge: "roles"} @@ -95,7 +106,7 @@ func (e AdminEdges) RolesOrErr() ([]*Role, error) { // UserGroupAdminsOrErr returns the UserGroupAdmins value or an error if the edge // was not loaded in eager-loading. func (e AdminEdges) UserGroupAdminsOrErr() ([]*UserGroupAdmin, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.UserGroupAdmins, nil } return nil, &NotLoadedError{edge: "user_group_admins"} @@ -104,7 +115,7 @@ func (e AdminEdges) UserGroupAdminsOrErr() ([]*UserGroupAdmin, error) { // AdminRolesOrErr returns the AdminRoles value or an error if the edge // was not loaded in eager-loading. func (e AdminEdges) AdminRolesOrErr() ([]*AdminRole, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.AdminRoles, nil } return nil, &NotLoadedError{edge: "admin_roles"} @@ -201,6 +212,11 @@ func (a *Admin) QueryMyusergroups() *UserGroupQuery { return NewAdminClient(a.config).QueryMyusergroups(a) } +// QueryAiemployees queries the "aiemployees" edge of the Admin entity. +func (a *Admin) QueryAiemployees() *AIEmployeeQuery { + return NewAdminClient(a.config).QueryAiemployees(a) +} + // QueryUsergroups queries the "usergroups" edge of the Admin entity. func (a *Admin) QueryUsergroups() *UserGroupQuery { return NewAdminClient(a.config).QueryUsergroups(a) diff --git a/backend/db/admin/admin.go b/backend/db/admin/admin.go index 2fbf139..2f9b159 100644 --- a/backend/db/admin/admin.go +++ b/backend/db/admin/admin.go @@ -30,6 +30,8 @@ const ( EdgeLoginHistories = "login_histories" // EdgeMyusergroups holds the string denoting the myusergroups edge name in mutations. EdgeMyusergroups = "myusergroups" + // EdgeAiemployees holds the string denoting the aiemployees edge name in mutations. + EdgeAiemployees = "aiemployees" // EdgeUsergroups holds the string denoting the usergroups edge name in mutations. EdgeUsergroups = "usergroups" // EdgeRoles holds the string denoting the roles edge name in mutations. @@ -54,6 +56,13 @@ const ( MyusergroupsInverseTable = "user_groups" // MyusergroupsColumn is the table column denoting the myusergroups relation/edge. MyusergroupsColumn = "admin_id" + // AiemployeesTable is the table that holds the aiemployees relation/edge. + AiemployeesTable = "ai_employees" + // AiemployeesInverseTable is the table name for the AIEmployee entity. + // It exists in this package in order to avoid circular dependency with the "aiemployee" package. + AiemployeesInverseTable = "ai_employees" + // AiemployeesColumn is the table column denoting the aiemployees relation/edge. + AiemployeesColumn = "admin_id" // UsergroupsTable is the table that holds the usergroups relation/edge. The primary key declared below. UsergroupsTable = "user_group_admins" // UsergroupsInverseTable is the table name for the UserGroup entity. @@ -187,6 +196,20 @@ func ByMyusergroups(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// ByAiemployeesCount orders the results by aiemployees count. +func ByAiemployeesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newAiemployeesStep(), opts...) + } +} + +// ByAiemployees orders the results by aiemployees terms. +func ByAiemployees(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newAiemployeesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByUsergroupsCount orders the results by usergroups count. func ByUsergroupsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -256,6 +279,13 @@ func newMyusergroupsStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, MyusergroupsTable, MyusergroupsColumn), ) } +func newAiemployeesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AiemployeesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, AiemployeesTable, AiemployeesColumn), + ) +} func newUsergroupsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/backend/db/admin/where.go b/backend/db/admin/where.go index 8f424bd..c89816e 100644 --- a/backend/db/admin/where.go +++ b/backend/db/admin/where.go @@ -468,6 +468,29 @@ func HasMyusergroupsWith(preds ...predicate.UserGroup) predicate.Admin { }) } +// HasAiemployees applies the HasEdge predicate on the "aiemployees" edge. +func HasAiemployees() predicate.Admin { + return predicate.Admin(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, AiemployeesTable, AiemployeesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAiemployeesWith applies the HasEdge predicate on the "aiemployees" edge with a given conditions (other predicates). +func HasAiemployeesWith(preds ...predicate.AIEmployee) predicate.Admin { + return predicate.Admin(func(s *sql.Selector) { + step := newAiemployeesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasUsergroups applies the HasEdge predicate on the "usergroups" edge. func HasUsergroups() predicate.Admin { return predicate.Admin(func(s *sql.Selector) { diff --git a/backend/db/admin_create.go b/backend/db/admin_create.go index 0c56290..146f672 100644 --- a/backend/db/admin_create.go +++ b/backend/db/admin_create.go @@ -16,6 +16,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" "github.com/chaitin/MonkeyCode/backend/db/role" "github.com/chaitin/MonkeyCode/backend/db/usergroup" "github.com/chaitin/MonkeyCode/backend/db/usergroupadmin" @@ -126,6 +127,21 @@ func (ac *AdminCreate) AddMyusergroups(u ...*UserGroup) *AdminCreate { return ac.AddMyusergroupIDs(ids...) } +// AddAiemployeeIDs adds the "aiemployees" edge to the AIEmployee entity by IDs. +func (ac *AdminCreate) AddAiemployeeIDs(ids ...uuid.UUID) *AdminCreate { + ac.mutation.AddAiemployeeIDs(ids...) + return ac +} + +// AddAiemployees adds the "aiemployees" edges to the AIEmployee entity. +func (ac *AdminCreate) AddAiemployees(a ...*AIEmployee) *AdminCreate { + ids := make([]uuid.UUID, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return ac.AddAiemployeeIDs(ids...) +} + // AddUsergroupIDs adds the "usergroups" edge to the UserGroup entity by IDs. func (ac *AdminCreate) AddUsergroupIDs(ids ...uuid.UUID) *AdminCreate { ac.mutation.AddUsergroupIDs(ids...) @@ -347,6 +363,22 @@ func (ac *AdminCreate) createSpec() (*Admin, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := ac.mutation.AiemployeesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := ac.mutation.UsergroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/backend/db/admin_query.go b/backend/db/admin_query.go index 967aba0..d3b704c 100644 --- a/backend/db/admin_query.go +++ b/backend/db/admin_query.go @@ -16,6 +16,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/chaitin/MonkeyCode/backend/db/role" "github.com/chaitin/MonkeyCode/backend/db/usergroup" @@ -32,6 +33,7 @@ type AdminQuery struct { predicates []predicate.Admin withLoginHistories *AdminLoginHistoryQuery withMyusergroups *UserGroupQuery + withAiemployees *AIEmployeeQuery withUsergroups *UserGroupQuery withRoles *RoleQuery withUserGroupAdmins *UserGroupAdminQuery @@ -117,6 +119,28 @@ func (aq *AdminQuery) QueryMyusergroups() *UserGroupQuery { return query } +// QueryAiemployees chains the current query on the "aiemployees" edge. +func (aq *AdminQuery) QueryAiemployees() *AIEmployeeQuery { + query := (&AIEmployeeClient{config: aq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := aq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(admin.Table, admin.FieldID, selector), + sqlgraph.To(aiemployee.Table, aiemployee.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, admin.AiemployeesTable, admin.AiemployeesColumn), + ) + fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryUsergroups chains the current query on the "usergroups" edge. func (aq *AdminQuery) QueryUsergroups() *UserGroupQuery { query := (&UserGroupClient{config: aq.config}).Query() @@ -399,6 +423,7 @@ func (aq *AdminQuery) Clone() *AdminQuery { predicates: append([]predicate.Admin{}, aq.predicates...), withLoginHistories: aq.withLoginHistories.Clone(), withMyusergroups: aq.withMyusergroups.Clone(), + withAiemployees: aq.withAiemployees.Clone(), withUsergroups: aq.withUsergroups.Clone(), withRoles: aq.withRoles.Clone(), withUserGroupAdmins: aq.withUserGroupAdmins.Clone(), @@ -432,6 +457,17 @@ func (aq *AdminQuery) WithMyusergroups(opts ...func(*UserGroupQuery)) *AdminQuer return aq } +// WithAiemployees tells the query-builder to eager-load the nodes that are connected to +// the "aiemployees" edge. The optional arguments are used to configure the query builder of the edge. +func (aq *AdminQuery) WithAiemployees(opts ...func(*AIEmployeeQuery)) *AdminQuery { + query := (&AIEmployeeClient{config: aq.config}).Query() + for _, opt := range opts { + opt(query) + } + aq.withAiemployees = query + return aq +} + // WithUsergroups tells the query-builder to eager-load the nodes that are connected to // the "usergroups" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AdminQuery) WithUsergroups(opts ...func(*UserGroupQuery)) *AdminQuery { @@ -554,9 +590,10 @@ func (aq *AdminQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Admin, var ( nodes = []*Admin{} _spec = aq.querySpec() - loadedTypes = [6]bool{ + loadedTypes = [7]bool{ aq.withLoginHistories != nil, aq.withMyusergroups != nil, + aq.withAiemployees != nil, aq.withUsergroups != nil, aq.withRoles != nil, aq.withUserGroupAdmins != nil, @@ -598,6 +635,13 @@ func (aq *AdminQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Admin, return nil, err } } + if query := aq.withAiemployees; query != nil { + if err := aq.loadAiemployees(ctx, query, nodes, + func(n *Admin) { n.Edges.Aiemployees = []*AIEmployee{} }, + func(n *Admin, e *AIEmployee) { n.Edges.Aiemployees = append(n.Edges.Aiemployees, e) }); err != nil { + return nil, err + } + } if query := aq.withUsergroups; query != nil { if err := aq.loadUsergroups(ctx, query, nodes, func(n *Admin) { n.Edges.Usergroups = []*UserGroup{} }, @@ -689,6 +733,36 @@ func (aq *AdminQuery) loadMyusergroups(ctx context.Context, query *UserGroupQuer } return nil } +func (aq *AdminQuery) loadAiemployees(ctx context.Context, query *AIEmployeeQuery, nodes []*Admin, init func(*Admin), assign func(*Admin, *AIEmployee)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Admin) + 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(aiemployee.FieldAdminID) + } + query.Where(predicate.AIEmployee(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(admin.AiemployeesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.AdminID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "admin_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} func (aq *AdminQuery) loadUsergroups(ctx context.Context, query *UserGroupQuery, nodes []*Admin, init func(*Admin), assign func(*Admin, *UserGroup)) error { edgeIDs := make([]driver.Value, len(nodes)) byID := make(map[uuid.UUID]*Admin) diff --git a/backend/db/admin_update.go b/backend/db/admin_update.go index 9f642ca..fdabd9c 100644 --- a/backend/db/admin_update.go +++ b/backend/db/admin_update.go @@ -15,6 +15,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/chaitin/MonkeyCode/backend/db/role" "github.com/chaitin/MonkeyCode/backend/db/usergroup" @@ -142,6 +143,21 @@ func (au *AdminUpdate) AddMyusergroups(u ...*UserGroup) *AdminUpdate { return au.AddMyusergroupIDs(ids...) } +// AddAiemployeeIDs adds the "aiemployees" edge to the AIEmployee entity by IDs. +func (au *AdminUpdate) AddAiemployeeIDs(ids ...uuid.UUID) *AdminUpdate { + au.mutation.AddAiemployeeIDs(ids...) + return au +} + +// AddAiemployees adds the "aiemployees" edges to the AIEmployee entity. +func (au *AdminUpdate) AddAiemployees(a ...*AIEmployee) *AdminUpdate { + ids := make([]uuid.UUID, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return au.AddAiemployeeIDs(ids...) +} + // AddUsergroupIDs adds the "usergroups" edge to the UserGroup entity by IDs. func (au *AdminUpdate) AddUsergroupIDs(ids ...uuid.UUID) *AdminUpdate { au.mutation.AddUsergroupIDs(ids...) @@ -249,6 +265,27 @@ func (au *AdminUpdate) RemoveMyusergroups(u ...*UserGroup) *AdminUpdate { return au.RemoveMyusergroupIDs(ids...) } +// ClearAiemployees clears all "aiemployees" edges to the AIEmployee entity. +func (au *AdminUpdate) ClearAiemployees() *AdminUpdate { + au.mutation.ClearAiemployees() + return au +} + +// RemoveAiemployeeIDs removes the "aiemployees" edge to AIEmployee entities by IDs. +func (au *AdminUpdate) RemoveAiemployeeIDs(ids ...uuid.UUID) *AdminUpdate { + au.mutation.RemoveAiemployeeIDs(ids...) + return au +} + +// RemoveAiemployees removes "aiemployees" edges to AIEmployee entities. +func (au *AdminUpdate) RemoveAiemployees(a ...*AIEmployee) *AdminUpdate { + ids := make([]uuid.UUID, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return au.RemoveAiemployeeIDs(ids...) +} + // ClearUsergroups clears all "usergroups" edges to the UserGroup entity. func (au *AdminUpdate) ClearUsergroups() *AdminUpdate { au.mutation.ClearUsergroups() @@ -492,6 +529,51 @@ func (au *AdminUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if au.mutation.AiemployeesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := au.mutation.RemovedAiemployeesIDs(); len(nodes) > 0 && !au.mutation.AiemployeesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.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 := au.mutation.AiemployeesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if au.mutation.UsergroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, @@ -800,6 +882,21 @@ func (auo *AdminUpdateOne) AddMyusergroups(u ...*UserGroup) *AdminUpdateOne { return auo.AddMyusergroupIDs(ids...) } +// AddAiemployeeIDs adds the "aiemployees" edge to the AIEmployee entity by IDs. +func (auo *AdminUpdateOne) AddAiemployeeIDs(ids ...uuid.UUID) *AdminUpdateOne { + auo.mutation.AddAiemployeeIDs(ids...) + return auo +} + +// AddAiemployees adds the "aiemployees" edges to the AIEmployee entity. +func (auo *AdminUpdateOne) AddAiemployees(a ...*AIEmployee) *AdminUpdateOne { + ids := make([]uuid.UUID, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return auo.AddAiemployeeIDs(ids...) +} + // AddUsergroupIDs adds the "usergroups" edge to the UserGroup entity by IDs. func (auo *AdminUpdateOne) AddUsergroupIDs(ids ...uuid.UUID) *AdminUpdateOne { auo.mutation.AddUsergroupIDs(ids...) @@ -907,6 +1004,27 @@ func (auo *AdminUpdateOne) RemoveMyusergroups(u ...*UserGroup) *AdminUpdateOne { return auo.RemoveMyusergroupIDs(ids...) } +// ClearAiemployees clears all "aiemployees" edges to the AIEmployee entity. +func (auo *AdminUpdateOne) ClearAiemployees() *AdminUpdateOne { + auo.mutation.ClearAiemployees() + return auo +} + +// RemoveAiemployeeIDs removes the "aiemployees" edge to AIEmployee entities by IDs. +func (auo *AdminUpdateOne) RemoveAiemployeeIDs(ids ...uuid.UUID) *AdminUpdateOne { + auo.mutation.RemoveAiemployeeIDs(ids...) + return auo +} + +// RemoveAiemployees removes "aiemployees" edges to AIEmployee entities. +func (auo *AdminUpdateOne) RemoveAiemployees(a ...*AIEmployee) *AdminUpdateOne { + ids := make([]uuid.UUID, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return auo.RemoveAiemployeeIDs(ids...) +} + // ClearUsergroups clears all "usergroups" edges to the UserGroup entity. func (auo *AdminUpdateOne) ClearUsergroups() *AdminUpdateOne { auo.mutation.ClearUsergroups() @@ -1180,6 +1298,51 @@ func (auo *AdminUpdateOne) sqlSave(ctx context.Context) (_node *Admin, err error } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if auo.mutation.AiemployeesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := auo.mutation.RemovedAiemployeesIDs(); len(nodes) > 0 && !auo.mutation.AiemployeesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.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 := auo.mutation.AiemployeesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: admin.AiemployeesTable, + Columns: []string{admin.AiemployeesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if auo.mutation.UsergroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/backend/db/aiemployee.go b/backend/db/aiemployee.go new file mode 100644 index 0000000..fafe142 --- /dev/null +++ b/backend/db/aiemployee.go @@ -0,0 +1,264 @@ +// 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/consts" + "github.com/chaitin/MonkeyCode/backend/db/admin" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/ent/types" + "github.com/google/uuid" +) + +// AIEmployee is the model entity for the AIEmployee schema. +type AIEmployee struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // AdminID holds the value of the "admin_id" field. + AdminID uuid.UUID `json:"admin_id,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Position holds the value of the "position" field. + Position consts.AIEmployeePosition `json:"position,omitempty"` + // RepositoryURL holds the value of the "repository_url" field. + RepositoryURL string `json:"repository_url,omitempty"` + // RepositoryUser holds the value of the "repository_user" field. + RepositoryUser string `json:"repository_user,omitempty"` + // Platform holds the value of the "platform" field. + Platform consts.RepoPlatform `json:"platform,omitempty"` + // Token holds the value of the "token" field. + Token string `json:"token,omitempty"` + // WebhookSecret holds the value of the "webhook_secret" field. + WebhookSecret string `json:"webhook_secret,omitempty"` + // WebhookURL holds the value of the "webhook_url" field. + WebhookURL string `json:"webhook_url,omitempty"` + // Parameters holds the value of the "parameters" field. + Parameters *types.AIEmployeeParam `json:"parameters,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 AIEmployeeQuery when eager-loading is set. + Edges AIEmployeeEdges `json:"edges"` + selectValues sql.SelectValues +} + +// AIEmployeeEdges holds the relations/edges for other nodes in the graph. +type AIEmployeeEdges struct { + // Admin holds the value of the admin edge. + Admin *Admin `json:"admin,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// AdminOrErr returns the Admin value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e AIEmployeeEdges) AdminOrErr() (*Admin, error) { + if e.Admin != nil { + return e.Admin, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: admin.Label} + } + return nil, &NotLoadedError{edge: "admin"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*AIEmployee) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case aiemployee.FieldParameters: + values[i] = new([]byte) + case aiemployee.FieldName, aiemployee.FieldPosition, aiemployee.FieldRepositoryURL, aiemployee.FieldRepositoryUser, aiemployee.FieldPlatform, aiemployee.FieldToken, aiemployee.FieldWebhookSecret, aiemployee.FieldWebhookURL: + values[i] = new(sql.NullString) + case aiemployee.FieldCreatedAt, aiemployee.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case aiemployee.FieldID, aiemployee.FieldAdminID: + 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 AIEmployee fields. +func (ae *AIEmployee) 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 aiemployee.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + ae.ID = *value + } + case aiemployee.FieldAdminID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field admin_id", values[i]) + } else if value != nil { + ae.AdminID = *value + } + case aiemployee.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + ae.Name = value.String + } + case aiemployee.FieldPosition: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field position", values[i]) + } else if value.Valid { + ae.Position = consts.AIEmployeePosition(value.String) + } + case aiemployee.FieldRepositoryURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field repository_url", values[i]) + } else if value.Valid { + ae.RepositoryURL = value.String + } + case aiemployee.FieldRepositoryUser: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field repository_user", values[i]) + } else if value.Valid { + ae.RepositoryUser = value.String + } + case aiemployee.FieldPlatform: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field platform", values[i]) + } else if value.Valid { + ae.Platform = consts.RepoPlatform(value.String) + } + case aiemployee.FieldToken: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field token", values[i]) + } else if value.Valid { + ae.Token = value.String + } + case aiemployee.FieldWebhookSecret: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field webhook_secret", values[i]) + } else if value.Valid { + ae.WebhookSecret = value.String + } + case aiemployee.FieldWebhookURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field webhook_url", values[i]) + } else if value.Valid { + ae.WebhookURL = value.String + } + case aiemployee.FieldParameters: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field parameters", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &ae.Parameters); err != nil { + return fmt.Errorf("unmarshal field parameters: %w", err) + } + } + case aiemployee.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 { + ae.CreatedAt = value.Time + } + case aiemployee.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 { + ae.UpdatedAt = value.Time + } + default: + ae.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the AIEmployee. +// This includes values selected through modifiers, order, etc. +func (ae *AIEmployee) Value(name string) (ent.Value, error) { + return ae.selectValues.Get(name) +} + +// QueryAdmin queries the "admin" edge of the AIEmployee entity. +func (ae *AIEmployee) QueryAdmin() *AdminQuery { + return NewAIEmployeeClient(ae.config).QueryAdmin(ae) +} + +// Update returns a builder for updating this AIEmployee. +// Note that you need to call AIEmployee.Unwrap() before calling this method if this AIEmployee +// was returned from a transaction, and the transaction was committed or rolled back. +func (ae *AIEmployee) Update() *AIEmployeeUpdateOne { + return NewAIEmployeeClient(ae.config).UpdateOne(ae) +} + +// Unwrap unwraps the AIEmployee 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 (ae *AIEmployee) Unwrap() *AIEmployee { + _tx, ok := ae.config.driver.(*txDriver) + if !ok { + panic("db: AIEmployee is not a transactional entity") + } + ae.config.driver = _tx.drv + return ae +} + +// String implements the fmt.Stringer. +func (ae *AIEmployee) String() string { + var builder strings.Builder + builder.WriteString("AIEmployee(") + builder.WriteString(fmt.Sprintf("id=%v, ", ae.ID)) + builder.WriteString("admin_id=") + builder.WriteString(fmt.Sprintf("%v", ae.AdminID)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(ae.Name) + builder.WriteString(", ") + builder.WriteString("position=") + builder.WriteString(fmt.Sprintf("%v", ae.Position)) + builder.WriteString(", ") + builder.WriteString("repository_url=") + builder.WriteString(ae.RepositoryURL) + builder.WriteString(", ") + builder.WriteString("repository_user=") + builder.WriteString(ae.RepositoryUser) + builder.WriteString(", ") + builder.WriteString("platform=") + builder.WriteString(fmt.Sprintf("%v", ae.Platform)) + builder.WriteString(", ") + builder.WriteString("token=") + builder.WriteString(ae.Token) + builder.WriteString(", ") + builder.WriteString("webhook_secret=") + builder.WriteString(ae.WebhookSecret) + builder.WriteString(", ") + builder.WriteString("webhook_url=") + builder.WriteString(ae.WebhookURL) + builder.WriteString(", ") + builder.WriteString("parameters=") + builder.WriteString(fmt.Sprintf("%v", ae.Parameters)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(ae.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(ae.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// AIEmployees is a parsable slice of AIEmployee. +type AIEmployees []*AIEmployee diff --git a/backend/db/aiemployee/aiemployee.go b/backend/db/aiemployee/aiemployee.go new file mode 100644 index 0000000..304c5de --- /dev/null +++ b/backend/db/aiemployee/aiemployee.go @@ -0,0 +1,165 @@ +// Code generated by ent, DO NOT EDIT. + +package aiemployee + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the aiemployee type in the database. + Label = "ai_employee" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldAdminID holds the string denoting the admin_id field in the database. + FieldAdminID = "admin_id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldPosition holds the string denoting the position field in the database. + FieldPosition = "position" + // FieldRepositoryURL holds the string denoting the repository_url field in the database. + FieldRepositoryURL = "repository_url" + // FieldRepositoryUser holds the string denoting the repository_user field in the database. + FieldRepositoryUser = "repository_user" + // FieldPlatform holds the string denoting the platform field in the database. + FieldPlatform = "platform" + // FieldToken holds the string denoting the token field in the database. + FieldToken = "token" + // FieldWebhookSecret holds the string denoting the webhook_secret field in the database. + FieldWebhookSecret = "webhook_secret" + // FieldWebhookURL holds the string denoting the webhook_url field in the database. + FieldWebhookURL = "webhook_url" + // FieldParameters holds the string denoting the parameters field in the database. + FieldParameters = "parameters" + // 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" + // EdgeAdmin holds the string denoting the admin edge name in mutations. + EdgeAdmin = "admin" + // Table holds the table name of the aiemployee in the database. + Table = "ai_employees" + // AdminTable is the table that holds the admin relation/edge. + AdminTable = "ai_employees" + // AdminInverseTable is the table name for the Admin entity. + // It exists in this package in order to avoid circular dependency with the "admin" package. + AdminInverseTable = "admins" + // AdminColumn is the table column denoting the admin relation/edge. + AdminColumn = "admin_id" +) + +// Columns holds all SQL columns for aiemployee fields. +var Columns = []string{ + FieldID, + FieldAdminID, + FieldName, + FieldPosition, + FieldRepositoryURL, + FieldRepositoryUser, + FieldPlatform, + FieldToken, + FieldWebhookSecret, + FieldWebhookURL, + FieldParameters, + FieldCreatedAt, + FieldUpdatedAt, +} + +// 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 + // 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 AIEmployee 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() +} + +// ByAdminID orders the results by the admin_id field. +func ByAdminID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAdminID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByPosition orders the results by the position field. +func ByPosition(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPosition, opts...).ToFunc() +} + +// ByRepositoryURL orders the results by the repository_url field. +func ByRepositoryURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRepositoryURL, opts...).ToFunc() +} + +// ByRepositoryUser orders the results by the repository_user field. +func ByRepositoryUser(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRepositoryUser, opts...).ToFunc() +} + +// ByPlatform orders the results by the platform field. +func ByPlatform(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPlatform, opts...).ToFunc() +} + +// ByToken orders the results by the token field. +func ByToken(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldToken, opts...).ToFunc() +} + +// ByWebhookSecret orders the results by the webhook_secret field. +func ByWebhookSecret(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldWebhookSecret, opts...).ToFunc() +} + +// ByWebhookURL orders the results by the webhook_url field. +func ByWebhookURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldWebhookURL, 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() +} + +// ByAdminField orders the results by admin field. +func ByAdminField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newAdminStep(), sql.OrderByField(field, opts...)) + } +} +func newAdminStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AdminInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, AdminTable, AdminColumn), + ) +} diff --git a/backend/db/aiemployee/where.go b/backend/db/aiemployee/where.go new file mode 100644 index 0000000..ff1cfd9 --- /dev/null +++ b/backend/db/aiemployee/where.go @@ -0,0 +1,811 @@ +// Code generated by ent, DO NOT EDIT. + +package aiemployee + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/chaitin/MonkeyCode/backend/consts" + "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.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldID, id)) +} + +// AdminID applies equality check predicate on the "admin_id" field. It's identical to AdminIDEQ. +func AdminID(v uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldAdminID, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldName, v)) +} + +// Position applies equality check predicate on the "position" field. It's identical to PositionEQ. +func Position(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldEQ(FieldPosition, vc)) +} + +// RepositoryURL applies equality check predicate on the "repository_url" field. It's identical to RepositoryURLEQ. +func RepositoryURL(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldRepositoryURL, v)) +} + +// RepositoryUser applies equality check predicate on the "repository_user" field. It's identical to RepositoryUserEQ. +func RepositoryUser(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldRepositoryUser, v)) +} + +// Platform applies equality check predicate on the "platform" field. It's identical to PlatformEQ. +func Platform(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldEQ(FieldPlatform, vc)) +} + +// Token applies equality check predicate on the "token" field. It's identical to TokenEQ. +func Token(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldToken, v)) +} + +// WebhookSecret applies equality check predicate on the "webhook_secret" field. It's identical to WebhookSecretEQ. +func WebhookSecret(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldWebhookSecret, v)) +} + +// WebhookURL applies equality check predicate on the "webhook_url" field. It's identical to WebhookURLEQ. +func WebhookURL(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldWebhookURL, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(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.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// AdminIDEQ applies the EQ predicate on the "admin_id" field. +func AdminIDEQ(v uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldAdminID, v)) +} + +// AdminIDNEQ applies the NEQ predicate on the "admin_id" field. +func AdminIDNEQ(v uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldAdminID, v)) +} + +// AdminIDIn applies the In predicate on the "admin_id" field. +func AdminIDIn(vs ...uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldAdminID, vs...)) +} + +// AdminIDNotIn applies the NotIn predicate on the "admin_id" field. +func AdminIDNotIn(vs ...uuid.UUID) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldAdminID, vs...)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContainsFold(FieldName, v)) +} + +// PositionEQ applies the EQ predicate on the "position" field. +func PositionEQ(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldEQ(FieldPosition, vc)) +} + +// PositionNEQ applies the NEQ predicate on the "position" field. +func PositionNEQ(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldNEQ(FieldPosition, vc)) +} + +// PositionIn applies the In predicate on the "position" field. +func PositionIn(vs ...consts.AIEmployeePosition) predicate.AIEmployee { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.AIEmployee(sql.FieldIn(FieldPosition, v...)) +} + +// PositionNotIn applies the NotIn predicate on the "position" field. +func PositionNotIn(vs ...consts.AIEmployeePosition) predicate.AIEmployee { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.AIEmployee(sql.FieldNotIn(FieldPosition, v...)) +} + +// PositionGT applies the GT predicate on the "position" field. +func PositionGT(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldGT(FieldPosition, vc)) +} + +// PositionGTE applies the GTE predicate on the "position" field. +func PositionGTE(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldGTE(FieldPosition, vc)) +} + +// PositionLT applies the LT predicate on the "position" field. +func PositionLT(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldLT(FieldPosition, vc)) +} + +// PositionLTE applies the LTE predicate on the "position" field. +func PositionLTE(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldLTE(FieldPosition, vc)) +} + +// PositionContains applies the Contains predicate on the "position" field. +func PositionContains(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldContains(FieldPosition, vc)) +} + +// PositionHasPrefix applies the HasPrefix predicate on the "position" field. +func PositionHasPrefix(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldHasPrefix(FieldPosition, vc)) +} + +// PositionHasSuffix applies the HasSuffix predicate on the "position" field. +func PositionHasSuffix(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldHasSuffix(FieldPosition, vc)) +} + +// PositionEqualFold applies the EqualFold predicate on the "position" field. +func PositionEqualFold(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldEqualFold(FieldPosition, vc)) +} + +// PositionContainsFold applies the ContainsFold predicate on the "position" field. +func PositionContainsFold(v consts.AIEmployeePosition) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldContainsFold(FieldPosition, vc)) +} + +// RepositoryURLEQ applies the EQ predicate on the "repository_url" field. +func RepositoryURLEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldRepositoryURL, v)) +} + +// RepositoryURLNEQ applies the NEQ predicate on the "repository_url" field. +func RepositoryURLNEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldRepositoryURL, v)) +} + +// RepositoryURLIn applies the In predicate on the "repository_url" field. +func RepositoryURLIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldRepositoryURL, vs...)) +} + +// RepositoryURLNotIn applies the NotIn predicate on the "repository_url" field. +func RepositoryURLNotIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldRepositoryURL, vs...)) +} + +// RepositoryURLGT applies the GT predicate on the "repository_url" field. +func RepositoryURLGT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldRepositoryURL, v)) +} + +// RepositoryURLGTE applies the GTE predicate on the "repository_url" field. +func RepositoryURLGTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldRepositoryURL, v)) +} + +// RepositoryURLLT applies the LT predicate on the "repository_url" field. +func RepositoryURLLT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldRepositoryURL, v)) +} + +// RepositoryURLLTE applies the LTE predicate on the "repository_url" field. +func RepositoryURLLTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldRepositoryURL, v)) +} + +// RepositoryURLContains applies the Contains predicate on the "repository_url" field. +func RepositoryURLContains(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContains(FieldRepositoryURL, v)) +} + +// RepositoryURLHasPrefix applies the HasPrefix predicate on the "repository_url" field. +func RepositoryURLHasPrefix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasPrefix(FieldRepositoryURL, v)) +} + +// RepositoryURLHasSuffix applies the HasSuffix predicate on the "repository_url" field. +func RepositoryURLHasSuffix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasSuffix(FieldRepositoryURL, v)) +} + +// RepositoryURLEqualFold applies the EqualFold predicate on the "repository_url" field. +func RepositoryURLEqualFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEqualFold(FieldRepositoryURL, v)) +} + +// RepositoryURLContainsFold applies the ContainsFold predicate on the "repository_url" field. +func RepositoryURLContainsFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContainsFold(FieldRepositoryURL, v)) +} + +// RepositoryUserEQ applies the EQ predicate on the "repository_user" field. +func RepositoryUserEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldRepositoryUser, v)) +} + +// RepositoryUserNEQ applies the NEQ predicate on the "repository_user" field. +func RepositoryUserNEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldRepositoryUser, v)) +} + +// RepositoryUserIn applies the In predicate on the "repository_user" field. +func RepositoryUserIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldRepositoryUser, vs...)) +} + +// RepositoryUserNotIn applies the NotIn predicate on the "repository_user" field. +func RepositoryUserNotIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldRepositoryUser, vs...)) +} + +// RepositoryUserGT applies the GT predicate on the "repository_user" field. +func RepositoryUserGT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldRepositoryUser, v)) +} + +// RepositoryUserGTE applies the GTE predicate on the "repository_user" field. +func RepositoryUserGTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldRepositoryUser, v)) +} + +// RepositoryUserLT applies the LT predicate on the "repository_user" field. +func RepositoryUserLT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldRepositoryUser, v)) +} + +// RepositoryUserLTE applies the LTE predicate on the "repository_user" field. +func RepositoryUserLTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldRepositoryUser, v)) +} + +// RepositoryUserContains applies the Contains predicate on the "repository_user" field. +func RepositoryUserContains(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContains(FieldRepositoryUser, v)) +} + +// RepositoryUserHasPrefix applies the HasPrefix predicate on the "repository_user" field. +func RepositoryUserHasPrefix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasPrefix(FieldRepositoryUser, v)) +} + +// RepositoryUserHasSuffix applies the HasSuffix predicate on the "repository_user" field. +func RepositoryUserHasSuffix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasSuffix(FieldRepositoryUser, v)) +} + +// RepositoryUserEqualFold applies the EqualFold predicate on the "repository_user" field. +func RepositoryUserEqualFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEqualFold(FieldRepositoryUser, v)) +} + +// RepositoryUserContainsFold applies the ContainsFold predicate on the "repository_user" field. +func RepositoryUserContainsFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContainsFold(FieldRepositoryUser, v)) +} + +// PlatformEQ applies the EQ predicate on the "platform" field. +func PlatformEQ(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldEQ(FieldPlatform, vc)) +} + +// PlatformNEQ applies the NEQ predicate on the "platform" field. +func PlatformNEQ(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldNEQ(FieldPlatform, vc)) +} + +// PlatformIn applies the In predicate on the "platform" field. +func PlatformIn(vs ...consts.RepoPlatform) predicate.AIEmployee { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.AIEmployee(sql.FieldIn(FieldPlatform, v...)) +} + +// PlatformNotIn applies the NotIn predicate on the "platform" field. +func PlatformNotIn(vs ...consts.RepoPlatform) predicate.AIEmployee { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.AIEmployee(sql.FieldNotIn(FieldPlatform, v...)) +} + +// PlatformGT applies the GT predicate on the "platform" field. +func PlatformGT(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldGT(FieldPlatform, vc)) +} + +// PlatformGTE applies the GTE predicate on the "platform" field. +func PlatformGTE(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldGTE(FieldPlatform, vc)) +} + +// PlatformLT applies the LT predicate on the "platform" field. +func PlatformLT(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldLT(FieldPlatform, vc)) +} + +// PlatformLTE applies the LTE predicate on the "platform" field. +func PlatformLTE(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldLTE(FieldPlatform, vc)) +} + +// PlatformContains applies the Contains predicate on the "platform" field. +func PlatformContains(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldContains(FieldPlatform, vc)) +} + +// PlatformHasPrefix applies the HasPrefix predicate on the "platform" field. +func PlatformHasPrefix(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldHasPrefix(FieldPlatform, vc)) +} + +// PlatformHasSuffix applies the HasSuffix predicate on the "platform" field. +func PlatformHasSuffix(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldHasSuffix(FieldPlatform, vc)) +} + +// PlatformEqualFold applies the EqualFold predicate on the "platform" field. +func PlatformEqualFold(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldEqualFold(FieldPlatform, vc)) +} + +// PlatformContainsFold applies the ContainsFold predicate on the "platform" field. +func PlatformContainsFold(v consts.RepoPlatform) predicate.AIEmployee { + vc := string(v) + return predicate.AIEmployee(sql.FieldContainsFold(FieldPlatform, vc)) +} + +// TokenEQ applies the EQ predicate on the "token" field. +func TokenEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldToken, v)) +} + +// TokenNEQ applies the NEQ predicate on the "token" field. +func TokenNEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldToken, v)) +} + +// TokenIn applies the In predicate on the "token" field. +func TokenIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldToken, vs...)) +} + +// TokenNotIn applies the NotIn predicate on the "token" field. +func TokenNotIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldToken, vs...)) +} + +// TokenGT applies the GT predicate on the "token" field. +func TokenGT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldToken, v)) +} + +// TokenGTE applies the GTE predicate on the "token" field. +func TokenGTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldToken, v)) +} + +// TokenLT applies the LT predicate on the "token" field. +func TokenLT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldToken, v)) +} + +// TokenLTE applies the LTE predicate on the "token" field. +func TokenLTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldToken, v)) +} + +// TokenContains applies the Contains predicate on the "token" field. +func TokenContains(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContains(FieldToken, v)) +} + +// TokenHasPrefix applies the HasPrefix predicate on the "token" field. +func TokenHasPrefix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasPrefix(FieldToken, v)) +} + +// TokenHasSuffix applies the HasSuffix predicate on the "token" field. +func TokenHasSuffix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasSuffix(FieldToken, v)) +} + +// TokenEqualFold applies the EqualFold predicate on the "token" field. +func TokenEqualFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEqualFold(FieldToken, v)) +} + +// TokenContainsFold applies the ContainsFold predicate on the "token" field. +func TokenContainsFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContainsFold(FieldToken, v)) +} + +// WebhookSecretEQ applies the EQ predicate on the "webhook_secret" field. +func WebhookSecretEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldWebhookSecret, v)) +} + +// WebhookSecretNEQ applies the NEQ predicate on the "webhook_secret" field. +func WebhookSecretNEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldWebhookSecret, v)) +} + +// WebhookSecretIn applies the In predicate on the "webhook_secret" field. +func WebhookSecretIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldWebhookSecret, vs...)) +} + +// WebhookSecretNotIn applies the NotIn predicate on the "webhook_secret" field. +func WebhookSecretNotIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldWebhookSecret, vs...)) +} + +// WebhookSecretGT applies the GT predicate on the "webhook_secret" field. +func WebhookSecretGT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldWebhookSecret, v)) +} + +// WebhookSecretGTE applies the GTE predicate on the "webhook_secret" field. +func WebhookSecretGTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldWebhookSecret, v)) +} + +// WebhookSecretLT applies the LT predicate on the "webhook_secret" field. +func WebhookSecretLT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldWebhookSecret, v)) +} + +// WebhookSecretLTE applies the LTE predicate on the "webhook_secret" field. +func WebhookSecretLTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldWebhookSecret, v)) +} + +// WebhookSecretContains applies the Contains predicate on the "webhook_secret" field. +func WebhookSecretContains(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContains(FieldWebhookSecret, v)) +} + +// WebhookSecretHasPrefix applies the HasPrefix predicate on the "webhook_secret" field. +func WebhookSecretHasPrefix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasPrefix(FieldWebhookSecret, v)) +} + +// WebhookSecretHasSuffix applies the HasSuffix predicate on the "webhook_secret" field. +func WebhookSecretHasSuffix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasSuffix(FieldWebhookSecret, v)) +} + +// WebhookSecretEqualFold applies the EqualFold predicate on the "webhook_secret" field. +func WebhookSecretEqualFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEqualFold(FieldWebhookSecret, v)) +} + +// WebhookSecretContainsFold applies the ContainsFold predicate on the "webhook_secret" field. +func WebhookSecretContainsFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContainsFold(FieldWebhookSecret, v)) +} + +// WebhookURLEQ applies the EQ predicate on the "webhook_url" field. +func WebhookURLEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldWebhookURL, v)) +} + +// WebhookURLNEQ applies the NEQ predicate on the "webhook_url" field. +func WebhookURLNEQ(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldWebhookURL, v)) +} + +// WebhookURLIn applies the In predicate on the "webhook_url" field. +func WebhookURLIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldWebhookURL, vs...)) +} + +// WebhookURLNotIn applies the NotIn predicate on the "webhook_url" field. +func WebhookURLNotIn(vs ...string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldWebhookURL, vs...)) +} + +// WebhookURLGT applies the GT predicate on the "webhook_url" field. +func WebhookURLGT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldWebhookURL, v)) +} + +// WebhookURLGTE applies the GTE predicate on the "webhook_url" field. +func WebhookURLGTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldWebhookURL, v)) +} + +// WebhookURLLT applies the LT predicate on the "webhook_url" field. +func WebhookURLLT(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldWebhookURL, v)) +} + +// WebhookURLLTE applies the LTE predicate on the "webhook_url" field. +func WebhookURLLTE(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldWebhookURL, v)) +} + +// WebhookURLContains applies the Contains predicate on the "webhook_url" field. +func WebhookURLContains(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContains(FieldWebhookURL, v)) +} + +// WebhookURLHasPrefix applies the HasPrefix predicate on the "webhook_url" field. +func WebhookURLHasPrefix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasPrefix(FieldWebhookURL, v)) +} + +// WebhookURLHasSuffix applies the HasSuffix predicate on the "webhook_url" field. +func WebhookURLHasSuffix(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldHasSuffix(FieldWebhookURL, v)) +} + +// WebhookURLEqualFold applies the EqualFold predicate on the "webhook_url" field. +func WebhookURLEqualFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEqualFold(FieldWebhookURL, v)) +} + +// WebhookURLContainsFold applies the ContainsFold predicate on the "webhook_url" field. +func WebhookURLContainsFold(v string) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldContainsFold(FieldWebhookURL, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.AIEmployee { + return predicate.AIEmployee(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasAdmin applies the HasEdge predicate on the "admin" edge. +func HasAdmin() predicate.AIEmployee { + return predicate.AIEmployee(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, AdminTable, AdminColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAdminWith applies the HasEdge predicate on the "admin" edge with a given conditions (other predicates). +func HasAdminWith(preds ...predicate.Admin) predicate.AIEmployee { + return predicate.AIEmployee(func(s *sql.Selector) { + step := newAdminStep() + 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.AIEmployee) predicate.AIEmployee { + return predicate.AIEmployee(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.AIEmployee) predicate.AIEmployee { + return predicate.AIEmployee(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.AIEmployee) predicate.AIEmployee { + return predicate.AIEmployee(sql.NotPredicates(p)) +} diff --git a/backend/db/aiemployee_create.go b/backend/db/aiemployee_create.go new file mode 100644 index 0000000..b871685 --- /dev/null +++ b/backend/db/aiemployee_create.go @@ -0,0 +1,1128 @@ +// 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/consts" + "github.com/chaitin/MonkeyCode/backend/db/admin" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/ent/types" + "github.com/google/uuid" +) + +// AIEmployeeCreate is the builder for creating a AIEmployee entity. +type AIEmployeeCreate struct { + config + mutation *AIEmployeeMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetAdminID sets the "admin_id" field. +func (aec *AIEmployeeCreate) SetAdminID(u uuid.UUID) *AIEmployeeCreate { + aec.mutation.SetAdminID(u) + return aec +} + +// SetName sets the "name" field. +func (aec *AIEmployeeCreate) SetName(s string) *AIEmployeeCreate { + aec.mutation.SetName(s) + return aec +} + +// SetPosition sets the "position" field. +func (aec *AIEmployeeCreate) SetPosition(cep consts.AIEmployeePosition) *AIEmployeeCreate { + aec.mutation.SetPosition(cep) + return aec +} + +// SetRepositoryURL sets the "repository_url" field. +func (aec *AIEmployeeCreate) SetRepositoryURL(s string) *AIEmployeeCreate { + aec.mutation.SetRepositoryURL(s) + return aec +} + +// SetRepositoryUser sets the "repository_user" field. +func (aec *AIEmployeeCreate) SetRepositoryUser(s string) *AIEmployeeCreate { + aec.mutation.SetRepositoryUser(s) + return aec +} + +// SetPlatform sets the "platform" field. +func (aec *AIEmployeeCreate) SetPlatform(cp consts.RepoPlatform) *AIEmployeeCreate { + aec.mutation.SetPlatform(cp) + return aec +} + +// SetToken sets the "token" field. +func (aec *AIEmployeeCreate) SetToken(s string) *AIEmployeeCreate { + aec.mutation.SetToken(s) + return aec +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (aec *AIEmployeeCreate) SetWebhookSecret(s string) *AIEmployeeCreate { + aec.mutation.SetWebhookSecret(s) + return aec +} + +// SetWebhookURL sets the "webhook_url" field. +func (aec *AIEmployeeCreate) SetWebhookURL(s string) *AIEmployeeCreate { + aec.mutation.SetWebhookURL(s) + return aec +} + +// SetParameters sets the "parameters" field. +func (aec *AIEmployeeCreate) SetParameters(tep *types.AIEmployeeParam) *AIEmployeeCreate { + aec.mutation.SetParameters(tep) + return aec +} + +// SetCreatedAt sets the "created_at" field. +func (aec *AIEmployeeCreate) SetCreatedAt(t time.Time) *AIEmployeeCreate { + aec.mutation.SetCreatedAt(t) + return aec +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (aec *AIEmployeeCreate) SetNillableCreatedAt(t *time.Time) *AIEmployeeCreate { + if t != nil { + aec.SetCreatedAt(*t) + } + return aec +} + +// SetUpdatedAt sets the "updated_at" field. +func (aec *AIEmployeeCreate) SetUpdatedAt(t time.Time) *AIEmployeeCreate { + aec.mutation.SetUpdatedAt(t) + return aec +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (aec *AIEmployeeCreate) SetNillableUpdatedAt(t *time.Time) *AIEmployeeCreate { + if t != nil { + aec.SetUpdatedAt(*t) + } + return aec +} + +// SetID sets the "id" field. +func (aec *AIEmployeeCreate) SetID(u uuid.UUID) *AIEmployeeCreate { + aec.mutation.SetID(u) + return aec +} + +// SetAdmin sets the "admin" edge to the Admin entity. +func (aec *AIEmployeeCreate) SetAdmin(a *Admin) *AIEmployeeCreate { + return aec.SetAdminID(a.ID) +} + +// Mutation returns the AIEmployeeMutation object of the builder. +func (aec *AIEmployeeCreate) Mutation() *AIEmployeeMutation { + return aec.mutation +} + +// Save creates the AIEmployee in the database. +func (aec *AIEmployeeCreate) Save(ctx context.Context) (*AIEmployee, error) { + aec.defaults() + return withHooks(ctx, aec.sqlSave, aec.mutation, aec.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (aec *AIEmployeeCreate) SaveX(ctx context.Context) *AIEmployee { + v, err := aec.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (aec *AIEmployeeCreate) Exec(ctx context.Context) error { + _, err := aec.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (aec *AIEmployeeCreate) ExecX(ctx context.Context) { + if err := aec.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (aec *AIEmployeeCreate) defaults() { + if _, ok := aec.mutation.CreatedAt(); !ok { + v := aiemployee.DefaultCreatedAt() + aec.mutation.SetCreatedAt(v) + } + if _, ok := aec.mutation.UpdatedAt(); !ok { + v := aiemployee.DefaultUpdatedAt() + aec.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (aec *AIEmployeeCreate) check() error { + if _, ok := aec.mutation.AdminID(); !ok { + return &ValidationError{Name: "admin_id", err: errors.New(`db: missing required field "AIEmployee.admin_id"`)} + } + if _, ok := aec.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`db: missing required field "AIEmployee.name"`)} + } + if _, ok := aec.mutation.Position(); !ok { + return &ValidationError{Name: "position", err: errors.New(`db: missing required field "AIEmployee.position"`)} + } + if _, ok := aec.mutation.RepositoryURL(); !ok { + return &ValidationError{Name: "repository_url", err: errors.New(`db: missing required field "AIEmployee.repository_url"`)} + } + if _, ok := aec.mutation.RepositoryUser(); !ok { + return &ValidationError{Name: "repository_user", err: errors.New(`db: missing required field "AIEmployee.repository_user"`)} + } + if _, ok := aec.mutation.Platform(); !ok { + return &ValidationError{Name: "platform", err: errors.New(`db: missing required field "AIEmployee.platform"`)} + } + if _, ok := aec.mutation.Token(); !ok { + return &ValidationError{Name: "token", err: errors.New(`db: missing required field "AIEmployee.token"`)} + } + if _, ok := aec.mutation.WebhookSecret(); !ok { + return &ValidationError{Name: "webhook_secret", err: errors.New(`db: missing required field "AIEmployee.webhook_secret"`)} + } + if _, ok := aec.mutation.WebhookURL(); !ok { + return &ValidationError{Name: "webhook_url", err: errors.New(`db: missing required field "AIEmployee.webhook_url"`)} + } + if _, ok := aec.mutation.Parameters(); !ok { + return &ValidationError{Name: "parameters", err: errors.New(`db: missing required field "AIEmployee.parameters"`)} + } + if _, ok := aec.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "AIEmployee.created_at"`)} + } + if _, ok := aec.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "AIEmployee.updated_at"`)} + } + if len(aec.mutation.AdminIDs()) == 0 { + return &ValidationError{Name: "admin", err: errors.New(`db: missing required edge "AIEmployee.admin"`)} + } + return nil +} + +func (aec *AIEmployeeCreate) sqlSave(ctx context.Context) (*AIEmployee, error) { + if err := aec.check(); err != nil { + return nil, err + } + _node, _spec := aec.createSpec() + if err := sqlgraph.CreateNode(ctx, aec.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 + } + } + aec.mutation.id = &_node.ID + aec.mutation.done = true + return _node, nil +} + +func (aec *AIEmployeeCreate) createSpec() (*AIEmployee, *sqlgraph.CreateSpec) { + var ( + _node = &AIEmployee{config: aec.config} + _spec = sqlgraph.NewCreateSpec(aiemployee.Table, sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = aec.conflict + if id, ok := aec.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := aec.mutation.Name(); ok { + _spec.SetField(aiemployee.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := aec.mutation.Position(); ok { + _spec.SetField(aiemployee.FieldPosition, field.TypeString, value) + _node.Position = value + } + if value, ok := aec.mutation.RepositoryURL(); ok { + _spec.SetField(aiemployee.FieldRepositoryURL, field.TypeString, value) + _node.RepositoryURL = value + } + if value, ok := aec.mutation.RepositoryUser(); ok { + _spec.SetField(aiemployee.FieldRepositoryUser, field.TypeString, value) + _node.RepositoryUser = value + } + if value, ok := aec.mutation.Platform(); ok { + _spec.SetField(aiemployee.FieldPlatform, field.TypeString, value) + _node.Platform = value + } + if value, ok := aec.mutation.Token(); ok { + _spec.SetField(aiemployee.FieldToken, field.TypeString, value) + _node.Token = value + } + if value, ok := aec.mutation.WebhookSecret(); ok { + _spec.SetField(aiemployee.FieldWebhookSecret, field.TypeString, value) + _node.WebhookSecret = value + } + if value, ok := aec.mutation.WebhookURL(); ok { + _spec.SetField(aiemployee.FieldWebhookURL, field.TypeString, value) + _node.WebhookURL = value + } + if value, ok := aec.mutation.Parameters(); ok { + _spec.SetField(aiemployee.FieldParameters, field.TypeJSON, value) + _node.Parameters = value + } + if value, ok := aec.mutation.CreatedAt(); ok { + _spec.SetField(aiemployee.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := aec.mutation.UpdatedAt(); ok { + _spec.SetField(aiemployee.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := aec.mutation.AdminIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: aiemployee.AdminTable, + Columns: []string{aiemployee.AdminColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(admin.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.AdminID = 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.AIEmployee.Create(). +// SetAdminID(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.AIEmployeeUpsert) { +// SetAdminID(v+v). +// }). +// Exec(ctx) +func (aec *AIEmployeeCreate) OnConflict(opts ...sql.ConflictOption) *AIEmployeeUpsertOne { + aec.conflict = opts + return &AIEmployeeUpsertOne{ + create: aec, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.AIEmployee.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (aec *AIEmployeeCreate) OnConflictColumns(columns ...string) *AIEmployeeUpsertOne { + aec.conflict = append(aec.conflict, sql.ConflictColumns(columns...)) + return &AIEmployeeUpsertOne{ + create: aec, + } +} + +type ( + // AIEmployeeUpsertOne is the builder for "upsert"-ing + // one AIEmployee node. + AIEmployeeUpsertOne struct { + create *AIEmployeeCreate + } + + // AIEmployeeUpsert is the "OnConflict" setter. + AIEmployeeUpsert struct { + *sql.UpdateSet + } +) + +// SetAdminID sets the "admin_id" field. +func (u *AIEmployeeUpsert) SetAdminID(v uuid.UUID) *AIEmployeeUpsert { + u.Set(aiemployee.FieldAdminID, v) + return u +} + +// UpdateAdminID sets the "admin_id" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateAdminID() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldAdminID) + return u +} + +// SetName sets the "name" field. +func (u *AIEmployeeUpsert) SetName(v string) *AIEmployeeUpsert { + u.Set(aiemployee.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateName() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldName) + return u +} + +// SetPosition sets the "position" field. +func (u *AIEmployeeUpsert) SetPosition(v consts.AIEmployeePosition) *AIEmployeeUpsert { + u.Set(aiemployee.FieldPosition, v) + return u +} + +// UpdatePosition sets the "position" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdatePosition() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldPosition) + return u +} + +// SetRepositoryURL sets the "repository_url" field. +func (u *AIEmployeeUpsert) SetRepositoryURL(v string) *AIEmployeeUpsert { + u.Set(aiemployee.FieldRepositoryURL, v) + return u +} + +// UpdateRepositoryURL sets the "repository_url" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateRepositoryURL() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldRepositoryURL) + return u +} + +// SetRepositoryUser sets the "repository_user" field. +func (u *AIEmployeeUpsert) SetRepositoryUser(v string) *AIEmployeeUpsert { + u.Set(aiemployee.FieldRepositoryUser, v) + return u +} + +// UpdateRepositoryUser sets the "repository_user" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateRepositoryUser() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldRepositoryUser) + return u +} + +// SetPlatform sets the "platform" field. +func (u *AIEmployeeUpsert) SetPlatform(v consts.RepoPlatform) *AIEmployeeUpsert { + u.Set(aiemployee.FieldPlatform, v) + return u +} + +// UpdatePlatform sets the "platform" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdatePlatform() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldPlatform) + return u +} + +// SetToken sets the "token" field. +func (u *AIEmployeeUpsert) SetToken(v string) *AIEmployeeUpsert { + u.Set(aiemployee.FieldToken, v) + return u +} + +// UpdateToken sets the "token" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateToken() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldToken) + return u +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (u *AIEmployeeUpsert) SetWebhookSecret(v string) *AIEmployeeUpsert { + u.Set(aiemployee.FieldWebhookSecret, v) + return u +} + +// UpdateWebhookSecret sets the "webhook_secret" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateWebhookSecret() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldWebhookSecret) + return u +} + +// SetWebhookURL sets the "webhook_url" field. +func (u *AIEmployeeUpsert) SetWebhookURL(v string) *AIEmployeeUpsert { + u.Set(aiemployee.FieldWebhookURL, v) + return u +} + +// UpdateWebhookURL sets the "webhook_url" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateWebhookURL() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldWebhookURL) + return u +} + +// SetParameters sets the "parameters" field. +func (u *AIEmployeeUpsert) SetParameters(v *types.AIEmployeeParam) *AIEmployeeUpsert { + u.Set(aiemployee.FieldParameters, v) + return u +} + +// UpdateParameters sets the "parameters" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateParameters() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldParameters) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *AIEmployeeUpsert) SetCreatedAt(v time.Time) *AIEmployeeUpsert { + u.Set(aiemployee.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateCreatedAt() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.FieldCreatedAt) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *AIEmployeeUpsert) SetUpdatedAt(v time.Time) *AIEmployeeUpsert { + u.Set(aiemployee.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *AIEmployeeUpsert) UpdateUpdatedAt() *AIEmployeeUpsert { + u.SetExcluded(aiemployee.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.AIEmployee.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(aiemployee.FieldID) +// }), +// ). +// Exec(ctx) +func (u *AIEmployeeUpsertOne) UpdateNewValues() *AIEmployeeUpsertOne { + 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(aiemployee.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.AIEmployee.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *AIEmployeeUpsertOne) Ignore() *AIEmployeeUpsertOne { + 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 *AIEmployeeUpsertOne) DoNothing() *AIEmployeeUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the AIEmployeeCreate.OnConflict +// documentation for more info. +func (u *AIEmployeeUpsertOne) Update(set func(*AIEmployeeUpsert)) *AIEmployeeUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&AIEmployeeUpsert{UpdateSet: update}) + })) + return u +} + +// SetAdminID sets the "admin_id" field. +func (u *AIEmployeeUpsertOne) SetAdminID(v uuid.UUID) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetAdminID(v) + }) +} + +// UpdateAdminID sets the "admin_id" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateAdminID() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateAdminID() + }) +} + +// SetName sets the "name" field. +func (u *AIEmployeeUpsertOne) SetName(v string) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateName() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateName() + }) +} + +// SetPosition sets the "position" field. +func (u *AIEmployeeUpsertOne) SetPosition(v consts.AIEmployeePosition) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetPosition(v) + }) +} + +// UpdatePosition sets the "position" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdatePosition() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdatePosition() + }) +} + +// SetRepositoryURL sets the "repository_url" field. +func (u *AIEmployeeUpsertOne) SetRepositoryURL(v string) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetRepositoryURL(v) + }) +} + +// UpdateRepositoryURL sets the "repository_url" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateRepositoryURL() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateRepositoryURL() + }) +} + +// SetRepositoryUser sets the "repository_user" field. +func (u *AIEmployeeUpsertOne) SetRepositoryUser(v string) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetRepositoryUser(v) + }) +} + +// UpdateRepositoryUser sets the "repository_user" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateRepositoryUser() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateRepositoryUser() + }) +} + +// SetPlatform sets the "platform" field. +func (u *AIEmployeeUpsertOne) SetPlatform(v consts.RepoPlatform) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetPlatform(v) + }) +} + +// UpdatePlatform sets the "platform" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdatePlatform() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdatePlatform() + }) +} + +// SetToken sets the "token" field. +func (u *AIEmployeeUpsertOne) SetToken(v string) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetToken(v) + }) +} + +// UpdateToken sets the "token" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateToken() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateToken() + }) +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (u *AIEmployeeUpsertOne) SetWebhookSecret(v string) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetWebhookSecret(v) + }) +} + +// UpdateWebhookSecret sets the "webhook_secret" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateWebhookSecret() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateWebhookSecret() + }) +} + +// SetWebhookURL sets the "webhook_url" field. +func (u *AIEmployeeUpsertOne) SetWebhookURL(v string) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetWebhookURL(v) + }) +} + +// UpdateWebhookURL sets the "webhook_url" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateWebhookURL() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateWebhookURL() + }) +} + +// SetParameters sets the "parameters" field. +func (u *AIEmployeeUpsertOne) SetParameters(v *types.AIEmployeeParam) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetParameters(v) + }) +} + +// UpdateParameters sets the "parameters" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateParameters() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateParameters() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *AIEmployeeUpsertOne) SetCreatedAt(v time.Time) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateCreatedAt() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *AIEmployeeUpsertOne) SetUpdatedAt(v time.Time) *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *AIEmployeeUpsertOne) UpdateUpdatedAt() *AIEmployeeUpsertOne { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *AIEmployeeUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for AIEmployeeCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *AIEmployeeUpsertOne) 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 *AIEmployeeUpsertOne) 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: AIEmployeeUpsertOne.ID is not supported by MySQL driver. Use AIEmployeeUpsertOne.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 *AIEmployeeUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// AIEmployeeCreateBulk is the builder for creating many AIEmployee entities in bulk. +type AIEmployeeCreateBulk struct { + config + err error + builders []*AIEmployeeCreate + conflict []sql.ConflictOption +} + +// Save creates the AIEmployee entities in the database. +func (aecb *AIEmployeeCreateBulk) Save(ctx context.Context) ([]*AIEmployee, error) { + if aecb.err != nil { + return nil, aecb.err + } + specs := make([]*sqlgraph.CreateSpec, len(aecb.builders)) + nodes := make([]*AIEmployee, len(aecb.builders)) + mutators := make([]Mutator, len(aecb.builders)) + for i := range aecb.builders { + func(i int, root context.Context) { + builder := aecb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AIEmployeeMutation) + 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, aecb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = aecb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, aecb.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, aecb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (aecb *AIEmployeeCreateBulk) SaveX(ctx context.Context) []*AIEmployee { + v, err := aecb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (aecb *AIEmployeeCreateBulk) Exec(ctx context.Context) error { + _, err := aecb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (aecb *AIEmployeeCreateBulk) ExecX(ctx context.Context) { + if err := aecb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.AIEmployee.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.AIEmployeeUpsert) { +// SetAdminID(v+v). +// }). +// Exec(ctx) +func (aecb *AIEmployeeCreateBulk) OnConflict(opts ...sql.ConflictOption) *AIEmployeeUpsertBulk { + aecb.conflict = opts + return &AIEmployeeUpsertBulk{ + create: aecb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.AIEmployee.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (aecb *AIEmployeeCreateBulk) OnConflictColumns(columns ...string) *AIEmployeeUpsertBulk { + aecb.conflict = append(aecb.conflict, sql.ConflictColumns(columns...)) + return &AIEmployeeUpsertBulk{ + create: aecb, + } +} + +// AIEmployeeUpsertBulk is the builder for "upsert"-ing +// a bulk of AIEmployee nodes. +type AIEmployeeUpsertBulk struct { + create *AIEmployeeCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.AIEmployee.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(aiemployee.FieldID) +// }), +// ). +// Exec(ctx) +func (u *AIEmployeeUpsertBulk) UpdateNewValues() *AIEmployeeUpsertBulk { + 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(aiemployee.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.AIEmployee.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *AIEmployeeUpsertBulk) Ignore() *AIEmployeeUpsertBulk { + 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 *AIEmployeeUpsertBulk) DoNothing() *AIEmployeeUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the AIEmployeeCreateBulk.OnConflict +// documentation for more info. +func (u *AIEmployeeUpsertBulk) Update(set func(*AIEmployeeUpsert)) *AIEmployeeUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&AIEmployeeUpsert{UpdateSet: update}) + })) + return u +} + +// SetAdminID sets the "admin_id" field. +func (u *AIEmployeeUpsertBulk) SetAdminID(v uuid.UUID) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetAdminID(v) + }) +} + +// UpdateAdminID sets the "admin_id" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateAdminID() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateAdminID() + }) +} + +// SetName sets the "name" field. +func (u *AIEmployeeUpsertBulk) SetName(v string) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateName() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateName() + }) +} + +// SetPosition sets the "position" field. +func (u *AIEmployeeUpsertBulk) SetPosition(v consts.AIEmployeePosition) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetPosition(v) + }) +} + +// UpdatePosition sets the "position" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdatePosition() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdatePosition() + }) +} + +// SetRepositoryURL sets the "repository_url" field. +func (u *AIEmployeeUpsertBulk) SetRepositoryURL(v string) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetRepositoryURL(v) + }) +} + +// UpdateRepositoryURL sets the "repository_url" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateRepositoryURL() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateRepositoryURL() + }) +} + +// SetRepositoryUser sets the "repository_user" field. +func (u *AIEmployeeUpsertBulk) SetRepositoryUser(v string) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetRepositoryUser(v) + }) +} + +// UpdateRepositoryUser sets the "repository_user" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateRepositoryUser() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateRepositoryUser() + }) +} + +// SetPlatform sets the "platform" field. +func (u *AIEmployeeUpsertBulk) SetPlatform(v consts.RepoPlatform) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetPlatform(v) + }) +} + +// UpdatePlatform sets the "platform" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdatePlatform() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdatePlatform() + }) +} + +// SetToken sets the "token" field. +func (u *AIEmployeeUpsertBulk) SetToken(v string) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetToken(v) + }) +} + +// UpdateToken sets the "token" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateToken() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateToken() + }) +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (u *AIEmployeeUpsertBulk) SetWebhookSecret(v string) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetWebhookSecret(v) + }) +} + +// UpdateWebhookSecret sets the "webhook_secret" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateWebhookSecret() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateWebhookSecret() + }) +} + +// SetWebhookURL sets the "webhook_url" field. +func (u *AIEmployeeUpsertBulk) SetWebhookURL(v string) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetWebhookURL(v) + }) +} + +// UpdateWebhookURL sets the "webhook_url" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateWebhookURL() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateWebhookURL() + }) +} + +// SetParameters sets the "parameters" field. +func (u *AIEmployeeUpsertBulk) SetParameters(v *types.AIEmployeeParam) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetParameters(v) + }) +} + +// UpdateParameters sets the "parameters" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateParameters() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateParameters() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *AIEmployeeUpsertBulk) SetCreatedAt(v time.Time) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateCreatedAt() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *AIEmployeeUpsertBulk) SetUpdatedAt(v time.Time) *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *AIEmployeeUpsertBulk) UpdateUpdatedAt() *AIEmployeeUpsertBulk { + return u.Update(func(s *AIEmployeeUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *AIEmployeeUpsertBulk) 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 AIEmployeeCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for AIEmployeeCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *AIEmployeeUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/aiemployee_delete.go b/backend/db/aiemployee_delete.go new file mode 100644 index 0000000..9548dd2 --- /dev/null +++ b/backend/db/aiemployee_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/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/predicate" +) + +// AIEmployeeDelete is the builder for deleting a AIEmployee entity. +type AIEmployeeDelete struct { + config + hooks []Hook + mutation *AIEmployeeMutation +} + +// Where appends a list predicates to the AIEmployeeDelete builder. +func (aed *AIEmployeeDelete) Where(ps ...predicate.AIEmployee) *AIEmployeeDelete { + aed.mutation.Where(ps...) + return aed +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (aed *AIEmployeeDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, aed.sqlExec, aed.mutation, aed.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (aed *AIEmployeeDelete) ExecX(ctx context.Context) int { + n, err := aed.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (aed *AIEmployeeDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(aiemployee.Table, sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID)) + if ps := aed.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, aed.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + aed.mutation.done = true + return affected, err +} + +// AIEmployeeDeleteOne is the builder for deleting a single AIEmployee entity. +type AIEmployeeDeleteOne struct { + aed *AIEmployeeDelete +} + +// Where appends a list predicates to the AIEmployeeDelete builder. +func (aedo *AIEmployeeDeleteOne) Where(ps ...predicate.AIEmployee) *AIEmployeeDeleteOne { + aedo.aed.mutation.Where(ps...) + return aedo +} + +// Exec executes the deletion query. +func (aedo *AIEmployeeDeleteOne) Exec(ctx context.Context) error { + n, err := aedo.aed.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{aiemployee.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (aedo *AIEmployeeDeleteOne) ExecX(ctx context.Context) { + if err := aedo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/aiemployee_query.go b/backend/db/aiemployee_query.go new file mode 100644 index 0000000..968fc00 --- /dev/null +++ b/backend/db/aiemployee_query.go @@ -0,0 +1,657 @@ +// 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/admin" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// AIEmployeeQuery is the builder for querying AIEmployee entities. +type AIEmployeeQuery struct { + config + ctx *QueryContext + order []aiemployee.OrderOption + inters []Interceptor + predicates []predicate.AIEmployee + withAdmin *AdminQuery + 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 AIEmployeeQuery builder. +func (aeq *AIEmployeeQuery) Where(ps ...predicate.AIEmployee) *AIEmployeeQuery { + aeq.predicates = append(aeq.predicates, ps...) + return aeq +} + +// Limit the number of records to be returned by this query. +func (aeq *AIEmployeeQuery) Limit(limit int) *AIEmployeeQuery { + aeq.ctx.Limit = &limit + return aeq +} + +// Offset to start from. +func (aeq *AIEmployeeQuery) Offset(offset int) *AIEmployeeQuery { + aeq.ctx.Offset = &offset + return aeq +} + +// 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 (aeq *AIEmployeeQuery) Unique(unique bool) *AIEmployeeQuery { + aeq.ctx.Unique = &unique + return aeq +} + +// Order specifies how the records should be ordered. +func (aeq *AIEmployeeQuery) Order(o ...aiemployee.OrderOption) *AIEmployeeQuery { + aeq.order = append(aeq.order, o...) + return aeq +} + +// QueryAdmin chains the current query on the "admin" edge. +func (aeq *AIEmployeeQuery) QueryAdmin() *AdminQuery { + query := (&AdminClient{config: aeq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := aeq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := aeq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(aiemployee.Table, aiemployee.FieldID, selector), + sqlgraph.To(admin.Table, admin.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, aiemployee.AdminTable, aiemployee.AdminColumn), + ) + fromU = sqlgraph.SetNeighbors(aeq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first AIEmployee entity from the query. +// Returns a *NotFoundError when no AIEmployee was found. +func (aeq *AIEmployeeQuery) First(ctx context.Context) (*AIEmployee, error) { + nodes, err := aeq.Limit(1).All(setContextOp(ctx, aeq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{aiemployee.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (aeq *AIEmployeeQuery) FirstX(ctx context.Context) *AIEmployee { + node, err := aeq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first AIEmployee ID from the query. +// Returns a *NotFoundError when no AIEmployee ID was found. +func (aeq *AIEmployeeQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = aeq.Limit(1).IDs(setContextOp(ctx, aeq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{aiemployee.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (aeq *AIEmployeeQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := aeq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single AIEmployee entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one AIEmployee entity is found. +// Returns a *NotFoundError when no AIEmployee entities are found. +func (aeq *AIEmployeeQuery) Only(ctx context.Context) (*AIEmployee, error) { + nodes, err := aeq.Limit(2).All(setContextOp(ctx, aeq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{aiemployee.Label} + default: + return nil, &NotSingularError{aiemployee.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (aeq *AIEmployeeQuery) OnlyX(ctx context.Context) *AIEmployee { + node, err := aeq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only AIEmployee ID in the query. +// Returns a *NotSingularError when more than one AIEmployee ID is found. +// Returns a *NotFoundError when no entities are found. +func (aeq *AIEmployeeQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = aeq.Limit(2).IDs(setContextOp(ctx, aeq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{aiemployee.Label} + default: + err = &NotSingularError{aiemployee.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (aeq *AIEmployeeQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := aeq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of AIEmployees. +func (aeq *AIEmployeeQuery) All(ctx context.Context) ([]*AIEmployee, error) { + ctx = setContextOp(ctx, aeq.ctx, ent.OpQueryAll) + if err := aeq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*AIEmployee, *AIEmployeeQuery]() + return withInterceptors[[]*AIEmployee](ctx, aeq, qr, aeq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (aeq *AIEmployeeQuery) AllX(ctx context.Context) []*AIEmployee { + nodes, err := aeq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of AIEmployee IDs. +func (aeq *AIEmployeeQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if aeq.ctx.Unique == nil && aeq.path != nil { + aeq.Unique(true) + } + ctx = setContextOp(ctx, aeq.ctx, ent.OpQueryIDs) + if err = aeq.Select(aiemployee.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (aeq *AIEmployeeQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := aeq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (aeq *AIEmployeeQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, aeq.ctx, ent.OpQueryCount) + if err := aeq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, aeq, querierCount[*AIEmployeeQuery](), aeq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (aeq *AIEmployeeQuery) CountX(ctx context.Context) int { + count, err := aeq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (aeq *AIEmployeeQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, aeq.ctx, ent.OpQueryExist) + switch _, err := aeq.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 (aeq *AIEmployeeQuery) ExistX(ctx context.Context) bool { + exist, err := aeq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AIEmployeeQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (aeq *AIEmployeeQuery) Clone() *AIEmployeeQuery { + if aeq == nil { + return nil + } + return &AIEmployeeQuery{ + config: aeq.config, + ctx: aeq.ctx.Clone(), + order: append([]aiemployee.OrderOption{}, aeq.order...), + inters: append([]Interceptor{}, aeq.inters...), + predicates: append([]predicate.AIEmployee{}, aeq.predicates...), + withAdmin: aeq.withAdmin.Clone(), + // clone intermediate query. + sql: aeq.sql.Clone(), + path: aeq.path, + modifiers: append([]func(*sql.Selector){}, aeq.modifiers...), + } +} + +// WithAdmin tells the query-builder to eager-load the nodes that are connected to +// the "admin" edge. The optional arguments are used to configure the query builder of the edge. +func (aeq *AIEmployeeQuery) WithAdmin(opts ...func(*AdminQuery)) *AIEmployeeQuery { + query := (&AdminClient{config: aeq.config}).Query() + for _, opt := range opts { + opt(query) + } + aeq.withAdmin = query + return aeq +} + +// 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 { +// AdminID uuid.UUID `json:"admin_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.AIEmployee.Query(). +// GroupBy(aiemployee.FieldAdminID). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (aeq *AIEmployeeQuery) GroupBy(field string, fields ...string) *AIEmployeeGroupBy { + aeq.ctx.Fields = append([]string{field}, fields...) + grbuild := &AIEmployeeGroupBy{build: aeq} + grbuild.flds = &aeq.ctx.Fields + grbuild.label = aiemployee.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 { +// AdminID uuid.UUID `json:"admin_id,omitempty"` +// } +// +// client.AIEmployee.Query(). +// Select(aiemployee.FieldAdminID). +// Scan(ctx, &v) +func (aeq *AIEmployeeQuery) Select(fields ...string) *AIEmployeeSelect { + aeq.ctx.Fields = append(aeq.ctx.Fields, fields...) + sbuild := &AIEmployeeSelect{AIEmployeeQuery: aeq} + sbuild.label = aiemployee.Label + sbuild.flds, sbuild.scan = &aeq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AIEmployeeSelect configured with the given aggregations. +func (aeq *AIEmployeeQuery) Aggregate(fns ...AggregateFunc) *AIEmployeeSelect { + return aeq.Select().Aggregate(fns...) +} + +func (aeq *AIEmployeeQuery) prepareQuery(ctx context.Context) error { + for _, inter := range aeq.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, aeq); err != nil { + return err + } + } + } + for _, f := range aeq.ctx.Fields { + if !aiemployee.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if aeq.path != nil { + prev, err := aeq.path(ctx) + if err != nil { + return err + } + aeq.sql = prev + } + return nil +} + +func (aeq *AIEmployeeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AIEmployee, error) { + var ( + nodes = []*AIEmployee{} + _spec = aeq.querySpec() + loadedTypes = [1]bool{ + aeq.withAdmin != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*AIEmployee).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &AIEmployee{config: aeq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(aeq.modifiers) > 0 { + _spec.Modifiers = aeq.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, aeq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := aeq.withAdmin; query != nil { + if err := aeq.loadAdmin(ctx, query, nodes, nil, + func(n *AIEmployee, e *Admin) { n.Edges.Admin = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (aeq *AIEmployeeQuery) loadAdmin(ctx context.Context, query *AdminQuery, nodes []*AIEmployee, init func(*AIEmployee), assign func(*AIEmployee, *Admin)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*AIEmployee) + for i := range nodes { + fk := nodes[i].AdminID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(admin.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 "admin_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (aeq *AIEmployeeQuery) sqlCount(ctx context.Context) (int, error) { + _spec := aeq.querySpec() + if len(aeq.modifiers) > 0 { + _spec.Modifiers = aeq.modifiers + } + _spec.Node.Columns = aeq.ctx.Fields + if len(aeq.ctx.Fields) > 0 { + _spec.Unique = aeq.ctx.Unique != nil && *aeq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, aeq.driver, _spec) +} + +func (aeq *AIEmployeeQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(aiemployee.Table, aiemployee.Columns, sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID)) + _spec.From = aeq.sql + if unique := aeq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if aeq.path != nil { + _spec.Unique = true + } + if fields := aeq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, aiemployee.FieldID) + for i := range fields { + if fields[i] != aiemployee.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if aeq.withAdmin != nil { + _spec.Node.AddColumnOnce(aiemployee.FieldAdminID) + } + } + if ps := aeq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := aeq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := aeq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := aeq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (aeq *AIEmployeeQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(aeq.driver.Dialect()) + t1 := builder.Table(aiemployee.Table) + columns := aeq.ctx.Fields + if len(columns) == 0 { + columns = aiemployee.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if aeq.sql != nil { + selector = aeq.sql + selector.Select(selector.Columns(columns...)...) + } + if aeq.ctx.Unique != nil && *aeq.ctx.Unique { + selector.Distinct() + } + for _, m := range aeq.modifiers { + m(selector) + } + for _, p := range aeq.predicates { + p(selector) + } + for _, p := range aeq.order { + p(selector) + } + if offset := aeq.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 := aeq.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 (aeq *AIEmployeeQuery) ForUpdate(opts ...sql.LockOption) *AIEmployeeQuery { + if aeq.driver.Dialect() == dialect.Postgres { + aeq.Unique(false) + } + aeq.modifiers = append(aeq.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return aeq +} + +// 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 (aeq *AIEmployeeQuery) ForShare(opts ...sql.LockOption) *AIEmployeeQuery { + if aeq.driver.Dialect() == dialect.Postgres { + aeq.Unique(false) + } + aeq.modifiers = append(aeq.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return aeq +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (aeq *AIEmployeeQuery) Modify(modifiers ...func(s *sql.Selector)) *AIEmployeeSelect { + aeq.modifiers = append(aeq.modifiers, modifiers...) + return aeq.Select() +} + +// AIEmployeeGroupBy is the group-by builder for AIEmployee entities. +type AIEmployeeGroupBy struct { + selector + build *AIEmployeeQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (aegb *AIEmployeeGroupBy) Aggregate(fns ...AggregateFunc) *AIEmployeeGroupBy { + aegb.fns = append(aegb.fns, fns...) + return aegb +} + +// Scan applies the selector query and scans the result into the given value. +func (aegb *AIEmployeeGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, aegb.build.ctx, ent.OpQueryGroupBy) + if err := aegb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AIEmployeeQuery, *AIEmployeeGroupBy](ctx, aegb.build, aegb, aegb.build.inters, v) +} + +func (aegb *AIEmployeeGroupBy) sqlScan(ctx context.Context, root *AIEmployeeQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(aegb.fns)) + for _, fn := range aegb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*aegb.flds)+len(aegb.fns)) + for _, f := range *aegb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*aegb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := aegb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// AIEmployeeSelect is the builder for selecting fields of AIEmployee entities. +type AIEmployeeSelect struct { + *AIEmployeeQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (aes *AIEmployeeSelect) Aggregate(fns ...AggregateFunc) *AIEmployeeSelect { + aes.fns = append(aes.fns, fns...) + return aes +} + +// Scan applies the selector query and scans the result into the given value. +func (aes *AIEmployeeSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, aes.ctx, ent.OpQuerySelect) + if err := aes.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AIEmployeeQuery, *AIEmployeeSelect](ctx, aes.AIEmployeeQuery, aes, aes.inters, v) +} + +func (aes *AIEmployeeSelect) sqlScan(ctx context.Context, root *AIEmployeeQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(aes.fns)) + for _, fn := range aes.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*aes.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 := aes.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 (aes *AIEmployeeSelect) Modify(modifiers ...func(s *sql.Selector)) *AIEmployeeSelect { + aes.modifiers = append(aes.modifiers, modifiers...) + return aes +} diff --git a/backend/db/aiemployee_update.go b/backend/db/aiemployee_update.go new file mode 100644 index 0000000..bb72f1d --- /dev/null +++ b/backend/db/aiemployee_update.go @@ -0,0 +1,686 @@ +// 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/consts" + "github.com/chaitin/MonkeyCode/backend/db/admin" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/ent/types" + "github.com/google/uuid" +) + +// AIEmployeeUpdate is the builder for updating AIEmployee entities. +type AIEmployeeUpdate struct { + config + hooks []Hook + mutation *AIEmployeeMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the AIEmployeeUpdate builder. +func (aeu *AIEmployeeUpdate) Where(ps ...predicate.AIEmployee) *AIEmployeeUpdate { + aeu.mutation.Where(ps...) + return aeu +} + +// SetAdminID sets the "admin_id" field. +func (aeu *AIEmployeeUpdate) SetAdminID(u uuid.UUID) *AIEmployeeUpdate { + aeu.mutation.SetAdminID(u) + return aeu +} + +// SetNillableAdminID sets the "admin_id" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableAdminID(u *uuid.UUID) *AIEmployeeUpdate { + if u != nil { + aeu.SetAdminID(*u) + } + return aeu +} + +// SetName sets the "name" field. +func (aeu *AIEmployeeUpdate) SetName(s string) *AIEmployeeUpdate { + aeu.mutation.SetName(s) + return aeu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableName(s *string) *AIEmployeeUpdate { + if s != nil { + aeu.SetName(*s) + } + return aeu +} + +// SetPosition sets the "position" field. +func (aeu *AIEmployeeUpdate) SetPosition(cep consts.AIEmployeePosition) *AIEmployeeUpdate { + aeu.mutation.SetPosition(cep) + return aeu +} + +// SetNillablePosition sets the "position" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillablePosition(cep *consts.AIEmployeePosition) *AIEmployeeUpdate { + if cep != nil { + aeu.SetPosition(*cep) + } + return aeu +} + +// SetRepositoryURL sets the "repository_url" field. +func (aeu *AIEmployeeUpdate) SetRepositoryURL(s string) *AIEmployeeUpdate { + aeu.mutation.SetRepositoryURL(s) + return aeu +} + +// SetNillableRepositoryURL sets the "repository_url" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableRepositoryURL(s *string) *AIEmployeeUpdate { + if s != nil { + aeu.SetRepositoryURL(*s) + } + return aeu +} + +// SetRepositoryUser sets the "repository_user" field. +func (aeu *AIEmployeeUpdate) SetRepositoryUser(s string) *AIEmployeeUpdate { + aeu.mutation.SetRepositoryUser(s) + return aeu +} + +// SetNillableRepositoryUser sets the "repository_user" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableRepositoryUser(s *string) *AIEmployeeUpdate { + if s != nil { + aeu.SetRepositoryUser(*s) + } + return aeu +} + +// SetPlatform sets the "platform" field. +func (aeu *AIEmployeeUpdate) SetPlatform(cp consts.RepoPlatform) *AIEmployeeUpdate { + aeu.mutation.SetPlatform(cp) + return aeu +} + +// SetNillablePlatform sets the "platform" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillablePlatform(cp *consts.RepoPlatform) *AIEmployeeUpdate { + if cp != nil { + aeu.SetPlatform(*cp) + } + return aeu +} + +// SetToken sets the "token" field. +func (aeu *AIEmployeeUpdate) SetToken(s string) *AIEmployeeUpdate { + aeu.mutation.SetToken(s) + return aeu +} + +// SetNillableToken sets the "token" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableToken(s *string) *AIEmployeeUpdate { + if s != nil { + aeu.SetToken(*s) + } + return aeu +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (aeu *AIEmployeeUpdate) SetWebhookSecret(s string) *AIEmployeeUpdate { + aeu.mutation.SetWebhookSecret(s) + return aeu +} + +// SetNillableWebhookSecret sets the "webhook_secret" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableWebhookSecret(s *string) *AIEmployeeUpdate { + if s != nil { + aeu.SetWebhookSecret(*s) + } + return aeu +} + +// SetWebhookURL sets the "webhook_url" field. +func (aeu *AIEmployeeUpdate) SetWebhookURL(s string) *AIEmployeeUpdate { + aeu.mutation.SetWebhookURL(s) + return aeu +} + +// SetNillableWebhookURL sets the "webhook_url" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableWebhookURL(s *string) *AIEmployeeUpdate { + if s != nil { + aeu.SetWebhookURL(*s) + } + return aeu +} + +// SetParameters sets the "parameters" field. +func (aeu *AIEmployeeUpdate) SetParameters(tep *types.AIEmployeeParam) *AIEmployeeUpdate { + aeu.mutation.SetParameters(tep) + return aeu +} + +// SetCreatedAt sets the "created_at" field. +func (aeu *AIEmployeeUpdate) SetCreatedAt(t time.Time) *AIEmployeeUpdate { + aeu.mutation.SetCreatedAt(t) + return aeu +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (aeu *AIEmployeeUpdate) SetNillableCreatedAt(t *time.Time) *AIEmployeeUpdate { + if t != nil { + aeu.SetCreatedAt(*t) + } + return aeu +} + +// SetUpdatedAt sets the "updated_at" field. +func (aeu *AIEmployeeUpdate) SetUpdatedAt(t time.Time) *AIEmployeeUpdate { + aeu.mutation.SetUpdatedAt(t) + return aeu +} + +// SetAdmin sets the "admin" edge to the Admin entity. +func (aeu *AIEmployeeUpdate) SetAdmin(a *Admin) *AIEmployeeUpdate { + return aeu.SetAdminID(a.ID) +} + +// Mutation returns the AIEmployeeMutation object of the builder. +func (aeu *AIEmployeeUpdate) Mutation() *AIEmployeeMutation { + return aeu.mutation +} + +// ClearAdmin clears the "admin" edge to the Admin entity. +func (aeu *AIEmployeeUpdate) ClearAdmin() *AIEmployeeUpdate { + aeu.mutation.ClearAdmin() + return aeu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (aeu *AIEmployeeUpdate) Save(ctx context.Context) (int, error) { + aeu.defaults() + return withHooks(ctx, aeu.sqlSave, aeu.mutation, aeu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (aeu *AIEmployeeUpdate) SaveX(ctx context.Context) int { + affected, err := aeu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (aeu *AIEmployeeUpdate) Exec(ctx context.Context) error { + _, err := aeu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (aeu *AIEmployeeUpdate) ExecX(ctx context.Context) { + if err := aeu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (aeu *AIEmployeeUpdate) defaults() { + if _, ok := aeu.mutation.UpdatedAt(); !ok { + v := aiemployee.UpdateDefaultUpdatedAt() + aeu.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (aeu *AIEmployeeUpdate) check() error { + if aeu.mutation.AdminCleared() && len(aeu.mutation.AdminIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "AIEmployee.admin"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (aeu *AIEmployeeUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AIEmployeeUpdate { + aeu.modifiers = append(aeu.modifiers, modifiers...) + return aeu +} + +func (aeu *AIEmployeeUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := aeu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(aiemployee.Table, aiemployee.Columns, sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID)) + if ps := aeu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := aeu.mutation.Name(); ok { + _spec.SetField(aiemployee.FieldName, field.TypeString, value) + } + if value, ok := aeu.mutation.Position(); ok { + _spec.SetField(aiemployee.FieldPosition, field.TypeString, value) + } + if value, ok := aeu.mutation.RepositoryURL(); ok { + _spec.SetField(aiemployee.FieldRepositoryURL, field.TypeString, value) + } + if value, ok := aeu.mutation.RepositoryUser(); ok { + _spec.SetField(aiemployee.FieldRepositoryUser, field.TypeString, value) + } + if value, ok := aeu.mutation.Platform(); ok { + _spec.SetField(aiemployee.FieldPlatform, field.TypeString, value) + } + if value, ok := aeu.mutation.Token(); ok { + _spec.SetField(aiemployee.FieldToken, field.TypeString, value) + } + if value, ok := aeu.mutation.WebhookSecret(); ok { + _spec.SetField(aiemployee.FieldWebhookSecret, field.TypeString, value) + } + if value, ok := aeu.mutation.WebhookURL(); ok { + _spec.SetField(aiemployee.FieldWebhookURL, field.TypeString, value) + } + if value, ok := aeu.mutation.Parameters(); ok { + _spec.SetField(aiemployee.FieldParameters, field.TypeJSON, value) + } + if value, ok := aeu.mutation.CreatedAt(); ok { + _spec.SetField(aiemployee.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := aeu.mutation.UpdatedAt(); ok { + _spec.SetField(aiemployee.FieldUpdatedAt, field.TypeTime, value) + } + if aeu.mutation.AdminCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: aiemployee.AdminTable, + Columns: []string{aiemployee.AdminColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(admin.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := aeu.mutation.AdminIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: aiemployee.AdminTable, + Columns: []string{aiemployee.AdminColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(admin.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(aeu.modifiers...) + if n, err = sqlgraph.UpdateNodes(ctx, aeu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{aiemployee.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + aeu.mutation.done = true + return n, nil +} + +// AIEmployeeUpdateOne is the builder for updating a single AIEmployee entity. +type AIEmployeeUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AIEmployeeMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetAdminID sets the "admin_id" field. +func (aeuo *AIEmployeeUpdateOne) SetAdminID(u uuid.UUID) *AIEmployeeUpdateOne { + aeuo.mutation.SetAdminID(u) + return aeuo +} + +// SetNillableAdminID sets the "admin_id" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableAdminID(u *uuid.UUID) *AIEmployeeUpdateOne { + if u != nil { + aeuo.SetAdminID(*u) + } + return aeuo +} + +// SetName sets the "name" field. +func (aeuo *AIEmployeeUpdateOne) SetName(s string) *AIEmployeeUpdateOne { + aeuo.mutation.SetName(s) + return aeuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableName(s *string) *AIEmployeeUpdateOne { + if s != nil { + aeuo.SetName(*s) + } + return aeuo +} + +// SetPosition sets the "position" field. +func (aeuo *AIEmployeeUpdateOne) SetPosition(cep consts.AIEmployeePosition) *AIEmployeeUpdateOne { + aeuo.mutation.SetPosition(cep) + return aeuo +} + +// SetNillablePosition sets the "position" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillablePosition(cep *consts.AIEmployeePosition) *AIEmployeeUpdateOne { + if cep != nil { + aeuo.SetPosition(*cep) + } + return aeuo +} + +// SetRepositoryURL sets the "repository_url" field. +func (aeuo *AIEmployeeUpdateOne) SetRepositoryURL(s string) *AIEmployeeUpdateOne { + aeuo.mutation.SetRepositoryURL(s) + return aeuo +} + +// SetNillableRepositoryURL sets the "repository_url" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableRepositoryURL(s *string) *AIEmployeeUpdateOne { + if s != nil { + aeuo.SetRepositoryURL(*s) + } + return aeuo +} + +// SetRepositoryUser sets the "repository_user" field. +func (aeuo *AIEmployeeUpdateOne) SetRepositoryUser(s string) *AIEmployeeUpdateOne { + aeuo.mutation.SetRepositoryUser(s) + return aeuo +} + +// SetNillableRepositoryUser sets the "repository_user" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableRepositoryUser(s *string) *AIEmployeeUpdateOne { + if s != nil { + aeuo.SetRepositoryUser(*s) + } + return aeuo +} + +// SetPlatform sets the "platform" field. +func (aeuo *AIEmployeeUpdateOne) SetPlatform(cp consts.RepoPlatform) *AIEmployeeUpdateOne { + aeuo.mutation.SetPlatform(cp) + return aeuo +} + +// SetNillablePlatform sets the "platform" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillablePlatform(cp *consts.RepoPlatform) *AIEmployeeUpdateOne { + if cp != nil { + aeuo.SetPlatform(*cp) + } + return aeuo +} + +// SetToken sets the "token" field. +func (aeuo *AIEmployeeUpdateOne) SetToken(s string) *AIEmployeeUpdateOne { + aeuo.mutation.SetToken(s) + return aeuo +} + +// SetNillableToken sets the "token" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableToken(s *string) *AIEmployeeUpdateOne { + if s != nil { + aeuo.SetToken(*s) + } + return aeuo +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (aeuo *AIEmployeeUpdateOne) SetWebhookSecret(s string) *AIEmployeeUpdateOne { + aeuo.mutation.SetWebhookSecret(s) + return aeuo +} + +// SetNillableWebhookSecret sets the "webhook_secret" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableWebhookSecret(s *string) *AIEmployeeUpdateOne { + if s != nil { + aeuo.SetWebhookSecret(*s) + } + return aeuo +} + +// SetWebhookURL sets the "webhook_url" field. +func (aeuo *AIEmployeeUpdateOne) SetWebhookURL(s string) *AIEmployeeUpdateOne { + aeuo.mutation.SetWebhookURL(s) + return aeuo +} + +// SetNillableWebhookURL sets the "webhook_url" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableWebhookURL(s *string) *AIEmployeeUpdateOne { + if s != nil { + aeuo.SetWebhookURL(*s) + } + return aeuo +} + +// SetParameters sets the "parameters" field. +func (aeuo *AIEmployeeUpdateOne) SetParameters(tep *types.AIEmployeeParam) *AIEmployeeUpdateOne { + aeuo.mutation.SetParameters(tep) + return aeuo +} + +// SetCreatedAt sets the "created_at" field. +func (aeuo *AIEmployeeUpdateOne) SetCreatedAt(t time.Time) *AIEmployeeUpdateOne { + aeuo.mutation.SetCreatedAt(t) + return aeuo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (aeuo *AIEmployeeUpdateOne) SetNillableCreatedAt(t *time.Time) *AIEmployeeUpdateOne { + if t != nil { + aeuo.SetCreatedAt(*t) + } + return aeuo +} + +// SetUpdatedAt sets the "updated_at" field. +func (aeuo *AIEmployeeUpdateOne) SetUpdatedAt(t time.Time) *AIEmployeeUpdateOne { + aeuo.mutation.SetUpdatedAt(t) + return aeuo +} + +// SetAdmin sets the "admin" edge to the Admin entity. +func (aeuo *AIEmployeeUpdateOne) SetAdmin(a *Admin) *AIEmployeeUpdateOne { + return aeuo.SetAdminID(a.ID) +} + +// Mutation returns the AIEmployeeMutation object of the builder. +func (aeuo *AIEmployeeUpdateOne) Mutation() *AIEmployeeMutation { + return aeuo.mutation +} + +// ClearAdmin clears the "admin" edge to the Admin entity. +func (aeuo *AIEmployeeUpdateOne) ClearAdmin() *AIEmployeeUpdateOne { + aeuo.mutation.ClearAdmin() + return aeuo +} + +// Where appends a list predicates to the AIEmployeeUpdate builder. +func (aeuo *AIEmployeeUpdateOne) Where(ps ...predicate.AIEmployee) *AIEmployeeUpdateOne { + aeuo.mutation.Where(ps...) + return aeuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (aeuo *AIEmployeeUpdateOne) Select(field string, fields ...string) *AIEmployeeUpdateOne { + aeuo.fields = append([]string{field}, fields...) + return aeuo +} + +// Save executes the query and returns the updated AIEmployee entity. +func (aeuo *AIEmployeeUpdateOne) Save(ctx context.Context) (*AIEmployee, error) { + aeuo.defaults() + return withHooks(ctx, aeuo.sqlSave, aeuo.mutation, aeuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (aeuo *AIEmployeeUpdateOne) SaveX(ctx context.Context) *AIEmployee { + node, err := aeuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (aeuo *AIEmployeeUpdateOne) Exec(ctx context.Context) error { + _, err := aeuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (aeuo *AIEmployeeUpdateOne) ExecX(ctx context.Context) { + if err := aeuo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (aeuo *AIEmployeeUpdateOne) defaults() { + if _, ok := aeuo.mutation.UpdatedAt(); !ok { + v := aiemployee.UpdateDefaultUpdatedAt() + aeuo.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (aeuo *AIEmployeeUpdateOne) check() error { + if aeuo.mutation.AdminCleared() && len(aeuo.mutation.AdminIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "AIEmployee.admin"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (aeuo *AIEmployeeUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AIEmployeeUpdateOne { + aeuo.modifiers = append(aeuo.modifiers, modifiers...) + return aeuo +} + +func (aeuo *AIEmployeeUpdateOne) sqlSave(ctx context.Context) (_node *AIEmployee, err error) { + if err := aeuo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(aiemployee.Table, aiemployee.Columns, sqlgraph.NewFieldSpec(aiemployee.FieldID, field.TypeUUID)) + id, ok := aeuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AIEmployee.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := aeuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, aiemployee.FieldID) + for _, f := range fields { + if !aiemployee.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != aiemployee.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := aeuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := aeuo.mutation.Name(); ok { + _spec.SetField(aiemployee.FieldName, field.TypeString, value) + } + if value, ok := aeuo.mutation.Position(); ok { + _spec.SetField(aiemployee.FieldPosition, field.TypeString, value) + } + if value, ok := aeuo.mutation.RepositoryURL(); ok { + _spec.SetField(aiemployee.FieldRepositoryURL, field.TypeString, value) + } + if value, ok := aeuo.mutation.RepositoryUser(); ok { + _spec.SetField(aiemployee.FieldRepositoryUser, field.TypeString, value) + } + if value, ok := aeuo.mutation.Platform(); ok { + _spec.SetField(aiemployee.FieldPlatform, field.TypeString, value) + } + if value, ok := aeuo.mutation.Token(); ok { + _spec.SetField(aiemployee.FieldToken, field.TypeString, value) + } + if value, ok := aeuo.mutation.WebhookSecret(); ok { + _spec.SetField(aiemployee.FieldWebhookSecret, field.TypeString, value) + } + if value, ok := aeuo.mutation.WebhookURL(); ok { + _spec.SetField(aiemployee.FieldWebhookURL, field.TypeString, value) + } + if value, ok := aeuo.mutation.Parameters(); ok { + _spec.SetField(aiemployee.FieldParameters, field.TypeJSON, value) + } + if value, ok := aeuo.mutation.CreatedAt(); ok { + _spec.SetField(aiemployee.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := aeuo.mutation.UpdatedAt(); ok { + _spec.SetField(aiemployee.FieldUpdatedAt, field.TypeTime, value) + } + if aeuo.mutation.AdminCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: aiemployee.AdminTable, + Columns: []string{aiemployee.AdminColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(admin.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := aeuo.mutation.AdminIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: aiemployee.AdminTable, + Columns: []string{aiemployee.AdminColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(admin.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(aeuo.modifiers...) + _node = &AIEmployee{config: aeuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, aeuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{aiemployee.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + aeuo.mutation.done = true + return _node, nil +} diff --git a/backend/db/aitask.go b/backend/db/aitask.go new file mode 100644 index 0000000..3dd53ac --- /dev/null +++ b/backend/db/aitask.go @@ -0,0 +1,182 @@ +// 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/aitask" + "github.com/google/uuid" +) + +// AITask is the model entity for the AITask schema. +type AITask struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // EmployeeID holds the value of the "employee_id" field. + EmployeeID uuid.UUID `json:"employee_id,omitempty"` + // Status holds the value of the "status" field. + Status string `json:"status,omitempty"` + // Output holds the value of the "output" field. + Output *string `json:"output,omitempty"` + // Logs holds the value of the "logs" field. + Logs *string `json:"logs,omitempty"` + // ErrorMessage holds the value of the "error_message" field. + ErrorMessage *string `json:"error_message,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"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*AITask) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case aitask.FieldStatus, aitask.FieldOutput, aitask.FieldLogs, aitask.FieldErrorMessage: + values[i] = new(sql.NullString) + case aitask.FieldCreatedAt, aitask.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case aitask.FieldID, aitask.FieldEmployeeID: + 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 AITask fields. +func (at *AITask) 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 aitask.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + at.ID = *value + } + case aitask.FieldEmployeeID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field employee_id", values[i]) + } else if value != nil { + at.EmployeeID = *value + } + case aitask.FieldStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + at.Status = value.String + } + case aitask.FieldOutput: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field output", values[i]) + } else if value.Valid { + at.Output = new(string) + *at.Output = value.String + } + case aitask.FieldLogs: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field logs", values[i]) + } else if value.Valid { + at.Logs = new(string) + *at.Logs = value.String + } + case aitask.FieldErrorMessage: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field error_message", values[i]) + } else if value.Valid { + at.ErrorMessage = new(string) + *at.ErrorMessage = value.String + } + case aitask.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 { + at.CreatedAt = value.Time + } + case aitask.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 { + at.UpdatedAt = value.Time + } + default: + at.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the AITask. +// This includes values selected through modifiers, order, etc. +func (at *AITask) Value(name string) (ent.Value, error) { + return at.selectValues.Get(name) +} + +// Update returns a builder for updating this AITask. +// Note that you need to call AITask.Unwrap() before calling this method if this AITask +// was returned from a transaction, and the transaction was committed or rolled back. +func (at *AITask) Update() *AITaskUpdateOne { + return NewAITaskClient(at.config).UpdateOne(at) +} + +// Unwrap unwraps the AITask 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 (at *AITask) Unwrap() *AITask { + _tx, ok := at.config.driver.(*txDriver) + if !ok { + panic("db: AITask is not a transactional entity") + } + at.config.driver = _tx.drv + return at +} + +// String implements the fmt.Stringer. +func (at *AITask) String() string { + var builder strings.Builder + builder.WriteString("AITask(") + builder.WriteString(fmt.Sprintf("id=%v, ", at.ID)) + builder.WriteString("employee_id=") + builder.WriteString(fmt.Sprintf("%v", at.EmployeeID)) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(at.Status) + builder.WriteString(", ") + if v := at.Output; v != nil { + builder.WriteString("output=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := at.Logs; v != nil { + builder.WriteString("logs=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := at.ErrorMessage; v != nil { + builder.WriteString("error_message=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(at.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(at.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// AITasks is a parsable slice of AITask. +type AITasks []*AITask diff --git a/backend/db/aitask/aitask.go b/backend/db/aitask/aitask.go new file mode 100644 index 0000000..edaf86a --- /dev/null +++ b/backend/db/aitask/aitask.go @@ -0,0 +1,106 @@ +// Code generated by ent, DO NOT EDIT. + +package aitask + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the aitask type in the database. + Label = "ai_task" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldEmployeeID holds the string denoting the employee_id field in the database. + FieldEmployeeID = "employee_id" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldOutput holds the string denoting the output field in the database. + FieldOutput = "output" + // FieldLogs holds the string denoting the logs field in the database. + FieldLogs = "logs" + // FieldErrorMessage holds the string denoting the error_message field in the database. + FieldErrorMessage = "error_message" + // 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" + // Table holds the table name of the aitask in the database. + Table = "ai_tasks" +) + +// Columns holds all SQL columns for aitask fields. +var Columns = []string{ + FieldID, + FieldEmployeeID, + FieldStatus, + FieldOutput, + FieldLogs, + FieldErrorMessage, + FieldCreatedAt, + FieldUpdatedAt, +} + +// 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 ( + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus string + // 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 +) + +// OrderOption defines the ordering options for the AITask 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() +} + +// ByEmployeeID orders the results by the employee_id field. +func ByEmployeeID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEmployeeID, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByOutput orders the results by the output field. +func ByOutput(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOutput, opts...).ToFunc() +} + +// ByLogs orders the results by the logs field. +func ByLogs(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLogs, opts...).ToFunc() +} + +// ByErrorMessage orders the results by the error_message field. +func ByErrorMessage(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldErrorMessage, 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() +} diff --git a/backend/db/aitask/where.go b/backend/db/aitask/where.go new file mode 100644 index 0000000..7f839bf --- /dev/null +++ b/backend/db/aitask/where.go @@ -0,0 +1,516 @@ +// Code generated by ent, DO NOT EDIT. + +package aitask + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "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.AITask { + return predicate.AITask(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldID, id)) +} + +// EmployeeID applies equality check predicate on the "employee_id" field. It's identical to EmployeeIDEQ. +func EmployeeID(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldEmployeeID, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldStatus, v)) +} + +// Output applies equality check predicate on the "output" field. It's identical to OutputEQ. +func Output(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldOutput, v)) +} + +// Logs applies equality check predicate on the "logs" field. It's identical to LogsEQ. +func Logs(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldLogs, v)) +} + +// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ. +func ErrorMessage(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldErrorMessage, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.AITask { + return predicate.AITask(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.AITask { + return predicate.AITask(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// EmployeeIDEQ applies the EQ predicate on the "employee_id" field. +func EmployeeIDEQ(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldEmployeeID, v)) +} + +// EmployeeIDNEQ applies the NEQ predicate on the "employee_id" field. +func EmployeeIDNEQ(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldEmployeeID, v)) +} + +// EmployeeIDIn applies the In predicate on the "employee_id" field. +func EmployeeIDIn(vs ...uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldEmployeeID, vs...)) +} + +// EmployeeIDNotIn applies the NotIn predicate on the "employee_id" field. +func EmployeeIDNotIn(vs ...uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldEmployeeID, vs...)) +} + +// EmployeeIDGT applies the GT predicate on the "employee_id" field. +func EmployeeIDGT(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldEmployeeID, v)) +} + +// EmployeeIDGTE applies the GTE predicate on the "employee_id" field. +func EmployeeIDGTE(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldEmployeeID, v)) +} + +// EmployeeIDLT applies the LT predicate on the "employee_id" field. +func EmployeeIDLT(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldEmployeeID, v)) +} + +// EmployeeIDLTE applies the LTE predicate on the "employee_id" field. +func EmployeeIDLTE(v uuid.UUID) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldEmployeeID, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v string) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v string) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldStatus, v)) +} + +// StatusContains applies the Contains predicate on the "status" field. +func StatusContains(v string) predicate.AITask { + return predicate.AITask(sql.FieldContains(FieldStatus, v)) +} + +// StatusHasPrefix applies the HasPrefix predicate on the "status" field. +func StatusHasPrefix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasPrefix(FieldStatus, v)) +} + +// StatusHasSuffix applies the HasSuffix predicate on the "status" field. +func StatusHasSuffix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasSuffix(FieldStatus, v)) +} + +// StatusEqualFold applies the EqualFold predicate on the "status" field. +func StatusEqualFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldEqualFold(FieldStatus, v)) +} + +// StatusContainsFold applies the ContainsFold predicate on the "status" field. +func StatusContainsFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldContainsFold(FieldStatus, v)) +} + +// OutputEQ applies the EQ predicate on the "output" field. +func OutputEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldOutput, v)) +} + +// OutputNEQ applies the NEQ predicate on the "output" field. +func OutputNEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldOutput, v)) +} + +// OutputIn applies the In predicate on the "output" field. +func OutputIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldOutput, vs...)) +} + +// OutputNotIn applies the NotIn predicate on the "output" field. +func OutputNotIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldOutput, vs...)) +} + +// OutputGT applies the GT predicate on the "output" field. +func OutputGT(v string) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldOutput, v)) +} + +// OutputGTE applies the GTE predicate on the "output" field. +func OutputGTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldOutput, v)) +} + +// OutputLT applies the LT predicate on the "output" field. +func OutputLT(v string) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldOutput, v)) +} + +// OutputLTE applies the LTE predicate on the "output" field. +func OutputLTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldOutput, v)) +} + +// OutputContains applies the Contains predicate on the "output" field. +func OutputContains(v string) predicate.AITask { + return predicate.AITask(sql.FieldContains(FieldOutput, v)) +} + +// OutputHasPrefix applies the HasPrefix predicate on the "output" field. +func OutputHasPrefix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasPrefix(FieldOutput, v)) +} + +// OutputHasSuffix applies the HasSuffix predicate on the "output" field. +func OutputHasSuffix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasSuffix(FieldOutput, v)) +} + +// OutputIsNil applies the IsNil predicate on the "output" field. +func OutputIsNil() predicate.AITask { + return predicate.AITask(sql.FieldIsNull(FieldOutput)) +} + +// OutputNotNil applies the NotNil predicate on the "output" field. +func OutputNotNil() predicate.AITask { + return predicate.AITask(sql.FieldNotNull(FieldOutput)) +} + +// OutputEqualFold applies the EqualFold predicate on the "output" field. +func OutputEqualFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldEqualFold(FieldOutput, v)) +} + +// OutputContainsFold applies the ContainsFold predicate on the "output" field. +func OutputContainsFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldContainsFold(FieldOutput, v)) +} + +// LogsEQ applies the EQ predicate on the "logs" field. +func LogsEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldLogs, v)) +} + +// LogsNEQ applies the NEQ predicate on the "logs" field. +func LogsNEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldLogs, v)) +} + +// LogsIn applies the In predicate on the "logs" field. +func LogsIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldLogs, vs...)) +} + +// LogsNotIn applies the NotIn predicate on the "logs" field. +func LogsNotIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldLogs, vs...)) +} + +// LogsGT applies the GT predicate on the "logs" field. +func LogsGT(v string) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldLogs, v)) +} + +// LogsGTE applies the GTE predicate on the "logs" field. +func LogsGTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldLogs, v)) +} + +// LogsLT applies the LT predicate on the "logs" field. +func LogsLT(v string) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldLogs, v)) +} + +// LogsLTE applies the LTE predicate on the "logs" field. +func LogsLTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldLogs, v)) +} + +// LogsContains applies the Contains predicate on the "logs" field. +func LogsContains(v string) predicate.AITask { + return predicate.AITask(sql.FieldContains(FieldLogs, v)) +} + +// LogsHasPrefix applies the HasPrefix predicate on the "logs" field. +func LogsHasPrefix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasPrefix(FieldLogs, v)) +} + +// LogsHasSuffix applies the HasSuffix predicate on the "logs" field. +func LogsHasSuffix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasSuffix(FieldLogs, v)) +} + +// LogsIsNil applies the IsNil predicate on the "logs" field. +func LogsIsNil() predicate.AITask { + return predicate.AITask(sql.FieldIsNull(FieldLogs)) +} + +// LogsNotNil applies the NotNil predicate on the "logs" field. +func LogsNotNil() predicate.AITask { + return predicate.AITask(sql.FieldNotNull(FieldLogs)) +} + +// LogsEqualFold applies the EqualFold predicate on the "logs" field. +func LogsEqualFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldEqualFold(FieldLogs, v)) +} + +// LogsContainsFold applies the ContainsFold predicate on the "logs" field. +func LogsContainsFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldContainsFold(FieldLogs, v)) +} + +// ErrorMessageEQ applies the EQ predicate on the "error_message" field. +func ErrorMessageEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldErrorMessage, v)) +} + +// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field. +func ErrorMessageNEQ(v string) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldErrorMessage, v)) +} + +// ErrorMessageIn applies the In predicate on the "error_message" field. +func ErrorMessageIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldErrorMessage, vs...)) +} + +// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field. +func ErrorMessageNotIn(vs ...string) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldErrorMessage, vs...)) +} + +// ErrorMessageGT applies the GT predicate on the "error_message" field. +func ErrorMessageGT(v string) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldErrorMessage, v)) +} + +// ErrorMessageGTE applies the GTE predicate on the "error_message" field. +func ErrorMessageGTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldErrorMessage, v)) +} + +// ErrorMessageLT applies the LT predicate on the "error_message" field. +func ErrorMessageLT(v string) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldErrorMessage, v)) +} + +// ErrorMessageLTE applies the LTE predicate on the "error_message" field. +func ErrorMessageLTE(v string) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldErrorMessage, v)) +} + +// ErrorMessageContains applies the Contains predicate on the "error_message" field. +func ErrorMessageContains(v string) predicate.AITask { + return predicate.AITask(sql.FieldContains(FieldErrorMessage, v)) +} + +// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field. +func ErrorMessageHasPrefix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasPrefix(FieldErrorMessage, v)) +} + +// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field. +func ErrorMessageHasSuffix(v string) predicate.AITask { + return predicate.AITask(sql.FieldHasSuffix(FieldErrorMessage, v)) +} + +// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field. +func ErrorMessageIsNil() predicate.AITask { + return predicate.AITask(sql.FieldIsNull(FieldErrorMessage)) +} + +// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field. +func ErrorMessageNotNil() predicate.AITask { + return predicate.AITask(sql.FieldNotNull(FieldErrorMessage)) +} + +// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field. +func ErrorMessageEqualFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldEqualFold(FieldErrorMessage, v)) +} + +// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field. +func ErrorMessageContainsFold(v string) predicate.AITask { + return predicate.AITask(sql.FieldContainsFold(FieldErrorMessage, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.AITask { + return predicate.AITask(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.AITask { + return predicate.AITask(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.AITask { + return predicate.AITask(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.AITask) predicate.AITask { + return predicate.AITask(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.AITask) predicate.AITask { + return predicate.AITask(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.AITask) predicate.AITask { + return predicate.AITask(sql.NotPredicates(p)) +} diff --git a/backend/db/aitask_create.go b/backend/db/aitask_create.go new file mode 100644 index 0000000..6c894b6 --- /dev/null +++ b/backend/db/aitask_create.go @@ -0,0 +1,926 @@ +// 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/aitask" + "github.com/google/uuid" +) + +// AITaskCreate is the builder for creating a AITask entity. +type AITaskCreate struct { + config + mutation *AITaskMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetEmployeeID sets the "employee_id" field. +func (atc *AITaskCreate) SetEmployeeID(u uuid.UUID) *AITaskCreate { + atc.mutation.SetEmployeeID(u) + return atc +} + +// SetStatus sets the "status" field. +func (atc *AITaskCreate) SetStatus(s string) *AITaskCreate { + atc.mutation.SetStatus(s) + return atc +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (atc *AITaskCreate) SetNillableStatus(s *string) *AITaskCreate { + if s != nil { + atc.SetStatus(*s) + } + return atc +} + +// SetOutput sets the "output" field. +func (atc *AITaskCreate) SetOutput(s string) *AITaskCreate { + atc.mutation.SetOutput(s) + return atc +} + +// SetNillableOutput sets the "output" field if the given value is not nil. +func (atc *AITaskCreate) SetNillableOutput(s *string) *AITaskCreate { + if s != nil { + atc.SetOutput(*s) + } + return atc +} + +// SetLogs sets the "logs" field. +func (atc *AITaskCreate) SetLogs(s string) *AITaskCreate { + atc.mutation.SetLogs(s) + return atc +} + +// SetNillableLogs sets the "logs" field if the given value is not nil. +func (atc *AITaskCreate) SetNillableLogs(s *string) *AITaskCreate { + if s != nil { + atc.SetLogs(*s) + } + return atc +} + +// SetErrorMessage sets the "error_message" field. +func (atc *AITaskCreate) SetErrorMessage(s string) *AITaskCreate { + atc.mutation.SetErrorMessage(s) + return atc +} + +// SetNillableErrorMessage sets the "error_message" field if the given value is not nil. +func (atc *AITaskCreate) SetNillableErrorMessage(s *string) *AITaskCreate { + if s != nil { + atc.SetErrorMessage(*s) + } + return atc +} + +// SetCreatedAt sets the "created_at" field. +func (atc *AITaskCreate) SetCreatedAt(t time.Time) *AITaskCreate { + atc.mutation.SetCreatedAt(t) + return atc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (atc *AITaskCreate) SetNillableCreatedAt(t *time.Time) *AITaskCreate { + if t != nil { + atc.SetCreatedAt(*t) + } + return atc +} + +// SetUpdatedAt sets the "updated_at" field. +func (atc *AITaskCreate) SetUpdatedAt(t time.Time) *AITaskCreate { + atc.mutation.SetUpdatedAt(t) + return atc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (atc *AITaskCreate) SetNillableUpdatedAt(t *time.Time) *AITaskCreate { + if t != nil { + atc.SetUpdatedAt(*t) + } + return atc +} + +// SetID sets the "id" field. +func (atc *AITaskCreate) SetID(u uuid.UUID) *AITaskCreate { + atc.mutation.SetID(u) + return atc +} + +// Mutation returns the AITaskMutation object of the builder. +func (atc *AITaskCreate) Mutation() *AITaskMutation { + return atc.mutation +} + +// Save creates the AITask in the database. +func (atc *AITaskCreate) Save(ctx context.Context) (*AITask, error) { + atc.defaults() + return withHooks(ctx, atc.sqlSave, atc.mutation, atc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (atc *AITaskCreate) SaveX(ctx context.Context) *AITask { + v, err := atc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (atc *AITaskCreate) Exec(ctx context.Context) error { + _, err := atc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (atc *AITaskCreate) ExecX(ctx context.Context) { + if err := atc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (atc *AITaskCreate) defaults() { + if _, ok := atc.mutation.Status(); !ok { + v := aitask.DefaultStatus + atc.mutation.SetStatus(v) + } + if _, ok := atc.mutation.CreatedAt(); !ok { + v := aitask.DefaultCreatedAt() + atc.mutation.SetCreatedAt(v) + } + if _, ok := atc.mutation.UpdatedAt(); !ok { + v := aitask.DefaultUpdatedAt() + atc.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (atc *AITaskCreate) check() error { + if _, ok := atc.mutation.EmployeeID(); !ok { + return &ValidationError{Name: "employee_id", err: errors.New(`db: missing required field "AITask.employee_id"`)} + } + if _, ok := atc.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`db: missing required field "AITask.status"`)} + } + if _, ok := atc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "AITask.created_at"`)} + } + if _, ok := atc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "AITask.updated_at"`)} + } + return nil +} + +func (atc *AITaskCreate) sqlSave(ctx context.Context) (*AITask, error) { + if err := atc.check(); err != nil { + return nil, err + } + _node, _spec := atc.createSpec() + if err := sqlgraph.CreateNode(ctx, atc.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 + } + } + atc.mutation.id = &_node.ID + atc.mutation.done = true + return _node, nil +} + +func (atc *AITaskCreate) createSpec() (*AITask, *sqlgraph.CreateSpec) { + var ( + _node = &AITask{config: atc.config} + _spec = sqlgraph.NewCreateSpec(aitask.Table, sqlgraph.NewFieldSpec(aitask.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = atc.conflict + if id, ok := atc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := atc.mutation.EmployeeID(); ok { + _spec.SetField(aitask.FieldEmployeeID, field.TypeUUID, value) + _node.EmployeeID = value + } + if value, ok := atc.mutation.Status(); ok { + _spec.SetField(aitask.FieldStatus, field.TypeString, value) + _node.Status = value + } + if value, ok := atc.mutation.Output(); ok { + _spec.SetField(aitask.FieldOutput, field.TypeString, value) + _node.Output = &value + } + if value, ok := atc.mutation.Logs(); ok { + _spec.SetField(aitask.FieldLogs, field.TypeString, value) + _node.Logs = &value + } + if value, ok := atc.mutation.ErrorMessage(); ok { + _spec.SetField(aitask.FieldErrorMessage, field.TypeString, value) + _node.ErrorMessage = &value + } + if value, ok := atc.mutation.CreatedAt(); ok { + _spec.SetField(aitask.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := atc.mutation.UpdatedAt(); ok { + _spec.SetField(aitask.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.AITask.Create(). +// SetEmployeeID(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.AITaskUpsert) { +// SetEmployeeID(v+v). +// }). +// Exec(ctx) +func (atc *AITaskCreate) OnConflict(opts ...sql.ConflictOption) *AITaskUpsertOne { + atc.conflict = opts + return &AITaskUpsertOne{ + create: atc, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.AITask.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (atc *AITaskCreate) OnConflictColumns(columns ...string) *AITaskUpsertOne { + atc.conflict = append(atc.conflict, sql.ConflictColumns(columns...)) + return &AITaskUpsertOne{ + create: atc, + } +} + +type ( + // AITaskUpsertOne is the builder for "upsert"-ing + // one AITask node. + AITaskUpsertOne struct { + create *AITaskCreate + } + + // AITaskUpsert is the "OnConflict" setter. + AITaskUpsert struct { + *sql.UpdateSet + } +) + +// SetEmployeeID sets the "employee_id" field. +func (u *AITaskUpsert) SetEmployeeID(v uuid.UUID) *AITaskUpsert { + u.Set(aitask.FieldEmployeeID, v) + return u +} + +// UpdateEmployeeID sets the "employee_id" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateEmployeeID() *AITaskUpsert { + u.SetExcluded(aitask.FieldEmployeeID) + return u +} + +// SetStatus sets the "status" field. +func (u *AITaskUpsert) SetStatus(v string) *AITaskUpsert { + u.Set(aitask.FieldStatus, v) + return u +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateStatus() *AITaskUpsert { + u.SetExcluded(aitask.FieldStatus) + return u +} + +// SetOutput sets the "output" field. +func (u *AITaskUpsert) SetOutput(v string) *AITaskUpsert { + u.Set(aitask.FieldOutput, v) + return u +} + +// UpdateOutput sets the "output" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateOutput() *AITaskUpsert { + u.SetExcluded(aitask.FieldOutput) + return u +} + +// ClearOutput clears the value of the "output" field. +func (u *AITaskUpsert) ClearOutput() *AITaskUpsert { + u.SetNull(aitask.FieldOutput) + return u +} + +// SetLogs sets the "logs" field. +func (u *AITaskUpsert) SetLogs(v string) *AITaskUpsert { + u.Set(aitask.FieldLogs, v) + return u +} + +// UpdateLogs sets the "logs" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateLogs() *AITaskUpsert { + u.SetExcluded(aitask.FieldLogs) + return u +} + +// ClearLogs clears the value of the "logs" field. +func (u *AITaskUpsert) ClearLogs() *AITaskUpsert { + u.SetNull(aitask.FieldLogs) + return u +} + +// SetErrorMessage sets the "error_message" field. +func (u *AITaskUpsert) SetErrorMessage(v string) *AITaskUpsert { + u.Set(aitask.FieldErrorMessage, v) + return u +} + +// UpdateErrorMessage sets the "error_message" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateErrorMessage() *AITaskUpsert { + u.SetExcluded(aitask.FieldErrorMessage) + return u +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (u *AITaskUpsert) ClearErrorMessage() *AITaskUpsert { + u.SetNull(aitask.FieldErrorMessage) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *AITaskUpsert) SetCreatedAt(v time.Time) *AITaskUpsert { + u.Set(aitask.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateCreatedAt() *AITaskUpsert { + u.SetExcluded(aitask.FieldCreatedAt) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *AITaskUpsert) SetUpdatedAt(v time.Time) *AITaskUpsert { + u.Set(aitask.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *AITaskUpsert) UpdateUpdatedAt() *AITaskUpsert { + u.SetExcluded(aitask.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.AITask.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(aitask.FieldID) +// }), +// ). +// Exec(ctx) +func (u *AITaskUpsertOne) UpdateNewValues() *AITaskUpsertOne { + 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(aitask.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.AITask.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *AITaskUpsertOne) Ignore() *AITaskUpsertOne { + 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 *AITaskUpsertOne) DoNothing() *AITaskUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the AITaskCreate.OnConflict +// documentation for more info. +func (u *AITaskUpsertOne) Update(set func(*AITaskUpsert)) *AITaskUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&AITaskUpsert{UpdateSet: update}) + })) + return u +} + +// SetEmployeeID sets the "employee_id" field. +func (u *AITaskUpsertOne) SetEmployeeID(v uuid.UUID) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetEmployeeID(v) + }) +} + +// UpdateEmployeeID sets the "employee_id" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateEmployeeID() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateEmployeeID() + }) +} + +// SetStatus sets the "status" field. +func (u *AITaskUpsertOne) SetStatus(v string) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateStatus() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateStatus() + }) +} + +// SetOutput sets the "output" field. +func (u *AITaskUpsertOne) SetOutput(v string) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetOutput(v) + }) +} + +// UpdateOutput sets the "output" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateOutput() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateOutput() + }) +} + +// ClearOutput clears the value of the "output" field. +func (u *AITaskUpsertOne) ClearOutput() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.ClearOutput() + }) +} + +// SetLogs sets the "logs" field. +func (u *AITaskUpsertOne) SetLogs(v string) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetLogs(v) + }) +} + +// UpdateLogs sets the "logs" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateLogs() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateLogs() + }) +} + +// ClearLogs clears the value of the "logs" field. +func (u *AITaskUpsertOne) ClearLogs() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.ClearLogs() + }) +} + +// SetErrorMessage sets the "error_message" field. +func (u *AITaskUpsertOne) SetErrorMessage(v string) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetErrorMessage(v) + }) +} + +// UpdateErrorMessage sets the "error_message" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateErrorMessage() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateErrorMessage() + }) +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (u *AITaskUpsertOne) ClearErrorMessage() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.ClearErrorMessage() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *AITaskUpsertOne) SetCreatedAt(v time.Time) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateCreatedAt() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *AITaskUpsertOne) SetUpdatedAt(v time.Time) *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *AITaskUpsertOne) UpdateUpdatedAt() *AITaskUpsertOne { + return u.Update(func(s *AITaskUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *AITaskUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for AITaskCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *AITaskUpsertOne) 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 *AITaskUpsertOne) 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: AITaskUpsertOne.ID is not supported by MySQL driver. Use AITaskUpsertOne.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 *AITaskUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// AITaskCreateBulk is the builder for creating many AITask entities in bulk. +type AITaskCreateBulk struct { + config + err error + builders []*AITaskCreate + conflict []sql.ConflictOption +} + +// Save creates the AITask entities in the database. +func (atcb *AITaskCreateBulk) Save(ctx context.Context) ([]*AITask, error) { + if atcb.err != nil { + return nil, atcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(atcb.builders)) + nodes := make([]*AITask, len(atcb.builders)) + mutators := make([]Mutator, len(atcb.builders)) + for i := range atcb.builders { + func(i int, root context.Context) { + builder := atcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AITaskMutation) + 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, atcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = atcb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, atcb.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, atcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (atcb *AITaskCreateBulk) SaveX(ctx context.Context) []*AITask { + v, err := atcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (atcb *AITaskCreateBulk) Exec(ctx context.Context) error { + _, err := atcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (atcb *AITaskCreateBulk) ExecX(ctx context.Context) { + if err := atcb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.AITask.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.AITaskUpsert) { +// SetEmployeeID(v+v). +// }). +// Exec(ctx) +func (atcb *AITaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *AITaskUpsertBulk { + atcb.conflict = opts + return &AITaskUpsertBulk{ + create: atcb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.AITask.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (atcb *AITaskCreateBulk) OnConflictColumns(columns ...string) *AITaskUpsertBulk { + atcb.conflict = append(atcb.conflict, sql.ConflictColumns(columns...)) + return &AITaskUpsertBulk{ + create: atcb, + } +} + +// AITaskUpsertBulk is the builder for "upsert"-ing +// a bulk of AITask nodes. +type AITaskUpsertBulk struct { + create *AITaskCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.AITask.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(aitask.FieldID) +// }), +// ). +// Exec(ctx) +func (u *AITaskUpsertBulk) UpdateNewValues() *AITaskUpsertBulk { + 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(aitask.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.AITask.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *AITaskUpsertBulk) Ignore() *AITaskUpsertBulk { + 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 *AITaskUpsertBulk) DoNothing() *AITaskUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the AITaskCreateBulk.OnConflict +// documentation for more info. +func (u *AITaskUpsertBulk) Update(set func(*AITaskUpsert)) *AITaskUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&AITaskUpsert{UpdateSet: update}) + })) + return u +} + +// SetEmployeeID sets the "employee_id" field. +func (u *AITaskUpsertBulk) SetEmployeeID(v uuid.UUID) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetEmployeeID(v) + }) +} + +// UpdateEmployeeID sets the "employee_id" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateEmployeeID() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateEmployeeID() + }) +} + +// SetStatus sets the "status" field. +func (u *AITaskUpsertBulk) SetStatus(v string) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateStatus() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateStatus() + }) +} + +// SetOutput sets the "output" field. +func (u *AITaskUpsertBulk) SetOutput(v string) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetOutput(v) + }) +} + +// UpdateOutput sets the "output" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateOutput() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateOutput() + }) +} + +// ClearOutput clears the value of the "output" field. +func (u *AITaskUpsertBulk) ClearOutput() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.ClearOutput() + }) +} + +// SetLogs sets the "logs" field. +func (u *AITaskUpsertBulk) SetLogs(v string) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetLogs(v) + }) +} + +// UpdateLogs sets the "logs" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateLogs() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateLogs() + }) +} + +// ClearLogs clears the value of the "logs" field. +func (u *AITaskUpsertBulk) ClearLogs() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.ClearLogs() + }) +} + +// SetErrorMessage sets the "error_message" field. +func (u *AITaskUpsertBulk) SetErrorMessage(v string) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetErrorMessage(v) + }) +} + +// UpdateErrorMessage sets the "error_message" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateErrorMessage() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateErrorMessage() + }) +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (u *AITaskUpsertBulk) ClearErrorMessage() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.ClearErrorMessage() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *AITaskUpsertBulk) SetCreatedAt(v time.Time) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateCreatedAt() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *AITaskUpsertBulk) SetUpdatedAt(v time.Time) *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *AITaskUpsertBulk) UpdateUpdatedAt() *AITaskUpsertBulk { + return u.Update(func(s *AITaskUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *AITaskUpsertBulk) 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 AITaskCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for AITaskCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *AITaskUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/aitask_delete.go b/backend/db/aitask_delete.go new file mode 100644 index 0000000..0736301 --- /dev/null +++ b/backend/db/aitask_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/aitask" + "github.com/chaitin/MonkeyCode/backend/db/predicate" +) + +// AITaskDelete is the builder for deleting a AITask entity. +type AITaskDelete struct { + config + hooks []Hook + mutation *AITaskMutation +} + +// Where appends a list predicates to the AITaskDelete builder. +func (atd *AITaskDelete) Where(ps ...predicate.AITask) *AITaskDelete { + atd.mutation.Where(ps...) + return atd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (atd *AITaskDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, atd.sqlExec, atd.mutation, atd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (atd *AITaskDelete) ExecX(ctx context.Context) int { + n, err := atd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (atd *AITaskDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(aitask.Table, sqlgraph.NewFieldSpec(aitask.FieldID, field.TypeUUID)) + if ps := atd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, atd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + atd.mutation.done = true + return affected, err +} + +// AITaskDeleteOne is the builder for deleting a single AITask entity. +type AITaskDeleteOne struct { + atd *AITaskDelete +} + +// Where appends a list predicates to the AITaskDelete builder. +func (atdo *AITaskDeleteOne) Where(ps ...predicate.AITask) *AITaskDeleteOne { + atdo.atd.mutation.Where(ps...) + return atdo +} + +// Exec executes the deletion query. +func (atdo *AITaskDeleteOne) Exec(ctx context.Context) error { + n, err := atdo.atd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{aitask.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (atdo *AITaskDeleteOne) ExecX(ctx context.Context) { + if err := atdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/aitask_query.go b/backend/db/aitask_query.go new file mode 100644 index 0000000..b675afe --- /dev/null +++ b/backend/db/aitask_query.go @@ -0,0 +1,578 @@ +// 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/aitask" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// AITaskQuery is the builder for querying AITask entities. +type AITaskQuery struct { + config + ctx *QueryContext + order []aitask.OrderOption + inters []Interceptor + predicates []predicate.AITask + 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 AITaskQuery builder. +func (atq *AITaskQuery) Where(ps ...predicate.AITask) *AITaskQuery { + atq.predicates = append(atq.predicates, ps...) + return atq +} + +// Limit the number of records to be returned by this query. +func (atq *AITaskQuery) Limit(limit int) *AITaskQuery { + atq.ctx.Limit = &limit + return atq +} + +// Offset to start from. +func (atq *AITaskQuery) Offset(offset int) *AITaskQuery { + atq.ctx.Offset = &offset + return atq +} + +// 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 (atq *AITaskQuery) Unique(unique bool) *AITaskQuery { + atq.ctx.Unique = &unique + return atq +} + +// Order specifies how the records should be ordered. +func (atq *AITaskQuery) Order(o ...aitask.OrderOption) *AITaskQuery { + atq.order = append(atq.order, o...) + return atq +} + +// First returns the first AITask entity from the query. +// Returns a *NotFoundError when no AITask was found. +func (atq *AITaskQuery) First(ctx context.Context) (*AITask, error) { + nodes, err := atq.Limit(1).All(setContextOp(ctx, atq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{aitask.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (atq *AITaskQuery) FirstX(ctx context.Context) *AITask { + node, err := atq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first AITask ID from the query. +// Returns a *NotFoundError when no AITask ID was found. +func (atq *AITaskQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = atq.Limit(1).IDs(setContextOp(ctx, atq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{aitask.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (atq *AITaskQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := atq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single AITask entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one AITask entity is found. +// Returns a *NotFoundError when no AITask entities are found. +func (atq *AITaskQuery) Only(ctx context.Context) (*AITask, error) { + nodes, err := atq.Limit(2).All(setContextOp(ctx, atq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{aitask.Label} + default: + return nil, &NotSingularError{aitask.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (atq *AITaskQuery) OnlyX(ctx context.Context) *AITask { + node, err := atq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only AITask ID in the query. +// Returns a *NotSingularError when more than one AITask ID is found. +// Returns a *NotFoundError when no entities are found. +func (atq *AITaskQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = atq.Limit(2).IDs(setContextOp(ctx, atq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{aitask.Label} + default: + err = &NotSingularError{aitask.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (atq *AITaskQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := atq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of AITasks. +func (atq *AITaskQuery) All(ctx context.Context) ([]*AITask, error) { + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryAll) + if err := atq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*AITask, *AITaskQuery]() + return withInterceptors[[]*AITask](ctx, atq, qr, atq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (atq *AITaskQuery) AllX(ctx context.Context) []*AITask { + nodes, err := atq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of AITask IDs. +func (atq *AITaskQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if atq.ctx.Unique == nil && atq.path != nil { + atq.Unique(true) + } + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryIDs) + if err = atq.Select(aitask.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (atq *AITaskQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := atq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (atq *AITaskQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryCount) + if err := atq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, atq, querierCount[*AITaskQuery](), atq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (atq *AITaskQuery) CountX(ctx context.Context) int { + count, err := atq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (atq *AITaskQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryExist) + switch _, err := atq.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 (atq *AITaskQuery) ExistX(ctx context.Context) bool { + exist, err := atq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AITaskQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (atq *AITaskQuery) Clone() *AITaskQuery { + if atq == nil { + return nil + } + return &AITaskQuery{ + config: atq.config, + ctx: atq.ctx.Clone(), + order: append([]aitask.OrderOption{}, atq.order...), + inters: append([]Interceptor{}, atq.inters...), + predicates: append([]predicate.AITask{}, atq.predicates...), + // clone intermediate query. + sql: atq.sql.Clone(), + path: atq.path, + modifiers: append([]func(*sql.Selector){}, atq.modifiers...), + } +} + +// 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 { +// EmployeeID uuid.UUID `json:"employee_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.AITask.Query(). +// GroupBy(aitask.FieldEmployeeID). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (atq *AITaskQuery) GroupBy(field string, fields ...string) *AITaskGroupBy { + atq.ctx.Fields = append([]string{field}, fields...) + grbuild := &AITaskGroupBy{build: atq} + grbuild.flds = &atq.ctx.Fields + grbuild.label = aitask.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 { +// EmployeeID uuid.UUID `json:"employee_id,omitempty"` +// } +// +// client.AITask.Query(). +// Select(aitask.FieldEmployeeID). +// Scan(ctx, &v) +func (atq *AITaskQuery) Select(fields ...string) *AITaskSelect { + atq.ctx.Fields = append(atq.ctx.Fields, fields...) + sbuild := &AITaskSelect{AITaskQuery: atq} + sbuild.label = aitask.Label + sbuild.flds, sbuild.scan = &atq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AITaskSelect configured with the given aggregations. +func (atq *AITaskQuery) Aggregate(fns ...AggregateFunc) *AITaskSelect { + return atq.Select().Aggregate(fns...) +} + +func (atq *AITaskQuery) prepareQuery(ctx context.Context) error { + for _, inter := range atq.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, atq); err != nil { + return err + } + } + } + for _, f := range atq.ctx.Fields { + if !aitask.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if atq.path != nil { + prev, err := atq.path(ctx) + if err != nil { + return err + } + atq.sql = prev + } + return nil +} + +func (atq *AITaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AITask, error) { + var ( + nodes = []*AITask{} + _spec = atq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*AITask).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &AITask{config: atq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + if len(atq.modifiers) > 0 { + _spec.Modifiers = atq.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, atq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (atq *AITaskQuery) sqlCount(ctx context.Context) (int, error) { + _spec := atq.querySpec() + if len(atq.modifiers) > 0 { + _spec.Modifiers = atq.modifiers + } + _spec.Node.Columns = atq.ctx.Fields + if len(atq.ctx.Fields) > 0 { + _spec.Unique = atq.ctx.Unique != nil && *atq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, atq.driver, _spec) +} + +func (atq *AITaskQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(aitask.Table, aitask.Columns, sqlgraph.NewFieldSpec(aitask.FieldID, field.TypeUUID)) + _spec.From = atq.sql + if unique := atq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if atq.path != nil { + _spec.Unique = true + } + if fields := atq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, aitask.FieldID) + for i := range fields { + if fields[i] != aitask.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := atq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := atq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := atq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := atq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (atq *AITaskQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(atq.driver.Dialect()) + t1 := builder.Table(aitask.Table) + columns := atq.ctx.Fields + if len(columns) == 0 { + columns = aitask.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if atq.sql != nil { + selector = atq.sql + selector.Select(selector.Columns(columns...)...) + } + if atq.ctx.Unique != nil && *atq.ctx.Unique { + selector.Distinct() + } + for _, m := range atq.modifiers { + m(selector) + } + for _, p := range atq.predicates { + p(selector) + } + for _, p := range atq.order { + p(selector) + } + if offset := atq.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 := atq.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 (atq *AITaskQuery) ForUpdate(opts ...sql.LockOption) *AITaskQuery { + if atq.driver.Dialect() == dialect.Postgres { + atq.Unique(false) + } + atq.modifiers = append(atq.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return atq +} + +// 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 (atq *AITaskQuery) ForShare(opts ...sql.LockOption) *AITaskQuery { + if atq.driver.Dialect() == dialect.Postgres { + atq.Unique(false) + } + atq.modifiers = append(atq.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return atq +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (atq *AITaskQuery) Modify(modifiers ...func(s *sql.Selector)) *AITaskSelect { + atq.modifiers = append(atq.modifiers, modifiers...) + return atq.Select() +} + +// AITaskGroupBy is the group-by builder for AITask entities. +type AITaskGroupBy struct { + selector + build *AITaskQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (atgb *AITaskGroupBy) Aggregate(fns ...AggregateFunc) *AITaskGroupBy { + atgb.fns = append(atgb.fns, fns...) + return atgb +} + +// Scan applies the selector query and scans the result into the given value. +func (atgb *AITaskGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, atgb.build.ctx, ent.OpQueryGroupBy) + if err := atgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AITaskQuery, *AITaskGroupBy](ctx, atgb.build, atgb, atgb.build.inters, v) +} + +func (atgb *AITaskGroupBy) sqlScan(ctx context.Context, root *AITaskQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(atgb.fns)) + for _, fn := range atgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*atgb.flds)+len(atgb.fns)) + for _, f := range *atgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*atgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := atgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// AITaskSelect is the builder for selecting fields of AITask entities. +type AITaskSelect struct { + *AITaskQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ats *AITaskSelect) Aggregate(fns ...AggregateFunc) *AITaskSelect { + ats.fns = append(ats.fns, fns...) + return ats +} + +// Scan applies the selector query and scans the result into the given value. +func (ats *AITaskSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ats.ctx, ent.OpQuerySelect) + if err := ats.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AITaskQuery, *AITaskSelect](ctx, ats.AITaskQuery, ats, ats.inters, v) +} + +func (ats *AITaskSelect) sqlScan(ctx context.Context, root *AITaskQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ats.fns)) + for _, fn := range ats.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ats.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 := ats.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 (ats *AITaskSelect) Modify(modifiers ...func(s *sql.Selector)) *AITaskSelect { + ats.modifiers = append(ats.modifiers, modifiers...) + return ats +} diff --git a/backend/db/aitask_update.go b/backend/db/aitask_update.go new file mode 100644 index 0000000..3c868e2 --- /dev/null +++ b/backend/db/aitask_update.go @@ -0,0 +1,485 @@ +// 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/aitask" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// AITaskUpdate is the builder for updating AITask entities. +type AITaskUpdate struct { + config + hooks []Hook + mutation *AITaskMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the AITaskUpdate builder. +func (atu *AITaskUpdate) Where(ps ...predicate.AITask) *AITaskUpdate { + atu.mutation.Where(ps...) + return atu +} + +// SetEmployeeID sets the "employee_id" field. +func (atu *AITaskUpdate) SetEmployeeID(u uuid.UUID) *AITaskUpdate { + atu.mutation.SetEmployeeID(u) + return atu +} + +// SetNillableEmployeeID sets the "employee_id" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableEmployeeID(u *uuid.UUID) *AITaskUpdate { + if u != nil { + atu.SetEmployeeID(*u) + } + return atu +} + +// SetStatus sets the "status" field. +func (atu *AITaskUpdate) SetStatus(s string) *AITaskUpdate { + atu.mutation.SetStatus(s) + return atu +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableStatus(s *string) *AITaskUpdate { + if s != nil { + atu.SetStatus(*s) + } + return atu +} + +// SetOutput sets the "output" field. +func (atu *AITaskUpdate) SetOutput(s string) *AITaskUpdate { + atu.mutation.SetOutput(s) + return atu +} + +// SetNillableOutput sets the "output" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableOutput(s *string) *AITaskUpdate { + if s != nil { + atu.SetOutput(*s) + } + return atu +} + +// ClearOutput clears the value of the "output" field. +func (atu *AITaskUpdate) ClearOutput() *AITaskUpdate { + atu.mutation.ClearOutput() + return atu +} + +// SetLogs sets the "logs" field. +func (atu *AITaskUpdate) SetLogs(s string) *AITaskUpdate { + atu.mutation.SetLogs(s) + return atu +} + +// SetNillableLogs sets the "logs" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableLogs(s *string) *AITaskUpdate { + if s != nil { + atu.SetLogs(*s) + } + return atu +} + +// ClearLogs clears the value of the "logs" field. +func (atu *AITaskUpdate) ClearLogs() *AITaskUpdate { + atu.mutation.ClearLogs() + return atu +} + +// SetErrorMessage sets the "error_message" field. +func (atu *AITaskUpdate) SetErrorMessage(s string) *AITaskUpdate { + atu.mutation.SetErrorMessage(s) + return atu +} + +// SetNillableErrorMessage sets the "error_message" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableErrorMessage(s *string) *AITaskUpdate { + if s != nil { + atu.SetErrorMessage(*s) + } + return atu +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (atu *AITaskUpdate) ClearErrorMessage() *AITaskUpdate { + atu.mutation.ClearErrorMessage() + return atu +} + +// SetCreatedAt sets the "created_at" field. +func (atu *AITaskUpdate) SetCreatedAt(t time.Time) *AITaskUpdate { + atu.mutation.SetCreatedAt(t) + return atu +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableCreatedAt(t *time.Time) *AITaskUpdate { + if t != nil { + atu.SetCreatedAt(*t) + } + return atu +} + +// SetUpdatedAt sets the "updated_at" field. +func (atu *AITaskUpdate) SetUpdatedAt(t time.Time) *AITaskUpdate { + atu.mutation.SetUpdatedAt(t) + return atu +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (atu *AITaskUpdate) SetNillableUpdatedAt(t *time.Time) *AITaskUpdate { + if t != nil { + atu.SetUpdatedAt(*t) + } + return atu +} + +// Mutation returns the AITaskMutation object of the builder. +func (atu *AITaskUpdate) Mutation() *AITaskMutation { + return atu.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (atu *AITaskUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, atu.sqlSave, atu.mutation, atu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (atu *AITaskUpdate) SaveX(ctx context.Context) int { + affected, err := atu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (atu *AITaskUpdate) Exec(ctx context.Context) error { + _, err := atu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (atu *AITaskUpdate) ExecX(ctx context.Context) { + if err := atu.Exec(ctx); err != nil { + panic(err) + } +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (atu *AITaskUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AITaskUpdate { + atu.modifiers = append(atu.modifiers, modifiers...) + return atu +} + +func (atu *AITaskUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := sqlgraph.NewUpdateSpec(aitask.Table, aitask.Columns, sqlgraph.NewFieldSpec(aitask.FieldID, field.TypeUUID)) + if ps := atu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := atu.mutation.EmployeeID(); ok { + _spec.SetField(aitask.FieldEmployeeID, field.TypeUUID, value) + } + if value, ok := atu.mutation.Status(); ok { + _spec.SetField(aitask.FieldStatus, field.TypeString, value) + } + if value, ok := atu.mutation.Output(); ok { + _spec.SetField(aitask.FieldOutput, field.TypeString, value) + } + if atu.mutation.OutputCleared() { + _spec.ClearField(aitask.FieldOutput, field.TypeString) + } + if value, ok := atu.mutation.Logs(); ok { + _spec.SetField(aitask.FieldLogs, field.TypeString, value) + } + if atu.mutation.LogsCleared() { + _spec.ClearField(aitask.FieldLogs, field.TypeString) + } + if value, ok := atu.mutation.ErrorMessage(); ok { + _spec.SetField(aitask.FieldErrorMessage, field.TypeString, value) + } + if atu.mutation.ErrorMessageCleared() { + _spec.ClearField(aitask.FieldErrorMessage, field.TypeString) + } + if value, ok := atu.mutation.CreatedAt(); ok { + _spec.SetField(aitask.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := atu.mutation.UpdatedAt(); ok { + _spec.SetField(aitask.FieldUpdatedAt, field.TypeTime, value) + } + _spec.AddModifiers(atu.modifiers...) + if n, err = sqlgraph.UpdateNodes(ctx, atu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{aitask.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + atu.mutation.done = true + return n, nil +} + +// AITaskUpdateOne is the builder for updating a single AITask entity. +type AITaskUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AITaskMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetEmployeeID sets the "employee_id" field. +func (atuo *AITaskUpdateOne) SetEmployeeID(u uuid.UUID) *AITaskUpdateOne { + atuo.mutation.SetEmployeeID(u) + return atuo +} + +// SetNillableEmployeeID sets the "employee_id" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableEmployeeID(u *uuid.UUID) *AITaskUpdateOne { + if u != nil { + atuo.SetEmployeeID(*u) + } + return atuo +} + +// SetStatus sets the "status" field. +func (atuo *AITaskUpdateOne) SetStatus(s string) *AITaskUpdateOne { + atuo.mutation.SetStatus(s) + return atuo +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableStatus(s *string) *AITaskUpdateOne { + if s != nil { + atuo.SetStatus(*s) + } + return atuo +} + +// SetOutput sets the "output" field. +func (atuo *AITaskUpdateOne) SetOutput(s string) *AITaskUpdateOne { + atuo.mutation.SetOutput(s) + return atuo +} + +// SetNillableOutput sets the "output" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableOutput(s *string) *AITaskUpdateOne { + if s != nil { + atuo.SetOutput(*s) + } + return atuo +} + +// ClearOutput clears the value of the "output" field. +func (atuo *AITaskUpdateOne) ClearOutput() *AITaskUpdateOne { + atuo.mutation.ClearOutput() + return atuo +} + +// SetLogs sets the "logs" field. +func (atuo *AITaskUpdateOne) SetLogs(s string) *AITaskUpdateOne { + atuo.mutation.SetLogs(s) + return atuo +} + +// SetNillableLogs sets the "logs" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableLogs(s *string) *AITaskUpdateOne { + if s != nil { + atuo.SetLogs(*s) + } + return atuo +} + +// ClearLogs clears the value of the "logs" field. +func (atuo *AITaskUpdateOne) ClearLogs() *AITaskUpdateOne { + atuo.mutation.ClearLogs() + return atuo +} + +// SetErrorMessage sets the "error_message" field. +func (atuo *AITaskUpdateOne) SetErrorMessage(s string) *AITaskUpdateOne { + atuo.mutation.SetErrorMessage(s) + return atuo +} + +// SetNillableErrorMessage sets the "error_message" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableErrorMessage(s *string) *AITaskUpdateOne { + if s != nil { + atuo.SetErrorMessage(*s) + } + return atuo +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (atuo *AITaskUpdateOne) ClearErrorMessage() *AITaskUpdateOne { + atuo.mutation.ClearErrorMessage() + return atuo +} + +// SetCreatedAt sets the "created_at" field. +func (atuo *AITaskUpdateOne) SetCreatedAt(t time.Time) *AITaskUpdateOne { + atuo.mutation.SetCreatedAt(t) + return atuo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableCreatedAt(t *time.Time) *AITaskUpdateOne { + if t != nil { + atuo.SetCreatedAt(*t) + } + return atuo +} + +// SetUpdatedAt sets the "updated_at" field. +func (atuo *AITaskUpdateOne) SetUpdatedAt(t time.Time) *AITaskUpdateOne { + atuo.mutation.SetUpdatedAt(t) + return atuo +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (atuo *AITaskUpdateOne) SetNillableUpdatedAt(t *time.Time) *AITaskUpdateOne { + if t != nil { + atuo.SetUpdatedAt(*t) + } + return atuo +} + +// Mutation returns the AITaskMutation object of the builder. +func (atuo *AITaskUpdateOne) Mutation() *AITaskMutation { + return atuo.mutation +} + +// Where appends a list predicates to the AITaskUpdate builder. +func (atuo *AITaskUpdateOne) Where(ps ...predicate.AITask) *AITaskUpdateOne { + atuo.mutation.Where(ps...) + return atuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (atuo *AITaskUpdateOne) Select(field string, fields ...string) *AITaskUpdateOne { + atuo.fields = append([]string{field}, fields...) + return atuo +} + +// Save executes the query and returns the updated AITask entity. +func (atuo *AITaskUpdateOne) Save(ctx context.Context) (*AITask, error) { + return withHooks(ctx, atuo.sqlSave, atuo.mutation, atuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (atuo *AITaskUpdateOne) SaveX(ctx context.Context) *AITask { + node, err := atuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (atuo *AITaskUpdateOne) Exec(ctx context.Context) error { + _, err := atuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (atuo *AITaskUpdateOne) ExecX(ctx context.Context) { + if err := atuo.Exec(ctx); err != nil { + panic(err) + } +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (atuo *AITaskUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AITaskUpdateOne { + atuo.modifiers = append(atuo.modifiers, modifiers...) + return atuo +} + +func (atuo *AITaskUpdateOne) sqlSave(ctx context.Context) (_node *AITask, err error) { + _spec := sqlgraph.NewUpdateSpec(aitask.Table, aitask.Columns, sqlgraph.NewFieldSpec(aitask.FieldID, field.TypeUUID)) + id, ok := atuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AITask.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := atuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, aitask.FieldID) + for _, f := range fields { + if !aitask.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != aitask.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := atuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := atuo.mutation.EmployeeID(); ok { + _spec.SetField(aitask.FieldEmployeeID, field.TypeUUID, value) + } + if value, ok := atuo.mutation.Status(); ok { + _spec.SetField(aitask.FieldStatus, field.TypeString, value) + } + if value, ok := atuo.mutation.Output(); ok { + _spec.SetField(aitask.FieldOutput, field.TypeString, value) + } + if atuo.mutation.OutputCleared() { + _spec.ClearField(aitask.FieldOutput, field.TypeString) + } + if value, ok := atuo.mutation.Logs(); ok { + _spec.SetField(aitask.FieldLogs, field.TypeString, value) + } + if atuo.mutation.LogsCleared() { + _spec.ClearField(aitask.FieldLogs, field.TypeString) + } + if value, ok := atuo.mutation.ErrorMessage(); ok { + _spec.SetField(aitask.FieldErrorMessage, field.TypeString, value) + } + if atuo.mutation.ErrorMessageCleared() { + _spec.ClearField(aitask.FieldErrorMessage, field.TypeString) + } + if value, ok := atuo.mutation.CreatedAt(); ok { + _spec.SetField(aitask.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := atuo.mutation.UpdatedAt(); ok { + _spec.SetField(aitask.FieldUpdatedAt, field.TypeTime, value) + } + _spec.AddModifiers(atuo.modifiers...) + _node = &AITask{config: atuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, atuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{aitask.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + atuo.mutation.done = true + return _node, nil +} diff --git a/backend/db/client.go b/backend/db/client.go index cd3d1c9..fff83a7 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -19,6 +19,8 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/aitask" "github.com/chaitin/MonkeyCode/backend/db/apikey" "github.com/chaitin/MonkeyCode/backend/db/billingplan" "github.com/chaitin/MonkeyCode/backend/db/billingquota" @@ -54,6 +56,10 @@ type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema + // AIEmployee is the client for interacting with the AIEmployee builders. + AIEmployee *AIEmployeeClient + // AITask is the client for interacting with the AITask builders. + AITask *AITaskClient // Admin is the client for interacting with the Admin builders. Admin *AdminClient // AdminLoginHistory is the client for interacting with the AdminLoginHistory builders. @@ -123,6 +129,8 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) + c.AIEmployee = NewAIEmployeeClient(c.config) + c.AITask = NewAITaskClient(c.config) c.Admin = NewAdminClient(c.config) c.AdminLoginHistory = NewAdminLoginHistoryClient(c.config) c.AdminRole = NewAdminRoleClient(c.config) @@ -244,6 +252,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { return &Tx{ ctx: ctx, config: cfg, + AIEmployee: NewAIEmployeeClient(cfg), + AITask: NewAITaskClient(cfg), Admin: NewAdminClient(cfg), AdminLoginHistory: NewAdminLoginHistoryClient(cfg), AdminRole: NewAdminRoleClient(cfg), @@ -292,6 +302,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) return &Tx{ ctx: ctx, config: cfg, + AIEmployee: NewAIEmployeeClient(cfg), + AITask: NewAITaskClient(cfg), Admin: NewAdminClient(cfg), AdminLoginHistory: NewAdminLoginHistoryClient(cfg), AdminRole: NewAdminRoleClient(cfg), @@ -327,7 +339,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). -// Admin. +// AIEmployee. // Query(). // Count(ctx) func (c *Client) Debug() *Client { @@ -350,12 +362,13 @@ func (c *Client) Close() error { // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ - c.Admin, c.AdminLoginHistory, c.AdminRole, c.ApiKey, c.BillingPlan, - c.BillingQuota, c.BillingRecord, c.BillingUsage, c.CodeSnippet, c.Extension, - c.InviteCode, c.License, c.Model, c.ModelProvider, c.ModelProviderModel, - c.Role, c.SecurityScanning, c.SecurityScanningResult, c.Setting, c.Task, - c.TaskRecord, c.User, c.UserGroup, c.UserGroupAdmin, c.UserGroupUser, - c.UserIdentity, c.UserLoginHistory, c.Workspace, c.WorkspaceFile, + c.AIEmployee, c.AITask, c.Admin, c.AdminLoginHistory, c.AdminRole, c.ApiKey, + c.BillingPlan, c.BillingQuota, c.BillingRecord, c.BillingUsage, c.CodeSnippet, + c.Extension, c.InviteCode, c.License, c.Model, c.ModelProvider, + c.ModelProviderModel, c.Role, c.SecurityScanning, c.SecurityScanningResult, + c.Setting, c.Task, c.TaskRecord, c.User, c.UserGroup, c.UserGroupAdmin, + c.UserGroupUser, c.UserIdentity, c.UserLoginHistory, c.Workspace, + c.WorkspaceFile, } { n.Use(hooks...) } @@ -365,12 +378,13 @@ func (c *Client) Use(hooks ...Hook) { // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ - c.Admin, c.AdminLoginHistory, c.AdminRole, c.ApiKey, c.BillingPlan, - c.BillingQuota, c.BillingRecord, c.BillingUsage, c.CodeSnippet, c.Extension, - c.InviteCode, c.License, c.Model, c.ModelProvider, c.ModelProviderModel, - c.Role, c.SecurityScanning, c.SecurityScanningResult, c.Setting, c.Task, - c.TaskRecord, c.User, c.UserGroup, c.UserGroupAdmin, c.UserGroupUser, - c.UserIdentity, c.UserLoginHistory, c.Workspace, c.WorkspaceFile, + c.AIEmployee, c.AITask, c.Admin, c.AdminLoginHistory, c.AdminRole, c.ApiKey, + c.BillingPlan, c.BillingQuota, c.BillingRecord, c.BillingUsage, c.CodeSnippet, + c.Extension, c.InviteCode, c.License, c.Model, c.ModelProvider, + c.ModelProviderModel, c.Role, c.SecurityScanning, c.SecurityScanningResult, + c.Setting, c.Task, c.TaskRecord, c.User, c.UserGroup, c.UserGroupAdmin, + c.UserGroupUser, c.UserIdentity, c.UserLoginHistory, c.Workspace, + c.WorkspaceFile, } { n.Intercept(interceptors...) } @@ -379,6 +393,10 @@ func (c *Client) Intercept(interceptors ...Interceptor) { // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { + case *AIEmployeeMutation: + return c.AIEmployee.mutate(ctx, m) + case *AITaskMutation: + return c.AITask.mutate(ctx, m) case *AdminMutation: return c.Admin.mutate(ctx, m) case *AdminLoginHistoryMutation: @@ -442,6 +460,288 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { } } +// AIEmployeeClient is a client for the AIEmployee schema. +type AIEmployeeClient struct { + config +} + +// NewAIEmployeeClient returns a client for the AIEmployee from the given config. +func NewAIEmployeeClient(c config) *AIEmployeeClient { + return &AIEmployeeClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `aiemployee.Hooks(f(g(h())))`. +func (c *AIEmployeeClient) Use(hooks ...Hook) { + c.hooks.AIEmployee = append(c.hooks.AIEmployee, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `aiemployee.Intercept(f(g(h())))`. +func (c *AIEmployeeClient) Intercept(interceptors ...Interceptor) { + c.inters.AIEmployee = append(c.inters.AIEmployee, interceptors...) +} + +// Create returns a builder for creating a AIEmployee entity. +func (c *AIEmployeeClient) Create() *AIEmployeeCreate { + mutation := newAIEmployeeMutation(c.config, OpCreate) + return &AIEmployeeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of AIEmployee entities. +func (c *AIEmployeeClient) CreateBulk(builders ...*AIEmployeeCreate) *AIEmployeeCreateBulk { + return &AIEmployeeCreateBulk{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 *AIEmployeeClient) MapCreateBulk(slice any, setFunc func(*AIEmployeeCreate, int)) *AIEmployeeCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AIEmployeeCreateBulk{err: fmt.Errorf("calling to AIEmployeeClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AIEmployeeCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AIEmployeeCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for AIEmployee. +func (c *AIEmployeeClient) Update() *AIEmployeeUpdate { + mutation := newAIEmployeeMutation(c.config, OpUpdate) + return &AIEmployeeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AIEmployeeClient) UpdateOne(ae *AIEmployee) *AIEmployeeUpdateOne { + mutation := newAIEmployeeMutation(c.config, OpUpdateOne, withAIEmployee(ae)) + return &AIEmployeeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AIEmployeeClient) UpdateOneID(id uuid.UUID) *AIEmployeeUpdateOne { + mutation := newAIEmployeeMutation(c.config, OpUpdateOne, withAIEmployeeID(id)) + return &AIEmployeeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for AIEmployee. +func (c *AIEmployeeClient) Delete() *AIEmployeeDelete { + mutation := newAIEmployeeMutation(c.config, OpDelete) + return &AIEmployeeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *AIEmployeeClient) DeleteOne(ae *AIEmployee) *AIEmployeeDeleteOne { + return c.DeleteOneID(ae.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *AIEmployeeClient) DeleteOneID(id uuid.UUID) *AIEmployeeDeleteOne { + builder := c.Delete().Where(aiemployee.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AIEmployeeDeleteOne{builder} +} + +// Query returns a query builder for AIEmployee. +func (c *AIEmployeeClient) Query() *AIEmployeeQuery { + return &AIEmployeeQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeAIEmployee}, + inters: c.Interceptors(), + } +} + +// Get returns a AIEmployee entity by its id. +func (c *AIEmployeeClient) Get(ctx context.Context, id uuid.UUID) (*AIEmployee, error) { + return c.Query().Where(aiemployee.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AIEmployeeClient) GetX(ctx context.Context, id uuid.UUID) *AIEmployee { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryAdmin queries the admin edge of a AIEmployee. +func (c *AIEmployeeClient) QueryAdmin(ae *AIEmployee) *AdminQuery { + query := (&AdminClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := ae.ID + step := sqlgraph.NewStep( + sqlgraph.From(aiemployee.Table, aiemployee.FieldID, id), + sqlgraph.To(admin.Table, admin.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, aiemployee.AdminTable, aiemployee.AdminColumn), + ) + fromV = sqlgraph.Neighbors(ae.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *AIEmployeeClient) Hooks() []Hook { + return c.hooks.AIEmployee +} + +// Interceptors returns the client interceptors. +func (c *AIEmployeeClient) Interceptors() []Interceptor { + return c.inters.AIEmployee +} + +func (c *AIEmployeeClient) mutate(ctx context.Context, m *AIEmployeeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AIEmployeeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AIEmployeeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AIEmployeeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AIEmployeeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown AIEmployee mutation op: %q", m.Op()) + } +} + +// AITaskClient is a client for the AITask schema. +type AITaskClient struct { + config +} + +// NewAITaskClient returns a client for the AITask from the given config. +func NewAITaskClient(c config) *AITaskClient { + return &AITaskClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `aitask.Hooks(f(g(h())))`. +func (c *AITaskClient) Use(hooks ...Hook) { + c.hooks.AITask = append(c.hooks.AITask, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `aitask.Intercept(f(g(h())))`. +func (c *AITaskClient) Intercept(interceptors ...Interceptor) { + c.inters.AITask = append(c.inters.AITask, interceptors...) +} + +// Create returns a builder for creating a AITask entity. +func (c *AITaskClient) Create() *AITaskCreate { + mutation := newAITaskMutation(c.config, OpCreate) + return &AITaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of AITask entities. +func (c *AITaskClient) CreateBulk(builders ...*AITaskCreate) *AITaskCreateBulk { + return &AITaskCreateBulk{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 *AITaskClient) MapCreateBulk(slice any, setFunc func(*AITaskCreate, int)) *AITaskCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AITaskCreateBulk{err: fmt.Errorf("calling to AITaskClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AITaskCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AITaskCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for AITask. +func (c *AITaskClient) Update() *AITaskUpdate { + mutation := newAITaskMutation(c.config, OpUpdate) + return &AITaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AITaskClient) UpdateOne(at *AITask) *AITaskUpdateOne { + mutation := newAITaskMutation(c.config, OpUpdateOne, withAITask(at)) + return &AITaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AITaskClient) UpdateOneID(id uuid.UUID) *AITaskUpdateOne { + mutation := newAITaskMutation(c.config, OpUpdateOne, withAITaskID(id)) + return &AITaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for AITask. +func (c *AITaskClient) Delete() *AITaskDelete { + mutation := newAITaskMutation(c.config, OpDelete) + return &AITaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *AITaskClient) DeleteOne(at *AITask) *AITaskDeleteOne { + return c.DeleteOneID(at.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *AITaskClient) DeleteOneID(id uuid.UUID) *AITaskDeleteOne { + builder := c.Delete().Where(aitask.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AITaskDeleteOne{builder} +} + +// Query returns a query builder for AITask. +func (c *AITaskClient) Query() *AITaskQuery { + return &AITaskQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeAITask}, + inters: c.Interceptors(), + } +} + +// Get returns a AITask entity by its id. +func (c *AITaskClient) Get(ctx context.Context, id uuid.UUID) (*AITask, error) { + return c.Query().Where(aitask.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AITaskClient) GetX(ctx context.Context, id uuid.UUID) *AITask { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *AITaskClient) Hooks() []Hook { + return c.hooks.AITask +} + +// Interceptors returns the client interceptors. +func (c *AITaskClient) Interceptors() []Interceptor { + return c.inters.AITask +} + +func (c *AITaskClient) mutate(ctx context.Context, m *AITaskMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AITaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AITaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AITaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AITaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown AITask mutation op: %q", m.Op()) + } +} + // AdminClient is a client for the Admin schema. type AdminClient struct { config @@ -582,6 +882,22 @@ func (c *AdminClient) QueryMyusergroups(a *Admin) *UserGroupQuery { return query } +// QueryAiemployees queries the aiemployees edge of a Admin. +func (c *AdminClient) QueryAiemployees(a *Admin) *AIEmployeeQuery { + query := (&AIEmployeeClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := a.ID + step := sqlgraph.NewStep( + sqlgraph.From(admin.Table, admin.FieldID, id), + sqlgraph.To(aiemployee.Table, aiemployee.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, admin.AiemployeesTable, admin.AiemployeesColumn), + ) + fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryUsergroups queries the usergroups edge of a Admin. func (c *AdminClient) QueryUsergroups(a *Admin) *UserGroupQuery { query := (&UserGroupClient{config: c.config}).Query() @@ -5142,17 +5458,17 @@ func (c *WorkspaceFileClient) mutate(ctx context.Context, m *WorkspaceFileMutati // hooks and interceptors per client, for fast access. type ( hooks struct { - Admin, AdminLoginHistory, AdminRole, ApiKey, BillingPlan, BillingQuota, - BillingRecord, BillingUsage, CodeSnippet, Extension, InviteCode, License, - Model, ModelProvider, ModelProviderModel, Role, SecurityScanning, + AIEmployee, AITask, Admin, AdminLoginHistory, AdminRole, ApiKey, BillingPlan, + BillingQuota, BillingRecord, BillingUsage, CodeSnippet, Extension, InviteCode, + License, Model, ModelProvider, ModelProviderModel, Role, SecurityScanning, SecurityScanningResult, Setting, Task, TaskRecord, User, UserGroup, UserGroupAdmin, UserGroupUser, UserIdentity, UserLoginHistory, Workspace, WorkspaceFile []ent.Hook } inters struct { - Admin, AdminLoginHistory, AdminRole, ApiKey, BillingPlan, BillingQuota, - BillingRecord, BillingUsage, CodeSnippet, Extension, InviteCode, License, - Model, ModelProvider, ModelProviderModel, Role, SecurityScanning, + AIEmployee, AITask, Admin, AdminLoginHistory, AdminRole, ApiKey, BillingPlan, + BillingQuota, BillingRecord, BillingUsage, CodeSnippet, Extension, InviteCode, + License, Model, ModelProvider, ModelProviderModel, Role, SecurityScanning, SecurityScanningResult, Setting, Task, TaskRecord, User, UserGroup, UserGroupAdmin, UserGroupUser, UserIdentity, UserLoginHistory, Workspace, WorkspaceFile []ent.Interceptor diff --git a/backend/db/ent.go b/backend/db/ent.go index b871405..a25119b 100644 --- a/backend/db/ent.go +++ b/backend/db/ent.go @@ -15,6 +15,8 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/aitask" "github.com/chaitin/MonkeyCode/backend/db/apikey" "github.com/chaitin/MonkeyCode/backend/db/billingplan" "github.com/chaitin/MonkeyCode/backend/db/billingquota" @@ -101,6 +103,8 @@ var ( func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + aiemployee.Table: aiemployee.ValidColumn, + aitask.Table: aitask.ValidColumn, admin.Table: admin.ValidColumn, adminloginhistory.Table: adminloginhistory.ValidColumn, adminrole.Table: adminrole.ValidColumn, diff --git a/backend/db/hook/hook.go b/backend/db/hook/hook.go index 00add62..f60c7cb 100644 --- a/backend/db/hook/hook.go +++ b/backend/db/hook/hook.go @@ -9,6 +9,30 @@ import ( "github.com/chaitin/MonkeyCode/backend/db" ) +// The AIEmployeeFunc type is an adapter to allow the use of ordinary +// function as AIEmployee mutator. +type AIEmployeeFunc func(context.Context, *db.AIEmployeeMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f AIEmployeeFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.AIEmployeeMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.AIEmployeeMutation", m) +} + +// The AITaskFunc type is an adapter to allow the use of ordinary +// function as AITask mutator. +type AITaskFunc func(context.Context, *db.AITaskMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f AITaskFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.AITaskMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.AITaskMutation", m) +} + // The AdminFunc type is an adapter to allow the use of ordinary // function as Admin mutator. type AdminFunc func(context.Context, *db.AdminMutation) (db.Value, error) diff --git a/backend/db/intercept/intercept.go b/backend/db/intercept/intercept.go index 7aa988d..541c2e5 100644 --- a/backend/db/intercept/intercept.go +++ b/backend/db/intercept/intercept.go @@ -11,6 +11,8 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/aitask" "github.com/chaitin/MonkeyCode/backend/db/apikey" "github.com/chaitin/MonkeyCode/backend/db/billingplan" "github.com/chaitin/MonkeyCode/backend/db/billingquota" @@ -96,6 +98,60 @@ func (f TraverseFunc) Traverse(ctx context.Context, q db.Query) error { return f(ctx, query) } +// The AIEmployeeFunc type is an adapter to allow the use of ordinary function as a Querier. +type AIEmployeeFunc func(context.Context, *db.AIEmployeeQuery) (db.Value, error) + +// Query calls f(ctx, q). +func (f AIEmployeeFunc) Query(ctx context.Context, q db.Query) (db.Value, error) { + if q, ok := q.(*db.AIEmployeeQuery); ok { + return f(ctx, q) + } + return nil, fmt.Errorf("unexpected query type %T. expect *db.AIEmployeeQuery", q) +} + +// The TraverseAIEmployee type is an adapter to allow the use of ordinary function as Traverser. +type TraverseAIEmployee func(context.Context, *db.AIEmployeeQuery) error + +// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. +func (f TraverseAIEmployee) Intercept(next db.Querier) db.Querier { + return next +} + +// Traverse calls f(ctx, q). +func (f TraverseAIEmployee) Traverse(ctx context.Context, q db.Query) error { + if q, ok := q.(*db.AIEmployeeQuery); ok { + return f(ctx, q) + } + return fmt.Errorf("unexpected query type %T. expect *db.AIEmployeeQuery", q) +} + +// The AITaskFunc type is an adapter to allow the use of ordinary function as a Querier. +type AITaskFunc func(context.Context, *db.AITaskQuery) (db.Value, error) + +// Query calls f(ctx, q). +func (f AITaskFunc) Query(ctx context.Context, q db.Query) (db.Value, error) { + if q, ok := q.(*db.AITaskQuery); ok { + return f(ctx, q) + } + return nil, fmt.Errorf("unexpected query type %T. expect *db.AITaskQuery", q) +} + +// The TraverseAITask type is an adapter to allow the use of ordinary function as Traverser. +type TraverseAITask func(context.Context, *db.AITaskQuery) error + +// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. +func (f TraverseAITask) Intercept(next db.Querier) db.Querier { + return next +} + +// Traverse calls f(ctx, q). +func (f TraverseAITask) Traverse(ctx context.Context, q db.Query) error { + if q, ok := q.(*db.AITaskQuery); ok { + return f(ctx, q) + } + return fmt.Errorf("unexpected query type %T. expect *db.AITaskQuery", q) +} + // The AdminFunc type is an adapter to allow the use of ordinary function as a Querier. type AdminFunc func(context.Context, *db.AdminQuery) (db.Value, error) @@ -882,6 +938,10 @@ func (f TraverseWorkspaceFile) Traverse(ctx context.Context, q db.Query) error { // NewQuery returns the generic Query interface for the given typed query. func NewQuery(q db.Query) (Query, error) { switch q := q.(type) { + case *db.AIEmployeeQuery: + return &query[*db.AIEmployeeQuery, predicate.AIEmployee, aiemployee.OrderOption]{typ: db.TypeAIEmployee, tq: q}, nil + case *db.AITaskQuery: + return &query[*db.AITaskQuery, predicate.AITask, aitask.OrderOption]{typ: db.TypeAITask, tq: q}, nil case *db.AdminQuery: return &query[*db.AdminQuery, predicate.Admin, admin.OrderOption]{typ: db.TypeAdmin, tq: q}, nil case *db.AdminLoginHistoryQuery: diff --git a/backend/db/migrate/schema.go b/backend/db/migrate/schema.go index e895f12..f96e5b3 100644 --- a/backend/db/migrate/schema.go +++ b/backend/db/migrate/schema.go @@ -9,6 +9,53 @@ import ( ) var ( + // AiEmployeesColumns holds the columns for the "ai_employees" table. + AiEmployeesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "name", Type: field.TypeString}, + {Name: "position", Type: field.TypeString}, + {Name: "repository_url", Type: field.TypeString}, + {Name: "repository_user", Type: field.TypeString}, + {Name: "platform", Type: field.TypeString}, + {Name: "token", Type: field.TypeString}, + {Name: "webhook_secret", Type: field.TypeString}, + {Name: "webhook_url", Type: field.TypeString}, + {Name: "parameters", Type: field.TypeJSON}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "admin_id", Type: field.TypeUUID}, + } + // AiEmployeesTable holds the schema information for the "ai_employees" table. + AiEmployeesTable = &schema.Table{ + Name: "ai_employees", + Columns: AiEmployeesColumns, + PrimaryKey: []*schema.Column{AiEmployeesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "ai_employees_admins_aiemployees", + Columns: []*schema.Column{AiEmployeesColumns[12]}, + RefColumns: []*schema.Column{AdminsColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } + // AiTasksColumns holds the columns for the "ai_tasks" table. + AiTasksColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "employee_id", Type: field.TypeUUID}, + {Name: "status", Type: field.TypeString, Default: "pending"}, + {Name: "output", Type: field.TypeString, Nullable: true, Size: 2147483647}, + {Name: "logs", Type: field.TypeString, Nullable: true, Size: 2147483647}, + {Name: "error_message", Type: field.TypeString, Nullable: true, Size: 2147483647}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + } + // AiTasksTable holds the schema information for the "ai_tasks" table. + AiTasksTable = &schema.Table{ + Name: "ai_tasks", + Columns: AiTasksColumns, + PrimaryKey: []*schema.Column{AiTasksColumns[0]}, + } // AdminsColumns holds the columns for the "admins" table. AdminsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -831,6 +878,8 @@ var ( } // Tables holds all the tables in the schema. Tables = []*schema.Table{ + AiEmployeesTable, + AiTasksTable, AdminsTable, AdminLoginHistoriesTable, AdminRolesTable, @@ -864,6 +913,13 @@ var ( ) func init() { + AiEmployeesTable.ForeignKeys[0].RefTable = AdminsTable + AiEmployeesTable.Annotation = &entsql.Annotation{ + Table: "ai_employees", + } + AiTasksTable.Annotation = &entsql.Annotation{ + Table: "ai_tasks", + } AdminsTable.Annotation = &entsql.Annotation{ Table: "admins", } diff --git a/backend/db/mutation.go b/backend/db/mutation.go index 7046f0b..1b9cfd4 100644 --- a/backend/db/mutation.go +++ b/backend/db/mutation.go @@ -15,6 +15,8 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" "github.com/chaitin/MonkeyCode/backend/db/adminrole" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/aitask" "github.com/chaitin/MonkeyCode/backend/db/apikey" "github.com/chaitin/MonkeyCode/backend/db/billingplan" "github.com/chaitin/MonkeyCode/backend/db/billingquota" @@ -56,6 +58,8 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. + TypeAIEmployee = "AIEmployee" + TypeAITask = "AITask" TypeAdmin = "Admin" TypeAdminLoginHistory = "AdminLoginHistory" TypeAdminRole = "AdminRole" @@ -87,6 +91,1702 @@ const ( TypeWorkspaceFile = "WorkspaceFile" ) +// AIEmployeeMutation represents an operation that mutates the AIEmployee nodes in the graph. +type AIEmployeeMutation struct { + config + op Op + typ string + id *uuid.UUID + name *string + position *consts.AIEmployeePosition + repository_url *string + repository_user *string + platform *consts.RepoPlatform + token *string + webhook_secret *string + webhook_url *string + parameters **types.AIEmployeeParam + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + admin *uuid.UUID + clearedadmin bool + done bool + oldValue func(context.Context) (*AIEmployee, error) + predicates []predicate.AIEmployee +} + +var _ ent.Mutation = (*AIEmployeeMutation)(nil) + +// aiemployeeOption allows management of the mutation configuration using functional options. +type aiemployeeOption func(*AIEmployeeMutation) + +// newAIEmployeeMutation creates new mutation for the AIEmployee entity. +func newAIEmployeeMutation(c config, op Op, opts ...aiemployeeOption) *AIEmployeeMutation { + m := &AIEmployeeMutation{ + config: c, + op: op, + typ: TypeAIEmployee, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withAIEmployeeID sets the ID field of the mutation. +func withAIEmployeeID(id uuid.UUID) aiemployeeOption { + return func(m *AIEmployeeMutation) { + var ( + err error + once sync.Once + value *AIEmployee + ) + m.oldValue = func(ctx context.Context) (*AIEmployee, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().AIEmployee.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withAIEmployee sets the old AIEmployee of the mutation. +func withAIEmployee(node *AIEmployee) aiemployeeOption { + return func(m *AIEmployeeMutation) { + m.oldValue = func(context.Context) (*AIEmployee, 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 AIEmployeeMutation) 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 AIEmployeeMutation) 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 AIEmployee entities. +func (m *AIEmployeeMutation) 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 *AIEmployeeMutation) 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 *AIEmployeeMutation) 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().AIEmployee.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetAdminID sets the "admin_id" field. +func (m *AIEmployeeMutation) SetAdminID(u uuid.UUID) { + m.admin = &u +} + +// AdminID returns the value of the "admin_id" field in the mutation. +func (m *AIEmployeeMutation) AdminID() (r uuid.UUID, exists bool) { + v := m.admin + if v == nil { + return + } + return *v, true +} + +// OldAdminID returns the old "admin_id" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldAdminID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAdminID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAdminID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAdminID: %w", err) + } + return oldValue.AdminID, nil +} + +// ResetAdminID resets all changes to the "admin_id" field. +func (m *AIEmployeeMutation) ResetAdminID() { + m.admin = nil +} + +// SetName sets the "name" field. +func (m *AIEmployeeMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *AIEmployeeMutation) 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 AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) 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 *AIEmployeeMutation) ResetName() { + m.name = nil +} + +// SetPosition sets the "position" field. +func (m *AIEmployeeMutation) SetPosition(cep consts.AIEmployeePosition) { + m.position = &cep +} + +// Position returns the value of the "position" field in the mutation. +func (m *AIEmployeeMutation) Position() (r consts.AIEmployeePosition, exists bool) { + v := m.position + if v == nil { + return + } + return *v, true +} + +// OldPosition returns the old "position" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldPosition(ctx context.Context) (v consts.AIEmployeePosition, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPosition is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPosition requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPosition: %w", err) + } + return oldValue.Position, nil +} + +// ResetPosition resets all changes to the "position" field. +func (m *AIEmployeeMutation) ResetPosition() { + m.position = nil +} + +// SetRepositoryURL sets the "repository_url" field. +func (m *AIEmployeeMutation) SetRepositoryURL(s string) { + m.repository_url = &s +} + +// RepositoryURL returns the value of the "repository_url" field in the mutation. +func (m *AIEmployeeMutation) RepositoryURL() (r string, exists bool) { + v := m.repository_url + if v == nil { + return + } + return *v, true +} + +// OldRepositoryURL returns the old "repository_url" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldRepositoryURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRepositoryURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRepositoryURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRepositoryURL: %w", err) + } + return oldValue.RepositoryURL, nil +} + +// ResetRepositoryURL resets all changes to the "repository_url" field. +func (m *AIEmployeeMutation) ResetRepositoryURL() { + m.repository_url = nil +} + +// SetRepositoryUser sets the "repository_user" field. +func (m *AIEmployeeMutation) SetRepositoryUser(s string) { + m.repository_user = &s +} + +// RepositoryUser returns the value of the "repository_user" field in the mutation. +func (m *AIEmployeeMutation) RepositoryUser() (r string, exists bool) { + v := m.repository_user + if v == nil { + return + } + return *v, true +} + +// OldRepositoryUser returns the old "repository_user" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldRepositoryUser(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRepositoryUser is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRepositoryUser requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRepositoryUser: %w", err) + } + return oldValue.RepositoryUser, nil +} + +// ResetRepositoryUser resets all changes to the "repository_user" field. +func (m *AIEmployeeMutation) ResetRepositoryUser() { + m.repository_user = nil +} + +// SetPlatform sets the "platform" field. +func (m *AIEmployeeMutation) SetPlatform(cp consts.RepoPlatform) { + m.platform = &cp +} + +// Platform returns the value of the "platform" field in the mutation. +func (m *AIEmployeeMutation) Platform() (r consts.RepoPlatform, exists bool) { + v := m.platform + if v == nil { + return + } + return *v, true +} + +// OldPlatform returns the old "platform" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldPlatform(ctx context.Context) (v consts.RepoPlatform, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPlatform is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPlatform requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPlatform: %w", err) + } + return oldValue.Platform, nil +} + +// ResetPlatform resets all changes to the "platform" field. +func (m *AIEmployeeMutation) ResetPlatform() { + m.platform = nil +} + +// SetToken sets the "token" field. +func (m *AIEmployeeMutation) SetToken(s string) { + m.token = &s +} + +// Token returns the value of the "token" field in the mutation. +func (m *AIEmployeeMutation) Token() (r string, exists bool) { + v := m.token + if v == nil { + return + } + return *v, true +} + +// OldToken returns the old "token" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldToken(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldToken is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldToken requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldToken: %w", err) + } + return oldValue.Token, nil +} + +// ResetToken resets all changes to the "token" field. +func (m *AIEmployeeMutation) ResetToken() { + m.token = nil +} + +// SetWebhookSecret sets the "webhook_secret" field. +func (m *AIEmployeeMutation) SetWebhookSecret(s string) { + m.webhook_secret = &s +} + +// WebhookSecret returns the value of the "webhook_secret" field in the mutation. +func (m *AIEmployeeMutation) WebhookSecret() (r string, exists bool) { + v := m.webhook_secret + if v == nil { + return + } + return *v, true +} + +// OldWebhookSecret returns the old "webhook_secret" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldWebhookSecret(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWebhookSecret is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWebhookSecret requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWebhookSecret: %w", err) + } + return oldValue.WebhookSecret, nil +} + +// ResetWebhookSecret resets all changes to the "webhook_secret" field. +func (m *AIEmployeeMutation) ResetWebhookSecret() { + m.webhook_secret = nil +} + +// SetWebhookURL sets the "webhook_url" field. +func (m *AIEmployeeMutation) SetWebhookURL(s string) { + m.webhook_url = &s +} + +// WebhookURL returns the value of the "webhook_url" field in the mutation. +func (m *AIEmployeeMutation) WebhookURL() (r string, exists bool) { + v := m.webhook_url + if v == nil { + return + } + return *v, true +} + +// OldWebhookURL returns the old "webhook_url" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldWebhookURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWebhookURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWebhookURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWebhookURL: %w", err) + } + return oldValue.WebhookURL, nil +} + +// ResetWebhookURL resets all changes to the "webhook_url" field. +func (m *AIEmployeeMutation) ResetWebhookURL() { + m.webhook_url = nil +} + +// SetParameters sets the "parameters" field. +func (m *AIEmployeeMutation) SetParameters(tep *types.AIEmployeeParam) { + m.parameters = &tep +} + +// Parameters returns the value of the "parameters" field in the mutation. +func (m *AIEmployeeMutation) Parameters() (r *types.AIEmployeeParam, exists bool) { + v := m.parameters + if v == nil { + return + } + return *v, true +} + +// OldParameters returns the old "parameters" field's value of the AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) OldParameters(ctx context.Context) (v *types.AIEmployeeParam, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldParameters is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldParameters requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldParameters: %w", err) + } + return oldValue.Parameters, nil +} + +// ResetParameters resets all changes to the "parameters" field. +func (m *AIEmployeeMutation) ResetParameters() { + m.parameters = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *AIEmployeeMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *AIEmployeeMutation) 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 AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) 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 *AIEmployeeMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *AIEmployeeMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *AIEmployeeMutation) 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 AIEmployee entity. +// If the AIEmployee 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 *AIEmployeeMutation) 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 *AIEmployeeMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// ClearAdmin clears the "admin" edge to the Admin entity. +func (m *AIEmployeeMutation) ClearAdmin() { + m.clearedadmin = true + m.clearedFields[aiemployee.FieldAdminID] = struct{}{} +} + +// AdminCleared reports if the "admin" edge to the Admin entity was cleared. +func (m *AIEmployeeMutation) AdminCleared() bool { + return m.clearedadmin +} + +// AdminIDs returns the "admin" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// AdminID instead. It exists only for internal usage by the builders. +func (m *AIEmployeeMutation) AdminIDs() (ids []uuid.UUID) { + if id := m.admin; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetAdmin resets all changes to the "admin" edge. +func (m *AIEmployeeMutation) ResetAdmin() { + m.admin = nil + m.clearedadmin = false +} + +// Where appends a list predicates to the AIEmployeeMutation builder. +func (m *AIEmployeeMutation) Where(ps ...predicate.AIEmployee) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the AIEmployeeMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AIEmployeeMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AIEmployee, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *AIEmployeeMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *AIEmployeeMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (AIEmployee). +func (m *AIEmployeeMutation) 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 *AIEmployeeMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.admin != nil { + fields = append(fields, aiemployee.FieldAdminID) + } + if m.name != nil { + fields = append(fields, aiemployee.FieldName) + } + if m.position != nil { + fields = append(fields, aiemployee.FieldPosition) + } + if m.repository_url != nil { + fields = append(fields, aiemployee.FieldRepositoryURL) + } + if m.repository_user != nil { + fields = append(fields, aiemployee.FieldRepositoryUser) + } + if m.platform != nil { + fields = append(fields, aiemployee.FieldPlatform) + } + if m.token != nil { + fields = append(fields, aiemployee.FieldToken) + } + if m.webhook_secret != nil { + fields = append(fields, aiemployee.FieldWebhookSecret) + } + if m.webhook_url != nil { + fields = append(fields, aiemployee.FieldWebhookURL) + } + if m.parameters != nil { + fields = append(fields, aiemployee.FieldParameters) + } + if m.created_at != nil { + fields = append(fields, aiemployee.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, aiemployee.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 *AIEmployeeMutation) Field(name string) (ent.Value, bool) { + switch name { + case aiemployee.FieldAdminID: + return m.AdminID() + case aiemployee.FieldName: + return m.Name() + case aiemployee.FieldPosition: + return m.Position() + case aiemployee.FieldRepositoryURL: + return m.RepositoryURL() + case aiemployee.FieldRepositoryUser: + return m.RepositoryUser() + case aiemployee.FieldPlatform: + return m.Platform() + case aiemployee.FieldToken: + return m.Token() + case aiemployee.FieldWebhookSecret: + return m.WebhookSecret() + case aiemployee.FieldWebhookURL: + return m.WebhookURL() + case aiemployee.FieldParameters: + return m.Parameters() + case aiemployee.FieldCreatedAt: + return m.CreatedAt() + case aiemployee.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 *AIEmployeeMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case aiemployee.FieldAdminID: + return m.OldAdminID(ctx) + case aiemployee.FieldName: + return m.OldName(ctx) + case aiemployee.FieldPosition: + return m.OldPosition(ctx) + case aiemployee.FieldRepositoryURL: + return m.OldRepositoryURL(ctx) + case aiemployee.FieldRepositoryUser: + return m.OldRepositoryUser(ctx) + case aiemployee.FieldPlatform: + return m.OldPlatform(ctx) + case aiemployee.FieldToken: + return m.OldToken(ctx) + case aiemployee.FieldWebhookSecret: + return m.OldWebhookSecret(ctx) + case aiemployee.FieldWebhookURL: + return m.OldWebhookURL(ctx) + case aiemployee.FieldParameters: + return m.OldParameters(ctx) + case aiemployee.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case aiemployee.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown AIEmployee 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 *AIEmployeeMutation) SetField(name string, value ent.Value) error { + switch name { + case aiemployee.FieldAdminID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAdminID(v) + return nil + case aiemployee.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case aiemployee.FieldPosition: + v, ok := value.(consts.AIEmployeePosition) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPosition(v) + return nil + case aiemployee.FieldRepositoryURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRepositoryURL(v) + return nil + case aiemployee.FieldRepositoryUser: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRepositoryUser(v) + return nil + case aiemployee.FieldPlatform: + v, ok := value.(consts.RepoPlatform) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPlatform(v) + return nil + case aiemployee.FieldToken: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetToken(v) + return nil + case aiemployee.FieldWebhookSecret: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWebhookSecret(v) + return nil + case aiemployee.FieldWebhookURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWebhookURL(v) + return nil + case aiemployee.FieldParameters: + v, ok := value.(*types.AIEmployeeParam) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetParameters(v) + return nil + case aiemployee.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 aiemployee.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 AIEmployee field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *AIEmployeeMutation) 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 *AIEmployeeMutation) 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 *AIEmployeeMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown AIEmployee numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *AIEmployeeMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *AIEmployeeMutation) 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 *AIEmployeeMutation) ClearField(name string) error { + return fmt.Errorf("unknown AIEmployee 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 *AIEmployeeMutation) ResetField(name string) error { + switch name { + case aiemployee.FieldAdminID: + m.ResetAdminID() + return nil + case aiemployee.FieldName: + m.ResetName() + return nil + case aiemployee.FieldPosition: + m.ResetPosition() + return nil + case aiemployee.FieldRepositoryURL: + m.ResetRepositoryURL() + return nil + case aiemployee.FieldRepositoryUser: + m.ResetRepositoryUser() + return nil + case aiemployee.FieldPlatform: + m.ResetPlatform() + return nil + case aiemployee.FieldToken: + m.ResetToken() + return nil + case aiemployee.FieldWebhookSecret: + m.ResetWebhookSecret() + return nil + case aiemployee.FieldWebhookURL: + m.ResetWebhookURL() + return nil + case aiemployee.FieldParameters: + m.ResetParameters() + return nil + case aiemployee.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case aiemployee.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown AIEmployee field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *AIEmployeeMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.admin != nil { + edges = append(edges, aiemployee.EdgeAdmin) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *AIEmployeeMutation) AddedIDs(name string) []ent.Value { + switch name { + case aiemployee.EdgeAdmin: + if id := m.admin; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *AIEmployeeMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *AIEmployeeMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *AIEmployeeMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedadmin { + edges = append(edges, aiemployee.EdgeAdmin) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *AIEmployeeMutation) EdgeCleared(name string) bool { + switch name { + case aiemployee.EdgeAdmin: + return m.clearedadmin + } + 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 *AIEmployeeMutation) ClearEdge(name string) error { + switch name { + case aiemployee.EdgeAdmin: + m.ClearAdmin() + return nil + } + return fmt.Errorf("unknown AIEmployee 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 *AIEmployeeMutation) ResetEdge(name string) error { + switch name { + case aiemployee.EdgeAdmin: + m.ResetAdmin() + return nil + } + return fmt.Errorf("unknown AIEmployee edge %s", name) +} + +// AITaskMutation represents an operation that mutates the AITask nodes in the graph. +type AITaskMutation struct { + config + op Op + typ string + id *uuid.UUID + employee_id *uuid.UUID + status *string + output *string + logs *string + error_message *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*AITask, error) + predicates []predicate.AITask +} + +var _ ent.Mutation = (*AITaskMutation)(nil) + +// aitaskOption allows management of the mutation configuration using functional options. +type aitaskOption func(*AITaskMutation) + +// newAITaskMutation creates new mutation for the AITask entity. +func newAITaskMutation(c config, op Op, opts ...aitaskOption) *AITaskMutation { + m := &AITaskMutation{ + config: c, + op: op, + typ: TypeAITask, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withAITaskID sets the ID field of the mutation. +func withAITaskID(id uuid.UUID) aitaskOption { + return func(m *AITaskMutation) { + var ( + err error + once sync.Once + value *AITask + ) + m.oldValue = func(ctx context.Context) (*AITask, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().AITask.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withAITask sets the old AITask of the mutation. +func withAITask(node *AITask) aitaskOption { + return func(m *AITaskMutation) { + m.oldValue = func(context.Context) (*AITask, 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 AITaskMutation) 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 AITaskMutation) 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 AITask entities. +func (m *AITaskMutation) 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 *AITaskMutation) 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 *AITaskMutation) 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().AITask.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetEmployeeID sets the "employee_id" field. +func (m *AITaskMutation) SetEmployeeID(u uuid.UUID) { + m.employee_id = &u +} + +// EmployeeID returns the value of the "employee_id" field in the mutation. +func (m *AITaskMutation) EmployeeID() (r uuid.UUID, exists bool) { + v := m.employee_id + if v == nil { + return + } + return *v, true +} + +// OldEmployeeID returns the old "employee_id" field's value of the AITask entity. +// If the AITask 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 *AITaskMutation) OldEmployeeID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEmployeeID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEmployeeID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEmployeeID: %w", err) + } + return oldValue.EmployeeID, nil +} + +// ResetEmployeeID resets all changes to the "employee_id" field. +func (m *AITaskMutation) ResetEmployeeID() { + m.employee_id = nil +} + +// SetStatus sets the "status" field. +func (m *AITaskMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *AITaskMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the AITask entity. +// If the AITask 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 *AITaskMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *AITaskMutation) ResetStatus() { + m.status = nil +} + +// SetOutput sets the "output" field. +func (m *AITaskMutation) SetOutput(s string) { + m.output = &s +} + +// Output returns the value of the "output" field in the mutation. +func (m *AITaskMutation) Output() (r string, exists bool) { + v := m.output + if v == nil { + return + } + return *v, true +} + +// OldOutput returns the old "output" field's value of the AITask entity. +// If the AITask 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 *AITaskMutation) OldOutput(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldOutput is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldOutput requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOutput: %w", err) + } + return oldValue.Output, nil +} + +// ClearOutput clears the value of the "output" field. +func (m *AITaskMutation) ClearOutput() { + m.output = nil + m.clearedFields[aitask.FieldOutput] = struct{}{} +} + +// OutputCleared returns if the "output" field was cleared in this mutation. +func (m *AITaskMutation) OutputCleared() bool { + _, ok := m.clearedFields[aitask.FieldOutput] + return ok +} + +// ResetOutput resets all changes to the "output" field. +func (m *AITaskMutation) ResetOutput() { + m.output = nil + delete(m.clearedFields, aitask.FieldOutput) +} + +// SetLogs sets the "logs" field. +func (m *AITaskMutation) SetLogs(s string) { + m.logs = &s +} + +// Logs returns the value of the "logs" field in the mutation. +func (m *AITaskMutation) Logs() (r string, exists bool) { + v := m.logs + if v == nil { + return + } + return *v, true +} + +// OldLogs returns the old "logs" field's value of the AITask entity. +// If the AITask 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 *AITaskMutation) OldLogs(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLogs is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLogs requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLogs: %w", err) + } + return oldValue.Logs, nil +} + +// ClearLogs clears the value of the "logs" field. +func (m *AITaskMutation) ClearLogs() { + m.logs = nil + m.clearedFields[aitask.FieldLogs] = struct{}{} +} + +// LogsCleared returns if the "logs" field was cleared in this mutation. +func (m *AITaskMutation) LogsCleared() bool { + _, ok := m.clearedFields[aitask.FieldLogs] + return ok +} + +// ResetLogs resets all changes to the "logs" field. +func (m *AITaskMutation) ResetLogs() { + m.logs = nil + delete(m.clearedFields, aitask.FieldLogs) +} + +// SetErrorMessage sets the "error_message" field. +func (m *AITaskMutation) SetErrorMessage(s string) { + m.error_message = &s +} + +// ErrorMessage returns the value of the "error_message" field in the mutation. +func (m *AITaskMutation) ErrorMessage() (r string, exists bool) { + v := m.error_message + if v == nil { + return + } + return *v, true +} + +// OldErrorMessage returns the old "error_message" field's value of the AITask entity. +// If the AITask 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 *AITaskMutation) OldErrorMessage(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldErrorMessage is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldErrorMessage requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err) + } + return oldValue.ErrorMessage, nil +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (m *AITaskMutation) ClearErrorMessage() { + m.error_message = nil + m.clearedFields[aitask.FieldErrorMessage] = struct{}{} +} + +// ErrorMessageCleared returns if the "error_message" field was cleared in this mutation. +func (m *AITaskMutation) ErrorMessageCleared() bool { + _, ok := m.clearedFields[aitask.FieldErrorMessage] + return ok +} + +// ResetErrorMessage resets all changes to the "error_message" field. +func (m *AITaskMutation) ResetErrorMessage() { + m.error_message = nil + delete(m.clearedFields, aitask.FieldErrorMessage) +} + +// SetCreatedAt sets the "created_at" field. +func (m *AITaskMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *AITaskMutation) 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 AITask entity. +// If the AITask 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 *AITaskMutation) 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 *AITaskMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *AITaskMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *AITaskMutation) 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 AITask entity. +// If the AITask 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 *AITaskMutation) 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 *AITaskMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// Where appends a list predicates to the AITaskMutation builder. +func (m *AITaskMutation) Where(ps ...predicate.AITask) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the AITaskMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AITaskMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AITask, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *AITaskMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *AITaskMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (AITask). +func (m *AITaskMutation) 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 *AITaskMutation) Fields() []string { + fields := make([]string, 0, 7) + if m.employee_id != nil { + fields = append(fields, aitask.FieldEmployeeID) + } + if m.status != nil { + fields = append(fields, aitask.FieldStatus) + } + if m.output != nil { + fields = append(fields, aitask.FieldOutput) + } + if m.logs != nil { + fields = append(fields, aitask.FieldLogs) + } + if m.error_message != nil { + fields = append(fields, aitask.FieldErrorMessage) + } + if m.created_at != nil { + fields = append(fields, aitask.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, aitask.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 *AITaskMutation) Field(name string) (ent.Value, bool) { + switch name { + case aitask.FieldEmployeeID: + return m.EmployeeID() + case aitask.FieldStatus: + return m.Status() + case aitask.FieldOutput: + return m.Output() + case aitask.FieldLogs: + return m.Logs() + case aitask.FieldErrorMessage: + return m.ErrorMessage() + case aitask.FieldCreatedAt: + return m.CreatedAt() + case aitask.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 *AITaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case aitask.FieldEmployeeID: + return m.OldEmployeeID(ctx) + case aitask.FieldStatus: + return m.OldStatus(ctx) + case aitask.FieldOutput: + return m.OldOutput(ctx) + case aitask.FieldLogs: + return m.OldLogs(ctx) + case aitask.FieldErrorMessage: + return m.OldErrorMessage(ctx) + case aitask.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case aitask.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown AITask 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 *AITaskMutation) SetField(name string, value ent.Value) error { + switch name { + case aitask.FieldEmployeeID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEmployeeID(v) + return nil + case aitask.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case aitask.FieldOutput: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOutput(v) + return nil + case aitask.FieldLogs: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLogs(v) + return nil + case aitask.FieldErrorMessage: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetErrorMessage(v) + return nil + case aitask.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 aitask.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 AITask field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *AITaskMutation) 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 *AITaskMutation) 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 *AITaskMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown AITask numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *AITaskMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(aitask.FieldOutput) { + fields = append(fields, aitask.FieldOutput) + } + if m.FieldCleared(aitask.FieldLogs) { + fields = append(fields, aitask.FieldLogs) + } + if m.FieldCleared(aitask.FieldErrorMessage) { + fields = append(fields, aitask.FieldErrorMessage) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *AITaskMutation) 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 *AITaskMutation) ClearField(name string) error { + switch name { + case aitask.FieldOutput: + m.ClearOutput() + return nil + case aitask.FieldLogs: + m.ClearLogs() + return nil + case aitask.FieldErrorMessage: + m.ClearErrorMessage() + return nil + } + return fmt.Errorf("unknown AITask 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 *AITaskMutation) ResetField(name string) error { + switch name { + case aitask.FieldEmployeeID: + m.ResetEmployeeID() + return nil + case aitask.FieldStatus: + m.ResetStatus() + return nil + case aitask.FieldOutput: + m.ResetOutput() + return nil + case aitask.FieldLogs: + m.ResetLogs() + return nil + case aitask.FieldErrorMessage: + m.ResetErrorMessage() + return nil + case aitask.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case aitask.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown AITask field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *AITaskMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *AITaskMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *AITaskMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *AITaskMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *AITaskMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *AITaskMutation) EdgeCleared(name string) bool { + 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 *AITaskMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown AITask 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 *AITaskMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown AITask edge %s", name) +} + // AdminMutation represents an operation that mutates the Admin nodes in the graph. type AdminMutation struct { config @@ -106,6 +1806,9 @@ type AdminMutation struct { myusergroups map[uuid.UUID]struct{} removedmyusergroups map[uuid.UUID]struct{} clearedmyusergroups bool + aiemployees map[uuid.UUID]struct{} + removedaiemployees map[uuid.UUID]struct{} + clearedaiemployees bool usergroups map[uuid.UUID]struct{} removedusergroups map[uuid.UUID]struct{} clearedusergroups bool @@ -551,6 +2254,60 @@ func (m *AdminMutation) ResetMyusergroups() { m.removedmyusergroups = nil } +// AddAiemployeeIDs adds the "aiemployees" edge to the AIEmployee entity by ids. +func (m *AdminMutation) AddAiemployeeIDs(ids ...uuid.UUID) { + if m.aiemployees == nil { + m.aiemployees = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.aiemployees[ids[i]] = struct{}{} + } +} + +// ClearAiemployees clears the "aiemployees" edge to the AIEmployee entity. +func (m *AdminMutation) ClearAiemployees() { + m.clearedaiemployees = true +} + +// AiemployeesCleared reports if the "aiemployees" edge to the AIEmployee entity was cleared. +func (m *AdminMutation) AiemployeesCleared() bool { + return m.clearedaiemployees +} + +// RemoveAiemployeeIDs removes the "aiemployees" edge to the AIEmployee entity by IDs. +func (m *AdminMutation) RemoveAiemployeeIDs(ids ...uuid.UUID) { + if m.removedaiemployees == nil { + m.removedaiemployees = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.aiemployees, ids[i]) + m.removedaiemployees[ids[i]] = struct{}{} + } +} + +// RemovedAiemployees returns the removed IDs of the "aiemployees" edge to the AIEmployee entity. +func (m *AdminMutation) RemovedAiemployeesIDs() (ids []uuid.UUID) { + for id := range m.removedaiemployees { + ids = append(ids, id) + } + return +} + +// AiemployeesIDs returns the "aiemployees" edge IDs in the mutation. +func (m *AdminMutation) AiemployeesIDs() (ids []uuid.UUID) { + for id := range m.aiemployees { + ids = append(ids, id) + } + return +} + +// ResetAiemployees resets all changes to the "aiemployees" edge. +func (m *AdminMutation) ResetAiemployees() { + m.aiemployees = nil + m.clearedaiemployees = false + m.removedaiemployees = nil +} + // AddUsergroupIDs adds the "usergroups" edge to the UserGroup entity by ids. func (m *AdminMutation) AddUsergroupIDs(ids ...uuid.UUID) { if m.usergroups == nil { @@ -985,13 +2742,16 @@ func (m *AdminMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *AdminMutation) AddedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.login_histories != nil { edges = append(edges, admin.EdgeLoginHistories) } if m.myusergroups != nil { edges = append(edges, admin.EdgeMyusergroups) } + if m.aiemployees != nil { + edges = append(edges, admin.EdgeAiemployees) + } if m.usergroups != nil { edges = append(edges, admin.EdgeUsergroups) } @@ -1023,6 +2783,12 @@ func (m *AdminMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case admin.EdgeAiemployees: + ids := make([]ent.Value, 0, len(m.aiemployees)) + for id := range m.aiemployees { + ids = append(ids, id) + } + return ids case admin.EdgeUsergroups: ids := make([]ent.Value, 0, len(m.usergroups)) for id := range m.usergroups { @@ -1053,13 +2819,16 @@ func (m *AdminMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *AdminMutation) RemovedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.removedlogin_histories != nil { edges = append(edges, admin.EdgeLoginHistories) } if m.removedmyusergroups != nil { edges = append(edges, admin.EdgeMyusergroups) } + if m.removedaiemployees != nil { + edges = append(edges, admin.EdgeAiemployees) + } if m.removedusergroups != nil { edges = append(edges, admin.EdgeUsergroups) } @@ -1091,6 +2860,12 @@ func (m *AdminMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case admin.EdgeAiemployees: + ids := make([]ent.Value, 0, len(m.removedaiemployees)) + for id := range m.removedaiemployees { + ids = append(ids, id) + } + return ids case admin.EdgeUsergroups: ids := make([]ent.Value, 0, len(m.removedusergroups)) for id := range m.removedusergroups { @@ -1121,13 +2896,16 @@ func (m *AdminMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AdminMutation) ClearedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.clearedlogin_histories { edges = append(edges, admin.EdgeLoginHistories) } if m.clearedmyusergroups { edges = append(edges, admin.EdgeMyusergroups) } + if m.clearedaiemployees { + edges = append(edges, admin.EdgeAiemployees) + } if m.clearedusergroups { edges = append(edges, admin.EdgeUsergroups) } @@ -1151,6 +2929,8 @@ func (m *AdminMutation) EdgeCleared(name string) bool { return m.clearedlogin_histories case admin.EdgeMyusergroups: return m.clearedmyusergroups + case admin.EdgeAiemployees: + return m.clearedaiemployees case admin.EdgeUsergroups: return m.clearedusergroups case admin.EdgeRoles: @@ -1181,6 +2961,9 @@ func (m *AdminMutation) ResetEdge(name string) error { case admin.EdgeMyusergroups: m.ResetMyusergroups() return nil + case admin.EdgeAiemployees: + m.ResetAiemployees() + return nil case admin.EdgeUsergroups: m.ResetUsergroups() return nil diff --git a/backend/db/page.go b/backend/db/page.go index a181dcd..1584a34 100644 --- a/backend/db/page.go +++ b/backend/db/page.go @@ -11,6 +11,34 @@ type PageInfo struct { TotalCount int64 `json:"total_count"` } +func (ae *AIEmployeeQuery) Page(ctx context.Context, page, size int) ([]*AIEmployee, *PageInfo, error) { + cnt, err := ae.Count(ctx) + if err != nil { + return nil, nil, err + } + offset := size * (page - 1) + rs, err := ae.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 (at *AITaskQuery) Page(ctx context.Context, page, size int) ([]*AITask, *PageInfo, error) { + cnt, err := at.Count(ctx) + if err != nil { + return nil, nil, err + } + offset := size * (page - 1) + rs, err := at.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 (a *AdminQuery) Page(ctx context.Context, page, size int) ([]*Admin, *PageInfo, error) { cnt, err := a.Count(ctx) if err != nil { diff --git a/backend/db/predicate/predicate.go b/backend/db/predicate/predicate.go index 8dbf712..c4be6be 100644 --- a/backend/db/predicate/predicate.go +++ b/backend/db/predicate/predicate.go @@ -6,6 +6,12 @@ import ( "entgo.io/ent/dialect/sql" ) +// AIEmployee is the predicate function for aiemployee builders. +type AIEmployee func(*sql.Selector) + +// AITask is the predicate function for aitask builders. +type AITask func(*sql.Selector) + // Admin is the predicate function for admin builders. type Admin func(*sql.Selector) diff --git a/backend/db/runtime/runtime.go b/backend/db/runtime/runtime.go index aed89d0..a0e460e 100644 --- a/backend/db/runtime/runtime.go +++ b/backend/db/runtime/runtime.go @@ -8,6 +8,8 @@ import ( "github.com/chaitin/MonkeyCode/backend/consts" "github.com/chaitin/MonkeyCode/backend/db/admin" "github.com/chaitin/MonkeyCode/backend/db/adminloginhistory" + "github.com/chaitin/MonkeyCode/backend/db/aiemployee" + "github.com/chaitin/MonkeyCode/backend/db/aitask" "github.com/chaitin/MonkeyCode/backend/db/apikey" "github.com/chaitin/MonkeyCode/backend/db/billingplan" "github.com/chaitin/MonkeyCode/backend/db/billingquota" @@ -39,6 +41,32 @@ import ( // (default values, validators, hooks and policies) and stitches it // to their package variables. func init() { + aiemployeeFields := schema.AIEmployee{}.Fields() + _ = aiemployeeFields + // aiemployeeDescCreatedAt is the schema descriptor for created_at field. + aiemployeeDescCreatedAt := aiemployeeFields[11].Descriptor() + // aiemployee.DefaultCreatedAt holds the default value on creation for the created_at field. + aiemployee.DefaultCreatedAt = aiemployeeDescCreatedAt.Default.(func() time.Time) + // aiemployeeDescUpdatedAt is the schema descriptor for updated_at field. + aiemployeeDescUpdatedAt := aiemployeeFields[12].Descriptor() + // aiemployee.DefaultUpdatedAt holds the default value on creation for the updated_at field. + aiemployee.DefaultUpdatedAt = aiemployeeDescUpdatedAt.Default.(func() time.Time) + // aiemployee.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + aiemployee.UpdateDefaultUpdatedAt = aiemployeeDescUpdatedAt.UpdateDefault.(func() time.Time) + aitaskFields := schema.AITask{}.Fields() + _ = aitaskFields + // aitaskDescStatus is the schema descriptor for status field. + aitaskDescStatus := aitaskFields[2].Descriptor() + // aitask.DefaultStatus holds the default value on creation for the status field. + aitask.DefaultStatus = aitaskDescStatus.Default.(string) + // aitaskDescCreatedAt is the schema descriptor for created_at field. + aitaskDescCreatedAt := aitaskFields[6].Descriptor() + // aitask.DefaultCreatedAt holds the default value on creation for the created_at field. + aitask.DefaultCreatedAt = aitaskDescCreatedAt.Default.(func() time.Time) + // aitaskDescUpdatedAt is the schema descriptor for updated_at field. + aitaskDescUpdatedAt := aitaskFields[7].Descriptor() + // aitask.DefaultUpdatedAt holds the default value on creation for the updated_at field. + aitask.DefaultUpdatedAt = aitaskDescUpdatedAt.Default.(func() time.Time) adminFields := schema.Admin{}.Fields() _ = adminFields // adminDescLastActiveAt is the schema descriptor for last_active_at field. diff --git a/backend/db/tx.go b/backend/db/tx.go index 86925f7..1f6417f 100644 --- a/backend/db/tx.go +++ b/backend/db/tx.go @@ -14,6 +14,10 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config + // AIEmployee is the client for interacting with the AIEmployee builders. + AIEmployee *AIEmployeeClient + // AITask is the client for interacting with the AITask builders. + AITask *AITaskClient // Admin is the client for interacting with the Admin builders. Admin *AdminClient // AdminLoginHistory is the client for interacting with the AdminLoginHistory builders. @@ -203,6 +207,8 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { + tx.AIEmployee = NewAIEmployeeClient(tx.config) + tx.AITask = NewAITaskClient(tx.config) tx.Admin = NewAdminClient(tx.config) tx.AdminLoginHistory = NewAdminLoginHistoryClient(tx.config) tx.AdminRole = NewAdminRoleClient(tx.config) @@ -241,7 +247,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Admin.QueryXXX(), the query will be executed +// applies a query, for example: AIEmployee.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe. diff --git a/backend/ent/schema/admin.go b/backend/ent/schema/admin.go index 779a179..363c5f1 100644 --- a/backend/ent/schema/admin.go +++ b/backend/ent/schema/admin.go @@ -44,6 +44,7 @@ func (Admin) Edges() []ent.Edge { return []ent.Edge{ edge.To("login_histories", AdminLoginHistory.Type), edge.To("myusergroups", UserGroup.Type), + edge.To("aiemployees", AIEmployee.Type), edge.From("usergroups", UserGroup.Type).Ref("admins").Through("user_group_admins", UserGroupAdmin.Type), edge.From("roles", Role.Type).Ref("admins").Through("admin_roles", AdminRole.Type), } diff --git a/backend/ent/schema/aiemployee.go b/backend/ent/schema/aiemployee.go new file mode 100644 index 0000000..db68f63 --- /dev/null +++ b/backend/ent/schema/aiemployee.go @@ -0,0 +1,54 @@ +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/consts" + "github.com/chaitin/MonkeyCode/backend/ent/types" +) + +// AIEmployee holds the schema definition for the AIEmployee entity. +type AIEmployee struct { + ent.Schema +} + +func (AIEmployee) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{ + Table: "ai_employees", + }, + } +} + +// Fields of the AIEmployee. +func (AIEmployee) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}), + field.UUID("admin_id", uuid.UUID{}), + field.String("name"), + field.String("position").GoType(consts.AIEmployeePosition("")), + field.String("repository_url"), + field.String("repository_user"), + field.String("platform").GoType(consts.RepoPlatform("")), + field.String("token"), + field.String("webhook_secret"), + field.String("webhook_url"), + field.JSON("parameters", &types.AIEmployeeParam{}), + field.Time("created_at").Default(time.Now), + field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), + } +} + +// Edges of the AIEmployee. +func (AIEmployee) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("admin", Admin.Type).Ref("aiemployees").Field("admin_id").Unique().Required(), + } +} diff --git a/backend/ent/schema/aitask.go b/backend/ent/schema/aitask.go new file mode 100644 index 0000000..b7664e8 --- /dev/null +++ b/backend/ent/schema/aitask.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/field" + "github.com/google/uuid" +) + +// AITask holds the schema definition for the AITask entity. +type AITask struct { + ent.Schema +} + +func (AITask) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "ai_tasks"}, + } +} + +// Fields of the AITask. +func (AITask) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}), + field.UUID("employee_id", uuid.UUID{}), + field.String("status").Default("pending"), + field.Text("output").Optional().Nillable(), + field.Text("logs").Optional().Nillable(), + field.Text("error_message").Optional().Nillable(), + field.Time("created_at").Default(time.Now), + field.Time("updated_at").Default(time.Now), + } +} + +// Edges of the AITask. +func (AITask) Edges() []ent.Edge { + return nil +} diff --git a/backend/ent/types/types.go b/backend/ent/types/types.go index 2a6f498..aafba28 100644 --- a/backend/ent/types/types.go +++ b/backend/ent/types/types.go @@ -50,3 +50,10 @@ func DefaultModelParam() *ModelParam { SupportPromptCache: false, } } + +type AIEmployeeParam struct { + IssueOpen bool `json:"issue_open"` // 是否处理新Issues + MrPrOpen bool `json:"mr_pr_open"` // 是否处理全部新增PR/MR + IssueAtComment bool `json:"issue_at_comment"` // 是否在issue评论中@工程师 + MrPrAtComment bool `json:"mr_pr_at_comment"` // 是否mr/pr在评论中@工程师 +} diff --git a/backend/errcode/errcode.go b/backend/errcode/errcode.go index c527fe3..26df6b7 100644 --- a/backend/errcode/errcode.go +++ b/backend/errcode/errcode.go @@ -23,4 +23,6 @@ var ( ErrCustomNotEnabled = web.NewBadRequestErr("err-custom-not-enabled") ErrUserLimit = web.NewBadRequestErr("err-user-limit") ErrOnlyAdmin = web.NewBadRequestErr("err-only-admin") + ErrInvalidSecret = web.NewBadRequestErr("err-invalid-secret") + ErrAIEmployeeLimit = web.NewBadRequestErr("err-ai-employee-limit") ) diff --git a/backend/errcode/locale.en.toml b/backend/errcode/locale.en.toml index d829e6b..d38a381 100644 --- a/backend/errcode/locale.en.toml +++ b/backend/errcode/locale.en.toml @@ -35,4 +35,10 @@ other = "DingTalk is not enabled" other = "OAuth is not enabled" [err-user-limit] -other = "User limit reached" \ No newline at end of file +other = "User limit reached" + +[err-invalid-secret] +other = "Invalid secret" + +[err-ai-employee-limit] +other = "Free edition only support one AI employee" \ No newline at end of file diff --git a/backend/errcode/locale.zh.toml b/backend/errcode/locale.zh.toml index b5c23ae..6db6902 100644 --- a/backend/errcode/locale.zh.toml +++ b/backend/errcode/locale.zh.toml @@ -35,4 +35,10 @@ other = "钉钉未启用" other = "OAuth未启用" [err-user-limit] -other = "用户数量已达上限" \ No newline at end of file +other = "用户数量已达上限" + +[err-invalid-secret] +other = "无效的密钥" + +[err-ai-employee-limit] +other = "开源版只支持创建一个AI员工" \ No newline at end of file diff --git a/backend/go.mod b/backend/go.mod index c16a166..0c7e248 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,13 +1,11 @@ module github.com/chaitin/MonkeyCode/backend -go 1.24.0 - -toolchain go1.24.2 +go 1.25.0 require ( - entgo.io/ent v0.14.4 + entgo.io/ent v0.14.5 github.com/GoYoko/web v1.4.0 - github.com/chaitin/ModelKit v1.4.3 + github.com/chaitin/ModelKit v1.5.1-0.20250822075523-d896029f3d7a github.com/doquangtan/socket.io/v4 v4.0.8 github.com/golang-migrate/migrate/v4 v4.18.3 github.com/google/uuid v1.6.0 @@ -19,13 +17,16 @@ require ( github.com/pgvector/pgvector-go v0.3.0 github.com/redis/go-redis/v9 v9.7.3 github.com/rokku-c/go-openai v1.35.7-fix2 + github.com/sashabaranov/go-openai v1.41.1 + github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.20.1 + gitlab.com/gitlab-org/api/client-go v0.142.0 golang.org/x/crypto v0.40.0 golang.org/x/oauth2 v0.30.0 golang.org/x/text v0.27.0 golang.org/x/time v0.12.0 google.golang.org/grpc v1.74.2 - google.golang.org/protobuf v1.36.6 + google.golang.org/protobuf v1.36.8 ) require ( @@ -75,13 +76,16 @@ require ( github.com/gofiber/websocket/v2 v2.2.1 // indirect github.com/google/generative-ai-go v0.20.1 // indirect github.com/google/go-cmp v0.7.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/s2a-go v0.1.9 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect github.com/googleapis/gax-go/v2 v2.15.0 // indirect github.com/goph/emperror v0.17.2 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-retryablehttp v0.7.8 // indirect github.com/hashicorp/hcl/v2 v2.23.0 // indirect github.com/invopop/yaml v0.1.0 // indirect github.com/joho/godotenv v1.5.1 // indirect @@ -110,7 +114,6 @@ require ( github.com/rs/xid v1.6.0 // indirect github.com/sagikazarmark/locafero v0.9.0 // indirect github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/slongfield/pyfmt v0.0.0-20220222012616-ea85ff4c361f // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.14.0 // indirect diff --git a/backend/go.sum b/backend/go.sum index 62ec2ba..fb71be6 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -12,8 +12,8 @@ cloud.google.com/go/compute/metadata v0.7.0 h1:PBWF+iiAerVNe8UCHxdOt6eHLVc3ydFeO cloud.google.com/go/compute/metadata v0.7.0/go.mod h1:j5MvL9PprKL39t166CoB1uVHfQMs4tFQZZcKwksXUjo= cloud.google.com/go/longrunning v0.5.7 h1:WLbHekDbjK1fVFD3ibpFFVoyizlLRl73I7YKuAKilhU= cloud.google.com/go/longrunning v0.5.7/go.mod h1:8GClkudohy1Fxm3owmBGid8W0pSgodEMwEAztp38Xng= -entgo.io/ent v0.14.4 h1:/DhDraSLXIkBhyiVoJeSshr4ZYi7femzhj6/TckzZuI= -entgo.io/ent v0.14.4/go.mod h1:aDPE/OziPEu8+OWbzy4UlvWmD2/kbRuWfK2A40hcxJM= +entgo.io/ent v0.14.5 h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4= +entgo.io/ent v0.14.5/go.mod h1:zTzLmWtPvGpmSwtkaayM2cm5m819NdM7z7tYPq3vN0U= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= @@ -54,8 +54,8 @@ github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFos github.com/certifi/gocertifi v0.0.0-20190105021004-abcd57078448/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chaitin/ModelKit v1.4.3 h1:LFbrMh4qv280hR/XNwc8U8iG7JTsZ4C0QuL0VC3xjPo= -github.com/chaitin/ModelKit v1.4.3/go.mod h1:IRTq/CXbuk8/Gr3Gy/78ZDBTN7HMmxW7YvRjrfW9jdA= +github.com/chaitin/ModelKit v1.5.1-0.20250822075523-d896029f3d7a h1:5J+cCU87hukEuTWlXO5D1UC6J3Bi+1xfihlSmgerUEM= +github.com/chaitin/ModelKit v1.5.1-0.20250822075523-d896029f3d7a/go.mod h1:IRTq/CXbuk8/Gr3Gy/78ZDBTN7HMmxW7YvRjrfW9jdA= github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= github.com/cloudwego/eino v0.3.51 h1:emSaDu49v9EEJYOusL42Li/VL5QBSyBvhxO9ZcKPZvs= @@ -95,6 +95,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/fasthttp/websocket v1.5.3 h1:TPpQuLwJYfd4LJPXvHDYPMFWbLjsT91n3GpWtCQtdek= github.com/fasthttp/websocket v1.5.3/go.mod h1:46gg/UBmTU1kUaTcwQXpUxtRwG2PvIZYeA8oL6vF3Fs= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= @@ -153,8 +155,11 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6 github.com/google/generative-ai-go v0.20.1 h1:6dEIujpgN2V0PgLhr6c/M1ynRdc7ARtiIDPFzj45uNQ= github.com/google/generative-ai-go v0.20.1/go.mod h1:TjOnZJmZKzarWbjUJgy+r3Ee7HGBRVLhOIgupnwR4Bg= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= @@ -177,8 +182,14 @@ github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= +github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos= github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -303,6 +314,8 @@ github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU= github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k= github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk= +github.com/sashabaranov/go-openai v1.41.1 h1:zf5tM+GuxpyiyD9XZg8nCqu52eYFQg9OOew0gnIuDy4= +github.com/sashabaranov/go-openai v1.41.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g= github.com/sebdah/goldie/v2 v2.5.5 h1:rx1mwF95RxZ3/83sdS4Yp7t2C5TCokvWP4TBRbAyEWY= @@ -388,6 +401,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6 github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= github.com/zclconf/go-cty-yaml v1.1.0 h1:nP+jp0qPHv2IhUVqmQSzjvqAWcObN0KBkUl2rWBdig0= github.com/zclconf/go-cty-yaml v1.1.0/go.mod h1:9YLUH4g7lOhVWqUbctnVlZ5KLpg7JAprQNgxSZ1Gyxs= +gitlab.com/gitlab-org/api/client-go v0.142.0 h1:cR8+RhDc7ooH0SiGNhgm3Nf5ZpW5D1R3DLshfAXJZmQ= +gitlab.com/gitlab-org/api/client-go v0.142.0/go.mod h1:3YuWlZCirs2TTcaAzM6qNwVHB7WvV67ATb0GGpBCdlQ= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ= @@ -406,8 +421,8 @@ go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mx go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= -go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/arch v0.19.0 h1:LmbDQUodHThXE+htjrnmVD73M//D9GTH6wFZjyDkjyU= @@ -490,6 +505,7 @@ golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0= golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.239.0 h1:2hZKUnFZEy81eugPs4e2XzIJ5SOwQg0G82bpXD65Puo= google.golang.org/api v0.239.0/go.mod h1:cOVEm2TpdAGHL2z+UwyS+kmlGr3bVWQQ6sYEqkKje50= google.golang.org/genai v1.13.0 h1:LRhwx5PU+bXhfnXyPEHu2kt9yc+MpvuYbajxSorOJjg= @@ -502,8 +518,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/grpc v1.74.2 h1:WoosgB65DlWVC9FqI82dGsZhWFNBSLjQ84bjROOpMu4= google.golang.org/grpc v1.74.2/go.mod h1:CtQ+BGjaAIXHs/5YS3i473GqwBBa1zGQNevxdeBEXrM= -google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= -google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= +google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/backend/migration/000020_create_ai_employee_table.down.sql b/backend/migration/000020_create_ai_employee_table.down.sql new file mode 100644 index 0000000..d25bb73 --- /dev/null +++ b/backend/migration/000020_create_ai_employee_table.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS ai_employees; \ No newline at end of file diff --git a/backend/migration/000020_create_ai_employee_table.up.sql b/backend/migration/000020_create_ai_employee_table.up.sql new file mode 100644 index 0000000..5c1e5c1 --- /dev/null +++ b/backend/migration/000020_create_ai_employee_table.up.sql @@ -0,0 +1,36 @@ +CREATE TABLE IF NOT EXISTS ai_employees ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + admin_id UUID NOT NULL, + name VARCHAR(255) NOT NULL, + position VARCHAR(50) NOT NULL, -- 研发工程师, 产品经理, 设计师 + repository_url TEXT NOT NULL, + repository_user VARCHAR(255) NOT NULL, + platform VARCHAR(50) NOT NULL, -- github, gitlab, bitbucket + token TEXT NOT NULL, + webhook_secret VARCHAR(64) NOT NULL, + webhook_url TEXT NOT NULL, + parameters JSONB NOT NULL, + created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX IF NOT EXISTS idx_ai_employees_position ON ai_employees (position); +CREATE INDEX IF NOT EXISTS idx_ai_employees_platform ON ai_employees (platform); +CREATE INDEX IF NOT EXISTS idx_ai_employees_repository_url ON ai_employees (repository_url); +CREATE INDEX IF NOT EXISTS idx_ai_employees_token ON ai_employees (token); +CREATE INDEX IF NOT EXISTS idx_ai_employees_admin_id ON ai_employees (admin_id); +CREATE INDEX IF NOT EXISTS idx_ai_employees_webhook_secret ON ai_employees (webhook_secret); + +CREATE TABLE IF NOT EXISTS ai_tasks ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + employee_id UUID NOT NULL, + status VARCHAR(50) NOT NULL, -- init, running, success, failed + output TEXT, + logs TEXT, + error_message TEXT, + created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX IF NOT EXISTS idx_ai_tasks_employee_id ON ai_tasks (employee_id); +CREATE INDEX IF NOT EXISTS idx_ai_tasks_status ON ai_tasks (status); diff --git a/backend/pkg/random/random.go b/backend/pkg/random/random.go new file mode 100644 index 0000000..8c2918b --- /dev/null +++ b/backend/pkg/random/random.go @@ -0,0 +1,17 @@ +package random + +import ( + "math/rand" + "time" +) + +const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + +func RandomString(length int) string { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + b := make([]byte, length) + for i := range b { + b[i] = letters[r.Intn(len(letters))] + } + return string(b) +} diff --git a/backend/pkg/store/redis.go b/backend/pkg/store/redis.go index 7e3ba01..84751ec 100644 --- a/backend/pkg/store/redis.go +++ b/backend/pkg/store/redis.go @@ -2,6 +2,7 @@ package store import ( "context" + "fmt" "net" "github.com/redis/go-redis/v9" @@ -10,7 +11,7 @@ import ( ) func NewRedisCli(cfg *config.Config) *redis.Client { - addr := net.JoinHostPort(cfg.Redis.Host, cfg.Redis.Port) + addr := net.JoinHostPort(cfg.Redis.Host, fmt.Sprintf("%d", cfg.Redis.Port)) rdb := redis.NewClient(&redis.Options{ Addr: addr, Password: cfg.Redis.Pass, diff --git a/backend/pro b/backend/pro index 8b72145..3662b07 160000 --- a/backend/pro +++ b/backend/pro @@ -1 +1 @@ -Subproject commit 8b7214572f1b93e4960a630d87de8fe6fe0534d2 +Subproject commit 3662b07c0f6d8f105a726a33e56fa4f2287dec26