-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UKET1-6] Migration 모듈 생성 및 기본 설정/파일 추가 (#107)
* feat : migration 모듈 생성 및 기본 구성 - build.gradle - application.yml - 기본 config - 메일 관련 properties - 기본 Entity - BaseException/ErrorCode - ErrorResponse * fix : application.yml에서 token을 ticket-token/admin-token으로 구분 TicketProperties, JwtConfig 등에서 수정 필요 * refactor : TokenProperties를 확장 가능하게 변경
- Loading branch information
1 parent
81e3c41
commit 36ba00a
Showing
22 changed files
with
655 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
group = 'com.uket' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
implementation 'org.springframework.boot:spring-boot-starter-mail' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
|
||
//spring-data | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
|
||
//database | ||
runtimeOnly 'com.mysql:mysql-connector-j' | ||
runtimeOnly 'com.h2database:h2' | ||
|
||
//QueryDsl | ||
api 'com.querydsl:querydsl-jpa:5.0.0:jakarta' | ||
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" | ||
annotationProcessor "jakarta.annotation:jakarta.annotation-api" | ||
annotationProcessor "jakarta.persistence:jakarta.persistence-api" | ||
|
||
//swagger | ||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.uket; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan; | ||
import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
|
||
@SpringBootApplication | ||
@ConfigurationPropertiesScan | ||
@EnableAspectJAutoProxy | ||
public class UketApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(UketApplication.class, args); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
migration/src/main/java/com/uket/app/config/BaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.uket.app.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class BaseConfig { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
migration/src/main/java/com/uket/app/config/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.uket.app.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class CorsConfig implements WebMvcConfigurer { | ||
|
||
private static final String ALLOWED_METHOD_NAMES = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,PATCH"; | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedMethods(ALLOWED_METHOD_NAMES.split(",")) | ||
.allowedOriginPatterns("*") | ||
.allowedHeaders("*") | ||
.exposedHeaders(HttpHeaders.AUTHORIZATION) | ||
.allowCredentials(true) | ||
.maxAge(3600); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
migration/src/main/java/com/uket/app/config/EmailConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.uket.app.config; | ||
|
||
import com.uket.app.properties.EmailProperties; | ||
import com.uket.app.properties.SmtpProperties; | ||
import java.util.Properties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class EmailConfig { | ||
|
||
private final EmailProperties emailProperties; | ||
private final SmtpProperties smtpProperties; | ||
|
||
@Bean | ||
public JavaMailSender javaMailSender() { | ||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); | ||
mailSender.setHost(emailProperties.host()); | ||
mailSender.setPort(emailProperties.port()); | ||
mailSender.setUsername(emailProperties.username()); | ||
mailSender.setPassword(emailProperties.password()); | ||
mailSender.setDefaultEncoding("UTF-8"); | ||
mailSender.setJavaMailProperties(getMailProperties()); | ||
|
||
return mailSender; | ||
} | ||
|
||
private Properties getMailProperties() { | ||
Properties properties = new Properties(); | ||
properties.put("mail.smtp.auth", smtpProperties.auth()); | ||
properties.put("mail.smtp.starttls.enable", smtpProperties.starttls().enable()); | ||
properties.put("mail.smtp.starttls.required", smtpProperties.starttls().required()); | ||
properties.put("mail.smtp.connectiontimeout", smtpProperties.connectiontimeout()); | ||
properties.put("mail.smtp.timeout", smtpProperties.timeout()); | ||
properties.put("mail.smtp.writetimeout", smtpProperties.writetimeout()); | ||
|
||
return properties; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
migration/src/main/java/com/uket/app/config/QuerydslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.uket.app.config; | ||
|
||
import com.querydsl.jpa.JPQLTemplates; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QuerydslConfig { | ||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(JPQLTemplates.DEFAULT, entityManager); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
migration/src/main/java/com/uket/app/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.uket.app.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.servers.Server; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpHeaders; | ||
|
||
@OpenAPIDefinition( | ||
servers = @Server(url = "/", description = "Default Server URL"), | ||
info = @Info( | ||
title = "Uket API 명세", | ||
description = "springdoc을 이용한 Swagger API 문서입니다.", | ||
version = "1.0", | ||
contact = @Contact( | ||
name = "springdoc 공식문서", | ||
url = "https://springdoc.org/" | ||
) | ||
) | ||
) | ||
@RequiredArgsConstructor | ||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
@Bean | ||
public OpenAPI customOpenAPI() { | ||
return new OpenAPI() | ||
.components(new Components().addSecuritySchemes("JWT", bearerAuth())); | ||
} | ||
|
||
public SecurityScheme bearerAuth() { | ||
return new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("Bearer") | ||
.bearerFormat("JWT") | ||
.in(SecurityScheme.In.HEADER) | ||
.name(HttpHeaders.AUTHORIZATION); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
migration/src/main/java/com/uket/app/domain/entity/BaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.uket.app.domain.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.sql.Timestamp; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class BaseEntity { | ||
|
||
@CreatedDate | ||
@Column(name = "created_at", updatable = false) | ||
private Timestamp createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(name = "modified_at") | ||
private Timestamp modifiedAt; | ||
} |
21 changes: 21 additions & 0 deletions
21
migration/src/main/java/com/uket/app/domain/entity/DeletableBaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.uket.app.domain.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class DeletableBaseEntity extends BaseEntity { | ||
|
||
@Column(name = "deleted_at") | ||
private LocalDateTime deletedAt; | ||
|
||
public void updateDeletedAt() { | ||
this.deletedAt = LocalDateTime.now(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
migration/src/main/java/com/uket/app/dto/response/ErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.uket.app.dto.response; | ||
|
||
import com.uket.app.exception.ErrorCode; | ||
|
||
public record ErrorResponse( | ||
String code, | ||
String message | ||
) { | ||
public static ErrorResponse of(String code, String message) { | ||
return new ErrorResponse(code, message); | ||
} | ||
|
||
public static ErrorResponse of(ErrorCode errorCode) { | ||
return new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
migration/src/main/java/com/uket/app/exception/BaseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.uket.app.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BaseException extends RuntimeException{ | ||
private final ErrorCode errorCode; | ||
|
||
public BaseException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
Oops, something went wrong.