-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
451 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
musicBackend/src/main/java/com/cph/musicbackend/controller/PostsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.cph.musicbackend.controller; | ||
|
||
import com.cph.musicbackend.aspect.RecognizeAddress; | ||
import com.cph.musicbackend.aspect.UserContext; | ||
import com.cph.musicbackend.common.CommonResult; | ||
import com.cph.musicbackend.entity.Posts; | ||
import com.cph.musicbackend.entity.User; | ||
import com.cph.musicbackend.mapper.PostsMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
public class PostsController { | ||
|
||
@Autowired | ||
PostsMapper postMapper; | ||
|
||
@PostMapping("/api/posts") | ||
@RecognizeAddress | ||
public CommonResult getPosts(){ | ||
User currentUser = UserContext.getCurrentUser(); | ||
List<Posts> posts = postMapper.getUserPosts(currentUser); | ||
posts.stream().forEach(p->{ | ||
p.setImages(Arrays.asList(p.getMedia().split(","))); | ||
}); | ||
return new CommonResult(200,"查询成功",posts); | ||
} | ||
|
||
@PostMapping("/api/likePost") | ||
@RecognizeAddress | ||
public CommonResult like(@RequestBody Posts p){ | ||
User currentUser = UserContext.getCurrentUser(); | ||
postMapper.like(currentUser,p); | ||
return new CommonResult(200,"操作成功",null); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
musicBackend/src/main/java/com/cph/musicbackend/entity/Posts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.cph.musicbackend.entity; | ||
|
||
import com.baomidou.mybatisplus.annotation.IdType; | ||
import com.baomidou.mybatisplus.annotation.TableField; | ||
import com.baomidou.mybatisplus.annotation.TableId; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Data | ||
@Accessors(chain = true) | ||
@TableName("posts") | ||
public class Posts { | ||
|
||
@TableId(type = IdType.AUTO, value = "id") | ||
private Integer id; | ||
private Integer userId; | ||
private Date createdTime; | ||
private String media; | ||
private String content; | ||
|
||
private String userIcon; | ||
private String userNickname; | ||
|
||
@TableField(exist = false) | ||
private Integer isLike; | ||
@TableField(exist = false) | ||
private List<String> images; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
musicBackend/src/main/java/com/cph/musicbackend/mapper/PostsMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.cph.musicbackend.mapper; | ||
|
||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
import com.cph.musicbackend.entity.Music; | ||
import com.cph.musicbackend.entity.Posts; | ||
import com.cph.musicbackend.entity.User; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import java.util.List; | ||
|
||
@Mapper | ||
public interface PostsMapper extends BaseMapper<Posts> { | ||
public List<Posts> getUserPosts(@Param("u") User user); | ||
|
||
public void like(@Param("u") User user, @Param("p") Posts p); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE mapper | ||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="com.cph.musicbackend.mapper.PostsMapper"> | ||
|
||
|
||
<resultMap id="BaseResultMap" type="com.cph.musicbackend.entity.Posts"> | ||
<id column="id" property="id" jdbcType="INTEGER"/> | ||
<result column="user_id" property="userId" jdbcType="INTEGER"/> | ||
<result column="created_time" property="createdTime" jdbcType="DATE"/> | ||
<result column="media" property="media" jdbcType="VARCHAR"/> | ||
<result column="content" property="content" jdbcType="VARCHAR"/> | ||
<result column="user_icon" property="userIcon" jdbcType="VARCHAR"/> | ||
<result column="user_nickname" property="userNickname" jdbcType="VARCHAR"/> | ||
<result column="is_like" property="isLike" jdbcType="INTEGER"/> | ||
</resultMap> | ||
|
||
|
||
<select id="getUserPosts" resultMap="BaseResultMap"> | ||
select a.id id, | ||
a.user_id user_id, | ||
a.created_time created_time, | ||
a.media media, | ||
a.content content, | ||
a.user_icon user_icon, | ||
a.user_nickname user_nickname, | ||
b.is_like is_like | ||
from posts a | ||
left join user_posts b | ||
on a.id = b.post_id and b.user_id = #{u.id} | ||
</select> | ||
|
||
|
||
<update id="like"> | ||
update user_posts | ||
set is_like = #{p.isLike} | ||
where user_id = #{u.id} | ||
and post_id = #{p.id} | ||
</update> | ||
</mapper> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,82 @@ | ||
.chat-box { | ||
width: 100%; | ||
height: 100%; | ||
background: linear-gradient(to bottom, #DDA0DD, #FFB6C1); | ||
.chat-input-container { | ||
display: flex; | ||
align-items: center; | ||
position: relative; | ||
padding: 10px; | ||
background-color: #fff; | ||
border-top: 1px solid #eaeaea; | ||
} | ||
|
||
html, | ||
body { | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
.chat-input { | ||
flex: 1; | ||
margin-right: 10px; | ||
border-radius: 20px; | ||
border: 1px solid #eaeaea; | ||
padding: 8px 12px; | ||
font-size: 14px; | ||
} | ||
.chat-header{ | ||
padding: 2px; | ||
/* margin-top: 2%; */ | ||
|
||
.send-button { | ||
margin-left: 10px; | ||
background-color: #007bff; | ||
border-color: #007bff; | ||
color: #fff; | ||
border-radius: 20px; | ||
} | ||
|
||
.emoji-picker-wrapper { | ||
position: absolute; | ||
bottom: 60px; | ||
/* 确保不会挡住输入框 */ | ||
right: 10px; | ||
z-index: 10; | ||
background-color: #fff; | ||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); | ||
border-radius: 10px; | ||
} | ||
|
||
.emoji-icon { | ||
margin-right: 10px; | ||
cursor: pointer; | ||
color: #888; | ||
} | ||
|
||
.emoji-icon:hover { | ||
color: #007bff; | ||
} | ||
.list-container { | ||
|
||
.chat-header { | ||
background-color: #f0f0f0; | ||
/* 顶部背景色 */ | ||
padding: 15px; | ||
/* 增加内边距,调整顶部区域的高度 */ | ||
min-height: 60px; | ||
/* 设置最小高度 */ | ||
border-bottom: 1px solid #eaeaea; | ||
/* 添加下边框 */ | ||
display: flex; | ||
/* 使用 flex 布局 */ | ||
align-items: center; | ||
/* 垂直居中对齐 */ | ||
} | ||
|
||
.chat-header .badge { | ||
margin-right: 10px; | ||
/* Badge 和 nickname 之间的间距 */ | ||
} | ||
|
||
.chat-header .nickname { | ||
font-size: 18px; | ||
/* 增加昵称字体大小 */ | ||
color: #333; | ||
/* 字体颜色 */ | ||
font-weight: bold; | ||
/* 加粗字体 */ | ||
} | ||
|
||
.chat-header .nickname-container { | ||
display: flex; | ||
/* 使用 flex 布局 */ | ||
flex-direction: column; | ||
/* 纵向排列 */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.