Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 3 additions & 10 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 Down Expand Up @@ -39,11 +39,4 @@ public class Book {
@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
67 changes: 8 additions & 59 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,70 +28,13 @@ 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;
this.loanDate = LocalDate.now();
this.expectedReturnDate = loanDate.plusDays(3);
this.expectedReturnDate = this.loanDate.plusDays(3);
Copy link
Owner

Choose a reason for hiding this comment

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

Que diferença fez o this e o Builder do topo? Tentou eliminar esse construtor pra fazer que nem fez com livro?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

É tipo uma ênfase pra evitar ambiguidade. As vezes eu gosto de colocar, pois o this vai driblar algum problema com variáveis ou parâmetros com o mesmo nome. Como tenho visto muitos conflitos aqui no Git, fiquei com medo de algo desse tipo.

Copy link
Owner

@gabrielvf64 gabrielvf64 Mar 10, 2025

Choose a reason for hiding this comment

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

Isso é mais em javascript. É uma alteração única sendo que em todo projeto não tá nesse padrão e os objetos estão sendo construidos sem problema.

Pra embasar mais ainda, você está com medo de conflitos no git, essa alteração do this vai justamente causar conflito em todas as branchs já abertas porque está alterando algo que já existe.

Reverte pra ser coisa a menos pra ver.

E quanto ao Builder e tentar replicar o que fez no book?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isso mesmo!

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;
}
}