models

package
v0.0.0-...-391b505 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrPgErrCodeField = byte(67) // C

	ErrPgForeignKeyViolation = "23503"
	ErrPgUniqueViolation     = "23505"
)

Variables

This section is empty.

Functions

func Connect

func Connect() *pg.DB

func Diet2UserUpdate

func Diet2UserUpdate(db *pg.Conn, dietID, userID string, applied bool) error

func Diet2UserUserExists

func Diet2UserUserExists(db *pg.Conn, u User) (bool, error)

func DietByIDExists

func DietByIDExists(db *pg.Conn, id string) (bool, error)

func Encrypt

func Encrypt(pw string) (string, error)

func EventIDLikeExists

func EventIDLikeExists(db *pg.Conn, like string) (bool, error)

func EventsDateOnly

func EventsDateOnly(db *pg.Conn, now time.Time) (dates []string, err error)

func LogError

func LogError(db *pg.Conn, userID, accessLogID, loc string, contents ...interface{})

func SettingByKey

func SettingByKey(db *pg.Conn, key string) string

func UserUpgradeExistsByID

func UserUpgradeExistsByID(db *pg.Conn, id string) (bool, error)

func UsersAllCount

func UsersAllCount(db *pg.Conn) (count int, err error)

func UsersAllOptionsCount

func UsersAllOptionsCount(db *pg.Conn, orderBy string, limit, page int) (int, error)

Types

type AccessLog

type AccessLog struct {
	ID        string `pg:",pk"`
	SessionID string
	IP        string
	Method    string
	Path      string
	Status    int
	Error     string
	CreatedAt time.Time `sql:"default:now()"`
}

func (*AccessLog) Create

func (a *AccessLog) Create(db *pg.Conn) error

type Campaign

type Campaign struct {
	CampaignBase
}

func CampaignRandomOne

func CampaignRandomOne(conn *pg.Conn) (cmp Campaign, err error)

func CampaignsAll

func CampaignsAll(conn *pg.Conn) (cmps []Campaign, err error)

func (*Campaign) Create

func (cmp *Campaign) Create(conn *pg.Conn) error

func (*Campaign) CreateNotPayed

func (cmp *Campaign) CreateNotPayed(conn *pg.Conn) error

type CampaignBase

type CampaignBase struct {
	ID      string
	IsReady bool

	Title    string
	SubTitle string
	ImageSrc string `pg:",use_zero" sql:",notnull"`
	Link     string `pg:",use_zero" sql:",notnull"`

	UserID string
	User   *User

	Price   int
	Payment string
	PayedAt *time.Time
	PayCode string

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt time.Time `pg:",soft_delete"`
	StartAt   time.Time
	EndAt     time.Time
}

type CampaignNotPayed

type CampaignNotPayed struct {
	TableName struct{} `sql:"campaigns_not_payed" json:"-"`
	CampaignBase
	PayLink string
}

func CampaignNotPayedByID

func CampaignNotPayedByID(conn *pg.Conn, id string) (cnp CampaignNotPayed, err error)

func CampaignNotPayedByPayCode

func CampaignNotPayedByPayCode(conn *pg.Conn, code string) (cnp CampaignNotPayed, err error)

func CampaignsNotPayedPayed

func CampaignsNotPayedPayed(conn *pg.Conn) (cnps []CampaignNotPayed, err error)

func (*CampaignNotPayed) Create

func (cnp *CampaignNotPayed) Create(conn *pg.Conn) error

func (*CampaignNotPayed) Move

func (cnp *CampaignNotPayed) Move(conn *pg.Conn) error

func (*CampaignNotPayed) UpdateAll

func (cnp *CampaignNotPayed) UpdateAll(conn *pg.Conn) error

func (*CampaignNotPayed) UpdatePayedAt

func (cnp *CampaignNotPayed) UpdatePayedAt(conn *pg.Conn) error

func (*CampaignNotPayed) UpdatePayment

func (cnp *CampaignNotPayed) UpdatePayment(conn *pg.Conn) error

type ClassTimetable

type ClassTimetable struct {
	Grade, Class int
	Subjects     [][]Subject
}

func ClassTimetableByGradeClass

func ClassTimetableByGradeClass(db *pg.Conn, grade, class int) (table ClassTimetable, err error)

type DDayEvent

type DDayEvent struct {
	TableName struct{} `sql:"dday_events" json:"-"`

	ID   string
	Name string
	Date time.Time

	Target int // -1: all, 1: grade1, 2: grade2, 3: grade3

	CreatedAt time.Time `sql:"default:now()" json:"-"`
}

func DDayEventAll

func DDayEventAll(db *pg.Conn) (de []DDayEvent, err error)

func DDayEventByGrade

