lab2 fixed books and changed LibraryApplication
This commit is contained in:
parent
bd96507bc7
commit
7f502d2548
@ -1,13 +1,64 @@
|
|||||||
package com.ip.library;
|
package com.ip.library;
|
||||||
|
|
||||||
|
import org.modelmapper.internal.util.Objects;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import com.ip.library.authors.model.AuthorEntity;
|
||||||
|
import com.ip.library.authors.service.AuthorService;
|
||||||
|
import com.ip.library.books.model.BookEntity;
|
||||||
|
import com.ip.library.books.service.BookService;
|
||||||
|
import com.ip.library.types.model.TypeEntity;
|
||||||
|
import com.ip.library.types.service.TypeService;
|
||||||
|
import com.ip.library.users.model.UserEntity;
|
||||||
|
import com.ip.library.users.service.UserService;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class LibraryApplication {
|
public class LibraryApplication implements CommandLineRunner {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(LibraryApplication.class);
|
||||||
|
|
||||||
|
AuthorService authorService;
|
||||||
|
TypeService typeService;
|
||||||
|
BookService bookService;
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
public LibraryApplication (AuthorService authorService, TypeService typeService,
|
||||||
|
BookService bookService, UserService userService) {
|
||||||
|
this.authorService = authorService;
|
||||||
|
this.typeService = typeService;
|
||||||
|
this.bookService = bookService;
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(LibraryApplication.class, args);
|
SpringApplication.run(LibraryApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) throws Exception {
|
||||||
|
if (args.length > 0 && args[0].equals("--populate")) {
|
||||||
|
log.info("Create default types values");
|
||||||
|
final var type1 = typeService.create(new TypeEntity(null, "type1"));
|
||||||
|
final var type2 = typeService.create(new TypeEntity(null, "type2"));
|
||||||
|
|
||||||
|
log.info("Create default authors values");
|
||||||
|
final var author1 = authorService.create(new AuthorEntity(null, "author1"));
|
||||||
|
final var author2 = authorService.create(new AuthorEntity(null, "author2"));
|
||||||
|
|
||||||
|
log.info("Create default users values");
|
||||||
|
final var user1 = userService.create(new UserEntity(null, "user1", "123", "user"));
|
||||||
|
final var user2 = userService.create(new UserEntity(null, "user2", "123", "user"));
|
||||||
|
final var admin1 = userService.create(new UserEntity(null, "admin1", "123", "admin"));
|
||||||
|
|
||||||
|
log.info("Create default books values");
|
||||||
|
final var book1 = bookService.create(new BookEntity(null, "book1", type1, author1));
|
||||||
|
final var book2 = bookService.create(new BookEntity(null, "book2", type1, author2));
|
||||||
|
final var book3 = bookService.create(new BookEntity(null, "book3", type2, author1));
|
||||||
|
final var book4 = bookService.create(new BookEntity(null, "book4", type2, author2));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,13 @@ package com.ip.library.books.api;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class BookDto {
|
public class BookDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
@NotNull
|
@NotNull
|
||||||
@Min(1)
|
@Min(1)
|
||||||
private Long typeId;
|
private Long typeId;
|
||||||
|
@ -7,6 +7,7 @@ import com.ip.library.types.model.TypeEntity;
|
|||||||
import com.ip.library.authors.model.AuthorEntity;
|
import com.ip.library.authors.model.AuthorEntity;
|
||||||
|
|
||||||
public class BookEntity extends BaseEntity {
|
public class BookEntity extends BaseEntity {
|
||||||
|
private String name;
|
||||||
private TypeEntity type;
|
private TypeEntity type;
|
||||||
private AuthorEntity author;
|
private AuthorEntity author;
|
||||||
|
|
||||||
@ -14,12 +15,21 @@ public class BookEntity extends BaseEntity {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookEntity(Long id, TypeEntity type, AuthorEntity author) {
|
public BookEntity(Long id, String name, TypeEntity type, AuthorEntity author) {
|
||||||
super(id);
|
super(id);
|
||||||
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public TypeEntity getType() {
|
public TypeEntity getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -49,6 +59,7 @@ public class BookEntity extends BaseEntity {
|
|||||||
return false;
|
return false;
|
||||||
final BookEntity other = (BookEntity) obj;
|
final BookEntity other = (BookEntity) obj;
|
||||||
return Objects.equals(other.getId(), id)
|
return Objects.equals(other.getId(), id)
|
||||||
|
&& Objects.equals(other.getName(), name)
|
||||||
&& Objects.equals(other.getType(), type)
|
&& Objects.equals(other.getType(), type)
|
||||||
&& Objects.equals(other.getAuthor(), author);
|
&& Objects.equals(other.getAuthor(), author);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user