feat: Created task lists that work in categories
All checks were successful
Build and Push App Image / build-and-push (push) Successful in 1m20s
All checks were successful
Build and Push App Image / build-and-push (push) Successful in 1m20s
This commit is contained in:
@@ -108,13 +108,95 @@ func (r *TaskRepository) EnsureIndexes(ctx context.Context) error {
|
||||
_, err := r.collection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "updated_at", Value: -1}}},
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "status_id", Value: 1}}},
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "category_id", Value: 1}}},
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "task_list_id", Value: 1}}},
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "parent_task_id", Value: 1}}},
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "note_links", Value: 1}}},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// TaskListRepository implements task list data access.
|
||||
type TaskListRepository struct {
|
||||
collection *mongo.Collection
|
||||
}
|
||||
|
||||
// NewTaskListRepository creates a new task list repository.
|
||||
func NewTaskListRepository(db *mongo.Database) *TaskListRepository {
|
||||
return &TaskListRepository{collection: db.Collection("task_lists")}
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) CreateTaskList(ctx context.Context, list *entities.TaskList) error {
|
||||
list.ID = bson.NewObjectID()
|
||||
list.CreatedAt = time.Now()
|
||||
list.UpdatedAt = time.Now()
|
||||
_, err := r.collection.InsertOne(ctx, list)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) GetTaskListByID(ctx context.Context, id bson.ObjectID) (*entities.TaskList, error) {
|
||||
var list entities.TaskList
|
||||
err := r.collection.FindOne(ctx, bson.M{"_id": id}).Decode(&list)
|
||||
if err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, errors.New("task list not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) ListTaskLists(ctx context.Context, spaceID bson.ObjectID) ([]*entities.TaskList, error) {
|
||||
cursor, err := r.collection.Find(ctx, bson.M{"space_id": spaceID}, options.Find().SetSort(bson.D{{Key: "name", Value: 1}}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
var lists []*entities.TaskList
|
||||
if err := cursor.All(ctx, &lists); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return lists, nil
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) ListTaskListsByCategory(ctx context.Context, spaceID bson.ObjectID, categoryID bson.ObjectID) ([]*entities.TaskList, error) {
|
||||
cursor, err := r.collection.Find(ctx, bson.M{"space_id": spaceID, "category_id": categoryID}, options.Find().SetSort(bson.D{{Key: "name", Value: 1}}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
var lists []*entities.TaskList
|
||||
if err := cursor.All(ctx, &lists); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return lists, nil
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) UpdateTaskList(ctx context.Context, list *entities.TaskList) error {
|
||||
list.UpdatedAt = time.Now()
|
||||
_, err := r.collection.ReplaceOne(ctx, bson.M{"_id": list.ID}, list)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) DeleteTaskList(ctx context.Context, id bson.ObjectID) error {
|
||||
_, err := r.collection.DeleteOne(ctx, bson.M{"_id": id})
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) DeleteTaskListsBySpaceID(ctx context.Context, spaceID bson.ObjectID) error {
|
||||
_, err := r.collection.DeleteMany(ctx, bson.M{"space_id": spaceID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *TaskListRepository) EnsureIndexes(ctx context.Context) error {
|
||||
_, err := r.collection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "name", Value: 1}}, Options: options.Index().SetUnique(true)},
|
||||
{Keys: bson.D{{Key: "space_id", Value: 1}, {Key: "category_id", Value: 1}}},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// TaskStatusRepository implements task status data access.
|
||||
type TaskStatusRepository struct {
|
||||
collection *mongo.Collection
|
||||
|
||||
Reference in New Issue
Block a user