Introduces group calling capabilities, including group invites and participant lifecycle management. Enhances the existing call system with support for media types (voice/video) and improved participant tracking. - Add `GroupInvite` and `ParticipantJoin/Leave` to `CallService`. - Implement WebSocket handlers for `call_group_invite` and `call_participant_join`. - Update `CallSession` model to support group IDs, media types, and tracking who ended the call. - Integrate `GroupService` into `CallService` via dependency injection. - Add error constants for group call limitations and participant capacity. - Update LiveKit webhook handling to process participant leave events. Refactor grade synchronization to remove semester-based filtering in favor of a more flexible user-based approach and improve GPA summary updates.
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"with_you/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type GradeRepository interface {
|
|
ListByUser(userID string) ([]*model.Grade, error)
|
|
DeleteByUser(ctx context.Context, userID string) error
|
|
BatchCreate(ctx context.Context, grades []*model.Grade) error
|
|
GetLatestGpaSummary(userID string) (*model.GpaSummary, error)
|
|
SaveGpaSummary(ctx context.Context, summary *model.GpaSummary) error
|
|
DeleteGpaSummaryByUser(ctx context.Context, userID string) error
|
|
}
|
|
|
|
type gradeRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewGradeRepository(db *gorm.DB) GradeRepository {
|
|
return &gradeRepository{db: db}
|
|
}
|
|
|
|
func (r *gradeRepository) ListByUser(userID string) ([]*model.Grade, error) {
|
|
var grades []*model.Grade
|
|
err := r.db.Where("user_id = ?", userID).
|
|
Order("term DESC, created_at ASC").
|
|
Find(&grades).Error
|
|
return grades, err
|
|
}
|
|
|
|
func (r *gradeRepository) DeleteByUser(ctx context.Context, userID string) error {
|
|
return r.db.WithContext(ctx).
|
|
Where("user_id = ?", userID).
|
|
Delete(&model.Grade{}).Error
|
|
}
|
|
|
|
func (r *gradeRepository) BatchCreate(ctx context.Context, grades []*model.Grade) error {
|
|
return r.db.WithContext(ctx).CreateInBatches(grades, 100).Error
|
|
}
|
|
|
|
func (r *gradeRepository) GetLatestGpaSummary(userID string) (*model.GpaSummary, error) {
|
|
var summary model.GpaSummary
|
|
err := r.db.Where("user_id = ?", userID).
|
|
Order("updated_at DESC").
|
|
First(&summary).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &summary, nil
|
|
}
|
|
|
|
func (r *gradeRepository) SaveGpaSummary(ctx context.Context, summary *model.GpaSummary) error {
|
|
return r.db.WithContext(ctx).Save(summary).Error
|
|
}
|
|
|
|
func (r *gradeRepository) DeleteGpaSummaryByUser(ctx context.Context, userID string) error {
|
|
return r.db.WithContext(ctx).
|
|
Where("user_id = ?", userID).
|
|
Delete(&model.GpaSummary{}).Error
|
|
}
|