From 2dddff0199fa64845be452b9cbcb91a9e2ae5eaa Mon Sep 17 00:00:00 2001 From: max Date: Tue, 25 Mar 2025 10:23:17 +0700 Subject: [PATCH] Init project --- .gitignore | 38 +++ .idea/.gitignore | 8 + .idea/encodings.xml | 7 + .idea/misc.xml | 17 ++ .idea/vcs.xml | 6 + pom.xml | 171 ++++++++++++ src/main/java/ru/cft/booklib/Main.java | 25 ++ .../ru/cft/booklib/controller/BooksApi.java | 22 ++ .../ru/cft/booklib/controller/ReadersApi.java | 22 ++ .../booklib/controller/TransactionsApi.java | 21 ++ .../booklib/controller/impl/BooksApiImpl.java | 23 ++ .../controller/impl/ReadersApiImpl.java | 19 ++ .../controller/impl/TransactionsApiImpl.java | 19 ++ src/main/java/ru/cft/booklib/model/Book.java | 180 ++++++++++++ .../java/ru/cft/booklib/model/BookCreate.java | 160 +++++++++++ src/main/java/ru/cft/booklib/model/Error.java | 98 +++++++ .../java/ru/cft/booklib/model/Reader.java | 189 +++++++++++++ .../ru/cft/booklib/model/ReaderCreate.java | 168 +++++++++++ .../ru/cft/booklib/model/Transaction.java | 214 ++++++++++++++ .../cft/booklib/model/TransactionCreate.java | 192 +++++++++++++ src/main/resources/META-INF/config.json | 13 + src/main/resources/openapi/book-library.yaml | 262 ++++++++++++++++++ 22 files changed, 1874 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/ru/cft/booklib/Main.java create mode 100644 src/main/java/ru/cft/booklib/controller/BooksApi.java create mode 100644 src/main/java/ru/cft/booklib/controller/ReadersApi.java create mode 100644 src/main/java/ru/cft/booklib/controller/TransactionsApi.java create mode 100644 src/main/java/ru/cft/booklib/controller/impl/BooksApiImpl.java create mode 100644 src/main/java/ru/cft/booklib/controller/impl/ReadersApiImpl.java create mode 100644 src/main/java/ru/cft/booklib/controller/impl/TransactionsApiImpl.java create mode 100644 src/main/java/ru/cft/booklib/model/Book.java create mode 100644 src/main/java/ru/cft/booklib/model/BookCreate.java create mode 100644 src/main/java/ru/cft/booklib/model/Error.java create mode 100644 src/main/java/ru/cft/booklib/model/Reader.java create mode 100644 src/main/java/ru/cft/booklib/model/ReaderCreate.java create mode 100644 src/main/java/ru/cft/booklib/model/Transaction.java create mode 100644 src/main/java/ru/cft/booklib/model/TransactionCreate.java create mode 100644 src/main/resources/META-INF/config.json create mode 100644 src/main/resources/openapi/book-library.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ba58be8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..39ad98e --- /dev/null +++ b/pom.xml @@ -0,0 +1,171 @@ + + + 4.0.0 + + ru.cft.booklib + cft-book-library + 1.0-SNAPSHOT + + + 3.14.0 + 21 + UTF-8 + UTF-8 + quarkus-bom + io.quarkus.platform + 3.19.4 + true + 3.5.2 + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy-jsonb + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + javax.annotation + javax.annotation-api + 1.3.2 + + + com.fasterxml.jackson.core + jackson-annotations + 2.18.3 + + + javax.validation + validation-api + 2.0.1.Final + + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + native-image-agent + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + org.openapitools + openapi-generator-maven-plugin + 7.8.0 + + ${project.basedir}/src/main/resources/openapi/book-library.yaml + jaxrs-spec + ru.cft.booklib.controller + ru.cft.booklib.model + + ApiUtil.java + + interfaceOnly=true,useSwaggerAnnotations=false + + quarkus + true + src/main/java + src/main/java + + + + + + + + + native + + + native + + + + false + true + + + + + + \ No newline at end of file diff --git a/src/main/java/ru/cft/booklib/Main.java b/src/main/java/ru/cft/booklib/Main.java new file mode 100644 index 0000000..9fac484 --- /dev/null +++ b/src/main/java/ru/cft/booklib/Main.java @@ -0,0 +1,25 @@ +package ru.cft.booklib; + +import io.quarkus.runtime.Quarkus; +import io.quarkus.runtime.QuarkusApplication; +import io.quarkus.runtime.annotations.QuarkusMain; + +@QuarkusMain +public class Main { + public static void main(String... args) { + Quarkus.run(MyApp.class, + (exitCode, exception) -> { + // do whatever + }, + args); + } + + public static class MyApp implements QuarkusApplication { + + @Override + public int run(String... args) throws Exception { + Quarkus.waitForExit(); + return 0; + } + } +} \ No newline at end of file diff --git a/src/main/java/ru/cft/booklib/controller/BooksApi.java b/src/main/java/ru/cft/booklib/controller/BooksApi.java new file mode 100644 index 0000000..ea1af98 --- /dev/null +++ b/src/main/java/ru/cft/booklib/controller/BooksApi.java @@ -0,0 +1,22 @@ +package ru.cft.booklib.controller; + +import jakarta.ws.rs.*; +import ru.cft.booklib.model.Book; +import ru.cft.booklib.model.BookCreate; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Path("/books") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public interface BooksApi { + + @POST + @Consumes({"application/json"}) + @Produces({"application/json"}) + Book bookPost(@Valid @NotNull BookCreate bookCreate); + + @GET + @Produces({"application/json"}) + List booksGet(); +} diff --git a/src/main/java/ru/cft/booklib/controller/ReadersApi.java b/src/main/java/ru/cft/booklib/controller/ReadersApi.java new file mode 100644 index 0000000..9adeee4 --- /dev/null +++ b/src/main/java/ru/cft/booklib/controller/ReadersApi.java @@ -0,0 +1,22 @@ +package ru.cft.booklib.controller; + +import jakarta.ws.rs.*; +import ru.cft.booklib.model.Reader; +import ru.cft.booklib.model.ReaderCreate; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Path("/readers") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public interface ReadersApi { + + @POST + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + Reader readerPost(@Valid @NotNull ReaderCreate readerCreate); + + @GET + @Produces({ "application/json" }) + List readersGet(); +} diff --git a/src/main/java/ru/cft/booklib/controller/TransactionsApi.java b/src/main/java/ru/cft/booklib/controller/TransactionsApi.java new file mode 100644 index 0000000..e78d9a8 --- /dev/null +++ b/src/main/java/ru/cft/booklib/controller/TransactionsApi.java @@ -0,0 +1,21 @@ +package ru.cft.booklib.controller; + +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.*; +import ru.cft.booklib.model.Transaction; +import ru.cft.booklib.model.TransactionCreate; +import java.util.List; + +@Path("/transactions") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public interface TransactionsApi { + + @GET + @Produces({ "application/json" }) + List transactionsGet(); + + @POST + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + Transaction transactionsPost(@NotNull TransactionCreate transactionCreate); +} diff --git a/src/main/java/ru/cft/booklib/controller/impl/BooksApiImpl.java b/src/main/java/ru/cft/booklib/controller/impl/BooksApiImpl.java new file mode 100644 index 0000000..b303d95 --- /dev/null +++ b/src/main/java/ru/cft/booklib/controller/impl/BooksApiImpl.java @@ -0,0 +1,23 @@ +package ru.cft.booklib.controller.impl; + +import ru.cft.booklib.controller.BooksApi; +import ru.cft.booklib.model.Book; +import ru.cft.booklib.model.BookCreate; + +import java.util.List; + +public class BooksApiImpl implements BooksApi { + @Override + public Book bookPost(BookCreate bookCreate) { + return null; + } + + @Override + public List booksGet() { + var book = new Book(); + book.setId(1); + book.setTitle("1984"); + + return List.of(book); + } +} diff --git a/src/main/java/ru/cft/booklib/controller/impl/ReadersApiImpl.java b/src/main/java/ru/cft/booklib/controller/impl/ReadersApiImpl.java new file mode 100644 index 0000000..cc71953 --- /dev/null +++ b/src/main/java/ru/cft/booklib/controller/impl/ReadersApiImpl.java @@ -0,0 +1,19 @@ +package ru.cft.booklib.controller.impl; + +import ru.cft.booklib.controller.ReadersApi; +import ru.cft.booklib.model.Reader; +import ru.cft.booklib.model.ReaderCreate; + +import java.util.List; + +public class ReadersApiImpl implements ReadersApi { + @Override + public Reader readerPost(ReaderCreate readerCreate) { + return null; + } + + @Override + public List readersGet() { + return List.of(); + } +} diff --git a/src/main/java/ru/cft/booklib/controller/impl/TransactionsApiImpl.java b/src/main/java/ru/cft/booklib/controller/impl/TransactionsApiImpl.java new file mode 100644 index 0000000..14b3594 --- /dev/null +++ b/src/main/java/ru/cft/booklib/controller/impl/TransactionsApiImpl.java @@ -0,0 +1,19 @@ +package ru.cft.booklib.controller.impl; + +import ru.cft.booklib.controller.TransactionsApi; +import ru.cft.booklib.model.Transaction; +import ru.cft.booklib.model.TransactionCreate; + +import java.util.List; + +public class TransactionsApiImpl implements TransactionsApi { + @Override + public List transactionsGet() { + return List.of(); + } + + @Override + public Transaction transactionsPost(TransactionCreate transactionCreate) { + return null; + } +} diff --git a/src/main/java/ru/cft/booklib/model/Book.java b/src/main/java/ru/cft/booklib/model/Book.java new file mode 100644 index 0000000..711828d --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/Book.java @@ -0,0 +1,180 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import javax.validation.Valid; +import javax.validation.constraints.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Книга + **/ + +@JsonTypeName("Book") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class Book { + private String title; + private @Valid List authors = new ArrayList<>(); + private Integer year; + private String genre; + private Integer id; + + /** + **/ + public Book title(String title) { + this.title = title; + return this; + } + + + @JsonProperty("title") + @NotNull public String getTitle() { + return title; + } + + @JsonProperty("title") + public void setTitle(String title) { + this.title = title; + } + + /** + **/ + public Book authors(List authors) { + this.authors = authors; + return this; + } + + + @JsonProperty("authors") + @NotNull @Size(min=1)public List getAuthors() { + return authors; + } + + @JsonProperty("authors") + public void setAuthors(List authors) { + this.authors = authors; + } + + public Book addAuthorsItem(String authorsItem) { + if (this.authors == null) { + this.authors = new ArrayList<>(); + } + + this.authors.add(authorsItem); + return this; + } + + public Book removeAuthorsItem(String authorsItem) { + if (authorsItem != null && this.authors != null) { + this.authors.remove(authorsItem); + } + + return this; + } + /** + **/ + public Book year(Integer year) { + this.year = year; + return this; + } + + + @JsonProperty("year") + public Integer getYear() { + return year; + } + + @JsonProperty("year") + public void setYear(Integer year) { + this.year = year; + } + + /** + **/ + public Book genre(String genre) { + this.genre = genre; + return this; + } + + + @JsonProperty("genre") + public String getGenre() { + return genre; + } + + @JsonProperty("genre") + public void setGenre(String genre) { + this.genre = genre; + } + + /** + **/ + public Book id(Integer id) { + this.id = id; + return this; + } + + + @JsonProperty("id") + @NotNull public Integer getId() { + return id; + } + + @JsonProperty("id") + public void setId(Integer id) { + this.id = id; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Book book = (Book) o; + return Objects.equals(this.title, book.title) && + Objects.equals(this.authors, book.authors) && + Objects.equals(this.year, book.year) && + Objects.equals(this.genre, book.genre) && + Objects.equals(this.id, book.id); + } + + @Override + public int hashCode() { + return Objects.hash(title, authors, year, genre, id); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Book {\n"); + + sb.append(" title: ").append(toIndentedString(title)).append("\n"); + sb.append(" authors: ").append(toIndentedString(authors)).append("\n"); + sb.append(" year: ").append(toIndentedString(year)).append("\n"); + sb.append(" genre: ").append(toIndentedString(genre)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/java/ru/cft/booklib/model/BookCreate.java b/src/main/java/ru/cft/booklib/model/BookCreate.java new file mode 100644 index 0000000..b5b456c --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/BookCreate.java @@ -0,0 +1,160 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Создание книги + **/ + +@JsonTypeName("BookCreate") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class BookCreate { + private String title; + private @Valid List authors = new ArrayList<>(); + private Integer year; + private String genre; + + /** + **/ + public BookCreate title(String title) { + this.title = title; + return this; + } + + + @JsonProperty("title") + @NotNull public String getTitle() { + return title; + } + + @JsonProperty("title") + public void setTitle(String title) { + this.title = title; + } + + /** + **/ + public BookCreate authors(List authors) { + this.authors = authors; + return this; + } + + + @JsonProperty("authors") + @NotNull @Size(min=1)public List getAuthors() { + return authors; + } + + @JsonProperty("authors") + public void setAuthors(List authors) { + this.authors = authors; + } + + public BookCreate addAuthorsItem(String authorsItem) { + if (this.authors == null) { + this.authors = new ArrayList<>(); + } + + this.authors.add(authorsItem); + return this; + } + + public BookCreate removeAuthorsItem(String authorsItem) { + if (authorsItem != null && this.authors != null) { + this.authors.remove(authorsItem); + } + + return this; + } + /** + **/ + public BookCreate year(Integer year) { + this.year = year; + return this; + } + + + @JsonProperty("year") + public Integer getYear() { + return year; + } + + @JsonProperty("year") + public void setYear(Integer year) { + this.year = year; + } + + /** + **/ + public BookCreate genre(String genre) { + this.genre = genre; + return this; + } + + + @JsonProperty("genre") + public String getGenre() { + return genre; + } + + @JsonProperty("genre") + public void setGenre(String genre) { + this.genre = genre; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BookCreate bookCreate = (BookCreate) o; + return Objects.equals(this.title, bookCreate.title) && + Objects.equals(this.authors, bookCreate.authors) && + Objects.equals(this.year, bookCreate.year) && + Objects.equals(this.genre, bookCreate.genre); + } + + @Override + public int hashCode() { + return Objects.hash(title, authors, year, genre); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BookCreate {\n"); + + sb.append(" title: ").append(toIndentedString(title)).append("\n"); + sb.append(" authors: ").append(toIndentedString(authors)).append("\n"); + sb.append(" year: ").append(toIndentedString(year)).append("\n"); + sb.append(" genre: ").append(toIndentedString(genre)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/java/ru/cft/booklib/model/Error.java b/src/main/java/ru/cft/booklib/model/Error.java new file mode 100644 index 0000000..8df9aaa --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/Error.java @@ -0,0 +1,98 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import javax.validation.constraints.NotNull; +import java.util.Objects; + +/** + * Http ошибка + **/ + +@JsonTypeName("Error") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class Error { + private Integer code; + private String message; + + /** + **/ + public Error code(Integer code) { + this.code = code; + return this; + } + + + @JsonProperty("code") + @NotNull public Integer getCode() { + return code; + } + + @JsonProperty("code") + public void setCode(Integer code) { + this.code = code; + } + + /** + **/ + public Error message(String message) { + this.message = message; + return this; + } + + + @JsonProperty("message") + @NotNull public String getMessage() { + return message; + } + + @JsonProperty("message") + public void setMessage(String message) { + this.message = message; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Error error = (Error) o; + return Objects.equals(this.code, error.code) && + Objects.equals(this.message, error.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, message); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Error {\n"); + + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/java/ru/cft/booklib/model/Reader.java b/src/main/java/ru/cft/booklib/model/Reader.java new file mode 100644 index 0000000..3ca882c --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/Reader.java @@ -0,0 +1,189 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; + +import javax.validation.constraints.NotNull; +import java.util.Objects; + +/** + * Читатель + **/ + +@JsonTypeName("Reader") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class Reader { + private String fullName; + public enum GenderEnum { + + MAN(String.valueOf("man")), FEMAIL(String.valueOf("femail")); + + + private String value; + + GenderEnum (String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + /** + * Convert a String into String, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static GenderEnum fromString(String s) { + for (GenderEnum b : GenderEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @JsonCreator + public static GenderEnum fromValue(String value) { + for (GenderEnum b : GenderEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private GenderEnum gender; + private Integer age; + private Integer id; + + /** + **/ + public Reader fullName(String fullName) { + this.fullName = fullName; + return this; + } + + + @JsonProperty("fullName") + @NotNull public String getFullName() { + return fullName; + } + + @JsonProperty("fullName") + public void setFullName(String fullName) { + this.fullName = fullName; + } + + /** + **/ + public Reader gender(GenderEnum gender) { + this.gender = gender; + return this; + } + + + @JsonProperty("gender") + public GenderEnum getGender() { + return gender; + } + + @JsonProperty("gender") + public void setGender(GenderEnum gender) { + this.gender = gender; + } + + /** + **/ + public Reader age(Integer age) { + this.age = age; + return this; + } + + + @JsonProperty("age") + public Integer getAge() { + return age; + } + + @JsonProperty("age") + public void setAge(Integer age) { + this.age = age; + } + + /** + **/ + public Reader id(Integer id) { + this.id = id; + return this; + } + + + @JsonProperty("id") + @NotNull public Integer getId() { + return id; + } + + @JsonProperty("id") + public void setId(Integer id) { + this.id = id; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Reader reader = (Reader) o; + return Objects.equals(this.fullName, reader.fullName) && + Objects.equals(this.gender, reader.gender) && + Objects.equals(this.age, reader.age) && + Objects.equals(this.id, reader.id); + } + + @Override + public int hashCode() { + return Objects.hash(fullName, gender, age, id); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Reader {\n"); + + sb.append(" fullName: ").append(toIndentedString(fullName)).append("\n"); + sb.append(" gender: ").append(toIndentedString(gender)).append("\n"); + sb.append(" age: ").append(toIndentedString(age)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/java/ru/cft/booklib/model/ReaderCreate.java b/src/main/java/ru/cft/booklib/model/ReaderCreate.java new file mode 100644 index 0000000..6fe1a12 --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/ReaderCreate.java @@ -0,0 +1,168 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; + +import javax.validation.constraints.NotNull; +import java.util.Objects; + +/** + * Добавление читателя + **/ + +@JsonTypeName("ReaderCreate") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class ReaderCreate { + private String fullName; + public enum GenderEnum { + + MAN(String.valueOf("man")), FEMAIL(String.valueOf("femail")); + + + private String value; + + GenderEnum (String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + /** + * Convert a String into String, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static GenderEnum fromString(String s) { + for (GenderEnum b : GenderEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @JsonCreator + public static GenderEnum fromValue(String value) { + for (GenderEnum b : GenderEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private GenderEnum gender; + private Integer age; + + /** + **/ + public ReaderCreate fullName(String fullName) { + this.fullName = fullName; + return this; + } + + + @JsonProperty("fullName") + @NotNull public String getFullName() { + return fullName; + } + + @JsonProperty("fullName") + public void setFullName(String fullName) { + this.fullName = fullName; + } + + /** + **/ + public ReaderCreate gender(GenderEnum gender) { + this.gender = gender; + return this; + } + + + @JsonProperty("gender") + public GenderEnum getGender() { + return gender; + } + + @JsonProperty("gender") + public void setGender(GenderEnum gender) { + this.gender = gender; + } + + /** + **/ + public ReaderCreate age(Integer age) { + this.age = age; + return this; + } + + + @JsonProperty("age") + public Integer getAge() { + return age; + } + + @JsonProperty("age") + public void setAge(Integer age) { + this.age = age; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ReaderCreate readerCreate = (ReaderCreate) o; + return Objects.equals(this.fullName, readerCreate.fullName) && + Objects.equals(this.gender, readerCreate.gender) && + Objects.equals(this.age, readerCreate.age); + } + + @Override + public int hashCode() { + return Objects.hash(fullName, gender, age); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ReaderCreate {\n"); + + sb.append(" fullName: ").append(toIndentedString(fullName)).append("\n"); + sb.append(" gender: ").append(toIndentedString(gender)).append("\n"); + sb.append(" age: ").append(toIndentedString(age)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/java/ru/cft/booklib/model/Transaction.java b/src/main/java/ru/cft/booklib/model/Transaction.java new file mode 100644 index 0000000..4a524fe --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/Transaction.java @@ -0,0 +1,214 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; + +import javax.validation.constraints.NotNull; +import java.util.Date; +import java.util.Objects; + +/** + * Выдача или возврат книги + **/ + +@JsonTypeName("Transaction") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class Transaction { + private Integer readerId; + private Integer bookId; + public enum ActionEnum { + + BORROW(String.valueOf("borrow")), RETURN(String.valueOf("return")); + + + private String value; + + ActionEnum (String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + /** + * Convert a String into String, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static ActionEnum fromString(String s) { + for (ActionEnum b : ActionEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @JsonCreator + public static ActionEnum fromValue(String value) { + for (ActionEnum b : ActionEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private ActionEnum action; + private Date date; + private Integer id; + + /** + * ID читателя + **/ + public Transaction readerId(Integer readerId) { + this.readerId = readerId; + return this; + } + + + @JsonProperty("readerId") + @NotNull public Integer getReaderId() { + return readerId; + } + + @JsonProperty("readerId") + public void setReaderId(Integer readerId) { + this.readerId = readerId; + } + + /** + * ID книги + **/ + public Transaction bookId(Integer bookId) { + this.bookId = bookId; + return this; + } + + + @JsonProperty("bookId") + @NotNull public Integer getBookId() { + return bookId; + } + + @JsonProperty("bookId") + public void setBookId(Integer bookId) { + this.bookId = bookId; + } + + /** + **/ + public Transaction action(ActionEnum action) { + this.action = action; + return this; + } + + + @JsonProperty("action") + @NotNull public ActionEnum getAction() { + return action; + } + + @JsonProperty("action") + public void setAction(ActionEnum action) { + this.action = action; + } + + /** + **/ + public Transaction date(Date date) { + this.date = date; + return this; + } + + + @JsonProperty("date") + @NotNull public Date getDate() { + return date; + } + + @JsonProperty("date") + public void setDate(Date date) { + this.date = date; + } + + /** + * ID транзакции + **/ + public Transaction id(Integer id) { + this.id = id; + return this; + } + + + @JsonProperty("id") + @NotNull public Integer getId() { + return id; + } + + @JsonProperty("id") + public void setId(Integer id) { + this.id = id; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Transaction transaction = (Transaction) o; + return Objects.equals(this.readerId, transaction.readerId) && + Objects.equals(this.bookId, transaction.bookId) && + Objects.equals(this.action, transaction.action) && + Objects.equals(this.date, transaction.date) && + Objects.equals(this.id, transaction.id); + } + + @Override + public int hashCode() { + return Objects.hash(readerId, bookId, action, date, id); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Transaction {\n"); + + sb.append(" readerId: ").append(toIndentedString(readerId)).append("\n"); + sb.append(" bookId: ").append(toIndentedString(bookId)).append("\n"); + sb.append(" action: ").append(toIndentedString(action)).append("\n"); + sb.append(" date: ").append(toIndentedString(date)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/java/ru/cft/booklib/model/TransactionCreate.java b/src/main/java/ru/cft/booklib/model/TransactionCreate.java new file mode 100644 index 0000000..19bbce1 --- /dev/null +++ b/src/main/java/ru/cft/booklib/model/TransactionCreate.java @@ -0,0 +1,192 @@ +package ru.cft.booklib.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; + +import javax.validation.constraints.NotNull; +import java.util.Date; +import java.util.Objects; + +/** + * Создание записи о выдаче или возврате книги + **/ + +@JsonTypeName("TransactionCreate") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-03-24T21:29:52.803984263+07:00[Asia/Novosibirsk]", comments = "Generator version: 7.8.0") +public class TransactionCreate { + private Integer readerId; + private Integer bookId; + public enum ActionEnum { + + BORROW(String.valueOf("borrow")), RETURN(String.valueOf("return")); + + + private String value; + + ActionEnum (String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + /** + * Convert a String into String, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static ActionEnum fromString(String s) { + for (ActionEnum b : ActionEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @JsonCreator + public static ActionEnum fromValue(String value) { + for (ActionEnum b : ActionEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private ActionEnum action; + private Date date; + + /** + * ID читателя + **/ + public TransactionCreate readerId(Integer readerId) { + this.readerId = readerId; + return this; + } + + + @JsonProperty("readerId") + @NotNull public Integer getReaderId() { + return readerId; + } + + @JsonProperty("readerId") + public void setReaderId(Integer readerId) { + this.readerId = readerId; + } + + /** + * ID книги + **/ + public TransactionCreate bookId(Integer bookId) { + this.bookId = bookId; + return this; + } + + + @JsonProperty("bookId") + @NotNull public Integer getBookId() { + return bookId; + } + + @JsonProperty("bookId") + public void setBookId(Integer bookId) { + this.bookId = bookId; + } + + /** + **/ + public TransactionCreate action(ActionEnum action) { + this.action = action; + return this; + } + + + @JsonProperty("action") + @NotNull public ActionEnum getAction() { + return action; + } + + @JsonProperty("action") + public void setAction(ActionEnum action) { + this.action = action; + } + + /** + **/ + public TransactionCreate date(Date date) { + this.date = date; + return this; + } + + + @JsonProperty("date") + @NotNull public Date getDate() { + return date; + } + + @JsonProperty("date") + public void setDate(Date date) { + this.date = date; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TransactionCreate transactionCreate = (TransactionCreate) o; + return Objects.equals(this.readerId, transactionCreate.readerId) && + Objects.equals(this.bookId, transactionCreate.bookId) && + Objects.equals(this.action, transactionCreate.action) && + Objects.equals(this.date, transactionCreate.date); + } + + @Override + public int hashCode() { + return Objects.hash(readerId, bookId, action, date); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TransactionCreate {\n"); + + sb.append(" readerId: ").append(toIndentedString(readerId)).append("\n"); + sb.append(" bookId: ").append(toIndentedString(bookId)).append("\n"); + sb.append(" action: ").append(toIndentedString(action)).append("\n"); + sb.append(" date: ").append(toIndentedString(date)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + +} + diff --git a/src/main/resources/META-INF/config.json b/src/main/resources/META-INF/config.json new file mode 100644 index 0000000..83dadde --- /dev/null +++ b/src/main/resources/META-INF/config.json @@ -0,0 +1,13 @@ +{ + "dateLibrary": "java8", + "useJakartaEe": true, + "hideGenerationTimestamp": true, + "modelPackage": "com.model", + "apiPackage": "com.model.rest", + "invokerPackage": "com.model.rest", + "serializableModel": true, + "useTags": true, + "useGzipFeature": true, + "interfaceOnly": true, + "java17" : true +} \ No newline at end of file diff --git a/src/main/resources/openapi/book-library.yaml b/src/main/resources/openapi/book-library.yaml new file mode 100644 index 0000000..34c5abc --- /dev/null +++ b/src/main/resources/openapi/book-library.yaml @@ -0,0 +1,262 @@ +openapi: 3.0.1 +info: + title: Library Automation API + description: API для автоматизации работы библиотеки + version: 1.0.0 + contact: + name: Max Rogov +servers: + - url: /api/v1 + description: Основной сервер API +paths: + /books: + get: + summary: Получить список книг + operationId: booksGet + security: + - BasicAuth: [] + responses: + '200': + description: Список книг + content: + application/json: + schema: + $ref: '#/components/schemas/Books' + '400': + $ref: '#/components/responses/BadRequest' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/InternalServerError' + post: + summary: Добавить новую книгу + operationId: bookPost + security: + - BasicAuth: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/BookCreate' + responses: + '201': + description: Книга добавлена + content: + application/json: + schema: + $ref: '#/components/schemas/Book' + '400': + $ref: '#/components/responses/BadRequest' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/InternalServerError' + /readers: + get: + summary: Получить список читателей + operationId: readersGet + security: + - BasicAuth: [] + responses: + '200': + description: Список читателей + content: + application/json: + schema: + $ref: '#/components/schemas/Readers' + '400': + $ref: '#/components/responses/BadRequest' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/InternalServerError' + post: + summary: Добавить читателя + operationId: readerPost + security: + - BasicAuth: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ReaderCreate' + responses: + '201': + description: Читатель добавлен + content: + application/json: + schema: + $ref: '#/components/schemas/Reader' + '400': + $ref: '#/components/responses/BadRequest' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/InternalServerError' + /transactions: + get: + summary: Получить список транзакций + operationId: transactionsGet + security: + - BasicAuth: [] + responses: + '200': + description: Список транзакций + content: + application/json: + schema: + $ref: '#/components/schemas/Transactions' + '400': + $ref: '#/components/responses/BadRequest' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/InternalServerError' + post: + summary: Оформить выдачу/возврат книги + operationId: transactionsPost + security: + - BasicAuth: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/TransactionCreate' + responses: + '201': + description: Транзакция зарегистрирована + content: + application/json: + schema: + $ref: '#/components/schemas/Transaction' + '400': + $ref: '#/components/responses/BadRequest' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/InternalServerError' +components: + securitySchemes: + BasicAuth: + type: http + scheme: basic + responses: + BadRequest: + description: Bad request + Unauthorized: + description: Unauthorized + Forbidden: + description: Forbidden + InternalServerError: + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + schemas: + Books: + type: array + items: + $ref: '#/components/schemas/Book' + Book: + description: Книга + allOf: + - properties: + id: + type: integer + required: [id] + - $ref: '#/components/schemas/BookCreate' + BookCreate: + description: Создание книги + properties: + title: + type: string + authors: + type: array + minItems: 1 + items: + type: string + year: + type: integer + genre: + type: string + required: [title, authors] + Readers: + type: array + items: + $ref: '#/components/schemas/Reader' + Reader: + description: Читатель + allOf: + - properties: + id: + type: integer + required: [id] + - $ref: '#/components/schemas/ReaderCreate' + ReaderCreate: + description: Добавление читателя + properties: + fullName: + type: string + gender: + type: string + enum: [man, femail] + x-enumNames: [man, femail] + age: + type: integer + required: [fullName] + Transactions: + description: Список транзакций + type: array + items: + $ref: '#/components/schemas/Transaction' + Transaction: + description: Выдача или возврат книги + allOf: + - properties: + id: + description: ID транзакции + type: integer + required: [id] + - $ref: '#/components/schemas/TransactionCreate' + TransactionCreate: + description: Создание записи о выдаче или возврате книги + properties: + readerId: + description: ID читателя + type: integer + bookId: + description: ID книги + type: integer + action: + type: string + enum: [borrow, return] + x-enumNames: [borrow, return] + date: + type: string + format: date-time + required: [readerId, bookId, action, date] + Error: + description: Http ошибка + properties: + code: + type: integer + message: + type: string + required: [code, message] +