mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Support comment reply.
This commit is contained in:
@@ -74,14 +74,24 @@ func CreateComment(req CommentRequest, userID uint, refID uint, ip string, cType
|
||||
return nil, model.NewRequestError("Comment content exceeds maximum length of 1024 characters")
|
||||
}
|
||||
|
||||
resourceExists, err := dao.ExistsResource(refID)
|
||||
if err != nil {
|
||||
log.Error("Error checking resource existence:", err)
|
||||
return nil, model.NewInternalServerError("Error checking resource existence")
|
||||
}
|
||||
if !resourceExists {
|
||||
return nil, model.NewNotFoundError("Resource not found")
|
||||
switch cType {
|
||||
case model.CommentTypeResource:
|
||||
resourceExists, err := dao.ExistsResource(refID)
|
||||
if err != nil {
|
||||
log.Error("Error checking resource existence:", err)
|
||||
return nil, model.NewInternalServerError("Error checking resource existence")
|
||||
}
|
||||
if !resourceExists {
|
||||
return nil, model.NewNotFoundError("Resource not found")
|
||||
}
|
||||
case model.CommentTypeReply:
|
||||
_, err := dao.GetCommentByID(refID)
|
||||
if err != nil {
|
||||
log.Error("Error getting reply comment:", err)
|
||||
return nil, model.NewNotFoundError("Reply comment not found")
|
||||
}
|
||||
}
|
||||
|
||||
userExists, err := dao.ExistsUserByID(userID)
|
||||
if err != nil {
|
||||
log.Error("Error checking user existence:", err)
|
||||
@@ -166,15 +176,6 @@ func ListResourceComments(resourceID uint, page int) ([]model.CommentView, int,
|
||||
}
|
||||
|
||||
func ListCommentReplies(commentID uint, page int) ([]model.CommentView, int, error) {
|
||||
comment, err := dao.GetCommentByID(commentID)
|
||||
if err != nil {
|
||||
log.Error("Error getting comment:", err)
|
||||
return nil, 0, model.NewNotFoundError("Comment not found")
|
||||
}
|
||||
if comment.Type != model.CommentTypeReply {
|
||||
return nil, 0, model.NewRequestError("This comment is not a reply")
|
||||
}
|
||||
|
||||
replies, totalPages, err := dao.GetCommentReplies(commentID, page, pageSize)
|
||||
if err != nil {
|
||||
log.Error("Error getting replies:", err)
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
@@ -19,7 +20,16 @@ func GetStoragePath() string {
|
||||
}
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(path, os.ModePerm); err != nil {
|
||||
panic("failed to create storage directory")
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
// Fallback to home directory if permission is denied
|
||||
userDir, _ := os.UserHomeDir()
|
||||
path = userDir + "/.nysoure"
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(path, os.ModePerm); err != nil {
|
||||
panic("Failed to create storage directory: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return path
|
||||
|
Reference in New Issue
Block a user