feat(runner): implement empty classroom sync functionality
Add support for fetching and synchronizing empty classroom data. This includes new protobuf definitions for task payloads and results, database models, repository, service, and HTTP handlers. - Add `TASK_TYPE_GET_EMPTY_CLASSROOM` to `TaskType` enum - Implement `EmptyClassroom` model and auto-migration - Add `EmptyClassroomHandler` with `GET` and `POST /sync` routes - Implement `EmptyClassroomSyncService` and `EmptyClassroomRepository` - Update dependency injection with wire sets
This commit is contained in:
41
internal/repository/empty_classroom_repo.go
Normal file
41
internal/repository/empty_classroom_repo.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"with_you/internal/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type EmptyClassroomRepository interface {
|
||||
ListByUserAndSemester(userID, semester string) ([]*model.EmptyClassroom, error)
|
||||
DeleteByUserAndSemester(ctx context.Context, userID, semester string) error
|
||||
BatchCreate(ctx context.Context, classrooms []*model.EmptyClassroom) error
|
||||
}
|
||||
|
||||
type emptyClassroomRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewEmptyClassroomRepository(db *gorm.DB) EmptyClassroomRepository {
|
||||
return &emptyClassroomRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *emptyClassroomRepository) ListByUserAndSemester(userID, semester string) ([]*model.EmptyClassroom, error) {
|
||||
var classrooms []*model.EmptyClassroom
|
||||
err := r.db.Where("user_id = ? AND semester = ?", userID, semester).
|
||||
Order("classroom ASC, weekday ASC").
|
||||
Find(&classrooms).Error
|
||||
return classrooms, err
|
||||
}
|
||||
|
||||
func (r *emptyClassroomRepository) DeleteByUserAndSemester(ctx context.Context, userID, semester string) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Where("user_id = ? AND semester = ?", userID, semester).
|
||||
Delete(&model.EmptyClassroom{}).Error
|
||||
}
|
||||
|
||||
func (r *emptyClassroomRepository) BatchCreate(ctx context.Context, classrooms []*model.EmptyClassroom) error {
|
||||
return r.db.WithContext(ctx).CreateInBatches(classrooms, 100).Error
|
||||
}
|
||||
Reference in New Issue
Block a user