Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LikDan committed Nov 4, 2023
1 parent 46a50ef commit dc47e36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions internal/schedule/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,11 @@ func (s *controller) AddScheduleInfo(ctx context.Context, dto dto2.AddScheduleIn
StudyPlaceId: user.StudyPlaceInfo.ID,
}

err := s.repository.AddScheduleInfo(ctx, entry)
if err != nil {
if err := s.repository.RemoveScheduleInfo(ctx, user.StudyPlaceInfo.ID, dto.Date); err != nil {
return entities.ScheduleInfoEntry{}, err
}

if err := s.repository.AddScheduleInfo(ctx, entry); err != nil {
return entities.ScheduleInfoEntry{}, err
}

Expand Down
11 changes: 9 additions & 2 deletions internal/schedule/repositories/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Repository interface {
FilterLessonMarks(ctx context.Context, lessonID primitive.ObjectID, marks []string) error

AddScheduleInfo(ctx context.Context, entry entities.ScheduleInfoEntry) error
RemoveScheduleInfo(ctx context.Context, studyPlaceID primitive.ObjectID, date time.Time) error
}

type repository struct {
Expand Down Expand Up @@ -175,8 +176,9 @@ return items;
"status": "general",
},
},
}, "as": "generalLessons"},
},
},
"as": "generalLessons",
}},
bson.M{
"$project": bson.M{
"lessons": bson.M{"$cond": bson.M{
Expand Down Expand Up @@ -454,3 +456,8 @@ func (s *repository) AddScheduleInfo(ctx context.Context, entry entities.Schedul
_, err := s.schedule.InsertOne(ctx, entry)
return err
}

func (s *repository) RemoveScheduleInfo(ctx context.Context, studyPlaceID primitive.ObjectID, date time.Time) error {
_, err := s.schedule.DeleteMany(ctx, bson.M{"studyPlaceID": studyPlaceID, "date": date})
return err
}

0 comments on commit dc47e36

Please sign in to comment.