Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

해커톤 작업 내역을 리팩토링 #94

Merged
merged 36 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b7ca3cc
chore: 스프링독 설정 파일 작성
jminkkk Jul 15, 2024
51bb109
refactor(codezap): ERD 변경에 따른 불필요한 도메인 삭제
zangsu Jul 18, 2024
33ebac5
refactor(domain): 의미 있는 상수 추출
zangsu Jul 18, 2024
4bb7794
refactor(codezap): global 패키지 하위 항목을 용도에 따라 패키징
zangsu Jul 18, 2024
35a741f
refactor(codezap): 패키지 이름 변경(thumbnail_snippet에서 언더바 제거)
zangsu Jul 18, 2024
86805f1
feat(exception): 커스텀 exception 추가
zangsu Jul 18, 2024
ce9c803
refactor(domain): Table 어노테이션 삭제
zangsu Jul 18, 2024
7e43676
refactor(domain): ThumbnailSnippet의 template 속성에 not null 제약조건 추가
zangsu Jul 18, 2024
7af7f99
chore: restAssured 의존성 추가
zangsu Jul 18, 2024
a98ed61
test(service): TemplateSerivce 테스트 코드 추가
zangsu Jul 18, 2024
ea6a80d
chore: validation 의존성 추가
zangsu Jul 18, 2024
c8d8db8
refactor(template): Snippet 도메인을 Template 하위로 이동
zangsu Jul 19, 2024
3ed0c06
feat(codezap): 템플릿 DTO 유효성 검증 및 테스트 추가
zangsu Jul 19, 2024
83d85ff
refactor(template): ThumbnailSnippet 도메인을 Template 하위로 이동
zangsu Jul 19, 2024
00c5586
chore: 의존성 구분을 위해 개행 추가
zangsu Jul 22, 2024
55f793e
refactor(serialization): 패키지 이름 변경
zangsu Jul 22, 2024
ed328e7
refactor(template): Location 헤더 수정 및 테스트 추가
zangsu Jul 22, 2024
1d61b33
test(integration): Template 목록 조회 및 상세 조회 테스트 코드 추가
zangsu Jul 22, 2024
1afee81
refactor(template): 메서드 네이밍 변경
zangsu Jul 22, 2024
368d8ed
refactor(domain): 상수 네이밍 변경
zangsu Jul 22, 2024
7e64c2f
refactor(response): dto 필드 네이밍 변경
zangsu Jul 22, 2024
473dbea
refactor(response): 테스트 코드에서 불필요한 매직 스트링 제거
zangsu Jul 22, 2024
9f61bb2
refactor(exception): 가독성을 위해 줄바꿈 및 사용하는 정적 팩토리 메서드 변경
zangsu Jul 22, 2024
dede216
refactor(controller): 빈 문자열 파라미터 제거
zangsu Jul 22, 2024
390d0d5
refactor(domain): not null 제약조건 설정 방법 변경
zangsu Jul 22, 2024
7466794
refactor(domain): 불필요한 JoinColumn 제거
zangsu Jul 22, 2024
ce60635
refactor(response): DTO 이름을 직관적으로 변경 및 내부 클래스로 이동
zangsu Jul 22, 2024
0a4f42f
refactor(response): 파라미터를 2개 이상 받는 정팩메 이름을 of 로 변경
zangsu Jul 22, 2024
43e2bb3
refactor(exception): 예외 메시지 변경
zangsu Jul 22, 2024
242708f
refactor(integration): 메서드 사이에 개행 추가
zangsu Jul 22, 2024
aefb907
refactor(template): id를 받지 않는 도메인 생성자에
zangsu Jul 22, 2024
e939f42
test(service): repository 의존성 추가 및 테스트 코드 변경
zangsu Jul 22, 2024
56a8a77
refactor(integration): 최대 길이 상수화
zangsu Jul 22, 2024
e5965d5
refactor(serialization): timezone 설정 제거
zangsu Jul 23, 2024
89cafb0
refactor(controller): IntegrationTest를 ControllerTest로 이름 변경
zangsu Jul 23, 2024
8b3de77
refactor(exception): MethodArgumentNotValid 예외처리 메서드 NPE 경고 해결
zangsu Jul 23, 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
6 changes: 4 additions & 2 deletions backend/build.gradle
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ repositories {
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'


compileOnly 'org.projectlombok:lombok:0.11.0' compileOnly 'org.projectlombok:lombok:0.11.0'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'


implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'

runtimeOnly 'com.mysql:mysql-connector-j:9.0.0' runtimeOnly 'com.mysql:mysql-connector-j:9.0.0'


testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.5.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
} }


Expand Down
36 changes: 0 additions & 36 deletions backend/src/main/java/codezap/extension/domain/Extension.java

This file was deleted.

This file was deleted.

Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
package codezap.global.domain; package codezap.global.auditing;


import java.time.LocalDateTime; import java.time.LocalDateTime;


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
package codezap.global.domain; package codezap.global.auditing;


import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
package codezap.global; package codezap.global.cors;


import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
package codezap.global.exception;

import org.springframework.http.HttpStatusCode;

import lombok.Getter;

@Getter
public class CodeZapException extends RuntimeException {
private final HttpStatusCode httpStatusCode;

public CodeZapException(HttpStatusCode httpStatusCode, String message) {
super(message);
this.httpStatusCode = httpStatusCode;
}
}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
package codezap.global.exception;

import java.util.stream.Collectors;

import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler
Copy link
Contributor

Choose a reason for hiding this comment

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

사소하지만 @ExceptionHandler@ExceptionHandler(CodeZapException.class) 로 해당 메서드가 어떤 exception을 처리하는지 명시해주면 좋을 것 같아요 😊

Copy link
Contributor

Choose a reason for hiding this comment

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

메서드명과 매개변수만으로도 충분히 어떤 exception을 처리하는지 알 수 있다고 생각해서 불필요한 코드라고 판단하였습니다.

public ResponseEntity<ProblemDetail> handleCodeZapException(CodeZapException codeZapException) {
return ResponseEntity.status(codeZapException.getHttpStatusCode())
.body(ProblemDetail.forStatusAndDetail(
codeZapException.getHttpStatusCode(),
codeZapException.getMessage())
);
}

@ExceptionHandler
public ResponseEntity<ProblemDetail> handleMethodArgumentNotValidException(
MethodArgumentNotValidException exception
) {
BindingResult bindingResult = exception.getBindingResult();
return ResponseEntity.badRequest()
.body(ProblemDetail.forStatusAndDetail(
HttpStatus.BAD_REQUEST,
bindingResult.getFieldErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.joining())
)
);
}

@ExceptionHandler
public ResponseEntity<ProblemDetail> handleException(Exception exception) {
return ResponseEntity.internalServerError()
.body(ProblemDetail.forStatusAndDetail(
HttpStatus.INTERNAL_SERVER_ERROR,
"서버에서 예상치 못한 오류가 발생하였습니다.")
);
}
}
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
package codezap.global; package codezap.global.serialization;


import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.TimeZone; import java.util.TimeZone;
Expand All @@ -15,10 +15,7 @@ public class DateTimeFormatConfiguration {


@Bean @Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
return jacksonObjectMapperBuilder -> { return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.serializers(
jacksonObjectMapperBuilder.timeZone(TimeZone.getTimeZone("UTC")); new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
jacksonObjectMapperBuilder.serializers(
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
};
} }
} }
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
package codezap.global; package codezap.global.swagger;


import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
Expand Down
28 changes: 0 additions & 28 deletions backend/src/main/java/codezap/language/domain/Language.java

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions backend/src/main/java/codezap/member/domain/Member.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import java.net.URI; import java.net.URI;


import jakarta.validation.Valid;

import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -21,14 +23,16 @@ public class TemplateController implements SpringDocTemplateController {


private final TemplateService templateService; private final TemplateService templateService;


public TemplateController(TemplateService templateService) {this.templateService = templateService;} public TemplateController(TemplateService templateService) {
this.templateService = templateService;
}


@PostMapping("") @PostMapping
public ResponseEntity<Void> create(@RequestBody CreateTemplateRequest createTemplateRequest) { public ResponseEntity<Void> create(@Valid @RequestBody CreateTemplateRequest createTemplateRequest) {
return ResponseEntity.created(URI.create("/templates" + templateService.create(createTemplateRequest))).build(); return ResponseEntity.created(URI.create("/templates/" + templateService.create(createTemplateRequest))).build();
} }


@GetMapping("") @GetMapping
public ResponseEntity<FindAllTemplatesResponse> getTemplates() { public ResponseEntity<FindAllTemplatesResponse> getTemplates() {
return ResponseEntity.ok(templateService.findAll()); return ResponseEntity.ok(templateService.findAll());
} }
Expand Down
Loading