Skip to content

Commit

Permalink
리팩토링 및 어노테이션 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
jungeunyooon committed Nov 26, 2023
1 parent 5d084e7 commit ce99921
Show file tree
Hide file tree
Showing 56 changed files with 533 additions and 418 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified 윤정은/spring/.gradle/8.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified 윤정은/spring/.gradle/8.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified 윤정은/spring/.gradle/8.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file not shown.
Binary file modified 윤정은/spring/.gradle/file-system.probe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class Application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,63 @@
import board.spring.dto.request.BoardSaveRequest;
import board.spring.dto.response.BoardDetailResponse;
import board.spring.dto.response.BoardListResponse;
import board.spring.dto.request.BoardUpdateRequest;
import board.spring.service.BoardService;
import lombok.RequiredArgsConstructor;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequiredArgsConstructor
@RequestMapping("/api/boards")
public class BoardController {

private final BoardService boardService;

// 게시글 작성
public BoardController(BoardService boardService){ this.boardService = boardService;}

@PostMapping
public ResponseEntity<Void> saveBoard(@RequestBody BoardSaveRequest request) {
public ResponseEntity<Void> saveBoard(@RequestBody @Valid BoardSaveRequest request) {
boardService.savePost(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

// 전체 게시글 목록 조회
@GetMapping
public List<BoardListResponse> findBoardList() {
List<BoardListResponse> responseList = boardService.findBoardList();
return responseList;
}

// 게시글 제목으로 게시글 목록을 검색
@GetMapping("/search")
public List<BoardListResponse> findBoardListByTitle(@RequestParam String title) {
List<BoardListResponse> responseList = boardService.findBoardListByTitle(title);
return responseList;
}

// 특정 회원이 작성한 게시글 조회
@GetMapping("/member/{memberId}")
public ResponseEntity<List<BoardListResponse>> findBoardListByEmail(@PathVariable Long memberId) {
ResponseEntity<List<BoardListResponse>> responseEntity = boardService.findPostListByEmail(memberId);
return responseEntity;
public List<BoardListResponse> findBoardListByEmail(@PathVariable Long memberId) {
List<BoardListResponse> responseList = boardService.findPostListByEmail(memberId);
return responseList;
}


// 게시글 상세 조회 (제목, 내용, 회원이름, 댓글)을 포함
@GetMapping("/{boardId}")
public ResponseEntity<BoardDetailResponse> findBoardDetail(@PathVariable Long boardId) {
return boardService.findDetail(boardId)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
public BoardDetailResponse findBoardDetail(@PathVariable Long boardId) {
return boardService.findDetail(boardId);
}

// 게시글 수정
@PutMapping("/{boardId}")
public ResponseEntity<Void> updateBoard(
@PathVariable Long boardId,
@RequestBody BoardSaveRequest request) {
@RequestBody BoardUpdateRequest request) {
boardService.updateBoard(boardId,request);
return ResponseEntity.ok().build();
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

// 게시글 삭제
@DeleteMapping("/{boardId}")
public ResponseEntity<Void> deleteBoard(@PathVariable Long boardId) {
boardService.deletePost(boardId);
return ResponseEntity.ok().build();
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,24 @@ public class CommentController {

private final CommentService commentService;

// 댓글 작성
@PostMapping
public ResponseEntity<Void> createComment(
@RequestParam Long memberId,
@RequestParam Long boardId,
@RequestBody CommentSaveRequest request) {

commentService.saveComment(memberId, boardId, request);
public ResponseEntity<Void> createComment(@RequestBody @Valid CommentSaveRequest request) {
commentService.saveComment(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

// 댓글 수정
@PutMapping("{commentId}")
@PutMapping("/{commentId}")
public ResponseEntity<Void> updateComment(
@PathVariable Long commentId,
@RequestBody CommentUpdateRequest request) {
commentService.updateComment(request, commentId);
return ResponseEntity.ok().build();
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

// 댓글 삭제
@DeleteMapping("{commentId}")
@DeleteMapping("/{commentId}")
public ResponseEntity<Void> deleteComment(@PathVariable Long commentId) {
commentService.deleteComment(commentId);
return ResponseEntity.ok().build();
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
package board.spring.controller;

import board.spring.dto.request.MemberLoginRequest;
import board.spring.dto.request.MemberSaveRequest;
import board.spring.dto.request.MemberSignInRequest;
import board.spring.dto.request.MemberSignUpRequest;
import board.spring.service.MemberService;
import lombok.RequiredArgsConstructor;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

@RestController
//@RequiredArgsConstructor
@RequestMapping("api/members")
public class MemberController {

private final MemberService memberService;

// @RequiredArgsConstructor를 대체하는 코드
public MemberController(MemberService memberService) {
this.memberService = memberService;
}

// 회원가입
@PostMapping
public ResponseEntity<Void> saveMember(@RequestBody MemberSaveRequest request) {
memberService.saveMember(request);
@PostMapping("/signup")
public ResponseEntity<Void> signUp(@RequestBody @Valid MemberSignUpRequest request) {
memberService.signUp(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

// 로그인
@PostMapping("/login")
public ResponseEntity<Void> loginMember(@RequestBody MemberLoginRequest request) {
if (memberService.loginMember(request)) {
return ResponseEntity.status(HttpStatus.OK).build();
}
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid email or password");
@PostMapping("/signin")
public ResponseEntity<Void> signIn(@RequestBody @Valid MemberSignInRequest request) {
memberService.signIn(request);
return ResponseEntity.status(HttpStatus.OK).build();
}
}
29 changes: 16 additions & 13 deletions 윤정은/spring/src/main/java/board/spring/domain/Board.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package board.spring.domain;

import board.spring.dto.request.BoardSaveRequest;
import board.spring.dto.request.BoardUpdateRequest;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
public class Board {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "board_id")
private Long id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

Expand All @@ -28,18 +21,28 @@ public class Board {
@Column(nullable = false)
private String content;

@OneToMany(mappedBy = "board")
@Column(nullable = false)
private List<Comment> comments = new ArrayList<>();
public Board() {}

public Board(final String title, final String content, final Member member) {
this.title = title;
this.content = content;
this.member = member;
}

public void update(BoardSaveRequest request){
public void update(BoardUpdateRequest request){
this.title = request.getTitle();
this.content = request.getContent();
}

public String getTitle() {
return title;
}

public String getContent() {
return content;
}

public Member getMember() {
return member;
}
}
37 changes: 19 additions & 18 deletions 윤정은/spring/src/main/java/board/spring/domain/Comment.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package board.spring.domain;

import board.spring.dto.request.CommentUpdateRequest;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.beans.ConstructorProperties;

@Entity
@Getter @Setter
@NoArgsConstructor
public class Comment {

@Id
Expand All @@ -19,25 +13,32 @@ public class Comment {

private String content;

@ManyToOne
@JoinColumn(name = "memberId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_Id")
private Member member;

@ManyToOne
@JoinColumn(name = "boardId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_Id")
private Board board;

public Comment() {}

public Comment(String newContent) {
this.content = newContent;
}

public void updateContent(String newContent) {
this.content = newContent;
}
public Comment(String content, Member member, Board board) {
this.content = content;
this.member = member;
this.board = board;
}

public void update(CommentUpdateRequest request) {
this.content = request.getContent();
}

public String getContent(){
return content;
}

public Member getMember(){
return member;
}

}
25 changes: 10 additions & 15 deletions 윤정은/spring/src/main/java/board/spring/domain/Member.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package board.spring.domain;

import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;


@Entity
public class Member {
Expand All @@ -12,31 +11,27 @@ public class Member {
@Column(name = "member_id")
private Long id;

@Column(nullable = false)
private String email;
@Column(nullable = false)
private String password;
@Column(nullable = false)
private String nickname;

@OneToMany(mappedBy = "member")
private List<Board> boards = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<Comment> comments = new ArrayList<>();
public Member() {}

public Member() {
//@NoArgsConstructor
}
public Member(String email, String password, String nickname) {
this.email = email;
this.password = password;
this.nickname = nickname;
}

public Member(String email, String password) {
this.email = email;
this.password = password;
public String getEmail() {
return email;
}

public Long getId() {
return id;
public String getPassword() {
return password;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

import board.spring.domain.Board;
import board.spring.domain.Member;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@AllArgsConstructor
@Getter @Setter
public class BoardSaveRequest {
@NotBlank(message = "공백일 수 없습니다.")
private String title;

@NotBlank(message = "공백일 수 없습니다.")
private String content;

@NotNull(message = "공백일 수 없습니다.")
private Long memberId;

public BoardSaveRequest(String title, String content,Long memberId){
this.title = title;
this.content = content;
this.memberId = memberId;
}

public Board toEntity(Member member){
return new Board(title, content, member);
}

public Long getMemberId() {
return memberId;
}
}
Loading

0 comments on commit ce99921

Please sign in to comment.