storage

package module
v0.0.0-...-13896a5 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MPL-2.0 Imports: 12 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MALE   gender = "MALE"
	FEMALE gender = "FEMALE"
)

Variables

This section is empty.

Functions

func FromInternalToProtoEvent

func FromInternalToProtoEvent(s string) pb.Event_EventType

func FromInternalToProtoGenderRestriction

func FromInternalToProtoGenderRestriction(g GenderRestriction) pb.Event_GenderRestriction

func FromProtoToInternalEventType

func FromProtoToInternalEventType(et pb.Event_EventType) string

Types

type Address

type Address struct {
	AddressLine1 string
	AddressLine2 string
	ZoneCode     string
	PostalCode   string
	City         string
	CountryCode  string
}

type AdhanFile

type AdhanFile struct {
	ID        uuid.UUID `gorm:"primaryKey;type:char(36)"`
	MasjidId  string    `gorm:"type:varchar(320)"`
	File      []byte
	CreatedAt time.Time
	UpdatedAt time.Time
}

func NewAdhanFile

func NewAdhanFile(a *pb.AdhanFile) *AdhanFile

NewAdhanFile creates a new AdhanFile struct given the AdhanFile proto.

func (*AdhanFile) ToProto

func (a *AdhanFile) ToProto() *pb.AdhanFile

type AsrJuristicMethod

type AsrJuristicMethod int64

The Juristic method to use for calculating Asr prayer times.

const (
	// Use the Shafi/Hanbali/Maliki method to calculate Asr timings.
	SHAFI_HANBALI_MALIKI AsrJuristicMethod = iota
	// Use the Hanafi method to calculate Asr timings.
	HANAFI
)

type BirthDate

type BirthDate struct {
	Year  int32 `gorm:"column:year"`
	Month Month `gorm:"column:month"`
	Day   int8  `gorm:"column:day"`
}

BirthDate represents the birth date of a user.

type CalculationMethod

type CalculationMethod int64

Defines the calculation method to use. If this field is set (excluding OTHER), then the Fajr and Isha angle fields are automatically set.

const (
	OTHER CalculationMethod = iota
	// Muslim World League
	// Uses Fajr angle of 18 and an Isha angle of 17
	MUSLIM_WORLD_LEAGUE
	// Egyptian General Authority of Survey
	// Uses Fajr angle of 19.5 and an Isha angle of 17.5
	EGYPTIAN
	// University of Islamic Sciences, Karachi
	// Uses Fajr angle of 18 and an Isha angle of 18
	KARACHI
	// Umm al-Qura University, Makkah
	// Uses a Fajr angle of 18.5 and an Isha angle of 90. Note: You should add a +30 minute custom
	// adjustment of Isha during Ramadan.
	UMM_AL_QURA
	// The Gulf Region
	// Uses Fajr and Isha angles of 18.2 degrees.
	DUBAI
	// Moonsighting Committee
	// Uses a Fajr angle of 18 and an Isha angle of 18. Also uses seasonal adjustment values.
	MOON_SIGHTING_COMMITTEE
	// Referred to as the ISNA method
	// This method is included for completeness, but is not recommended.
	// Uses a Fajr angle of 15 and an Isha angle of 15.
	NORTH_AMERICA
	// Kuwait
	// Uses a Fajr angle of 18 and an Isha angle of 17.5
	KUWAIT
	// Qatar
	// Modified version of Umm al-Qura that uses a Fajr angle of 18.
	QATAR
	// Singapore
	// Uses a Fajr angle of 20 and an Isha angle of 18
	SINGAPORE
	// UOIF
	// Uses a Fajr angle of 12 and an Isha angle of 12
	UOIF
)

type Event

