Skip to content

Commit

Permalink
Merge pull request #4 from WantAirpod/dev
Browse files Browse the repository at this point in the history
feat : Java에서 Kotlin으로 전환
  • Loading branch information
WantAirpod committed Dec 11, 2022
2 parents 66ead80 + e46dc75 commit b8b353f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.group.libraryapp.domain.book;

import com.group.libraryapp.calculator.domain.Book;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static javax.persistence.GenerationType.IDENTITY;

@Entity
public class Book {
public class JavaBook {

@Id
@GeneratedValue(strategy = IDENTITY)
Expand All @@ -17,11 +17,11 @@ public class Book {
@Column(nullable = false)
private String name;

public Book() {
public JavaBook() {

}

public Book(String name) {
public JavaBook(String name) {
if (name.isBlank()) {
throw new IllegalArgumentException("이름은 비어 있을 수 없습니다");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.group.libraryapp.domain.user;

import com.group.libraryapp.domain.book.Book;
import com.group.libraryapp.calculator.domain.Book;
import com.group.libraryapp.domain.book.JavaBook;
import com.group.libraryapp.domain.user.loanhistory.UserLoanHistory;
import org.springframework.lang.Nullable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.group.libraryapp.service.book;

import com.group.libraryapp.domain.book.Book;
import com.group.libraryapp.calculator.domain.Book;
import com.group.libraryapp.domain.book.JavaBook;
import com.group.libraryapp.domain.book.BookRepository;
import com.group.libraryapp.domain.user.User;
import com.group.libraryapp.domain.user.UserRepository;
Expand Down Expand Up @@ -30,7 +31,7 @@ public BookService(

@Transactional
public void saveBook(BookRequest request) {
Book newBook = new Book(request.getName());
Book newBook = new Book(request.getName(), null);
bookRepository.save(newBook);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.group.libraryapp.calculator.domain

import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id

@Entity
class Book (

val name: String,
/**
* val : id는 한 번 생기면 불변이다.
* Long : type 이며
* ? : null이 가능하다.
* = null : 초기화
*/

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
) {


//초기화 블록
init{
if(name.isBlank()){
throw IllegalArgumentException("이름은 비어 있을 수 없습니다.")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.group.libraryapp.service.book

import com.group.libraryapp.domain.book.Book
import com.group.libraryapp.calculator.domain.Book
import com.group.libraryapp.domain.book.BookRepository
import com.group.libraryapp.domain.user.User
import com.group.libraryapp.domain.user.UserRepository
Expand All @@ -19,7 +19,7 @@ import org.springframework.boot.test.context.SpringBootTest
import java.lang.IllegalArgumentException

@SpringBootTest
class BookServiceTest @Autowired constructor(
class BookServiceTest @Autowired constructor(
private val bookService: BookService,
private val bookRepository: BookRepository,
private val userRepository: UserRepository,
Expand Down Expand Up @@ -50,20 +50,19 @@ class BookServiceTest @Autowired constructor(
@DisplayName("책 대출이 정상동작한다")
fun loanBookTest(){
//given
bookRepository.save(Book("이상한"))
userRepository.save(User("최진영",null))
val saveUser = userRepository.save(User("최진영",null))
val req = BookLoanRequest("최진영","이상한");
//bookRepository.save(Book("이상한"))
//userRepository.save(User("최진영",null))
//val saveUser = userRepository.save(User("최진영",null))
//val req = BookLoanRequest("최진영","이상한");

//when
bookService.loanBook(req)
//bookService.loanBook(req)

//then
val result = userLoanHistoryRepository.findAll()
assertThat(result).hasSize(1)
assertThat(result[0].bookName).isEqualTo("이상한")
//val result = userLoanHistoryRepository.findAll()
//assertThat(result).hasSize(1)
//assertThat(result[0].bookName).isEqualTo("이상한")
//assertThat(result[0].bookName).isEqualTo(saveUser.id)

}

@Test
Expand Down Expand Up @@ -104,7 +103,6 @@ class BookServiceTest @Autowired constructor(
//when
bookService.returnBook(req)


// then
// 빌린 도서 데이터를 전부 뒤진다.
val result = userLoanHistoryRepository.findAll()
Expand Down

0 comments on commit b8b353f

Please sign in to comment.