2021-08-28 18:41:34 +03:00
|
|
|
package repositories
|
|
|
|
|
2022-04-13 09:38:15 +03:00
|
|
|
import (
|
|
|
|
"mime/multipart"
|
|
|
|
"time"
|
|
|
|
)
|
2021-08-28 18:41:34 +03:00
|
|
|
|
2021-10-04 11:40:53 +03:00
|
|
|
// DB Structs
|
|
|
|
// DB Structs
|
|
|
|
// DB Structs
|
|
|
|
|
2021-08-28 18:41:34 +03:00
|
|
|
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:"-"`
|
2021-08-28 18:41:34 +03:00
|
|
|
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:"-"`
|
2021-08-28 18:41:34 +03:00
|
|
|
}
|
|
|
|
|
2022-02-03 16:12:34 +03:00
|
|
|
func (p Post) GetThreadID() int {
|
2022-01-31 19:56:21 +03:00
|
|
|
if p.IsParent {
|
|
|
|
return p.ID
|
|
|
|
}
|
2022-02-03 18:22:46 +03:00
|
|
|
return *p.ParentID
|
2022-01-31 19:56:21 +03:00
|
|
|
}
|
|
|
|
|
2021-08-28 18:41:34 +03:00
|
|
|
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
|
|
|
|
2021-10-04 11:40:53 +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
|
|
|
|
2021-10-06 11:50:19 +03:00
|
|
|
// post-form.html
|
2021-10-04 11:40:53 +03:00
|
|
|
type HtmlFormData struct {
|
2022-01-27 20:23:51 +03:00
|
|
|
FirstPostID int
|
|
|
|
CaptchaID string
|
|
|
|
IsCaptchaActive bool
|
2022-04-13 09:38:15 +03:00
|
|
|
Errors
|
2022-04-12 11:41:12 +03:00
|
|
|
Inputs
|
2021-10-04 11:40:53 +03:00
|
|
|
}
|
|
|
|
|
2022-01-31 19:56:21 +03:00
|
|
|
// index.html
|
|
|
|
type HtmlPaginationData struct {
|
|
|
|
PagesCount int
|
|
|
|
Page int
|
|
|
|
}
|
|
|
|
|
2021-10-06 11:50:19 +03:00
|
|
|
// thread.html
|
2021-10-04 11:40:53 +03:00
|
|
|
type GetThreadHtmlData struct {
|
|
|
|
Thread []Post
|
|
|
|
FormData HtmlFormData
|
|
|
|
}
|
|
|
|
|
2021-10-06 11:50:19 +03:00
|
|
|
// index.html
|
2021-10-04 11:40:53 +03:00
|
|
|
type GetThreadsHtmlData struct {
|
2022-01-26 20:37:14 +03:00
|
|
|
Threads []Post `json:"threads"`
|
2022-01-31 19:56:21 +03:00
|
|
|
Pagination HtmlPaginationData
|
2021-10-04 11:40:53 +03:00
|
|
|
FormData HtmlFormData
|
2021-09-10 02:17:45 +03:00
|
|
|
}
|
2021-10-06 11:50:19 +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"
|