fix: parent id get for html template

This commit is contained in:
Yanislav Igonin 2022-02-03 17:22:46 +02:00
parent f4c2f9262e
commit 736be1f461
5 changed files with 9 additions and 7 deletions

View File

@ -320,7 +320,7 @@ func UpdateThread(c *gin.Context) {
}
post := Repositories.Post{
IsParent: false,
ParentID: threadID,
ParentID: &threadID,
Title: "",
Text: text,
IsSage: isSage,

View File

@ -115,7 +115,8 @@ func (r *PostsRepository) GetThreadByPostID(ID int) ([]Post, error) {
text,
is_sage,
created_at,
is_parent
is_parent,
parent_id
FROM posts
WHERE
(id = $1 AND is_parent = true AND is_deleted != true)
@ -142,6 +143,7 @@ func (r *PostsRepository) GetThreadByPostID(ID int) ([]Post, error) {
&post.IsSage,
&post.CreatedAt,
&post.IsParent,
&post.ParentID,
)
if err != nil {
return nil, err

View File

@ -47,7 +47,7 @@ func getPost(id int, pid *int) Post {
return Post{
ID: id,
IsParent: isParent,
ParentID: parentID,
ParentID: &parentID,
IsDeleted: false,
Title: randSeq(rand.Intn(100)),
Text: randSeq(rand.Intn(100)),

View File

@ -9,7 +9,7 @@ import "time"
type Post struct {
ID int `json:"id"`
IsParent bool `json:"-"`
ParentID int `json:"parentId"`
ParentID *int `json:"parentId"`
IsDeleted bool `json:"-"`
Title string `json:"title"`
Text string `json:"text"`
@ -23,7 +23,7 @@ func (p Post) GetThreadID() int {
if p.IsParent {
return p.ID
}
return p.ParentID
return *p.ParentID
}
type File struct {

View File

@ -75,11 +75,11 @@ func ValidatePost(title, text string, files []*multipart.FileHeader) string {
return Repositories.InvalidTextOrFilesErrorMessage
}
if len(title) > 100 {
if len([]rune(title)) > 100 {
return Repositories.InvalidTitleLengthErrorMessage
}
if len(text) > 1000 {
if len([]rune(text)) > 1000 {
return Repositories.InvalidTextLengthErrorMessage
}