remove source
This commit is contained in:
		
							parent
							
								
									3af9a2a41a
								
							
						
					
					
						commit
						ae9b4cd9c4
					
				| 
						 | 
					@ -29,7 +29,6 @@ func (s Service) Create(payload CreatePayload) {
 | 
				
			||||||
	// Get document
 | 
						// Get document
 | 
				
			||||||
	doc := Audit{
 | 
						doc := Audit{
 | 
				
			||||||
		ID:       mongodb.NewObjectID(),
 | 
							ID:       mongodb.NewObjectID(),
 | 
				
			||||||
		Source:   s.Source,
 | 
					 | 
				
			||||||
		Target:   payload.Target,
 | 
							Target:   payload.Target,
 | 
				
			||||||
		TargetID: payload.TargetID,
 | 
							TargetID: payload.TargetID,
 | 
				
			||||||
		Action:   payload.Action,
 | 
							Action:   payload.Action,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,6 @@ func (s Service) All(query AllQuery) []Audit {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Find db
 | 
						// Find db
 | 
				
			||||||
	cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{
 | 
						cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{
 | 
				
			||||||
		{"source", s.Source},
 | 
					 | 
				
			||||||
		{"target", query.Target},
 | 
							{"target", query.Target},
 | 
				
			||||||
		{"targetId", query.TargetID},
 | 
							{"targetId", query.TargetID},
 | 
				
			||||||
	}, &options.FindOptions{
 | 
						}, &options.FindOptions{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								audit.go
								
								
								
								
							
							
						
						
									
										6
									
								
								audit.go
								
								
								
								
							| 
						 | 
					@ -15,8 +15,6 @@ type MongoDBConfig struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Config ...
 | 
					// Config ...
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	// Source of server, e.g: selly
 | 
					 | 
				
			||||||
	Source string
 | 
					 | 
				
			||||||
	// Targets: staff, article, ...
 | 
						// Targets: staff, article, ...
 | 
				
			||||||
	Targets []string
 | 
						Targets []string
 | 
				
			||||||
	// MongoDB config, for save documents
 | 
						// MongoDB config, for save documents
 | 
				
			||||||
| 
						 | 
					@ -33,8 +31,8 @@ var s *Service
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewInstance ...
 | 
					// NewInstance ...
 | 
				
			||||||
func NewInstance(config Config) error {
 | 
					func NewInstance(config Config) error {
 | 
				
			||||||
	if config.Source == "" || len(config.Targets) == 0 || config.MongoDB.Host == "" {
 | 
						if len(config.Targets) == 0 || config.MongoDB.Host == "" {
 | 
				
			||||||
		return errors.New("please provide all necessary information: source, targets, mongodb")
 | 
							return errors.New("please provide all necessary information: targets, mongodb")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Connect MongoDB
 | 
						// Connect MongoDB
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +0,0 @@
 | 
				
			||||||
package audit
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// List actions
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	ActionCreate            = "create"
 | 
					 | 
				
			||||||
	ActionUpdate            = "update"
 | 
					 | 
				
			||||||
	ActionUpdatePermissions = "update-permissions"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
| 
						 | 
					@ -6,9 +6,9 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) indexDB() {
 | 
					func (s Service) indexDB() {
 | 
				
			||||||
	// Index key
 | 
						// Index key
 | 
				
			||||||
	commonIndex := mongodb.NewIndexKey("source", "target", "targetId")
 | 
						commonIndex := mongodb.NewIndexKey("target", "targetId")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Index all allowed sources
 | 
						// Index all targets
 | 
				
			||||||
	for _, target := range s.Targets {
 | 
						for _, target := range s.Targets {
 | 
				
			||||||
		mongodb.CreateIndex(getColName(target), commonIndex)
 | 
							mongodb.CreateIndex(getColName(target), commonIndex)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,6 @@ import (
 | 
				
			||||||
// Audit ...
 | 
					// Audit ...
 | 
				
			||||||
type Audit struct {
 | 
					type Audit struct {
 | 
				
			||||||
	ID        primitive.ObjectID `bson:"_id" json:"id"`
 | 
						ID        primitive.ObjectID `bson:"_id" json:"id"`
 | 
				
			||||||
	Source    string             `bson:"source" json:"source"`
 | 
					 | 
				
			||||||
	Target    string             `bson:"target" json:"target"`
 | 
						Target    string             `bson:"target" json:"target"`
 | 
				
			||||||
	TargetID  string             `bson:"targetId" json:"targetId"`
 | 
						TargetID  string             `bson:"targetId" json:"targetId"`
 | 
				
			||||||
	Action    string             `bson:"action" json:"action"`
 | 
						Action    string             `bson:"action" json:"action"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue