Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
173 changes: 173 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,176 @@ out/

### VS Code ###
.vscode/

# Created by https://www.toptal.com/developers/gitignore/api/windows,intellij,java
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,intellij,java

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

#비번 적힌 곳
application.yml

# End of https://www.toptal.com/developers/gitignore/api/windows,intellij,java
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ java {
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}
Expand All @@ -19,8 +25,13 @@ 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'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
Comment on lines +31 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

롬복을 도입한 이유와 도입할 때 어떤 점을 고려했는지 궁금합니다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Getter@Setter를 사용하려고 도입했는데 직접 get과 set을 짜서 도입만 하고 따로 사용은 안했습니다

}

tasks.named('test') {
Expand Down
Binary file removed gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Empty file modified gradlew
100755 → 100644
Empty file.
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/ArticleExist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class ArticleExist extends RuntimeException{
public ArticleExist(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/ArticleNotFound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class ArticleNotFound extends RuntimeException {
public ArticleNotFound(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/BoardNotFound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class BoardNotFound extends RuntimeException {
public BoardNotFound(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/EmailExist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class EmailExist extends RuntimeException {
public EmailExist(String message) {
super(message);
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/example/demo/Exception/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.demo.Exception;

import lombok.Getter;

@Getter
public enum ErrorCode {

Article_Not_Found(404,"NOT_FOUND","게시물을 찾을 수 없습니다."),
Board_Not_Found(404,"NOT_FOUND","게시판을 찾을 수 없습니다."),
Member_Not_Found(404,"NOT_FOUND","사용자를 찾을 수 없습니다."),

Email_Exist(409,"Exist","이미 이메일이 존재합니다."),
Fail_Member(400,"FAIL","사용자를 참조할 수 없습니다."),
Fail_Board(400,"FAIL","게시판을 참조할 수 없습니다."),

Null_Exist(400,"NULL","빈(Null) 값이 존재합니다."),

Remain_Article(400,"REMAIN","게시물이 남아있습니다.");

private final int code_id;
private final String code;
private final String message;

ErrorCode(int code_id, String code, String message) {
this.code_id = code_id;
this.code = code;
this.message = message;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/example/demo/Exception/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.demo.Exception;

import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class ErrorResponse {
private final LocalDateTime timestamp=LocalDateTime.now();
private int code_id;
private String code;
private String message;

public ErrorResponse(ErrorCode errorCode) {
this.code_id = errorCode.getCode_id();
this.code = errorCode.getCode();
this.message = errorCode.getMessage();
}

public ErrorResponse(ErrorCode errorCode, String message) {
this.code_id = errorCode.getCode_id();
this.code = errorCode.getCode();
this.message = message;
}
Comment on lines +14 to +24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 생성자를 사용한다면 정적 팩토리 메서드로 대체해보는 건 어떻게 생각하세요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정적 팩토리 메소드라는 용어가 익숙하지 않아서 정적 팩토리 메소드에 대해 한번 공부하고 긍정적으로 고려해보겠습니다.

}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/FailBoard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class FailBoard extends RuntimeException{
public FailBoard(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/FailMember.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class FailMember extends RuntimeException{
public FailMember(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.demo.Exception;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(ArticleNotFound.class)
public ResponseEntity<ErrorResponse> handleArticleNotFound(ArticleNotFound articleNotFound) {
ErrorResponse response=new ErrorResponse(ErrorCode.Article_Not_Found);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(BoardNotFound.class)
public ResponseEntity<ErrorResponse> handleBoardNotFound(BoardNotFound boardNotFound) {
ErrorResponse response=new ErrorResponse(ErrorCode.Board_Not_Found);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(MemberNotFound.class)
public ResponseEntity<ErrorResponse> handleMemberNotFound(MemberNotFound memberNotFound) {
ErrorResponse response=new ErrorResponse(ErrorCode.Member_Not_Found);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(EmailExist.class)
public ResponseEntity<ErrorResponse> handleEmailExist(EmailExist emailExist) {
ErrorResponse response=new ErrorResponse(ErrorCode.Email_Exist);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(FailMember.class)
public ResponseEntity<ErrorResponse> handleFailMember(FailMember failMember) {
ErrorResponse response=new ErrorResponse(ErrorCode.Fail_Member);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(FailBoard.class)
public ResponseEntity<ErrorResponse> handleFailBoard(FailBoard failBoard) {
ErrorResponse response=new ErrorResponse(ErrorCode.Fail_Board);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(NullExist.class)
public ResponseEntity<ErrorResponse> handleNullExist(NullExist nullExist) {
ErrorResponse response=new ErrorResponse(ErrorCode.Null_Exist);
return ResponseEntity.status(response.getCode_id()).body(response);
}

@ExceptionHandler(ArticleExist.class)
public ResponseEntity<ErrorResponse> handleArticleExist(ArticleExist articleExist) {
ErrorResponse response=new ErrorResponse(ErrorCode.Remain_Article);
return ResponseEntity.status(response.getCode_id()).body(response);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/MemberNotFound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class MemberNotFound extends RuntimeException {
public MemberNotFound(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/demo/Exception/NullExist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.demo.Exception;

public class NullExist extends RuntimeException{
public NullExist(String message) {
super(message);
}
}
Loading