func DDayEventByGrade(db *pg.Conn, grade int) (de []DDayEvent, err error)

func (*DDayEvent) Create

func (de *DDayEvent) Create(db *pg.Conn) error

type Diet

type Diet struct {
	ID string `pg:",pk"`

	Date      time.Time
	Timestamp string

	Type    int // MealType
	Content string

	Canceled bool `pg:",use_zero" sql:",notnull"`

	CreatedAt time.Time `sql:"default:now()"`
}

func DietByID

func DietByID(db *pg.Conn, id string) (d Diet, err error)

func DietReviewPossible

func DietReviewPossible(db *pg.Conn, dietID string, userID string) (d Diet, err error)

func DietsByTimestamp

func DietsByTimestamp(db *pg.Conn, ts string) (ds []Diet, err error)

func (*Diet) Create

func (d *Diet) Create(db *pg.Conn) error

func (*Diet) Update

func (d *Diet) Update(db *pg.Conn) error

type Diet2User

type Diet2User struct {
	TableName struct{} `sql:"diet2users" json:"-"`

	DietID  string `pg:",pk"`
	Diet    *Diet  `json:"-"`
	UserID  string `pg:",pk"`
	User    *User  `json:"-"`
	Applied bool   `pg:",use_zero" sql:",notnull"`

	CreatedAt time.Time `sql:"default:now()" json:"-"`
}

func Diet2UserByDietAndUser

func Diet2UserByDietAndUser(db *pg.Conn, dietID, userID string) (du Diet2User, err error)

func (*Diet2User) Create

func (du *Diet2User) Create(db *pg.Conn) (err error)

type DietReview

type DietReview struct {
	DietID string `pg:",pk"`
	Diet   *Diet  `json:"-"`
	UserID string `pg:",pk"`
	User   *User  `json:"-"`

	Rate      int `sql:",notnull" pg:",use_zero"`
	BestIndex int
	BestMenu  string

	CreatedAt time.Time `sql:"default:now()" json:"-"`
}

func (*DietReview) Create

func (r *DietReview) Create(db *pg.Conn) error

type ElectiveSubjectsToUser

type ElectiveSubjectsToUser struct {
	UserID             string `pg:",pk"`
	ElectiveSubjectIDs map[string]int

	CreatedAt time.Time `sql:"default:now()"`
	UpdatedAt time.Time
}

func (*ElectiveSubjectsToUser) Create

func (t *ElectiveSubjectsToUser) Create(db *pg.Conn) error

func (*ElectiveSubjectsToUser) Delete

func (t *ElectiveSubjectsToUser) Delete(db *pg.Conn) error

type ErrorLog

type ErrorLog struct {
	ID          string `pg:",pk"`
	UserID      string
	AccessLogID string
	Location    string
	Content     string
	CreatedAt   time.Time `sql:"default:now()"`
}

type Event

type Event struct {
	ID         string
	Name       string
	Date       time.Time
	DateString string
	Type       int `pg:",use_zero" sql:",notnull"`

	Grade1 bool `pg:",use_zero" sql:",notnull"`
	Grade2 bool `pg:",use_zero" sql:",notnull"`
	Grade3 bool `pg:",use_zero" sql:",notnull"`

	CreatedAt time.Time `sql:"default:now()" json:"-"`
}

func EventsByDate

func EventsByDate(db *pg.Conn, date string) (events []Event, err error)

func EventsByMonth

func EventsByMonth(db *pg.Conn, year, month int) (events []Event, err error)

func (*Event) Create

func (s *Event) Create(db *pg.Conn) (err error)

type Feedback

type Feedback struct {
	ID     string
	UserID string
	User   *User

	Content string
	Answer  string

	CreatedAt time.Time
}

func FeedbackByID

func FeedbackByID(db *pg.Conn, id string) (f Feedback, err error)

func FeedbacksAll

func FeedbacksAll(db *pg.Conn) (fs []Feedback, err error)

func FeedbacksByUser

func FeedbacksByUser(db *pg.Conn, userID string) (fs []Feedback, err error)

func (*Feedback) Create

func (f *Feedback) Create(db *pg.Conn) error

func (*Feedback) Update

func (f *Feedback) Update(db *pg.Conn) error

type Notice

type Notice struct {
	ID          string
	Title       string
	Content     string
	ContentHTML string
	Author      string
	CreatedAt   time.Time `sql:"default:now()"`
	UpdatedAt   time.Time
	DeletedAt   time.Time `pg:",soft_delete"`
}

func NoticeByID

func NoticeByID(db *pg.Conn, id string) (n Notice, err error)

func NoticeLast

func NoticeLast(db *pg.Conn) (n Notice, err error)

func NoticesAll

