helpers

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPinned added in v1.7.10

func HasPinned(u *model.User, c model.Course) bool

HasPinned reports whether u has pinned c. It reads the PinnedCourses that GetUserByID preloads, so it costs no query.

func ParseBookmarkToProto

func ParseBookmarkToProto(b model.Bookmark) *protobuf.Bookmark

ParseBookmarkToProto converts a Bookmark model to its protobuf representation.

func ParseCourseToProto

func ParseCourseToProto(c model.Course, u *model.User) *protobuf.Course

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

func ParseRunnerToProto(r model.Runner) *protobuf.Runner

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

func ParseSemesterToProto(semester model.Semester) *protobuf.Semester

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

func ParseUserToProto(u *model.User) *protobuf.User

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

func ParseWorkerToProto(w model.Worker) *protobuf.Worker

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

func ValidatePreferredName(value string, lastChange *model.UserSetting, now time.Time) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL