Skip to content

评论接口定义 #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions internal/comment/internal/domain/comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package domain

import "time"

type User struct {
ID int64
NickName string
Avatar string
}
type Comment struct {
ID int64
Content string
// 评论的人
User User
// 评论时间,因为评论本身是不允许修改的,所以这个时间基本上就是评论时间
Utime time.Time

// 回复这条评论的评论
// 直到必要的时候再去查询出来
Replies []Comment
}
15 changes: 15 additions & 0 deletions internal/comment/internal/repository/comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package repository
32 changes: 32 additions & 0 deletions internal/comment/internal/repository/dao/comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dao

// 记得标记一下 GORM 的内容
type Comment struct {
ID int64
Content string

// 这两个字段都可以为 0。如果是 0 就代表它自身就是一个根评论
// 根评论 ID
Ancestor int64
// 回复的 ID
Parent int64
// 评论的对象
Biz string
BizID int64
Utime int64
Ctime int64
}
54 changes: 54 additions & 0 deletions internal/comment/internal/web/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package web

import (
"github.com/ecodeclub/ginx"
"github.com/ecodeclub/ginx/session"
"github.com/gin-gonic/gin"
)

type Handler struct {
}

func (h *Handler) MemberRoutes(server *gin.Engine) {
// 在这里注册路由
group := server.Group("/comment")
group.POST("/", ginx.BS[CommentRequest](h.Comment))
// 目前按照评论时间的倒序(注意和replies接口的区别)排序
group.POST("/list", ginx.BS[CommentRequest](h.CommentList))
// 获得某个评论的所有子评论,孙子评论,按照评论时间排序(即先评论的在前面)
group.POST("/replies", ginx.BS[GetRepliesRequest](h.GetReplies))
}

func (h *Handler) Comment(ctx *ginx.Context, req CommentRequest, sess session.Session) (ginx.Result, error) {
// 返回评论 ID
return ginx.Result{
Data: 123,
}, nil
}

func (h *Handler) CommentList(ctx *ginx.Context, req CommentRequest, sess session.Session) (ginx.Result, error) {
// 查询某个业务下的评论,直接评论,
return ginx.Result{
Data: CommentList{},
}, nil
}

func (h *Handler) GetReplies(ctx *ginx.Context, req GetRepliesRequest, sess session.Session) (ginx.Result, error) {
return ginx.Result{
Data: CommentList{},
}, nil
}
61 changes: 61 additions & 0 deletions internal/comment/internal/web/vo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package web

type CommentRequest struct {
Comment Comment `json:"comment"`
}

type User struct {
ID int64
Nickname string
Avatar string
}
type Comment struct {
ID int64
// 回复某个评论
ParentID int64 `json:"parentID"`

// 评论的具体内容
Content string `json:"content"`

// 评论的人
User User `json:"user"`

// 针对什么东西的评论
// 注意,即便是回复某个评论,那么这两个字段依旧有值
Biz string `json:"biz"`
BizID int64 `json:"bizID"`
Utime int64 `json:"utime"`
}

type GetRepliesRequest struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
// 根评论 ID
Ancestor int64 `json:"ancestor"`
}

type CommentListRequest struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
Biz string `json:"biz"`
BizID int64 `json:"bizID"`
}

type CommentList struct {
Comments []Comment `json:"comments"`
Total int `json:"total"`
}
Loading