Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6075de0
예외 처리
invalid-email-address Jun 3, 2024
6e51fad
2차 실습
invalid-email-address Jun 3, 2024
ec8cf6a
BoardRepositoryJdbc 버그 해결
invalid-email-address Jun 3, 2024
d114447
데이터 찾기 방법이 변경되었습니다. (상상도 못한 버그 ㄴㅇㄱ)
invalid-email-address Jun 3, 2024
2f3aaeb
이메일 찾기에서 자기 자신을 제외시킵니다.
invalid-email-address Jun 3, 2024
c7981d3
SQL Query 잘 못 적었습니다.
invalid-email-address Jun 3, 2024
fed1088
ArticleUpdateRequest에 authorId를 추가하였습니다.
invalid-email-address Jun 3, 2024
e7f028c
Article의 author_id가 변경 될 수 있습니다.
invalid-email-address Jun 3, 2024
9e835dc
Article에서 존재하지 않는 유저나 게시판을 참조할 때 404를 배출합니다.
invalid-email-address Jun 3, 2024
18f30b2
Article이 생성될 때 존재하지 않는 유저나 게시판을 참조 할 경우 400을 내보냅니다.
invalid-email-address Jun 3, 2024
55ae36a
JDBC 대신 EntityManager를 주로 사용합니다.
invalid-email-address Jun 24, 2024
898439b
클래스 명을 RepositoryJDBC에서 Repository로 바꾸었습니다. (오해할 수도 있기 때문에)
invalid-email-address Jun 24, 2024
c3436da
entitymanager.persist() 일부를 entitymanager.merge()로 바꾸었습니다.
invalid-email-address Jun 24, 2024
6de2ba4
연관관계 매핑을 적용하였습니다.
invalid-email-address Jun 29, 2024
66300b1
JPARepository를 적용하였습니다.
invalid-email-address Jun 30, 2024
bc018a8
delete에서 Exception이 발생할 수 있습니다.
invalid-email-address Jul 1, 2024
d57963b
연관관계 편의 메서드를 적용하였습니다.
invalid-email-address Jul 1, 2024
5dfc944
gitignore 추가
invalid-email-address Jul 7, 2024
d0f6d2f
유저의 비밀번호를 암호화해서 저장합니다.
invalid-email-address Jul 7, 2024
3d71415
이메일 중복문제 해결
invalid-email-address Jul 7, 2024
d0e2b25
로그인과 회원가입 시스템을 구현하였습니다.
invalid-email-address Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bin/
out/
!**/src/main/**/out/
!**/src/test/**/out/
application.yml

### NetBeans ###
/nbproject/private/
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/example/demo/advice/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.demo.advice;

import com.example.demo.exception.HTTPApiException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLIntegrityConstraintViolationException;

@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(EmptyResultDataAccessException.class)
public ResponseEntity<String> handleEmptyResultDataAccessException(EmptyResultDataAccessException e) {
return new ResponseEntity<>("해당 데이터를 찾을 수 없음.", HttpStatusCode.valueOf(404));
}

@ExceptionHandler(HTTPApiException.class)
public ResponseEntity<String> handleHTTPApiException(HTTPApiException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatusCode.valueOf(e.getHttpCode()));
}

}
14 changes: 8 additions & 6 deletions src/main/java/com/example/demo/controller/ArticleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.net.URI;
import java.util.List;

