diff --git a/gates/src/main/java/ru/mlokoin/gates/controller/v1/GatesController.java b/gates/src/main/java/ru/mlokoin/gates/controller/v1/GatesController.java index c4a327d..672b27d 100644 --- a/gates/src/main/java/ru/mlokoin/gates/controller/v1/GatesController.java +++ b/gates/src/main/java/ru/mlokoin/gates/controller/v1/GatesController.java @@ -3,6 +3,7 @@ package ru.mlokoin.gates.controller.v1; import java.net.URI; import java.net.URISyntaxException; import java.time.Duration; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -13,6 +14,7 @@ import org.springframework.http.client.MultipartBodyBuilder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.reactive.function.BodyInserters; @@ -20,6 +22,7 @@ import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import ru.mlokoin.gates.model.fs.Document; +import ru.mlokoin.gates.model.fs.Post; import ru.mlokoin.gates.model.fs.xlsx.XlsxDocument; import ru.mlokoin.gates.repository.Storage; import ru.mlokoin.gates.teh.fs.MpFile; @@ -51,6 +54,12 @@ public class GatesController { public String documentList(Model model) { List docs = storage.getDocumentList(); model.addAttribute("documents", docs); + + List posts = storage.getPostList(); + model.addAttribute("posts", posts); + + Post post = new Post(); + model.addAttribute("newPost", post); return "documents"; } @@ -214,8 +223,11 @@ public class GatesController { * @return */ @PostMapping("/document/upload") - public String upload(@RequestParam("file") MultipartFile file) { - + public String upload(@RequestParam("file") MultipartFile file, Model model, @ModelAttribute("post") Post post) { + // System.out.println("Тип документа: " + type); + + System.out.println("Тип документа: " + post.getType()); + Document doc = new Document(); doc.setName(file.getOriginalFilename()); doc.setSize(file.getSize()); @@ -235,6 +247,18 @@ public class GatesController { .timeout(Duration.ofSeconds(1)) .block(); + post.setDocument(doc); + post = client.post() + .uri("http://resource-service-api:8181/post/create") + .body(Mono.just(post), Post.class) + .retrieve() + .bodyToMono(new ParameterizedTypeReference (){}) + .timeout(Duration.ofSeconds(1)) + .block(); + + System.out.println("Пакет передан в ресурсный сервис ..."); + System.out.println("Пакет: " + post.toString()); + // Добавление файла в файловое хранилище MultipartBodyBuilder builder = new MultipartBodyBuilder(); Boolean ok; @@ -249,6 +273,7 @@ public class GatesController { .bodyToMono(new ParameterizedTypeReference (){}) .block(); + System.out.println("Файл добавлен в хранилище: " + ok); System.out.println("ID: " + doc.getId()); System.out.println(doc.toString()); @@ -276,6 +301,11 @@ public class GatesController { return "view-xlsx"; } + // @GetMapping("/document/view-xlsx/{id}/{part}") + // public String viewPart(Model model, @PathVariable String id, @PathVariable String part) { + + // } + /** * Публикация "Реестра обученных" * - просмотр diff --git a/gates/src/main/java/ru/mlokoin/gates/model/fs/Post.java b/gates/src/main/java/ru/mlokoin/gates/model/fs/Post.java new file mode 100644 index 0000000..4039f53 --- /dev/null +++ b/gates/src/main/java/ru/mlokoin/gates/model/fs/Post.java @@ -0,0 +1,23 @@ +package ru.mlokoin.gates.model.fs; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@AllArgsConstructor +@NoArgsConstructor +@Data +public class Post implements Serializable { + private long id; + private String type;//тип документа (реестр/ списочный состав/ прочее) + private Document document; + + public Post(String type, Document document) { + this.type = type; + this.document = document; + } + +} diff --git a/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java b/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java index 450ba89..55a3099 100644 --- a/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java +++ b/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java @@ -20,6 +20,7 @@ import ru.mlokoin.gates.model.course.Course; import ru.mlokoin.gates.model.cretarea.ProgramCretarea; import ru.mlokoin.gates.model.education.EducatonEntry; import ru.mlokoin.gates.model.fs.Document; +import ru.mlokoin.gates.model.fs.Post; import ru.mlokoin.gates.model.fs.xlsx.XlsxCell; import ru.mlokoin.gates.model.fs.xlsx.XlsxDocument; import ru.mlokoin.gates.model.organization.Organization; @@ -37,6 +38,7 @@ import ru.mlokoin.gates.teh.strings.Stringer; public class Storage { private String storageLink = "http://storage-rs:8282/api/document/content/"; private String storageListLink = "http://resource-service-api:8181/storage-entry/list"; + private String postLink = "http://resource-service-api:8181/post/list"; private String programsLink = "http://resource-service-api:8181/program/list"; private String buildingsLink = "http://resource-service-api:8181/building/list"; private String coursesLink = "http://resource-service-api:8181/course/list"; @@ -63,6 +65,20 @@ public class Storage { .block(); } + /** + * Получение списка постов, размещенных в ресурсном сервисе + * @param id + * @return + */ + public List getPostList() { + System.out.println("Получение списка постов, размещенных в ресурсном сервисе ..."); + return client.method(HttpMethod.GET) + .uri(postLink) + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .block(); + } + /** * Получение всего содержимого xlsx-файла из файлового хранилища * по id документа в хранилище diff --git a/gates/src/main/resources/templates/documents.html b/gates/src/main/resources/templates/documents.html index 1a10e18..30fcc17 100644 --- a/gates/src/main/resources/templates/documents.html +++ b/gates/src/main/resources/templates/documents.html @@ -26,64 +26,70 @@ xmlns:th="http://www.thymeleaf.org"> -->

Добавление пакетов:

-
-
+ + + -
- + + +

Перечень файлов:

-
- - - - - - - - - - - - - - - - - - +
idnameextensionsize(bytes) - -
- - - - - - - -
+ + + + + + + - - - - -
idnameextensionsize(bytes) - -
- - -
-
-
- -
-
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ +
+ + + + diff --git a/gates/src/main/resources/templates/storage.html b/gates/src/main/resources/templates/storage.html index c37eb4a..b7bff22 100644 --- a/gates/src/main/resources/templates/storage.html +++ b/gates/src/main/resources/templates/storage.html @@ -30,60 +30,59 @@ xmlns:th="http://www.thymeleaf.org">

Перечень файлов:

-
-
- -
- -
- - - - - - - - - - - - - - - - - - - - + +
+ +
+ + +
namepathextensionsize(bytes) - -
- - - - - - - - -
- - -
-
+ + + + + + + + + + + + + + + + + + + + - - -
namepathextensionsize(bytes)DELSHOW
+ + + + + + + + +
+ + +
+
+ + + diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StorageController.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StorageController.java index a8acfac..7be24f7 100644 --- a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StorageController.java +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StorageController.java @@ -15,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import ru.molokoin.resourceserviceapi.entities.Post; import ru.molokoin.resourceserviceapi.entities.StorageEntry; +import ru.molokoin.resourceserviceapi.repositories.PostFace; import ru.molokoin.resourceserviceapi.repositories.StorageEntryFace; /** @@ -27,11 +29,19 @@ public class StorageController { @Autowired private StorageEntryFace repo; + @Autowired + private PostFace postRepo; + @GetMapping("/storage-entry/list") public ResponseEntity> getStorageEntries(){ return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); } + @GetMapping("/post/list") + public ResponseEntity> getPostList(){ + return new ResponseEntity<>(postRepo.findAll(), HttpStatus.OK); + } + @GetMapping("/storage-entry/{id}") public ResponseEntity getStorageEntryByID(@PathVariable Integer id){ return new ResponseEntity<>(repo.findStorageEntryById(id), HttpStatus.OK); @@ -45,6 +55,14 @@ public class StorageController { return new ResponseEntity<>(storageEntry, HttpStatus.CREATED); } + @PostMapping(path = "/post/create", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity savePost(@RequestBody Post post) { + postRepo.save(post); + return new ResponseEntity<>(post, HttpStatus.CREATED); + } + @PutMapping(path = "/storage-entry/update/{id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Post.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Post.java new file mode 100644 index 0000000..448e31f --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Post.java @@ -0,0 +1,32 @@ +package ru.molokoin.resourceserviceapi.entities; + +import java.io.Serializable; + +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToOne; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@AllArgsConstructor +@NoArgsConstructor +@Entity +@Data +public class Post implements Serializable { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private long id; + private String type;//тип документа (реестр/ списочный состав/ прочее) + + @OneToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + private StorageEntry document; +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/PostFace.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/PostFace.java new file mode 100644 index 0000000..43238a7 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/PostFace.java @@ -0,0 +1,13 @@ +package ru.molokoin.resourceserviceapi.repositories; + +import java.util.List; + +import org.springframework.data.repository.ListCrudRepository; +import org.springframework.stereotype.Repository; + +import ru.molokoin.resourceserviceapi.entities.Post; + +@Repository +public interface PostFace extends ListCrudRepository{ + List findAll(); +} diff --git a/storage-rs/src/main/resources/static/content/md/hello.md b/storage-rs/src/main/resources/static/content/md/hello.md index bb835e7..9141b0e 100644 --- a/storage-rs/src/main/resources/static/content/md/hello.md +++ b/storage-rs/src/main/resources/static/content/md/hello.md @@ -15,7 +15,7 @@ table_pack: - id - наименование пакета -- тип пакета(наименование загружаемой формы, для выбора последующего алгоритма обработки) +- тип пакета (наименование загружаемой формы, для выбора последующего алгоритма обработки) # API ## [GET domain:port/api/list-uploads](http://localhost:82/api/list-uploads)