diff --git a/backend/src/main/java/hu/pazmany/ExampleController.java b/backend/src/main/java/hu/pazmany/Controller.java similarity index 57% rename from backend/src/main/java/hu/pazmany/ExampleController.java rename to backend/src/main/java/hu/pazmany/Controller.java index f84dcbd61f71683c47d76021a4836a839f6018d7..8bc9ef2748cfbe76cffe3603085c594de913d03b 100644 --- a/backend/src/main/java/hu/pazmany/ExampleController.java +++ b/backend/src/main/java/hu/pazmany/Controller.java @@ -5,12 +5,14 @@ import org.springframework.web.bind.annotation.*; @CrossOrigin(origins = "http://localhost:3000") @RestController -public class ExampleController { +public class Controller { private final UserService userService; + private final DocumentService documentService; @Autowired - public ExampleController(UserService userService) { + public Controller(UserService userService, DocumentService documentService) { this.userService = userService; + this.documentService = documentService; } @PostMapping("/api/login") @@ -23,4 +25,14 @@ public class ExampleController { public void register(@RequestBody UserLoginDto userLoginDto) { userService.register(userLoginDto.getFullName(), userLoginDto.getUsername(), userLoginDto.getPassword()); } + + @PostMapping("/api/details") + public DocumentDto getDetails(@RequestBody DocumentDto documentDto) { + return documentService.getDetails(documentDto.getID(), documentDto.getSubject()); + } + +// @PostMapping("/api/setdetails") +// public void setDetails(@RequestBody DocumentDto documentDto) { +// documentService.setDetails(documentDto); +// } } \ No newline at end of file diff --git a/backend/src/main/java/hu/pazmany/Document.java b/backend/src/main/java/hu/pazmany/Document.java index 3cd372db0b903a5abcc48d2768a2ccd042cc59a2..ad1000625c306a2d6f200fb5ffd67bb6caf506c4 100644 --- a/backend/src/main/java/hu/pazmany/Document.java +++ b/backend/src/main/java/hu/pazmany/Document.java @@ -48,7 +48,7 @@ public class Document { this.id = id; } - public hu.pazmany.User getUser() { + public User getUser() { return user; } diff --git a/backend/src/main/java/hu/pazmany/DocumentDto.java b/backend/src/main/java/hu/pazmany/DocumentDto.java new file mode 100644 index 0000000000000000000000000000000000000000..a3e86e326bbb4d0f4acb232f67621e8b29a98f09 --- /dev/null +++ b/backend/src/main/java/hu/pazmany/DocumentDto.java @@ -0,0 +1,56 @@ +package hu.pazmany; + +import java.time.LocalDateTime; + +public class DocumentDto { + private Long id; + private String user; + private String subject; + private String title; + private String description; + private String uploaded; + private String filepath; + + public Long getID() { + return id; + } + public void setID(Long id) { + this.id = id; + } + public String getUser() { + return user; + } + public void setUser(String user) { + this.user = user; + } + public String getSubject() { + return subject; + } + public void setSubject(String subject) { + this.subject = subject; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getUploaded() { + return uploaded; + } + public void setUploaded(String uploaded) { + this.uploaded = uploaded; + } + public String getFilepath() { + return filepath; + } + public void setFilepath(String filepath) { + this.filepath = filepath; + } +} diff --git a/backend/src/main/java/hu/pazmany/DocumentRepository.java b/backend/src/main/java/hu/pazmany/DocumentRepository.java index 7b97f475228efa0f374a561d1a93a13f1010421b..394bdd225936ed14879b7ba6d8dced02dd8678f2 100644 --- a/backend/src/main/java/hu/pazmany/DocumentRepository.java +++ b/backend/src/main/java/hu/pazmany/DocumentRepository.java @@ -2,6 +2,7 @@ package hu.pazmany; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import java.util.Optional; public interface DocumentRepository extends JpaRepository<Document, Long>{ List<Document> findAllByUser(User user); diff --git a/backend/src/main/java/hu/pazmany/DocumentService.java b/backend/src/main/java/hu/pazmany/DocumentService.java new file mode 100644 index 0000000000000000000000000000000000000000..b10bfcfee488303c1cf0d2d43e7a548790a86321 --- /dev/null +++ b/backend/src/main/java/hu/pazmany/DocumentService.java @@ -0,0 +1,63 @@ +package hu.pazmany; + +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class DocumentService { + private final DocumentRepository documentRepository; + private final UserRepository userRepository; + private final SubjectRepository subjectRepository; + + public DocumentService(DocumentRepository documentRepository, UserRepository userRepository, SubjectRepository subjectRepository) { + this.documentRepository = documentRepository; + this.userRepository = userRepository; + this.subjectRepository = subjectRepository; + } + + public DocumentDto getDetails(long id, String subjectName) { + User user = new User(); + user.setUsername("kazsa"); + user.setPassword("keksz"); + user.setFullName("Kada Zsolt"); + userRepository.save(user); + + Subject subject = new Subject(); + subject.setSubjectId("PPKE-"); + subject.setName("Szofttech"); + subjectRepository.save(subject); + + Document document = new Document(); + document.setUser(user); + document.setSubject(subject); + document.setDescription("Előadás"); + document.setTitle("1. előadás"); + document.setFilepath("documents/1.eloadas_szoftvertechnologia_2024_v1.0.pdf"); + documentRepository.save(document); + + Document result = documentRepository.findAllByUser(user).get(0); + + DocumentDto doc = new DocumentDto(); + doc.setID(result.getId()); + doc.setUser(result.getUser().getFullName()); + doc.setSubject(result.getSubject().getName()); + doc.setTitle(result.getTitle()); + doc.setDescription(result.getDescription()); + doc.setFilepath(result.getFilepath()); + + return doc; + } + +// public void setDetails(DocumentDto documentDto) { +// Document document = new Document(); +// document.setId(documentDto.getID()); +// document.setUser(userRepository.findByUsername(documentDto.getUser())); +// document.setSubject(subjectRepository.findBySubjectId(documentDto.getSubject())); +// document.setTitle(documentDto.getTitle()); +// document.setDescription(documentDto.getDescription()); +//// document.setUploaded(documentDto.getUploaded()); +// document.setFilepath(documentDto.getFilepath()); +// documentRepository.save(document); +// } +} diff --git a/backend/src/main/java/hu/pazmany/UserService.java b/backend/src/main/java/hu/pazmany/UserService.java index ee97f97743f673ef89194c63c0ffb31056c8b1e3..ea3b4a204400ad2591222c405dce469c4e6351d1 100644 --- a/backend/src/main/java/hu/pazmany/UserService.java +++ b/backend/src/main/java/hu/pazmany/UserService.java @@ -1,6 +1,5 @@ package hu.pazmany; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index a00ab33962dcfdc65359907962b298a5bf22beec..706e4350d65f96cb186c95b581cfc4d418f55f1a 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -13,6 +13,7 @@ spring.h2.console.enabled=true spring.h2.console.path=/h2-console spring.h2.console.settings.trace=false spring.h2.console.settings.web-allow-others=true +spring.jpa.hibernate.ddl-auto=update springdoc.swagger-ui.path=/swagger-ui diff --git a/backend/src/main/resources/data.direktnemsqlakiterjesztes b/backend/src/main/resources/data.direktnemsqlakiterjesztes new file mode 100644 index 0000000000000000000000000000000000000000..f735b1834eba7ba0b9eef4d9a61a8e6d14a3c7fe --- /dev/null +++ b/backend/src/main/resources/data.direktnemsqlakiterjesztes @@ -0,0 +1,38 @@ +-- DROP TABLE documents; +-- DROP TABLE subjects; +-- DROP TABLE users; + +-- CREATE TABLE users ( +-- username VARCHAR(255) PRIMARY KEY, +-- fullName VARCHAR(255), +-- password VARCHAR(255) +-- ); +-- +-- CREATE TABLE subjects ( +-- subjectId VARCHAR(255) PRIMARY KEY, +-- name VARCHAR(255) +-- ); +-- +-- CREATE TABLE documents ( +-- id BIGINT AUTO_INCREMENT PRIMARY KEY, +-- userId VARCHAR(255) NOT NULL, +-- subjectId VARCHAR(255) NOT NULL, +-- title VARCHAR(255) NOT NULL, +-- description VARCHAR(255), +-- uploaded TIMESTAMP, +-- filepath VARCHAR(255) NOT NULL, +-- FOREIGN KEY (userId) REFERENCES users(username), +-- FOREIGN KEY (subjectId) REFERENCES subjects(subjectId) +-- ); + +-- INSERT INTO USERS(username, password, fullName) VALUES ('testUser', 'testPassword', 'Test User'); +-- INSERT INTO SUBJECTS(subjectId, name) VALUES ('testId', 'Test Subject'); +-- INSERT INTO DOCUMENTS(id, userId, subjectId, title, description, uploaded, filepath) VALUES (1, 'testUser', 'testId', 'Test Title', 'Test Description', CURRENT_TIMESTAMP, '/path/to/file'); + +-- INSERT INTO users (username, fullName, password) VALUES ('kazsa', 'Kada Zsolt', 'aaaa'); +-- +-- +-- INSERT INTO subjects (subjectId) VALUES ('Szofttech'); +-- +-- -- Assuming 'uploaded' timestamp is correctly formatted for your DBMS, e.g., '2024-01-01 10:00:00' +-- INSERT INTO documents (userId, subjectId, title, description, uploaded, filepath) VALUES ('kazsa', 'Szofttech', '1. előadás', 'Description of the document', '2024-01-01 10:00:00', 'documents/1.eloadas_szoftvertechnologia_2024_v1.0.pdf'); \ No newline at end of file diff --git a/documents/1.eloadas_szoftvertechnologia_2024_v1.0.pdf b/documents/1.eloadas_szoftvertechnologia_2024_v1.0.pdf new file mode 100644 index 0000000000000000000000000000000000000000..87778fa7278dd23a631b471de0a7265451b49c49 Binary files /dev/null and b/documents/1.eloadas_szoftvertechnologia_2024_v1.0.pdf differ diff --git a/frontend/src/components/browse-komponens.vue b/frontend/src/components/browse-komponens.vue index 9505d388386ad6a457629b9ed6c01572cc1aabd8..377294bc5db88c4b562e628870d82271cd7d2663 100644 --- a/frontend/src/components/browse-komponens.vue +++ b/frontend/src/components/browse-komponens.vue @@ -1,5 +1,65 @@ <script setup> +import {ref} from "vue"; +import axios from "axios"; + +const title = ref("Jegyzet címe") +const userName = ref("Feltöltő neve") +const description = ref("Jegyzet leírása") +let path = ref("") + +function getDocumentDetails(id) { + axios.post('http://localhost:8080/api/details', {id: id, subject: "Szofttech"}) + .then(response => { + console.log(response.data) + title.value = response.data["title"] + userName.value = response.data["user"] + description.value = response.data["description"] + path = response.data["filepath"] + }) + .catch(error => { + console.log(error); + }); +} + +function downloadFile() { + let url = "http://localhost:3000/" + path + console.log(url) + fetch(url, { + method: 'GET', + headers: { + // Add headers here if needed (e.g., Authentication tokens) + }, + }) + .then(response => response.blob()) // Converts the response to a Blob + .then(blob => { + // Create a URL for the blob object + const downloadUrl = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = downloadUrl; + link.setAttribute('download', 'doc1.pdf'); // Sets the file name for download + document.body.appendChild(link); + link.click(); + link.parentNode.removeChild(link); // Clean up + window.URL.revokeObjectURL(downloadUrl); // Free up storage--no longer needed + }) + .catch(e => console.error('Error downloading the file: ', e)); + } + +// axios.post('http://localhost:8080/api/setdetails', { +// id: 0, +// user: "kazso", +// subject: "szofttech", +// title: "1. előadás", +// description: "hehe", +// uploaded: "idk", +// filepath: "documents/1.eloadas_szoftvertechnologia_2024_v1.0.pdf" +// }).then(response => { +// console.log(response.data) +// }).catch(error => { +// console.log(error); +// }); + </script> <template> @@ -7,7 +67,7 @@ <main class="browse"> <ul class="browse-list"> <li class="module">Modul 1</li> - <li>Jegyzet</li> + <li id="0" @click=getDocumentDetails(0)>Jegyzet</li> <li>Jegyzet</li> <li class="module">Modul 2</li> <li>Jegyzet</li> @@ -15,12 +75,12 @@ </main> <main> <div class="note-page"> - <h2 class="note-header">Jegyzet</h2> + <h2 class="note-header">{{title}}</h2> <h3 class="note-description"> - Jegyzet leírása + {{description}} </h3> - <h4>Feltőltő neve</h4> - <button>Letöltés</button> + <h4>{{userName}}</h4> + <button @click="downloadFile">Letöltés</button> </div> </main> </div>