Documentation
¶
Overview ¶
Package helpers provides helper functions for parsing models to protobuf representations.
Package helpers provides helper functions for parsing models to protobuf representations.
Index ¶
- func HasPinned(u *model.User, c model.Course) bool
- func ParseBookmarkToProto(b model.Bookmark) *protobuf.Bookmark
- func ParseCourseToProto(c model.Course, u *model.User) *protobuf.Course
- func ParseDownloadToProto(download model.DownloadableVod) *protobuf.Download
- func ParseLectureHallToProto(lh *model.LectureHall) *protobuf.LectureHall
- func ParseNotificationToProto(notification model.Notification) *protobuf.UserGroupNotification
- func ParseRunnerToProto(r model.Runner) *protobuf.Runner
- func ParseSemesterToProto(semester model.Semester) *protobuf.Semester
- func ParseServerNotificationToProto(notification model.ServerNotification) *protobuf.ServerNotification
- func ParseStreamProgressToProto(progress model.StreamProgress) *protobuf.StreamProgress
- func ParseStreamToProto(stream model.Stream, course model.Course, user *model.User) *protobuf.Stream
- func ParseUserSettingToProto(setting model.UserSetting) *protobuf.UserSetting
- func ParseUserToProto(u *model.User) *protobuf.User
- func ParseVideoSectionToProto(section model.VideoSection) *protobuf.VideoSection
- func ParseWorkerToProto(w model.Worker) *protobuf.Worker
- func UpdateUserSettings(db *gorm.DB, user *model.User, req *protobuf.UpdateUserSettingsRequest) (settings []model.UserSetting, err error)
- func ValidatePreferredName(value string, lastChange *model.UserSetting, now time.Time) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasPinned ¶ added in v1.7.10
HasPinned reports whether u has pinned c. It reads the PinnedCourses that GetUserByID preloads, so it costs no query.
func ParseBookmarkToProto ¶
ParseBookmarkToProto converts a Bookmark model to its protobuf representation.
func ParseCourseToProto ¶
ParseCourseToProto converts a Course model to its protobuf representation.
Everything derived here is derived for u: the private lectures of a course the caller does not administer are left out of the last recording and the next lecture, and the pin is the caller's own.
func ParseDownloadToProto ¶
func ParseDownloadToProto(download model.DownloadableVod) *protobuf.Download
func ParseLectureHallToProto ¶
func ParseLectureHallToProto(lh *model.LectureHall) *protobuf.LectureHall
ParseLectureHallToProto converts a LectureHall model to its protobuf representation. Nil is normal for a stream not held in one, and maps to an absent message.
func ParseNotificationToProto ¶
func ParseNotificationToProto(notification model.Notification) *protobuf.UserGroupNotification
func ParseRunnerToProto ¶ added in v1.8.0
ParseRunnerToProto converts a Runner model to its protobuf representation. `alive` is derived here so a client cannot disagree with the scheduler about it.
func ParseSemesterToProto ¶
ParseSemesterToProto converts a Semester model to its protobuf representation.
func ParseServerNotificationToProto ¶
func ParseServerNotificationToProto(notification model.ServerNotification) *protobuf.ServerNotification
func ParseStreamProgressToProto ¶
func ParseStreamProgressToProto(progress model.StreamProgress) *protobuf.StreamProgress
ParseStreamProgressToProto converts a StreamProgress model to its protobuf representation.
func ParseStreamToProto ¶
func ParseStreamToProto(stream model.Stream, course model.Course, user *model.User) *protobuf.Stream
ParseStreamToProto converts a Stream model to its protobuf representation.
func ParseUserSettingToProto ¶
func ParseUserSettingToProto(setting model.UserSetting) *protobuf.UserSetting
ParseUserSettingToProto converts a UserSetting model to its protobuf representation.
func ParseUserToProto ¶
ParseUserToProto converts a User model to its protobuf representation.
func ParseVideoSectionToProto ¶
func ParseVideoSectionToProto(section model.VideoSection) *protobuf.VideoSection
ParseVideoSectionToProto converts a VideoSection model to its protobuf representation.
func ParseWorkerToProto ¶ added in v1.8.1
ParseWorkerToProto converts a Worker model to its protobuf representation. `alive` is derived here so a client cannot disagree with the scheduler about it.
func UpdateUserSettings ¶
func UpdateUserSettings(db *gorm.DB, user *model.User, req *protobuf.UpdateUserSettingsRequest) (settings []model.UserSetting, err error)
func ValidatePreferredName ¶ added in v1.7.10
ValidatePreferredName reports whether a user may set this preferred name now.
lastChange is their current setting, or nil if they have never set one. The clock is a parameter so the cooldown can be tested without waiting three months.
The cooldown runs from UpdatedAt, not CreatedAt: gorm's Save leaves CreatedAt at the first write, so measuring from it would rate-limit only the second change ever.
Types ¶
This section is empty.