Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
L-time committed Jun 7, 2024
1 parent ff08303 commit 94fce0d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 50 deletions.
2 changes: 1 addition & 1 deletion internal/index/mysql_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMysqlRepo_NewIndex(t *testing.T) {
index := &model.Index{
ID: 0,
Title: "test",
Description: "Test Field",
Description: "Test Index",
CreatorID: 382951,
CreatedAt: now,
UpdatedAt: now,
Expand Down
4 changes: 4 additions & 0 deletions internal/subject/mysql_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ func TestMysqlRepo_GetCharacterRelated(t *testing.T) {

require.True(t, found, "character 1 should be related to subject 8")
}

func Test_mysqlRepo_GetAllPost(t *testing.T) {

Check failure on line 164 in internal/subject/mysql_repository_test.go

View workflow job for this annotation

GitHub Actions / lint

Function Test_mysqlRepo_GetAllPost missing the call to method parallel

}
20 changes: 4 additions & 16 deletions web/handler/episode_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"errors"
"net/http"
"strconv"
"time"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -90,24 +89,13 @@ func (h Handler) GetEpisodeComments(c echo.Context) error {
return errgo.Wrap(err, "failed to find subject of episode")
}

var offset, limit int
offsetStr := c.QueryParam("offset")
limitStr := c.QueryParam("limit")
if offsetStr == "" {
offset = 0 // 默认为0
} else {
offset, err = strconv.Atoi(offsetStr)
}
if limitStr == "" {
limit = 25 // 默认25
} else {
limit, err = strconv.Atoi(limitStr)
}
pq, err := req.GetPageQuery(c, req.DefaultPageLimit, req.DefaultMaxPageLimit)
if err != nil {
return res.BadRequest(err.Error())
return res.BadRequest("cannot get offset and limit")
}

var r []model.EpisodeComment
r, err = h.episode.GetAllComment(c.Request().Context(), id, offset, limit)
r, err = h.episode.GetAllComment(c.Request().Context(), id, pq.Offset, pq.Limit)
if err != nil {
return res.NotFound("cannot get episode comments")
}
Expand Down
19 changes: 3 additions & 16 deletions web/handler/index/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package index

import (
"net/http"
"strconv"
"time"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -63,24 +62,12 @@ func (h Handler) GetComments(c echo.Context) error {
if !ok || r.NSFW && !user.AllowNSFW() {
return res.NotFound("index not found")
}
var offset, limit int
offsetStr := c.QueryParam("offset")
limitStr := c.QueryParam("limit")
if offsetStr == "" {
offset = 0 // 默认为0
} else {
offset, err = strconv.Atoi(offsetStr)
}
if limitStr == "" {
limit = 25 // 默认25
} else {
limit, err = strconv.Atoi(limitStr)
}
pq, err := req.GetPageQuery(c, req.DefaultPageLimit, req.DefaultMaxPageLimit)
if err != nil {
return res.BadRequest(err.Error())
return res.BadRequest("cannot get offset and limit")
}
var result []model.IndexComment
result, err = h.i.GetIndexComments(c.Request().Context(), id, offset, limit)
result, err = h.i.GetIndexComments(c.Request().Context(), id, pq.Offset, pq.Limit)

if err != nil {
return res.NotFound("comment not found")
Expand Down
4 changes: 2 additions & 2 deletions web/handler/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (h Handler) getIndexSubjects(
) error {
count, err := h.i.CountSubjects(c.Request().Context(), id, subjectType)
if err != nil {
return errgo.Wrap(err, "Field.CountSubjects")
return errgo.Wrap(err, "Index.CountSubjects")
}

if count == 0 {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (h Handler) NewIndex(c echo.Context) error {
}
ctx := c.Request().Context()
if err := h.i.New(ctx, i); err != nil {
return errgo.Wrap(err, "failed to crea te a new index")
return errgo.Wrap(err, "failed to create a new index")
}
u, err := h.u.GetByID(ctx, i.CreatorID)
if err != nil {
Expand Down
15 changes: 4 additions & 11 deletions web/handler/subject/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,12 @@ func (h Subject) GetComments(c echo.Context) error {
return errgo.Wrap(err, "failed to get subject")
}

var offset, limit int

offsetStr := c.QueryParam("offset")
limitStr := c.QueryParam("limit")

if offsetStr == "" {
offset = 0 // 默认为0
}
if limitStr == "" {
limit = 25 // 默认25
pq, err := req.GetPageQuery(c, req.DefaultPageLimit, req.DefaultMaxPageLimit)
if err != nil {
return res.BadRequest("cannot get offset and limit")
}

result, err := h.subject.GetAllPost(c.Request().Context(), s.ID, offset, limit)
result, err := h.subject.GetAllPost(c.Request().Context(), s.ID, pq.Offset, pq.Limit)
if err != nil {
return res.BadRequest("cannot found comment")
}
Expand Down
3 changes: 1 addition & 2 deletions web/handler/subject/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/bangumi/server/internal/episode"
"github.com/bangumi/server/internal/person"
"github.com/bangumi/server/internal/subject"
"github.com/bangumi/server/web/mw"
)

type Subject struct {
Expand Down Expand Up @@ -59,6 +58,6 @@ func (h *Subject) Routes(g *echo.Group) {
// comment
g.GET("/subjects/:id/post", h.GetComments)
g.GET("/subjects/:id/post/:post_id", h.GetComment)
g.PUT("/subjects/:id/post", h.AddComment, mw.NeedLogin)
// g.PUT("/subjects/:id/post", h.AddComment, mw.NeedLogin)
// g.DELETE("/subjects/:id/post/:post_id", h.RemoveComment, mw.NeedLogin)
}
4 changes: 2 additions & 2 deletions web/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func AddRouters(
v0.GET("/episodes", h.ListEpisode)

v0.GET("episodes/:id/comment", h.GetEpisodeComments)
v0.PUT("episodes/:id/comment", h.PostEpisodeComment, mw.NeedLogin)
// v0.PUT("episodes/:id/comment", h.PostEpisodeComment, mw.NeedLogin)
v0.GET("episodes/:id/comment/:comment_id", h.GetEpisodeComment)

// echo 中间件从前往后运行按顺序
Expand Down Expand Up @@ -122,7 +122,7 @@ func AddRouters(

v0.GET("/indices/:id/comment", i.GetComments, mw.NeedLogin)
v0.GET("/indices/:id/comment/:comment_id", i.GetComment, mw.NeedLogin)
v0.PUT("/indices/:id/comment", i.AddComment, mw.NeedLogin)
// v0.PUT("/indices/:id/comment", i.AddComment, mw.NeedLogin)
// v0.DELETE("/indices/:id/comment/:comment_id", i.RemoveComment, mw.NeedLogin)
}

Expand Down

0 comments on commit 94fce0d

Please sign in to comment.