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
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
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
|
|
}
|