mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-28 04:27:24 +00:00
user details page
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
"nysoure/server/dao"
|
||||
"nysoure/server/model"
|
||||
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
)
|
||||
|
||||
func CreateComment(content string, userID uint, resourceID uint) (*model.CommentView, error) {
|
||||
@@ -51,3 +52,16 @@ func ListComments(resourceID uint, page int) ([]model.CommentView, int, error) {
|
||||
}
|
||||
return res, totalPages, nil
|
||||
}
|
||||
|
||||
func ListCommentsWithUser(username string, page int) ([]model.CommentWithResourceView, int, error) {
|
||||
comments, totalPages, err := dao.GetCommentsWithUser(username, page, pageSize)
|
||||
if err != nil {
|
||||
log.Error("Error getting comments:", err)
|
||||
return nil, 0, model.NewInternalServerError("Error getting comments")
|
||||
}
|
||||
res := make([]model.CommentWithResourceView, 0, len(comments))
|
||||
for _, c := range comments {
|
||||
res = append(res, *c.ToViewWithResource())
|
||||
}
|
||||
return res, totalPages, nil
|
||||
}
|
||||
|
@@ -3,8 +3,6 @@ package service
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
"github.com/google/uuid"
|
||||
"image"
|
||||
"net/http"
|
||||
"nysoure/server/dao"
|
||||
@@ -13,6 +11,9 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
"github.com/google/uuid"
|
||||
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
@@ -116,7 +117,7 @@ func GetImage(id uint) ([]byte, error) {
|
||||
}
|
||||
data, err := os.ReadFile(imageDir + i.FileName)
|
||||
if err != nil {
|
||||
return nil, errors.New("Failed to read image file")
|
||||
return nil, errors.New("failed to read image file")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
@@ -124,3 +124,15 @@ func GetResourcesWithTag(tag string, page int) ([]model.ResourceView, int, error
|
||||
}
|
||||
return views, totalPages, nil
|
||||
}
|
||||
|
||||
func GetResourcesWithUser(username string, page int) ([]model.ResourceView, int, error) {
|
||||
resources, totalPages, err := dao.GetResourcesByUsername(username, page, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var views []model.ResourceView
|
||||
for _, r := range resources {
|
||||
views = append(views, r.ToView())
|
||||
}
|
||||
return views, totalPages, nil
|
||||
}
|
||||
|
@@ -256,3 +256,11 @@ func DeleteUser(adminID uint, targetUserID uint) error {
|
||||
|
||||
return dao.DeleteUser(targetUserID)
|
||||
}
|
||||
|
||||
func GetUserByUsername(username string) (model.UserView, error) {
|
||||
user, err := dao.GetUserByUsername(username)
|
||||
if err != nil {
|
||||
return model.UserView{}, err
|
||||
}
|
||||
return user.ToView(), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user