Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/main/java/com/box/library/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import com.box.library.author.Author;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "books")
public class Book {
Expand All @@ -34,16 +34,9 @@ public class Book {
private String publisher;
private String ISBN;


@Builder.Default
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private BookStatus status = BookStatus.AVAILABLE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fala jovem, estou levando uma exception ao criar o livro, aparentemente está tentando colocar null no status.
Acredito que esteja faltando a anotação para dizer que o status é aquele padrão available.
Se eu não me engano a annotation é "@Builder.Default". Depois dá um confere ae pfv.

image


public Book(String title, List<Author> authors, String publisher, String ISBN) {
this.title = title;
this.authors = authors;
this.publisher = publisher;
this.ISBN = ISBN;
}

}
9 changes: 8 additions & 1 deletion src/main/java/com/box/library/book/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ public BookService(BookRepository repository, AuthorService authorService) {

public Book create(CreateBookRequest request) {
var authors = authorService.findAllByIds(request.authorsIds());
var book = new Book(request.title(), authors, request.publisher(), request.ISBN());

var book = Book.builder()
.title(request.title())
.authors(authors)
.publisher(request.publisher())
.ISBN(request.ISBN())
.build();

return repository.save(book);
}

Expand Down
65 changes: 7 additions & 58 deletions src/main/java/com/box/library/loan/Loan.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.box.library.loan;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "loans")
public class Loan {
Expand All @@ -22,9 +28,7 @@ public class Loan {
private LocalDate returnDate;
private LoanStatus status;

public Loan() {
}

@Builder
public Loan(Long userId, List<Long> booksIds) {
this.userId = userId;
this.booksIds = booksIds;
Expand All @@ -33,59 +37,4 @@ public Loan(Long userId, List<Long> booksIds) {
this.status = LoanStatus.ACTIVE;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getUserId() {
return userId;
}

public void setUserId(Long userId) {
this.userId = userId;
}

public List<Long> getBooksIds() {
return booksIds;
}

public void setBooksIds(List<Long> booksIds) {
this.booksIds = booksIds;
}

public LocalDate getLoanDate() {
return loanDate;
}

public void setLoanDate(LocalDate loanDate) {
this.loanDate = loanDate;
}

public LocalDate getExpectedReturnDate() {
return expectedReturnDate;
}

public void setExpectedReturnDate(LocalDate expectedReturnDate) {
this.expectedReturnDate = expectedReturnDate;
}

public LocalDate getReturnDate() {
return returnDate;
}

public void setReturnDate(LocalDate returnDate) {
this.returnDate = returnDate;
}

public LoanStatus getStatus() {
return status;
}

public void setStatus(LoanStatus status) {
this.status = status;
}
}
24 changes: 5 additions & 19 deletions src/main/java/com/box/library/user/LibraryUser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.box.library.user;

import jakarta.persistence.*;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "users")
public class LibraryUser {
Expand All @@ -11,24 +16,5 @@ public class LibraryUser {
private Long id;

private String username;

public LibraryUser() {
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
}