diff --git a/internal/comment/internal/domain/comment.go b/internal/comment/internal/domain/comment.go new file mode 100644 index 00000000..e8c3bb46 --- /dev/null +++ b/internal/comment/internal/domain/comment.go @@ -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 +} diff --git a/internal/comment/internal/repository/comment.go b/internal/comment/internal/repository/comment.go new file mode 100644 index 00000000..9bd57e81 --- /dev/null +++ b/internal/comment/internal/repository/comment.go @@ -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 diff --git a/internal/comment/internal/repository/dao/comment.go b/internal/comment/internal/repository/dao/comment.go new file mode 100644 index 00000000..fad7ab5d --- /dev/null +++ b/internal/comment/internal/repository/dao/comment.go @@ -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 +} diff --git a/internal/comment/internal/web/handler.go b/internal/comment/internal/web/handler.go new file mode 100644 index 00000000..44288197 --- /dev/null +++ b/internal/comment/internal/web/handler.go @@ -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 +} diff --git a/internal/comment/internal/web/vo.go b/internal/comment/internal/web/vo.go new file mode 100644 index 00000000..564602ed --- /dev/null +++ b/internal/comment/internal/web/vo.go @@ -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"` +}