diff --git a/build.gradle b/build.gradle index 5c71d510..becf439f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.2.0' + id 'org.springframework.boot' version '3.3.0' id 'io.spring.dependency-management' version '1.1.4' } @@ -67,8 +67,8 @@ dependencies { // test && test h2 testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' - testRuntimeOnly 'com.h2database:h2:1.4.200' - +// testRuntimeOnly 'com.h2database:h2' + runtimeOnly 'com.h2database:h2' // swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' implementation 'org.springframework.boot:spring-boot-devtools' diff --git a/src/main/java/com/gt/genti/domain/Creator.java b/src/main/java/com/gt/genti/domain/Creator.java index 02ffceab..13cd246a 100644 --- a/src/main/java/com/gt/genti/domain/Creator.java +++ b/src/main/java/com/gt/genti/domain/Creator.java @@ -6,6 +6,8 @@ import com.gt.genti.domain.common.BaseTimeEntity; import com.gt.genti.domain.enums.BankType; +import com.gt.genti.domain.enums.Sex; +import com.gt.genti.domain.enums.UserStatus; import com.gt.genti.domain.enums.converter.db.BankTypeConverter; import jakarta.persistence.Column; @@ -17,6 +19,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import jakarta.persistence.PrePersist; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; @@ -50,7 +53,6 @@ public class Creator extends BaseTimeEntity { @Convert(converter = BankTypeConverter.class) @Column(name = "bank_type", nullable = false) - @ColumnDefault("NONE") BankType bankType; @Column(name = "account_number", nullable = false) @@ -64,6 +66,16 @@ public class Creator extends BaseTimeEntity { @Column(name = "completed_task_count", nullable = false) int completedTaskCount; + @PrePersist + public void prePersist() { + if (this.bankType == null) { + this.bankType = BankType.NONE; + } + if(this.workable == null){ + this.workable = true; + } + } + public Creator(User user) { this.workable = true; this.user = user; diff --git a/src/main/java/com/gt/genti/domain/DirectoryTraversalAttack.java b/src/main/java/com/gt/genti/domain/DirectoryTraversalAttack.java index 2315fb1c..1e7dd2dc 100644 --- a/src/main/java/com/gt/genti/domain/DirectoryTraversalAttack.java +++ b/src/main/java/com/gt/genti/domain/DirectoryTraversalAttack.java @@ -7,11 +7,13 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +@Table(name = "directory_traversal_attack") @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/com/gt/genti/domain/User.java b/src/main/java/com/gt/genti/domain/User.java index 22875edc..73178610 100644 --- a/src/main/java/com/gt/genti/domain/User.java +++ b/src/main/java/com/gt/genti/domain/User.java @@ -31,11 +31,14 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import jakarta.persistence.PrePersist; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +@Table(name = "users") // h2 예약어 해결법 못찾음 @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -57,7 +60,7 @@ public class User extends BaseTimeEntity { @Column(name = "email") String email; - @Column(name = "sex") + @Column(name = "sex", nullable = false) @Convert(converter = SexConverter.class) Sex sex; @@ -103,6 +106,7 @@ public class User extends BaseTimeEntity { LocalDateTime lastLoginDate; @Column(name = "login", nullable = false) + @ColumnDefault("false") Boolean login; // user hard delete시 deposit도 삭제 @@ -116,6 +120,19 @@ public class User extends BaseTimeEntity { @Column(name = "birth_date") LocalDate birthDate; + @PrePersist + public void prePersist() { + if (this.userStatus == null) { + this.userStatus = UserStatus.ACTIVATED; // 기본값 설정 + } + if (this.login == null) { + this.login = true; + } + if (this.sex == null){ + this.sex = Sex.NONE; + } + } + public static User createNewSocialUser(OAuthAttributes oauthAttributes) { String email = oauthAttributes.getEmail(); String username = oauthAttributes.getUsername(); @@ -184,7 +201,7 @@ public Boolean isLogin() { public User(List pictureProfileList, List pictureUserFaceList, String email, String introduction, String username, String nickname, UserStatus userStatus, Boolean emailVerified, String loginId, String password, - Creator creator, UserRole userRole, OauthType lastLoginSocialPlatform, LocalDateTime deletedAt) { + Creator creator, UserRole userRole, OauthType lastLoginSocialPlatform, LocalDateTime deletedAt, LocalDateTime lastLoginDate) { this.pictureProfileList = pictureProfileList; this.pictureUserFaceList = pictureUserFaceList; this.email = email; @@ -199,6 +216,7 @@ public User(List pictureProfileList, List pictu this.userRole = userRole; this.lastLoginSocialPlatform = lastLoginSocialPlatform; this.deletedAt = deletedAt; + this.lastLoginDate = lastLoginDate; } public void addRequestCount() { diff --git a/src/main/java/com/gt/genti/other/config/SecurityConfig.java b/src/main/java/com/gt/genti/other/config/SecurityConfig.java index e8f7527d..7eea8d55 100644 --- a/src/main/java/com/gt/genti/other/config/SecurityConfig.java +++ b/src/main/java/com/gt/genti/other/config/SecurityConfig.java @@ -63,7 +63,9 @@ public class SecurityConfig { "/swagger-ui/**", "/swagger-resources/**", "/v3/api-docs/**", - "/api-docs/**" + "/api-docs/**", + "/h2-console/**", + "/h2-console" }; public static String[] COMMON_RESOURCE_AND_ALLOWED_URL; diff --git a/src/main/java/com/gt/genti/repository/UserRepository.java b/src/main/java/com/gt/genti/repository/UserRepository.java index 49580c56..9dc82429 100644 --- a/src/main/java/com/gt/genti/repository/UserRepository.java +++ b/src/main/java/com/gt/genti/repository/UserRepository.java @@ -12,8 +12,6 @@ import com.gt.genti.domain.User; import com.gt.genti.domain.enums.UserRole; -import io.lettuce.core.Value; - public interface UserRepository extends JpaRepository { Optional findByEmail(String email); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 970bc741..e09f3f63 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -3,6 +3,7 @@ spring: group: local: deploy: + test: include: - secret - common diff --git a/src/test/java/com/gt/genti/service/MatchTest.java b/src/test/java/com/gt/genti/service/MatchTest.java index 634e6a74..a3cfa151 100644 --- a/src/test/java/com/gt/genti/service/MatchTest.java +++ b/src/test/java/com/gt/genti/service/MatchTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; +import java.time.LocalDateTime; import java.util.List; import org.jetbrains.annotations.NotNull; @@ -33,7 +34,7 @@ import com.gt.genti.repository.UserRepository; import com.gt.genti.service.config.TestConfig; -@ActiveProfiles("test") +@ActiveProfiles({"test", "common", "secret"}) @SpringBootTest(classes = TestConfig.class) public class MatchTest { @Autowired @@ -43,10 +44,10 @@ public class MatchTest { PictureService pictureService; @Autowired - UserRepository uploaderRepository; + UserRepository userRepository; @Autowired - UserService uploaderService; + UserService userService; @Autowired AdminService adminService; @@ -58,12 +59,12 @@ public class MatchTest { public void oneRequestWithAdminStrategy() { // given User requester = getTestUser(); - User savedUser = uploaderRepository.save(requester); + User savedUser = userRepository.save(requester); User adminUser = getTestAdminUser(); - User savedAdmin = uploaderRepository.save(adminUser); + User savedAdmin = userRepository.save(adminUser); // admin으로 uploaderrole 변경시 admin creator 생성됨 - uploaderService.updateUserRole(savedAdmin.getId(), + userService.updateUserRole(savedAdmin.getId(), UserRoleUpdateRequestDto.builder().userRole(UserRole.ADMIN).build()); CreatePicturePoseCommand command = getCreatePicturePoseCommand(savedUser); @@ -101,6 +102,7 @@ private User getTestAdminUser() { .userStatus(UserStatus.ACTIVATED) .lastLoginSocialPlatform(OauthType.GOOGLE) .username("adminusername") + .lastLoginDate(LocalDateTime.now()) .build(); } @@ -146,6 +148,7 @@ private static User getTestUser() { .nickname("nickname") .pictureUserFaceList(null) .username("username") + .lastLoginDate(LocalDateTime.now()) .build(); } } diff --git a/src/test/resources/application-test.yaml b/src/test/resources/application-test.yaml index 57c16b0c..da7d84db 100644 --- a/src/test/resources/application-test.yaml +++ b/src/test/resources/application-test.yaml @@ -15,19 +15,19 @@ spring: settings: web-allow-others: true datasource: - url: jdbc:h2:mem:test;MODE=MySQL + url: jdbc:h2:mem:test;MODE=MySQL;DATABASE_TO_UPPER=false;CASE_INSENSITIVE_IDENTIFIERS=true;DB_CLOSE_DELAY=-1 username: sa password: driver-class-name: org.h2.Driver jpa: hibernate: - ddl-auto: create + ddl-auto: update properties: hibernate: format_sql: 'true' use_sql_comments: 'true' show_sql: 'true' - dialect: org.hibernate.dialect.MySQL8Dialect + dialect: org.hibernate.dialect.MySQLDialect redis: host: localhost