Skip to content

Commit

Permalink
feat: 句子整体功能
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git committed Nov 22, 2024
1 parent a68ef9b commit c7c155c
Show file tree
Hide file tree
Showing 19 changed files with 438 additions and 55 deletions.
19 changes: 19 additions & 0 deletions api/sentence/sentence.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions api/sentence/v1/sentence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package v1

import (
"github.com/gogf/gf/v2/frame/g"
"github.com/oldme-git/oldme-api/internal/model"
"github.com/oldme-git/oldme-api/internal/model/entity"
)

type CreReq struct {
g.Meta `path:"sentence/create" method:"post" sm:"新增" tags:"句子"`
BookId model.Id `json:"book_id" v:"required"`
TagIds []model.Id `json:"tag_ids"`
Sentence string `json:"sentence" v:"required"`
}

type CreRes struct {
}

type UpdReq struct {
g.Meta `path:"sentence/update/{id}" method:"post" sm:"修改" tags:"句子"`
*model.IdInput
BookId model.Id `json:"book_id" v:"required"`
Sentence string `json:"sentence" v:"required"`
}

type UpdRes struct {
}

type ShowReq struct {
g.Meta `path:"sentence/show/{id}" method:"get" sm:"查询详情" tags:"句子"`
*model.IdInput
}

type ShowRes struct {
*entity.Sentence
TagList []entity.Tag `json:"tag_list"`
}

type DelReq struct {
g.Meta `path:"sentence/delete/{id}" method:"post" sm:"删除" tags:"句子"`
*model.IdInput
}

type DelRes struct {
}

type ListReq struct {
g.Meta `path:"sentence/list" method:"get" sm:"查询列表" tags:"句子"`
*model.Paging
BookId model.Id `json:"book_id"`
TagIds []model.Id `json:"tag_ids"`
}

type ListRes struct {
List []List `json:"list"`
Total uint `json:"total"`
}
9 changes: 9 additions & 0 deletions api/sentence/v1/sentence_struct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1

import "github.com/oldme-git/oldme-api/internal/model"

type List struct {
Id model.Id
BookId model.Id `json:"book_id"`
Sentence string `json:"sentence"`
}
2 changes: 2 additions & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/oldme-git/oldme-api/internal/controller/other"
"github.com/oldme-git/oldme-api/internal/controller/reply"
"github.com/oldme-git/oldme-api/internal/controller/saying"
"github.com/oldme-git/oldme-api/internal/controller/sentence"
"github.com/oldme-git/oldme-api/internal/controller/tag"
"github.com/oldme-git/oldme-api/internal/controller/tag_grp"
"github.com/oldme-git/oldme-api/internal/logic/middleware"
Expand Down Expand Up @@ -51,6 +52,7 @@ var (

tag_grp.NewV1(),
tag.NewV1(),
sentence.NewV1(),
)
})
})
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/sentence/sentence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================

package sentence
15 changes: 15 additions & 0 deletions internal/controller/sentence/sentence_new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================

package sentence

import (
"github.com/oldme-git/oldme-api/api/sentence"
)

type ControllerV1 struct{}

func NewV1() sentence.ISentenceV1 {
return &ControllerV1{}
}
19 changes: 19 additions & 0 deletions internal/controller/sentence/sentence_v1_cre.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sentence

import (
"context"

"github.com/oldme-git/oldme-api/internal/logic/sentence"
"github.com/oldme-git/oldme-api/internal/model"

"github.com/oldme-git/oldme-api/api/sentence/v1"
)

func (c *ControllerV1) Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) {
err = sentence.Cre(ctx, &model.SentenceInput{
BookId: req.BookId,
TagIds: req.TagIds,
Sentence: req.Sentence,
})
return
}
14 changes: 14 additions & 0 deletions internal/controller/sentence/sentence_v1_del.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package sentence

import (
"context"

"github.com/oldme-git/oldme-api/internal/logic/sentence"

"github.com/oldme-git/oldme-api/api/sentence/v1"
)

func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) {
err = sentence.Del(ctx, req.Id)
return
}
58 changes: 58 additions & 0 deletions internal/controller/sentence/sentence_v1_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package sentence

import (
"context"

"github.com/oldme-git/oldme-api/api/sentence/v1"
"github.com/oldme-git/oldme-api/internal/logic/sentence"
"github.com/oldme-git/oldme-api/internal/model"
)

func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
if req.Paging == nil {
req.Paging = &model.Paging{
Page: 1,
Size: 15,
}
}

var ids []model.Id
// 如果有tagId,根据tagId查询ids
if len(req.TagIds) > 0 {
ids, err = sentence.GetIdsByTagIds(ctx, req.TagIds, uint(req.Paging.Size))
if err != nil {
return nil, err
}
}

query := &model.SentenceQuery{
Paging: *req.Paging,
BookId: req.BookId,
Ids: ids,
}

data, total, err := sentence.List(ctx, query)
if err != nil {
return nil, err
}
var (
list []v1.List
s string
)
for _, v := range data {
if len(v.Sentence) > 100 {
s = v.Sentence[:100]
} else {
s = v.Sentence
}
list = append(list, v1.List{
Id: model.Id(v.Id),
BookId: model.Id(v.BookId),
Sentence: s,
})
}
return &v1.ListRes{
List: list,
Total: total,
}, nil
}
25 changes: 25 additions & 0 deletions internal/controller/sentence/sentence_v1_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package sentence

import (
"context"

"github.com/oldme-git/oldme-api/internal/logic/sentence"

"github.com/oldme-git/oldme-api/api/sentence/v1"
)

func (c *ControllerV1) Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) {
data, err := sentence.Show(ctx, req.Id)
if err != nil {
return nil, err
}
tagList, err := sentence.ShowTag(ctx, req.Id)
if err != nil {
return nil, err
}

return &v1.ShowRes{
Sentence: data,
TagList: tagList,
}, nil
}
19 changes: 19 additions & 0 deletions internal/controller/sentence/sentence_v1_upd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sentence

import (
"context"

"github.com/oldme-git/oldme-api/internal/logic/sentence"
"github.com/oldme-git/oldme-api/internal/model"

"github.com/oldme-git/oldme-api/api/sentence/v1"
)

func (c *ControllerV1) Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) {
err = sentence.Upd(ctx, &model.SentenceInput{
Id: req.Id,
BookId: req.BookId,
Sentence: req.Sentence,
})
return
}
27 changes: 0 additions & 27 deletions internal/dao/sentence_tags.go

This file was deleted.

1 change: 1 addition & 0 deletions internal/logic/logic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c7c155c

Please sign in to comment.