forked from KakaoTech-BootCamp-Team-2/Kaboo-Auth
-
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.
Feat: Member, Profile Entity, MemberRepository 추가
+ MemberRepositoryTest 추가 Related to: KakaoTech-BootCamp-Team-2#1
- Loading branch information
1 parent
51b5daf
commit 0f1e1eb
Showing
8 changed files
with
199 additions
and
20 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 |
---|---|---|
@@ -1,40 +1,41 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '3.3.2' | ||
id 'io.spring.dependency-management' version '1.1.6' | ||
id 'java' | ||
id 'org.springframework.boot' version '3.3.2' | ||
id 'io.spring.dependency-management' version '1.1.6' | ||
} | ||
|
||
group = 'kaboo' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-security' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'org.springframework.security:spring-security-test' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-security' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'org.springframework.security:spring-security-test' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
testRuntimeOnly 'com.h2database:h2' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
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,40 @@ | ||
package kaboo.kaboo_auth.domain.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class Member { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "member_id") | ||
private Long id; | ||
|
||
@Setter | ||
private String username; | ||
|
||
@Setter | ||
private String nickname; | ||
|
||
@Setter | ||
private String password; | ||
|
||
@Setter | ||
private String info; | ||
|
||
@Builder | ||
public Member(String username, String nickname, String password) { | ||
this.username = username; | ||
this.nickname = nickname; | ||
this.password = password; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/kaboo/kaboo_auth/domain/entity/ProfileImage.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,34 @@ | ||
package kaboo.kaboo_auth.domain.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToOne; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class ProfileImage { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
@Setter | ||
@Column(name = "image_name") | ||
private String imageName; | ||
|
||
public ProfileImage(Member member, String imageName) { | ||
this.member = member; | ||
this.imageName = imageName; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/kaboo/kaboo_auth/repository/MemberRepository.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,11 @@ | ||
package kaboo.kaboo_auth.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import kaboo.kaboo_auth.domain.entity.Member; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
Optional<Member> findByUsername(String username); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/kaboo/kaboo_auth/repository/ProfileImageRepository.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,8 @@ | ||
package kaboo.kaboo_auth.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import kaboo.kaboo_auth.domain.entity.ProfileImage; | ||
|
||
public interface ProfileImageRepository extends JpaRepository<ProfileImage, Long> { | ||
} |
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
spring.application.name=kaboo-auth | ||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver | ||
spring.datasource.url=${DB_URL} | ||
spring.datasource.username=${DB_USERNAME} | ||
spring.datasource.password=${DB_PASSWORD} | ||
spring.jpa.show-sql=true | ||
spring.jpa.hibernate.ddl-auto=create |
61 changes: 61 additions & 0 deletions
61
src/test/java/kaboo/kaboo_auth/repository/MemberRepositoryTest.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,61 @@ | ||
package kaboo.kaboo_auth.repository; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import kaboo.kaboo_auth.domain.entity.Member; | ||
|
||
@DataJpaTest | ||
@Transactional | ||
@DisplayName("Member Repository Test") | ||
class MemberRepositoryTest { | ||
@Autowired | ||
MemberRepository memberRepository; | ||
|
||
@Test | ||
@DisplayName("DB 저장 Test") | ||
void saveMemberTest() { | ||
// Given | ||
Member member = Member.builder().username("Alice").nickname("Alice").password("1234").build(); | ||
memberRepository.save(member); | ||
|
||
// When | ||
Member result = memberRepository.findById(member.getId()).get(); | ||
|
||
// Then | ||
assertEquals(result, member); | ||
} | ||
|
||
@Test | ||
@DisplayName("Username으로 찾기 성공 Test") | ||
void findByUsername_Success() { | ||
// Given | ||
Member member1 = Member.builder().username("Alice").nickname("Alice").password("1234").build(); | ||
memberRepository.save(member1); | ||
|
||
// When | ||
Member result = memberRepository.findByUsername("Alice").get(); | ||
|
||
// Then | ||
assertEquals(result, member1); | ||
} | ||
|
||
@Test | ||
@DisplayName("Username 존재하지 않을 때 Test") | ||
void findByUsername_Failure() { | ||
// Given | ||
|
||
// When | ||
Optional<Member> result = memberRepository.findByUsername("Alice"); | ||
|
||
// Then | ||
assertEquals(result, Optional.empty()); | ||
} | ||
} |
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,18 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:h2:mem:test;MODE=MariaDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE | ||
username: sa | ||
password: | ||
driverClassName: org.h2.Driver | ||
jpa: | ||
database-platform: org.hibernate.dialect.H2Dialect | ||
hibernate: | ||
ddl-auto: update | ||
show-sql: true | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
h2: | ||
console: | ||
enabled: true | ||
path: /h2-console |