Skip to content

Commit

Permalink
chore: page adjust and deps upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bs32g1038 committed Mar 24, 2024
1 parent 17d93fb commit 3a607a7
Show file tree
Hide file tree
Showing 52 changed files with 5,629 additions and 3,629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import com.jixialunbi.dto.request.IdRequest;
import com.jixialunbi.dto.request.PostRequest;
import com.jixialunbi.model.*;
import com.jixialunbi.repository.CommentRepository;
import com.jixialunbi.repository.PostCollectionRepository;
import com.jixialunbi.repository.PostLikeRepository;
import com.jixialunbi.repository.PostRepository;
import com.jixialunbi.repository.*;
import com.jixialunbi.service.CategoryService;
import com.jixialunbi.service.FollowUserService;
import com.jixialunbi.service.UserService;
Expand All @@ -33,6 +30,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import static io.jsonwebtoken.lang.Collections.isEmpty;


@RestController
Expand All @@ -51,6 +51,9 @@ public class PostController {
@Autowired
CommentRepository commentRepository;

@Autowired
TagRepository tagRepository;

@Autowired
UserService userService;

Expand All @@ -67,13 +70,13 @@ public ResponseEntity<Post> createPost(@Valid @RequestBody PostRequest postReque
User user = userService.getByAccount(principal.getName());
var post = new Post();
post.setTitle(postRequest.getTitle());
post.setCategory(categoryService.getById(postRequest.getCategoryId()));
post.setContent(postRequest.getContent());
post.setPics(postRequest.getPics());
post.setAuthor(user);
user.setPostCount(user.getPostCount() + 1);
if (!StrUtil.isEmpty(postRequest.getTags())) {
post.setTags(postRequest.getTags());
if (!isEmpty(postRequest.getTags())) {
var ids = postRequest.getTags();
post.setTags(tagRepository.findAllById(ids));
}
var result = postRepository.save(post);
return ResponseEntity.ok(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.util.List;

/**
* Data Transfer Object for Profile request
*/
Expand All @@ -19,10 +21,11 @@ public class PostRequest {
@Size(max = 12000)
private String content;

@NotNull
private long categoryId;
// @NotNull
// private long categoryId;

private String tags;
@NotNull
private List<Long> tags;

private String pics;
}
10 changes: 8 additions & 2 deletions server/src/main/java/com/jixialunbi/model/Post.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jixialunbi.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -43,8 +44,13 @@ public class Post {
@Transient
private boolean collected = false;

@Column(name = "tags")
private String tags;
@ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(name = "post_tag",
joinColumns = @JoinColumn(name = "post_id"),
inverseJoinColumns = @JoinColumn(name = "tag_id"))
@JsonIgnoreProperties({"posts"})
private List<Tag> tags = new ArrayList<>();


@Column(name = "pics")
private String pics;
Expand Down
40 changes: 40 additions & 0 deletions server/src/main/java/com/jixialunbi/model/Tag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.jixialunbi.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Getter
@Setter
@Entity
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@Column(name = "name")
private String name;

@Column(name = "description")
private String description;

@ManyToMany(mappedBy = "tags")
private List<Post> posts = new ArrayList<>();

@JsonFormat
@Column(name = "created_at", columnDefinition = "DATETIME DEFAULT NOW()")
private LocalDateTime createdAt;

@JsonFormat
@Column(name = "updated_at", columnDefinition = "DATETIME DEFAULT NOW()")
@UpdateTimestamp
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.jixialunbi.repository;

import com.jixialunbi.model.Category;
import com.jixialunbi.model.Tag;
import org.springframework.data.jpa.repository.JpaRepository;


public interface CategoryRepository extends JpaRepository<Category, Long> {
public interface TagRepository extends JpaRepository<Tag, Long> {

}
File renamed without changes.
3 changes: 3 additions & 0 deletions web/app/category/[categoryId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import home from '@/components/home';

export default home;
21 changes: 21 additions & 0 deletions web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'antd/dist/reset.css';
import '@/styles/global.css';
import '@/styles/style.scss';
import zhCN from 'antd/lib/locale/zh_CN';
import { ConfigProvider } from 'antd';
import { AntdRegistry } from '@ant-design/nextjs-registry';

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="zh-CN">
<title>积下_微社区</title>
<meta name="keywords" content="积下微社区, bbs, 论坛" />
<meta name="description" content="积下是一个简洁清爽的微社区,分享各种有趣内容,你感兴趣的都在这里!"></meta>
<body>
<AntdRegistry>
<ConfigProvider locale={zhCN}>{children}</ConfigProvider>
</AntdRegistry>
</body>
</html>
);
}
2 changes: 2 additions & 0 deletions web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Home from '@/components/home';
export default Home
2 changes: 2 additions & 0 deletions web/app/posts/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import post from '../../../components/post';
export default post;
3 changes: 3 additions & 0 deletions web/app/profile/[account]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Profile from '../../../components/Profile';

export default Profile;
3 changes: 3 additions & 0 deletions web/app/profile/edit/[account]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ProfileEdit from '../../../../components/ProfileEdit';

export default ProfileEdit;
3 changes: 3 additions & 0 deletions web/app/write/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Write from '../../components/Write';

export default Write;
30 changes: 15 additions & 15 deletions web/components/AppHeader/components/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { SearchOutlined } from '@ant-design/icons';
import { Button, Input } from 'antd';
import { useRouter } from 'next/router';
import { useRouter } from 'next/navigation';
import React, { useEffect, useState } from 'react';
import styles from './index.module.scss';
import { useAppStore } from '@/store';

export default function Search() {
const router = useRouter();
const { user } = useAppStore();
const [input, setInput] = useState('');
useEffect(() => {
if (router.query.q) {
setInput(router.query.q as any);
}
}, [router.query.q]);
// const router = useRouter();
// const { user } = useAppStore();
// const [input, setInput] = useState('');
// useEffect(() => {
// if (router.query.q) {
// setInput(router.query.q as any);
// }
// }, [router.query.q]);
return (
<div className={styles.inputSearch} style={{ width: 250 }}>
<Input
placeholder="搜索你想要的..."
className={styles.input}
size="small"
value={input}
// value={input}
onChange={(e) => {
setInput(e.target.value);
// setInput(e.target.value);
}}
onPressEnter={() => {
if (!input) {
return router.push('');
}
router.push('?type=search&&q=' + input);
// if (!input) {
// return router.push('');
// }
// router.push('?type=search&&q=' + input);
}}
></Input>
<SearchOutlined />
Expand Down
2 changes: 1 addition & 1 deletion web/components/AppHeader/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
font-size: 16px;
background-color: #fff;
border-radius: 2px;
padding: 15px 20px;
padding: 15px 0;
flex: 0;
}

Expand Down
7 changes: 3 additions & 4 deletions web/components/AppHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
LoginOutlined,
LogoutOutlined,
} from '@ant-design/icons';
import { useRouter } from 'next/router';
import { useRouter } from 'next/navigation';
import logo from './logo.png';
import classNames from 'classnames';
import Cookies from 'js-cookie';
Expand Down Expand Up @@ -44,12 +44,11 @@ export default function AppHeader() {
<span className={styles.headerlinks}>
<Link href="/" passHref={true} className={styles.title}>
<img className={styles.logo} src={logo.src} alt="" />
<h1 title="积下论笔社区">积下论笔社区</h1>
<h1 title="积下社区">积下社区</h1>
</Link>
</span>
</div>
<div className={styles.headerRight}>
{/* <Search></Search> */}
<Link href="/" passHref={true}>
<Button size="small" type="text">
<HomeOutlined></HomeOutlined>首页
Expand Down Expand Up @@ -95,7 +94,7 @@ export default function AppHeader() {
<Button
onClick={() => {
Cookies.remove('token');
router.reload();
router.refresh();
}}
type="text"
size="small"
Expand Down
2 changes: 1 addition & 1 deletion web/components/Layout/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

.wrap {
width: 665px;
width: 645px;
margin: 0 auto;
display: flex;
flex-direction: column;
Expand Down
2 changes: 2 additions & 0 deletions web/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client"

import { ArrowUpOutlined } from '@ant-design/icons';
import { FloatButton } from 'antd';
import React, { useEffect } from 'react';
Expand Down
18 changes: 18 additions & 0 deletions web/components/LoadAsyncMore/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use server'

import axios from '@/libs/axios';
import { AxiosRequestConfig } from 'axios';
import { useParams } from 'next/navigation';
import React from 'react';

interface Props {
url: string;
config?: AxiosRequestConfig<any>;
Component: React.FC<any>;
}

export default async function LoadAsyncMore(props: Props) {
const { url, config, Component } = props;
const data = await axios.get(url, config).then((res) => res.data);
return <Component data={data}></Component>;
}
6 changes: 3 additions & 3 deletions web/components/LoginModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function LoginModal() {
const { isShowLoginModal, setUser, showLoginModal } = useAppStore();
const [form] = useForm();
const [tab, setTab] = useState(LOGIN_TYPE.login);
const router = useRouter();
// const router = useRouter();
const { trigger: login } = useSWRMutation('/api/v1/auth/login', sendRequest);
const { trigger: register } = useSWRMutation('/api/v1/auth/signup', sendRequest);
const onFinish = (values: any) => {
Expand All @@ -43,7 +43,7 @@ export default function LoginModal() {
message.success('登录成功!');
Cookies.set('token', token);
setUser(res.data?.data);
router.reload();
// router.reload();
});
return;
}
Expand All @@ -55,7 +55,7 @@ export default function LoginModal() {
Cookies.set('token', res.token);
axios.defaults.headers.common = { Authorization: `bearer ${res.token}` };
setUser(res.user);
router.reload();
// router.reload();
});
});
};
Expand Down
8 changes: 3 additions & 5 deletions web/components/Profile/components/Posts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { useRouter } from 'next/router';
import { useParams, useRouter } from 'next/navigation';
import React from 'react';
import TopicItem from '../../../home/components/TopicItem';
import { useSWR } from '@/hooks';
import { Empty } from 'antd';

export default function Posts() {
const router = useRouter();
const account = router.query?.account;
const { account } = useParams();
const { data } = useSWR({ url: '/api/v1/posts?account=' + account });
const posts = data?.data;
return (
<div>
{posts?.items?.map((item: any) => (
<TopicItem item={item} key={item.id}></TopicItem>
))}
{posts?.items?.map((item: any) => <TopicItem item={item} key={item.id}></TopicItem>)}
{posts?.items?.length == 0 && <Empty image={Empty.PRESENTED_IMAGE_SIMPLE}></Empty>}
</div>
);
Expand Down
Loading

0 comments on commit 3a607a7

Please sign in to comment.