micrach/repositories/structs.go

98 lines
2.0 KiB
Go
Raw Permalink Normal View History

package repositories
2022-04-13 09:38:15 +03:00
import (
"mime/multipart"
"time"
)
// DB Structs
// DB Structs
// DB Structs
type Post struct {
ID int `json:"id"`
2021-08-31 19:48:02 +03:00
IsParent bool `json:"-"`
2022-02-03 18:22:46 +03:00
ParentID *int `json:"parentId"`
2021-08-31 19:48:02 +03:00
IsDeleted bool `json:"-"`
Title string `json:"title"`
Text string `json:"text"`
IsSage bool `json:"isSage"`
Files []File `json:"files"`
CreatedAt time.Time `json:"createdAt"`
2021-08-31 19:48:02 +03:00
UpdatedAt time.Time `json:"-"`
}
func (p Post) GetThreadID() int {
if p.IsParent {
return p.ID
}
2022-02-03 18:22:46 +03:00
return *p.ParentID
}
type File struct {
ID int `json:"-"`
PostID int `json:"-"`
CreatedAt time.Time `json:"-"`
Name string `json:"name"`
Ext string `json:"-"`
Size int `json:"size"`
}
2021-09-10 02:17:45 +03:00
// HTML Templates Structs
// HTML Templates Structs
// HTML Templates Structs
2022-04-12 11:39:02 +03:00
// post-form.html
2022-04-13 09:38:15 +03:00
type Errors struct {
2022-04-12 11:39:02 +03:00
Title string
Text string
Files string
}
2022-04-13 09:38:15 +03:00
type Inputs struct {
Title string
Text string
Files []*multipart.FileHeader
}
2022-04-12 11:39:02 +03:00
// post-form.html
type HtmlFormData struct {
FirstPostID int
CaptchaID string
IsCaptchaActive bool
2022-04-13 09:38:15 +03:00
Errors
2022-04-12 11:41:12 +03:00
Inputs
}
// index.html
type HtmlPaginationData struct {
PagesCount int
Page int
}
// thread.html
type GetThreadHtmlData struct {
Thread []Post
FormData HtmlFormData
}
// index.html
type GetThreadsHtmlData struct {
2022-01-26 20:37:14 +03:00
Threads []Post `json:"threads"`
Pagination HtmlPaginationData
FormData HtmlFormData
2021-09-10 02:17:45 +03:00
}
// 400.html
type BadRequestHtmlData struct {
Message string
}
2022-04-12 11:39:02 +03:00
const InvalidCaptchaErrorMessage = "Invalid captcha"
const InvalidTextOrFilesErrorMessage = "Text or files should not be empty"
const InvalidTitleLengthErrorMessage = "Title should not exceed 100 chars"
const InvalidTextLengthErrorMessage = "Text should not exceed 1000 chars"
const InvalidFilesLengthErrorMessage = "Maximum 4 files can be uploaded"
const InvalidFileSizeErrorMessage = "File size exceeded (3MB PER FILE)"
const InvalidFileExtErrorMessage = "Available file ext: PNG, JPG"
const ThreadIsArchivedErrorMessage = "Thread is archived"