type Event struct {
	ID                uuid.UUID `gorm:"primaryKey;type:char(36)"`
	OrganizationId    string
	Name              string
	Description       string
	StartTime         time.Time
	EndTime           time.Time
	GenderRestriction GenderRestriction `` /* 138-byte string literal not displayed */

	EventTypes      string
	IsPaid          bool
	RequiresRsvp    bool
	MaxParticipants int32
	LivestreamLink  string
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

func NewEvent

func NewEvent(ep *pb.Event) (*Event, error)

NewEvent creates a new Event struct given the Event proto.

func (*Event) ToProto

func (e *Event) ToProto() *pb.Event

type GenderRestriction

type GenderRestriction int64
const (
	NO_RESTRICTION GenderRestriction = iota
	MALE_ONLY
	FEMALE_ONLY
)

func FromProtoToInternalGenderRestriction

func FromProtoToInternalGenderRestriction(g pb.Event_GenderRestriction) GenderRestriction

type HighLatitudeRule

type HighLatitudeRule int64

The high latitude rule for calculating Fajr and Isha prayers.

const (
	NO_HIGH_LATITUDE_RULE HighLatitudeRule = iota

	// Fajr will never be earlier than the middle of the night, and Isha will never be later than
	// the middle of the night.
	MIDDLE_OF_THE_NIGHT

	// Fajr will never be earlier than the beginning of the last seventh of the night, and Isha will
	// never be later than the end of the first seventh of the night.
	SEVENTH_OF_THE_NIGHT

	// Similar to SEVENTH_OF_THE_NIGHT, but instead of 1/7th, the fraction of the night used
	// is fajrAngle / 60 and ishaAngle/60.
	TWILIGHT_ANGLE
)

type LikeStatus

type LikeStatus int

LikeStatus defines an enum that specifies the current status of the like.

const (
	LikeStatusUnspecified LikeStatus = iota
	// The like is initiated, so the user can see the pictures of the other profile.
	LikeStatusInitiated
	// The like has been completed, indicating mutual interest.
	LikeStatusCompleted
	// The like has been cancelled.
	LikeStatusCancelled
)

type Masjid

type Masjid struct {
	ID           uuid.UUID                `gorm:"primaryKey;type:char(36)"`
	Name         string                   `gorm:"type:varchar(320)"`
	IsVerified   bool                     `gorm:"default:false"`
	Address      Address                  `gorm:"embedded"`
	PhoneNumber  PhoneNumber              `gorm:"embedded"`
	PrayerConfig PrayerTimesConfiguration `gorm:"embedded"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

func NewMasjid

func NewMasjid(m *pb.Masjid) *Masjid

NewMasjid creates a new Masjid struct given the Masjid proto.

func (*Masjid) ToProto

func (m *Masjid) ToProto() *pb.Masjid

type MatchStatus

type MatchStatus int

MatchStatus defines an enum that specifies the current status of the match.

const (
	MatchStatusUnspecified MatchStatus = iota
	// The match has been initiated, so one side has sent the invite to the other.
	MatchStatusInitiated
	// The match has been accepted, indicating mutual interest.
	MatchStatusAccepted
	// The match has been rejected.
	MatchStatusRejected
	// The match has been ended.
	// This should occur after the match was in ACCEPTED status.
	MatchStatusEnded
)

type Month

type Month int

Month defines an enum for the month of the year.

const (
	// Default value.
	MonthUnspecified Month = iota
	MonthJanuary
	MonthFebruary
	MonthMarch
	MonthApril
	MonthMay
	MonthJune
	MonthJuly
	MonthAugust
	MonthSeptember
	MonthOctober
	MonthNovember
	MonthDecember
)

type NikkahLike

type NikkahLike struct {
	ID             uuid.UUID  `gorm:"primaryKey;type:char(36)"`
	LikerProfileID string     `gorm:"type:uuid"`
	LikedProfileID string     `gorm:"type:uuid"`
	Status         LikeStatus `gorm:"type:like_status"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

NikkahLike represents a like process initiated by a user towards another user's profile.

func NewNikkahLike

func NewNikkahLike(l *pb.NikkahLike) (*NikkahLike, error)

NewNikkahLike creates a new NikkahLike struct given the NikkahLike proto.

func (*NikkahLike) ToProto

func (l *NikkahLike) ToProto() *pb.NikkahLike

ToProto converts a NikkahLike struct to its corresponding proto message.

type NikkahMatch

type NikkahMatch struct {
	ID                 uuid.UUID   `gorm:"primaryKey;type:char(36)"`
	InitiatorProfileID uuid.UUID   `gorm:"type:uuid"`
	ReceiverProfileID  uuid.UUID   `gorm:"type:uuid"`
	Status             MatchStatus `gorm:"type:match_status"`
	CreatedAt          time.Time
	UpdatedAt          time.Time
}

NikkahMatch represents a successful match between two users.

func NewNikkahMatch

func NewNikkahMatch(nm *pb.NikkahMatch) (*NikkahMatch, error)

NewNikkahMatch creates a new NikkahMatch struct given the NikkahMatch proto.

func (*NikkahMatch) ToProto

func (nm *NikkahMatch) ToProto() *pb.NikkahMatch

ToProto converts a NikkahMatch struct to its corresponding proto message.

type NikkahProfile

type NikkahProfile struct {
	ID        uuid.UUID `gorm:"primaryKey;type:char(36)"`
	UserID    string    `gorm:"uniqueIndex;type:uuid"`
	Name      string    `gorm:"type:varchar(255)"`
	Gender    gender    `gorm:"type:gender"`
	BirthDate *BirthDate
	CreatedAt time.Time
	UpdatedAt time.Time
}

NikkahProfile represents a user's profile in the nikkah.io service.

func NewNikkahProfile

func NewNikkahProfile(np *pb.NikkahProfile) (*NikkahProfile, error)

NewNikkahProfile creates a new NikkahProfile struct given the NikkahProfile proto.

func (*NikkahProfile) ToProto

func (np *NikkahProfile) ToProto() *pb.NikkahProfile

ToProto converts a NikkahProfile struct to its corresponding proto message.

type PhoneNumber

type PhoneNumber struct {
	PhoneCountryCode string
	Number           string
	Extension        string
}

type PrayerAdjustments

type PrayerAdjustments struct {
	// Adjustment offset for Fajr in minutes. Value can be negative.
	FajrAdjustment int32 `gorm:"default:0"`
	// Adjustment offset for Dhuhr in minutes. Value can be negative.
	DhuhrAdjustment int32 `gorm:"default:0"`
	// Adjustment offset for Asr in minutes. Value can be negative.
	AsrAdjustment int32 `gorm:"default:0"`
	// Adjustment offset for Maghrib in minutes. Value can be negative.
	MaghribAdjustment int32 `gorm:"default:0"`
	// Adjustment offset for Isha in minutes. Value can be negative.
	IshaAdjustment int32 `gorm:"default:0"`
}

The manual adjustments to apply to the prayer timings. The value that each field is set to is the offset which will be added to the calculated time to obtain the final prayer time.

type PrayerTimesConfiguration

type PrayerTimesConfiguration struct {
	// The calculation method to use.
	CalculationMethod CalculationMethod `` /* 391-byte string literal not displayed */

	// The Fajr angle to use. This does not need to be set if the calculation method is set.
	// If both fields are set, then the calculation method field takes precedence.
	FajrAngle float64 `gorm:"default:0"`
	// The Isha angle to use. This does not need to be set if the calculation method is set.
	// If both fields are set, then the calculation method field takes precedence.
	IshaAngle float64 `gorm:"default:0"`
	// Minutes after Maghrib (if set, the time for Isha will be Maghrib plus the Isha interval).
	IshaInterval int32 `gorm:"default:0"`
	// The juristic method to use for calculating Asr timings.
	AsrMethod AsrJuristicMethod `sql:"type:ENUM('SHAFI_HANBALI_MALIKI', 
												'HANAFI')" 
												gorm:"column:asr_method"`
	// The high latitude rule to use to calculate Fajr and Isha prayers.
	HighLatitudeRule HighLatitudeRule `` /* 203-byte string literal not displayed */

	// The prayer adjustments (aka offsets) to apply to the calculated prayer times.
	Adjustments PrayerAdjustments `gorm:"embedded"`
}

A message that holds prayer times configuration. This message contains all the fields necessary to calculate prayer times.

type RevertMatch

type RevertMatch struct {
	ID                 uuid.UUID `gorm:"primaryKey"`
	InitiatorProfileID string
	ReceiverProfileID  string
	Status             MatchStatus
	CreatedAt          time.Time
	UpdatedAt          time.Time
}

RevertMatch represents a successful match between two users.

func NewRevertMatch

func NewRevertMatch(rm *pb.RevertMatch) (*RevertMatch, error)

NewRevertMatch creates a new RevertMatch struct given the RevertMatch proto. This assumes that the initiator profile ID and reciever profile ID were checked already.

func (*RevertMatch) ToProto

func (rm *RevertMatch) ToProto() *pb.RevertMatch

ToProto converts a RevertMatch struct to its corresponding proto message.

type RevertProfile

type RevertProfile struct {
	ID        uuid.UUID `gorm:"primaryKey"`
	UserID    string    `gorm:"uniqueIndex"`
	Name      string
	Gender    gender `gorm:"type:gender"`
	BirthDate BirthDate
	CreatedAt time.Time
	UpdatedAt time.Time
}

RevertProfile represents a user's profile in the reverts.io service.

func NewRevertProfile

func NewRevertProfile(rp *pb.RevertProfile) (*RevertProfile, error)

NewRevertProfile creates a new RevertProfile struct given the RevertProfile proto. This function assumes that the user ID has already been validated to exist.

func (*RevertProfile) ToProto

func (rp *RevertProfile) ToProto() *pb.RevertProfile

ToProto converts a RevertProfile struct to its corresponding proto message.

type StorageManager

type StorageManager struct {
	DB *gorm.DB
}

func (*StorageManager) CreateAdhanFile

func (s *StorageManager) CreateAdhanFile(a *pb.AdhanFile) (*AdhanFile, error)

CreateAdhanFile creates a AdhanFile in the database for the given AdhanFile proto.

func (*StorageManager) CreateEvent

func (s *StorageManager) CreateEvent(e *pb.Event) (*Event, error)

CreateEvent creates a Event in the database for the given Event proto.

func (*StorageManager) CreateMasjid

func (s *StorageManager) CreateMasjid(mp *pb.Masjid) (*Masjid, error)

CreateMasjid creates a Masjid in the database for the given Masjid proto.

func (*StorageManager) CreateUser

func (s *StorageManager) CreateUser(up *pb.User, pwd string) (*User, error)

CreateUser creates a User in the database for the given User and password.

func (*StorageManager) DeleteAdhanFile

func (s *StorageManager) DeleteAdhanFile(id string) error

DeleteAdhanFile deletes a AdhanFile with the given id.

func (*StorageManager) DeleteEvent

func (s *StorageManager) DeleteEvent(id string) error

DeleteEvent deletes a Event with the given id.

func (*StorageManager) DeleteMasjid

func (s *StorageManager) DeleteMasjid(id string) error

DeleteMasjid deletes a Masjid with the given id.

func (*StorageManager) DeleteUser

func (s *StorageManager) DeleteUser(id string) error

DeleteUser deletes a User with the given id if it exists. We expect the user to be authenticated via a token before this step.

func (*StorageManager) GetAdhanFile

func (s *StorageManager) GetAdhanFile(id string) (*AdhanFile, error)

GetAdhanFile returns a AdhanFile with the given id.

func (*StorageManager) GetEvent

func (s *StorageManager) GetEvent(id string) (*Event, error)

GetEvent returns a Event with the given id.

func (*StorageManager) GetMasjid

func (s *StorageManager) GetMasjid(id string) (*Masjid, error)

GetMasjid returns a Masjid with the given id.

func (*StorageManager) GetUser

func (s *StorageManager) GetUser(id string) (*User, error)

GetUser returns a User with the given id if it exists. We expect the user to be authenticated via a token before this step.

func (*StorageManager) UpdateAdhanFile

func (s *StorageManager) UpdateAdhanFile(a *pb.AdhanFile) (*AdhanFile, error)

UpdateAdhanFile updates a AdhanFile in the database for the given AdhanFile proto.

func (*StorageManager) UpdateEvent

func (s *StorageManager) UpdateEvent(e *pb.Event) (*Event, error)

UpdateEvent updates a Event in the database for the given Event proto.

func (*StorageManager) UpdateMasjid

func (s *StorageManager) UpdateMasjid(mp *pb.Masjid) (*Masjid, error)

UpdateMasjid updates a Masjid in the database for the given Masjid proto.

func (*StorageManager) UpdateUser

func (s *StorageManager) UpdateUser(up *pb.User) (*User, error)

UpdateUser updates a User in the database for the given User if it exists. We expect the user to be authenticated via a token before this step.

type User

type User struct {
	ID             uuid.UUID `gorm:"primaryKey;type:char(36)"`
	Email          string    `gorm:"type:varchar(320)"`
	Username       string    `gorm:"type:varchar(255)"`
	HashedPassword string    `gorm:"type:varchar(60)"`
	IsVerified     bool      `gorm:"default:false"`
	FirstName      string    `gorm:"type:varchar(255)"`
	LastName       string    `gorm:"type:varchar(255)"`
	PhoneNumber    string    `gorm:"type:varchar(255)"`
	Gender         gender    `gorm:"type:gender"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

User represents a registered user with email/password authentication TODO: make username and email unique. It currently causes postgres to throw a unique constraint violation.

func NewUser

func NewUser(up *pb.User, pwd string) (*User, error)

NewUser creates a new User struct given the User proto and plaintext password

func (*User) ToProto

func (u *User) ToProto() *pb.User

Jump to

Keyboard shortcuts

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