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.
This commit is contained in:
41
internal/repository/exam_repo.go
Normal file
41
internal/repository/exam_repo.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user