-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/crawlab-team/crawlab-core/interfaces" | ||
"github.com/crawlab-team/crawlab-core/models/service" | ||
"github.com/crawlab-team/crawlab-core/user" | ||
"go.uber.org/dig" | ||
) | ||
|
||
var EnvironmentController *environmentController | ||
|
||
var EnvironmentActions []Action | ||
|
||
type environmentController struct { | ||
ListActionControllerDelegate | ||
d ListActionControllerDelegate | ||
ctx *environmentContext | ||
} | ||
|
||
type environmentContext struct { | ||
modelSvc service.ModelService | ||
userSvc interfaces.UserService | ||
} | ||
|
||
func newEnvironmentContext() *environmentContext { | ||
// context | ||
ctx := &environmentContext{} | ||
|
||
// dependency injection | ||
c := dig.New() | ||
if err := c.Provide(service.NewService); err != nil { | ||
panic(err) | ||
} | ||
if err := c.Provide(user.ProvideGetUserService()); err != nil { | ||
panic(err) | ||
} | ||
if err := c.Invoke(func( | ||
modelSvc service.ModelService, | ||
userSvc interfaces.UserService, | ||
) { | ||
ctx.modelSvc = modelSvc | ||
ctx.userSvc = userSvc | ||
}); err != nil { | ||
panic(err) | ||
} | ||
|
||
return ctx | ||
} | ||
|
||
func newEnvironmentController() *environmentController { | ||
modelSvc, err := service.GetService() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctr := NewListPostActionControllerDelegate(ControllerIdEnvironment, modelSvc.GetBaseService(interfaces.ModelIdEnvironment), EnvironmentActions) | ||
d := NewListPostActionControllerDelegate(ControllerIdEnvironment, modelSvc.GetBaseService(interfaces.ModelIdEnvironment), EnvironmentActions) | ||
ctx := newEnvironmentContext() | ||
|
||
return &environmentController{ | ||
ListActionControllerDelegate: *ctr, | ||
d: *d, | ||
ctx: ctx, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package models | ||
|
||
import ( | ||
"github.com/crawlab-team/crawlab-core/interfaces" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
type Environment struct { | ||
Id primitive.ObjectID `json:"_id" bson:"_id"` | ||
Key string `json:"key" bson:"key"` | ||
Value string `json:"value" bson:"value"` | ||
} | ||
|
||
func (e *Environment) GetId() (id primitive.ObjectID) { | ||
return e.Id | ||
} | ||
|
||
func (e *Environment) SetId(id primitive.ObjectID) { | ||
e.Id = id | ||
} | ||
|
||
type EnvironmentList []Environment | ||
|
||
func (l *EnvironmentList) GetModels() (res []interfaces.Model) { | ||
for i := range *l { | ||
d := (*l)[i] | ||
res = append(res, &d) | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/crawlab-team/crawlab-core/errors" | ||
"github.com/crawlab-team/crawlab-core/interfaces" | ||
models2 "github.com/crawlab-team/crawlab-core/models/models" | ||
"github.com/crawlab-team/crawlab-db/mongo" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
func convertTypeEnvironment(d interface{}, err error) (res *models2.Environment, err2 error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
res, ok := d.(*models2.Environment) | ||
if !ok { | ||
return nil, errors.ErrorModelInvalidType | ||
} | ||
return res, nil | ||
} | ||
|
||
func (svc *Service) GetEnvironmentById(id primitive.ObjectID) (res *models2.Environment, err error) { | ||
d, err := svc.GetBaseService(interfaces.ModelIdEnvironment).GetById(id) | ||
return convertTypeEnvironment(d, err) | ||
} | ||
|
||
func (svc *Service) GetEnvironment(query bson.M, opts *mongo.FindOptions) (res *models2.Environment, err error) { | ||
d, err := svc.GetBaseService(interfaces.ModelIdEnvironment).Get(query, opts) | ||
return convertTypeEnvironment(d, err) | ||
} | ||
|
||
func (svc *Service) GetEnvironmentList(query bson.M, opts *mongo.FindOptions) (res []models2.Environment, err error) { | ||
l, err := svc.GetBaseService(interfaces.ModelIdEnvironment).GetList(query, opts) | ||
for _, doc := range l.GetModels() { | ||
d := doc.(*models2.Environment) | ||
res = append(res, *d) | ||
} | ||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters