Skip to content

Commit

Permalink
blog comment 功能调通
Browse files Browse the repository at this point in the history
  • Loading branch information
sofency committed Mar 22, 2024
1 parent 8abc2f2 commit 18a4d1e
Show file tree
Hide file tree
Showing 22 changed files with 280 additions and 59 deletions.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

.mvn/
.mvnw.cmd
.mvnw
57 changes: 38 additions & 19 deletions blog/components/BlogComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,60 @@
</Col>
</Row>

<Row type="flex" class="comment-detail">
<Row
type="flex"
class="comment-detail"
v-for="(comment, index) in comments"
:key="index"
>
<Col :span="2" :lg="2" class="comment-input-img">
<img src="/img/avatar.jpeg" alt="avatar" />
</Col>
<Col :span="22" :lg="22" class="comment-input-img">
<div class="user-comment-info">
<div>
<span class="user-name">sofency</span>
<span class="publish-time text-color">2023年8月8日</span>
<span class="comment-ip text-color">IP属地: 湖北</span>
<span class="publish-time text-color">{{
comment.parentComment.createTime
}}</span>
<span class="comment-ip text-color"
>IP属地: {{ comment.parentComment.ipAddress }}</span
>
<button class="reply text-color" @click="reply">回复</button>
</div>
<div class="message">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Accusantium in eligendi perferendis quis, deserunt harum quasi ea
similique iste laboriosam itaque dignissimos assumenda molestiae
impedit quidem. Eveniet similique nesciunt saepe!
{{ comment.parentComment.content }}
</div>
<Row type="flex" class="second-comment">
<!-- 子评论 -->
<Row
type="flex"
class="second-comment"
v-for="(child, child_index) in comment.childComment"
:key="child_index"
>
<Col :span="2" :lg="2" class="comment-input-img">
<img src="/img/avatar.jpeg" alt="avatar" />
</Col>
<Col :span="22" :lg="22">
<div>
<span class="user-name">sofency @ alice</span>
<span class="publish-time text-color">2023年8月8日</span>
<span class="comment-ip text-color">IP属地: 湖北</span>
<span class="user-name" v-if="child.replyName == null">{{
child.username
}}</span>
<span class="user-name" v-else
>{{ child.username }} @ {{ child.replyName }}</span
>

<span class="publish-time text-color">{{
child.createTime
}}</span>
<span class="comment-ip text-color"
>IP属地: {{ child.ipAddress }}</span
>
<button class="reply text-color">回复</button>
</div>

<div class="message">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Accusantium in eligendi perferendis quis, deserunt harum quasi
ea similique iste laboriosam itaque dignissimos assumenda
molestiae impedit quidem. Eveniet similique nesciunt saepe!
{{ child.content }}
</div>
</Col>
</Row>
Expand All @@ -78,14 +97,14 @@ import { Row, Col } from "ant-design-vue";
import $ from "jquery";
export default {
components: { Row, Col },
props: {
comments: Array,
},
data() {
return {
isLogin: false,
};
},
// mounted: {
// // 从状态树中获取刚才评论填写的数据
// },
methods: {
reply() {
Expand All @@ -108,7 +127,7 @@ export default {
},
comment: {
content: content,
blogId: 1,
blogId: params.slug,
},
},
}).then((res) => {
Expand Down
4 changes: 2 additions & 2 deletions blog/pages/blog/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="article-body">
<div v-html="parsedMarkdown"></div>
</div>
<BlogComment />
<BlogComment :comments="comments" />
</Col>
</Row>
</div>
Expand All @@ -28,7 +28,7 @@ import handleScroll from "../../static/slip";
export default {
async asyncData({ $axios, params }) {
const responseData = await $axios({ url: `/api/blog/${params.slug}` });
console.log(responseData.data);
console.log(responseData.data.data.comments[0].childComment);
return {
article: responseData.data.data.blog,
comments: responseData.data.data.comments,
Expand Down
4 changes: 0 additions & 4 deletions blog/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default {
console.log(responseData.data);
return { articles: responseData.data.data };
},
// async asyncData({ $content }) {
// const articles = await $content("articles").fetch();
// return { articles };
// },
mounted() {
window.addEventListener("scroll", handleScroll);
},
Expand Down
6 changes: 6 additions & 0 deletions nuxt-blog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
<version>1.20</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

/**
* <p>
* Ç°¶Ë¿ØÖÆÆ÷
* </p>
*
* @author sofency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sofency.top.nuxtblog.dto.CommentDTO;
import com.sofency.top.nuxtblog.dto.CommentListDTO;
import com.sofency.top.nuxtblog.dto.Result;
import com.sofency.top.nuxtblog.entity.Comment;
import com.sofency.top.nuxtblog.service.CommentService;
import com.sofency.top.nuxtblog.utils.IpUtils;
import com.sofency.top.nuxtblog.vo.CommentVO;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -33,14 +35,14 @@ public CommentController(CommentService commentService) {
}

@RequestMapping("")
public Result<Object> comment(@RequestBody CommentVO commentVO) throws JsonProcessingException, SQLDataException {
commentService.comment(commentVO);
public Result<Object> comment(@RequestBody CommentVO commentVO, HttpServletRequest request) throws JsonProcessingException, SQLDataException {
commentService.comment(request, commentVO);
return Result.success(null);
}

@GetMapping("/{blogId}")
public Result<Object> comment(@PathVariable("blogId") Integer blogId) {
List<CommentDTO> comments = commentService.getCommentByBlogId(blogId);
List<CommentListDTO> comments = commentService.getCommentByBlogId(blogId);
return Result.success(comments);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/**
* <p>
* Ç°¶Ë¿ØÖÆÆ÷
* 前端控制器
* </p>
*
* @author sofency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
@Builder
public class BlogDTO {
private Blog blog;
private List<CommentDTO> comments;
private List<CommentListDTO> comments;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,41 @@

import com.sofency.top.nuxtblog.entity.Comment;
import lombok.*;

import java.util.List;
import lombok.experimental.Accessors;

/**
* <p>Project: nuxt-blog - CommentDTO
* <p>Powered by echo On 2024-03-17 12:07:13
* <p>Project: nuxt-blog - CommentVO
* <p>Powered by echo On 2024-03-21 20:36:46
*
* @author sofency [[email protected]]
* @version 1.0
* @since 17
*/
@Getter
@Setter
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentDTO {
private Comment parentComment;
private List<Comment> childComment;
@ToString
public class CommentDTO extends Comment {
private String username;
private String parentName;
private String replyName;

public CommentDTO(Comment comment) {
this.setId(comment.getId());
this.setUserId(comment.getUserId());
this.setContent(comment.getContent());
this.setCreateTime(comment.getCreateTime());
this.setBlogId(comment.getBlogId());
this.setDeleted(comment.getDeleted());
this.setIpAddress(comment.getIpAddress());
this.setIpSource(comment.getIpSource());
this.setParentId(comment.getParentId());
this.setReplyUserId(comment.getReplyUserId());
this.setReview(comment.getReview());
this.setStatus(comment.getStatus());
this.setUpdateTime(comment.getUpdateTime());
this.setDeleted(comment.getDeleted());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sofency.top.nuxtblog.dto;

import com.sofency.top.nuxtblog.entity.Comment;
import lombok.*;

import java.util.List;

/**
* <p>Project: nuxt-blog - CommentDTO
* <p>Powered by echo On 2024-03-17 12:07:13
*
* @author sofency [[email protected]]
* @version 1.0
* @since 17
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentListDTO {
private CommentDTO parentComment;
private List<CommentDTO> childComment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
Expand Down Expand Up @@ -64,10 +66,12 @@ public class Blog extends Model<Blog> {

@ApiModelProperty("发表时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;

@ApiModelProperty("更新时间")
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
Expand Down Expand Up @@ -75,12 +77,21 @@ public class Comment extends Model<Comment> {

@ApiModelProperty("评论时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;

@ApiModelProperty("更新时间")
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;

@ApiModelProperty("IP地址")
@TableField(value = "ip_source")
private String ipSource;
@ApiModelProperty("IP属地")
@TableField(value = "update_time")
private String ipAddress;


public static final String ID = "id";

Expand All @@ -104,6 +115,10 @@ public class Comment extends Model<Comment> {

public static final String UPDATE_TIME = "update_time";

public static final String IP_SOURCE = "ip_source";

public static final String IP_ADDRESS = "ip_address";

@Override
public Serializable pkVal() {
return this.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class User extends Model<User> {

@ApiModelProperty("注册时间")
@TableField("register_time")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private Date registerTime;


Expand Down
Loading

0 comments on commit 18a4d1e

Please sign in to comment.