feat(api): implement exam and grade synchronization modules
All checks were successful
Build Backend / build (push) Successful in 2m18s
Build Backend / build-docker (push) Successful in 1m20s

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:
2026-05-12 01:28:18 +08:00
parent 628a6acbe9
commit 2f2bbc646e
20 changed files with 1052 additions and 212 deletions

View 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
}