diff --git a/build.gradle b/build.gradle index b0e7626..0faab72 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-redis' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' runtimeOnly 'com.mysql:mysql-connector-j' diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..8f7e8aa --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/src/main/java/com/integrated/techhub/common/config/RedisConfig.java b/src/main/java/com/integrated/techhub/common/config/RedisConfig.java new file mode 100644 index 0000000..38c78f6 --- /dev/null +++ b/src/main/java/com/integrated/techhub/common/config/RedisConfig.java @@ -0,0 +1,25 @@ +package com.integrated.techhub.common.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; + +@Configuration +@EnableRedisRepositories +public class RedisConfig { + + @Value("${spring.data.redis.host}") + private String host; + + @Value("${spring.data.redis.port}") + private int port; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(host, port); + } + +} \ No newline at end of file diff --git a/src/main/java/com/integrated/techhub/member/domain/AuthorityCode.java b/src/main/java/com/integrated/techhub/member/domain/AuthorityCode.java new file mode 100644 index 0000000..331509b --- /dev/null +++ b/src/main/java/com/integrated/techhub/member/domain/AuthorityCode.java @@ -0,0 +1,21 @@ +package com.integrated.techhub.member.domain; + +import lombok.Getter; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; + +@Getter +@RedisHash(value = "authority_code", timeToLive = 180) +public class AuthorityCode { + + @Id + private String email; + + private Integer value; + + public AuthorityCode(String email, Integer value) { + this.email = email; + this.value = value; + } + +} diff --git a/src/main/java/com/integrated/techhub/member/domain/Member.java b/src/main/java/com/integrated/techhub/member/domain/Member.java new file mode 100644 index 0000000..890f755 --- /dev/null +++ b/src/main/java/com/integrated/techhub/member/domain/Member.java @@ -0,0 +1,51 @@ +package com.integrated.techhub.member.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +@Getter +@Entity +@NoArgsConstructor(access = PROTECTED) +public class Member { + + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + + @Column(length = 32, nullable = false, unique = true) + private String email; + + @Column(length = 128, nullable = false) + private String password; + + @Column(length = 4, nullable = false) + private String nickname; + + @Column(length = 6, nullable = false) + private String name; + + @Column(length = 128) + private String bio; + + @Column + @Enumerated(value = STRING) + private Position position; + + public Member(String email, String password, String nickname, String name, String bio, Position position) { + this.email = email; + this.password = password; + this.nickname = nickname; + this.name = name; + this.bio = bio; + this.position = position; + } +} diff --git a/src/main/java/com/integrated/techhub/member/domain/Position.java b/src/main/java/com/integrated/techhub/member/domain/Position.java new file mode 100644 index 0000000..d2fd050 --- /dev/null +++ b/src/main/java/com/integrated/techhub/member/domain/Position.java @@ -0,0 +1,9 @@ +package com.integrated.techhub.member.domain; + +public enum Position { + + BE, + FE, + AOS + +} diff --git a/src/main/java/com/integrated/techhub/member/domain/repository/AuthorityCodeRepository.java b/src/main/java/com/integrated/techhub/member/domain/repository/AuthorityCodeRepository.java new file mode 100644 index 0000000..cacae74 --- /dev/null +++ b/src/main/java/com/integrated/techhub/member/domain/repository/AuthorityCodeRepository.java @@ -0,0 +1,10 @@ +package com.integrated.techhub.member.domain.repository; + +import com.integrated.techhub.member.domain.AuthorityCode; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AuthorityCodeRepository extends CrudRepository { + +} diff --git a/src/main/java/com/integrated/techhub/member/domain/repository/MemberRepository.java b/src/main/java/com/integrated/techhub/member/domain/repository/MemberRepository.java new file mode 100644 index 0000000..87f3365 --- /dev/null +++ b/src/main/java/com/integrated/techhub/member/domain/repository/MemberRepository.java @@ -0,0 +1,8 @@ +package com.integrated.techhub.member.domain.repository; + +import com.integrated.techhub.member.domain.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9be8e15..560f1a1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,10 @@ +# redis +spring: + data: + redis: + host: localhost + port: ${REDIS_OUT_BOUND_PORT} + --- # application spring: diff --git a/src/test/java/com/integrated/techhub/TechhubApplicationTests.java b/src/test/java/com/integrated/techhub/TechhubApplicationTests.java index 0d0cca3..882abbd 100644 --- a/src/test/java/com/integrated/techhub/TechhubApplicationTests.java +++ b/src/test/java/com/integrated/techhub/TechhubApplicationTests.java @@ -3,7 +3,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest +@SpringBootTest(properties = {"spring.location=classpath:application.yml"}) class TechhubApplicationTests { @Test diff --git a/src/test/java/com/integrated/techhub/member/domain/AuthorityCodeTest.java b/src/test/java/com/integrated/techhub/member/domain/AuthorityCodeTest.java new file mode 100644 index 0000000..85423cd --- /dev/null +++ b/src/test/java/com/integrated/techhub/member/domain/AuthorityCodeTest.java @@ -0,0 +1,14 @@ +package com.integrated.techhub.member.domain; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class AuthorityCodeTest { + + @Test + void 생성자를_생성할수_있다() { + assertDoesNotThrow(() -> new AuthorityCode("email@email.com", 987654)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/integrated/techhub/member/domain/MemberTest.java b/src/test/java/com/integrated/techhub/member/domain/MemberTest.java new file mode 100644 index 0000000..1b00f14 --- /dev/null +++ b/src/test/java/com/integrated/techhub/member/domain/MemberTest.java @@ -0,0 +1,15 @@ +package com.integrated.techhub.member.domain; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +class MemberTest { + + @Test + void 생성자를_생성할수_있다() { + assertDoesNotThrow(() -> new Member("moomin@gmail.com", "moomin12", "무민", + "홍길동", "반갑습니다", Position.BE)); + } + +} \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index c5b3d44..76ca71e 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -19,6 +19,10 @@ spring: h2: console: enabled: true + data: + redis: + host: localhost + port: 6379 jwt: secret-key: this1-is2-techhub3-test4-secret5-key6 expire-length: 604800000