Updated frontend components and modified UserController, Board, and User

entities
This commit is contained in:
hyunu00
2024-09-23 16:54:38 +09:00
parent 3df5b69c77
commit afb873173c
6 changed files with 14 additions and 19 deletions

View File

@ -3,7 +3,7 @@ import { useParams, Link, useNavigate } from 'react-router-dom';
import './App.css';
function BoardList({ user }) {
const { category = "all" } = useParams(); // URL 파라미터로부터 카테고리 가져오기
const { category = "all" } = useParams();
const [boards, setBoards] = useState([]);
const [error, setError] = useState(null);
const [currentPage, setCurrentPage] = useState(0);
@ -13,7 +13,7 @@ function BoardList({ user }) {
const [selectedCategory, setSelectedCategory] = useState(category); // 검색을 위한 선택된 카테고리
const navigate = useNavigate(); // 페이지 이동을 위한 useNavigate
// 카테고리 한글 변환 함수
// 카테고리 한글 변환
const getCategoryNameInKorean = (categoryId) => {
switch (categoryId) {
case 'all':
@ -79,7 +79,7 @@ function BoardList({ user }) {
const noticeBoards = boards.filter(board => board.boardCategory === 2); // 공지사항
const otherBoards = boards.filter(board => board.boardCategory !== 2); // 기타 게시물
// 기타 게시물 최신순으로 정렬 (updatedDate 기준 내림차순)
// 기타 게시물 최신순으로 정렬
otherBoards.sort((a, b) => new Date(b.updatedDate) - new Date(a.updatedDate));
// 제목이나 내용에 검색어가 포함된 게시물 필터링

View File

@ -26,8 +26,9 @@ function CreatePost() {
body: JSON.stringify(newPost),
});
// 로그인 되어있는 사용자만 글 작성 가능
if (!response.ok) {
console.error(`Error: ${response.status}`); // 상태 코드를 출력하여 문제 확인
console.error(`Error: ${response.status}`); // 오류 상태 확인
if (response.status === 401) {
alert('로그인이 필요합니다.');
navigate('/login'); // 로그인 페이지로 이동

View File

@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom'; // React Router의 Link를 사용하여 페이지 이동 적용
import './App.css'; // 테이블 스타일 적용
import { Link } from 'react-router-dom';
import './App.css';
//내가 작성한 게시물
function MyPosts({ user }) {
const [posts, setPosts] = useState([]);
const [error, setError] = useState(null);

View File

@ -28,13 +28,13 @@ public class UserController {
@PostMapping("/register")
public ResponseEntity<?> createUser(@RequestBody User user, HttpSession session) {
try {
// 로그인된 사용자 ID를 세션에서 가져오기
// 로그인된 사용자 ID 가져오기
User loggedInUser = (User) session.getAttribute("user");
if (loggedInUser == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("로그인이 필요합니다.");
}
// 사용자 생성 시 필수 필드 확인 (유효성 검사)
// 사용자 생성 시 필드 확인
if (user.getUserId() == null || user.getUserPassword() == null || user.getUserName() == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("필수 필드가 누락되었습니다.");
}
@ -57,7 +57,7 @@ public class UserController {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("아이디 또는 비밀번호가 잘못되었습니다.");
}
// 로그인 성공 시 세션에 사용자 정보 저장
// 로그인 성공 시 사용자 정보 저장
session.setAttribute("user", authenticatedUser);
return ResponseEntity.ok("로그인 성공");
}
@ -65,7 +65,7 @@ public class UserController {
// 로그아웃 처리
@PostMapping("/logout")
public ResponseEntity<?> logout(HttpSession session) {
session.invalidate(); // 세션 무효화
session.invalidate();
return ResponseEntity.ok("로그아웃 성공");
}
@ -105,8 +105,6 @@ public class UserController {
}
}
// 비밀번호 업데이트 (별도 API)
@PutMapping("/{id}/password")
public ResponseEntity<?> updatePassword(@PathVariable String id, @RequestBody String newPassword, HttpSession session) {
try {

View File

@ -38,14 +38,12 @@ public class Board {
@Column(name = "UDT_USER", nullable = false)
private String updatedBy;
// @PrePersist: 엔티티가 처음 저장될 때 자동으로 날짜 필드를 설정
@PrePersist
protected void onCreate() {
this.createdDate = LocalDateTime.now();
this.updatedDate = LocalDateTime.now();
}
// @PreUpdate: 엔티티가 업데이트될 때 자동으로 날짜 필드를 변경
@PreUpdate
protected void onUpdate() {
this.updatedDate = LocalDateTime.now();

View File

@ -39,18 +39,16 @@ public class User {
@Column(name = "UDT_USER", nullable = false)
private String updatedBy;
// 레코드가 생성될 때 자동으로 설정
@PrePersist
protected void onCreate() {
this.createdDate = LocalDateTime.now();
this.createdBy = "System"; // 실제 사용자 정보로 변경 가능
this.createdBy = "System";
}
// 레코드가 수정될 때 자동으로 설정
@PreUpdate
protected void onUpdate() {
this.updatedDate = LocalDateTime.now();
this.updatedBy = "System"; // 실제 사용자 정보로 변경 가능
this.updatedBy = "System";
}
// Getters and Setters