func NoticesAll(db *pg.Conn, limit int) (ns []Notice, err error)

func (*Notice) Create

func (n *Notice) Create(db *pg.Conn) error

func (*Notice) Delete

func (n *Notice) Delete(db *pg.Conn) error

func (*Notice) Update

func (n *Notice) Update(db *pg.Conn) error

Update 함수는 제목과 작성자와 내용을 업뎃해요

type Session

type Session struct {
	ID        string
	UserID    string
	User      *User
	CreatedAt time.Time `sql:"default:now()"`
	DeletedAt time.Time `pg:",soft_delete"`
}

func SessionByID

func SessionByID(db *pg.Conn, id string) (s Session, err error)

func (*Session) Delete

func (s *Session) Delete(db *pg.Conn) (err error)

type Setting

type Setting struct {
	Key   string `pk:",pk"`
	Value string
}

type Subject

type Subject struct {
	ID        int `pg:",pk" json:",omitempty"`
	Grade     int
	ShortName string
	FullName  string
	Teacher   string
	Room      string

	/*
		형식은 0000000, 각각
		1) 예술 과목 여부
		2) 교양 과목 여부
		3) 외국어 과목 여부
		4) 선택A
		5) 선택B
		6) 선택C
		7) 선택D
		...를 나타낸다.

		ClassTimetables 테이블에서는 1이 0개 또는 1개 존재해야한다.
		ElectiveSubjects 테이블에서는 1개 이상 존재해야 한다.
	*/
	AvailableBit int
	// contains filtered or unexported fields
}

type Token

type Token struct {
	ID        string
	Type      int // 1: pw_change
	UserID    string
	User      *User
	CreatedAt time.Time `sql:"default:now()"`
	UsedAt    time.Time
}

func TokenByID

func TokenByID(db *pg.Conn, id string) (t Token, err error)

func (*Token) Create

func (t *Token) Create(db *pg.Conn) error

func (*Token) Use

func (t *Token) Use(db *pg.Conn) error

type User

type User struct {
	ID string `pg:",pk"`

	EnterYear int `sql:",unique:gcn"`
	Grade     int `sql:",unique:gcn"`
	Class     int `sql:",unique:gcn"`
	Number    int `sql:",unique:gcn"`
	Name      string

	Sex int // 1: male 2: female

	Email    string `sql:",unique"`
	Password string `json:"-"`

	Barcode        string `sql:",unique"`
	KitchenMemCode string `sql:",unique"`

	BirthYear  int
	BirthMonth int
	BirthDay   int

	Roles string

	Residence int // 1: 기숙 2: 광양

	CreatedAt time.Time `sql:"default:now()"`
	UpdatedAt time.Time `sql:"default:now()"`
}

func UserByEmail

func UserByEmail(db *pg.Conn, email string) (u User, err error)

func UserByID

func UserByID(db *pg.Conn, id string) (u User, err error)

func UsersAll

func UsersAll(db *pg.Conn) (us []User, err error)

func UsersAllOptions

func UsersAllOptions(db *pg.Conn, orderBy string, limit, page int) (us []User, err error)

func UsersLikeName

func UsersLikeName(db *pg.Conn, name string, orderBy string, limit, page int) (us []User, err error)

func (User) Campaigns

func (u User) Campaigns(conn *pg.Conn, active bool) (cmps []Campaign, err error)

func (User) CampaignsNotPayed

func (u User) CampaignsNotPayed(conn *pg.Conn) (cnps []CampaignNotPayed, err error)

func (User) CanRegister

func (u User) CanRegister(db *pg.Conn) (ure *apierror.UserRegisterError)

func (*User) Create

func (u *User) Create(db *pg.Conn) error

func (User) ElectiveSubjects

func (u User) ElectiveSubjects(db *pg.Conn) (est ElectiveSubjectsToUser, err error)

func (User) NewSession

func (u User) NewSession(db *pg.Conn) (s Session, err error)

func (*User) UpdatePw

func (u *User) UpdatePw(db *pg.Conn) error

func (*User) UpdateRoles

func (u *User) UpdateRoles(db *pg.Conn) error

func (*User) UpdateV1

func (u *User) UpdateV1(db *pg.Conn) error

func (*User) UpgradeHakbun

func (u *User) UpgradeHakbun(db *pg.Conn) error

func (*User) ValidateUserRegister

func (u *User) ValidateUserRegister() (ure *apierror.UserRegisterError)

type UserUpgrade

type UserUpgrade struct {
	ID string `pg:",pk"`

	Grade  int `sql:",unique:gcn"`
	Class  int `sql:",unique:gcn"`
	Number int `sql:",unique:gcn"`

	CreatedAt time.Time `sql:"default:now()"`
}

Jump to

Keyboard shortcuts

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