import com.example.demo.exception.HTTPApiException;
import com.example.demo.proxyservice.ArticleProxyService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -21,16 +23,16 @@
@RestController
public class ArticleController {

private final ArticleService articleService;
private final ArticleProxyService articleService;

public ArticleController(ArticleService articleService) {
public ArticleController(ArticleProxyService articleService) {
this.articleService = articleService;
}

@GetMapping("/articles")
public ResponseEntity<List<ArticleResponse>> getArticles(
@RequestParam Long boardId
) {
) throws HTTPApiException {
List<ArticleResponse> response = articleService.getByBoardId(boardId);
return ResponseEntity.ok(response);
}
Expand All @@ -46,7 +48,7 @@ public ResponseEntity<ArticleResponse> getArticle(
@PostMapping("/articles")
public ResponseEntity<ArticleResponse> crateArticle(
@RequestBody ArticleCreateRequest request
) {
) throws HTTPApiException {
ArticleResponse response = articleService.create(request);
return ResponseEntity.created(URI.create("/articles/" + response.id())).body(response);
}
Expand All @@ -55,15 +57,15 @@ public ResponseEntity<ArticleResponse> crateArticle(
public ResponseEntity<ArticleResponse> updateArticle(
@PathVariable Long id,
@RequestBody ArticleUpdateRequest request
) {
) throws HTTPApiException {
ArticleResponse response = articleService.update(id, request);
return ResponseEntity.ok(response);
}

@DeleteMapping("/articles/{id}")
public ResponseEntity<Void> updateArticle(
@PathVariable Long id
) {
) throws HTTPApiException {
articleService.delete(id);
return ResponseEntity.noContent().build();
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/example/demo/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import com.example.demo.exception.HTTPApiException;
import com.example.demo.proxyservice.BoardProxyService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -19,9 +21,9 @@
@RestController
public class BoardController {

private final BoardService boardService;
private final BoardProxyService boardService;

public BoardController(BoardService boardService) {
public BoardController(BoardProxyService boardService) {
this.boardService = boardService;
}

Expand All @@ -40,22 +42,22 @@ public BoardResponse getBoard(
@PostMapping("/boards")
public BoardResponse createBoard(
@RequestBody BoardCreateRequest request
) {
) throws HTTPApiException {
return boardService.createBoard(request);
}

@PutMapping("/boards/{id}")
public BoardResponse updateBoard(
@PathVariable Long id,
@RequestBody BoardUpdateRequest updateRequest
) {
) throws HTTPApiException {
return boardService.update(id, updateRequest);
}

@DeleteMapping("/boards/{id}")
public ResponseEntity<Void> deleteBoard(
@PathVariable Long id
) {
) throws HTTPApiException {
boardService.deleteBoard(id);
return ResponseEntity.noContent().build();
}
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/example/demo/controller/LoginController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.example.demo.controller;

import com.example.demo.entity.Member;
import com.example.demo.exception.HTTPApiException;
import com.example.demo.proxyservice.ArticleProxyService;
import com.example.demo.proxyservice.LoginProxyService;
import com.example.demo.proxyservice.MemberProxyService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttribute;

@Controller
public class LoginController {

private final LoginProxyService loginService;
private final ArticleProxyService articleService;

public LoginController(LoginProxyService loginService, ArticleProxyService articleService) {
this.loginService = loginService;
this.articleService = articleService;
}

@GetMapping("/login")
public String getLoginPage() {
return "login";
}

@PostMapping("/login")
public String postLoginPage(
@RequestParam(required = false) String email,
@RequestParam(required = false) String password,
HttpServletRequest request
) throws HTTPApiException {
return loginService.login(email, password, request);
}

@GetMapping("/showmethearticles")
public String myArticles(
@SessionAttribute(name = "loginMember", required = false) Member member,
Model model
) throws HTTPApiException {
return loginService.myArticles(member, model);
}

@GetMapping("/sign")
public String getSignPage() {
return "sign";
}

@PostMapping("/sign")
public String postSign(
@RequestParam(required = false)String name,
@RequestParam(required = false)String email,
@RequestParam(required = false)String password
) throws HTTPApiException {
return loginService.postSign(name, email, password);
}
}
12 changes: 7 additions & 5 deletions src/main/java/com/example/demo/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import com.example.demo.exception.HTTPApiException;
import com.example.demo.proxyservice.MemberProxyService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -19,9 +21,9 @@
@RestController
public class MemberController {

private final MemberService memberService;
private final MemberProxyService memberService;

public MemberController(MemberService memberService) {
public MemberController(MemberProxyService memberService) {
this.memberService = memberService;
}

Expand All @@ -42,7 +44,7 @@ public ResponseEntity<MemberResponse> getMember(
@PostMapping("/members")
public ResponseEntity<MemberResponse> create(
@RequestBody MemberCreateRequest request
) {
) throws HTTPApiException {
MemberResponse response = memberService.create(request);
return ResponseEntity.ok(response);
}
Expand All @@ -51,15 +53,15 @@ public ResponseEntity<MemberResponse> create(
public ResponseEntity<MemberResponse> updateMember(
@PathVariable Long id,
@RequestBody MemberUpdateRequest request
) {
) throws HTTPApiException {
MemberResponse response = memberService.update(id, request);
return ResponseEntity.ok(response);
}

@DeleteMapping("/members/{id}")
public ResponseEntity<Void> deleteMember(
@PathVariable Long id
) {
) throws HTTPApiException {
memberService.delete(id);
return ResponseEntity.noContent().build();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/example/demo/controller/PageController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package com.example.demo.controller;

import com.example.demo.entity.Member;
import com.example.demo.exception.HTTPApiException;
import com.example.demo.proxyservice.ArticleProxyService;
import com.example.demo.proxyservice.MemberProxyService;
import com.example.demo.service.MemberService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttribute;


@Controller
Expand All @@ -23,4 +33,5 @@ public String getArticlesPage() {
public String getArticleDetailPage() {
return "article";
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.controller.dto.request;

public record ArticleUpdateRequest(
Long authorId,
Long boardId,
String title,
String description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.time.LocalDateTime;

import com.example.demo.domain.Article;
import com.example.demo.domain.Board;
import com.example.demo.domain.Member;
import com.example.demo.entity.Article;
import com.example.demo.entity.Board;
import com.example.demo.entity.Member;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand All @@ -24,11 +24,11 @@ public record ArticleResponse(
LocalDateTime modifiedDate
) {

public static ArticleResponse of(Article article, Member member, Board board) {
public static ArticleResponse of(Article article) {
return new ArticleResponse(
article.getId(),
member.getId(),
board.getId(),
article.getAuthor().getId(),
article.getBoard().getId(),
article.getTitle(),
article.getContent(),
article.getCreatedAt(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.demo.controller.dto.response;

import com.example.demo.domain.Board;
import com.example.demo.entity.Board;

public record BoardResponse(
Long id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.demo.controller.dto.response;

import com.example.demo.domain.Member;
import com.example.demo.entity.Member;

public record MemberResponse(
Long id,
Expand Down
Loading