Skip to content

Commit

Permalink
Merge pull request #7 from woowacourse-integrated-service/feature/#3
Browse files Browse the repository at this point in the history
feat:Member, AuthorityCode 생성
  • Loading branch information
parkmuhyeun authored Sep 16, 2023
2 parents 3a69381 + 66a5315 commit 1510230
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
51 changes: 51 additions & 0 deletions src/main/java/com/integrated/techhub/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.integrated.techhub.member.domain;

public enum Position {

BE,
FE,
AOS

}
Original file line number Diff line number Diff line change
@@ -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<AuthorityCode, String> {

}
Original file line number Diff line number Diff line change
@@ -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<Member, Long> {

}
7 changes: 7 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# redis
spring:
data:
redis:
host: localhost
port: ${REDIS_OUT_BOUND_PORT}

---
# application
spring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 protected]", 987654));
}

}
15 changes: 15 additions & 0 deletions src/test/java/com/integrated/techhub/member/domain/MemberTest.java
Original file line number Diff line number Diff line change
@@ -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("[email protected]", "moomin12", "무민",
"홍길동", "반갑습니다", Position.BE));
}

}
4 changes: 4 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1510230

Please sign in to comment.