Files
backend/internal/repository/exam_repo.go
lan 2f2bbc646e
All checks were successful
Build Backend / build (push) Successful in 2m18s
Build Backend / build-docker (push) Successful in 1m20s
feat(api): implement exam and grade synchronization modules
Add new functionality for managing and synchronizing academic grades and exam schedules. This includes new models, repositories, services, and HTTP handlers, along with updated gRPC definitions and dependency injection configuration.

Additionally, improve the reliability of unread message count tracking by implementing an atomic Lua script for Redis operations in the conversation cache.
2026-05-12 01:28:18 +08:00

42 lines
1.1 KiB
Go

package repository
import (
"context"
"with_you/internal/model"
"gorm.io/gorm"
)
type ExamRepository interface {
ListByUserAndSemester(userID, semester string) ([]*model.Exam, error)
DeleteByUserAndSemester(ctx context.Context, userID, semester string) error
BatchCreate(ctx context.Context, exams []*model.Exam) error
}
type examRepository struct {
db *gorm.DB
}
func NewExamRepository(db *gorm.DB) ExamRepository {
return &examRepository{db: db}
}
func (r *examRepository) ListByUserAndSemester(userID, semester string) ([]*model.Exam, error) {
var exams []*model.Exam
err := r.db.Where("user_id = ? AND semester = ?", userID, semester).
Order("created_at ASC").
Find(&exams).Error
return exams, err
}
func (r *examRepository) DeleteByUserAndSemester(ctx context.Context, userID, semester string) error {
return r.db.WithContext(ctx).
Where("user_id = ? AND semester = ?", userID, semester).
Delete(&model.Exam{}).Error
}
func (r *examRepository) BatchCreate(ctx context.Context, exams []*model.Exam) error {
return r.db.WithContext(ctx).CreateInBatches(exams, 100).Error
}