-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
187 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,105 @@ | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.js</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
import React, { useState } from "react"; | ||
import Book from './Book' | ||
import BookForm from './BookForm' | ||
|
||
|
||
const API_URL = 'https://shark.ontrack.global'; | ||
//const API_URL = 'http://localhost:8080'; | ||
|
||
const App = ()=> { | ||
|
||
const [books, setBooks] = useState([]); | ||
const [searchedBook, setSearchedBook] = useState(null); | ||
const [searchId, setSearchId] = useState(""); | ||
const [wordReport, setWordReport] = useState(""); | ||
|
||
const searchBooks = async () =>{ | ||
const response = await fetch(`${API_URL}/book/get`,{ | ||
method: 'GET', // *GET, POST, PUT, DELETE, etc. | ||
}) | ||
const data = await response.json(); | ||
setBooks(data) | ||
} | ||
|
||
const searchBook = async (bookId) =>{{ | ||
const response = await fetch(`${API_URL}/book/get/${bookId}`,{ | ||
method: 'GET', // *GET, POST, PUT, DELETE, etc. | ||
}) | ||
const data = await response.json(); | ||
setSearchedBook(data[0]) | ||
}} | ||
|
||
const downloadReport = async(word) => { | ||
const response = await fetch(`${API_URL}/book/report/${word}`,{ | ||
method: 'GET', | ||
}) | ||
const data = await (await response.text()).slice(17); | ||
console.log(data) | ||
window.open(`${API_URL}/book/report/download/${data}`) | ||
//const response2 = await fetch(`${API_URL}/book/report/download/${data}`) | ||
|
||
} | ||
|
||
return ( | ||
<> | ||
<div> | ||
<h1>Libros</h1> | ||
</div> | ||
<div> | ||
<h2>Obtener Todos</h2> | ||
<button | ||
onClick={ () => searchBooks()} | ||
>Buscar Todos los Libros</button> | ||
<button | ||
onClick = { () => setBooks([])} | ||
>Limpiar</button> | ||
{ | ||
books?.length > 0 ? ( | ||
<div> | ||
{books.map((book)=> ( | ||
<Book book = {book}/> | ||
))} | ||
</div> | ||
) : ( | ||
<></> | ||
) | ||
} | ||
</div> | ||
<div> | ||
<h2>Obtener Libro por Id</h2> | ||
<input | ||
value = {searchId} | ||
onChange = {(e)=> setSearchId(e.target.value)} | ||
placeholder= "Ingrese el id del libro" | ||
/> | ||
<button | ||
onClick = {() => searchBook(searchId)} | ||
>Buscar</button> | ||
{ | ||
searchedBook !== null ? (<Book book = {searchedBook}/>): (<></>) | ||
} | ||
</div> | ||
<div> | ||
<h2>Crear Un Libro</h2> | ||
<BookForm /> | ||
</div> | ||
<div> | ||
<h2>Reportes</h2> | ||
<h3>Libros por palabra clave</h3> | ||
<input | ||
value = {wordReport} | ||
onChange = {(e)=> setWordReport(e.target.value)} | ||
placeholder= "Ingrese la palabra clave que desea buscar" | ||
/> | ||
<br/> | ||
<button | ||
onClick = {() => downloadReport(wordReport)} | ||
>Generar Reporte</button> | ||
|
||
|
||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default App; | ||
export default App; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
const Book = ({ book}) => { | ||
return ( | ||
<div> | ||
<h3>Title: {book.Title}</h3> | ||
<h4>Author: {book.Author}, Year Published: {book.PublicationYear}</h4> | ||
</div> | ||
) | ||
} | ||
|
||
export default Book; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from "react"; | ||
import { useState } from "react"; | ||
|
||
const BookForm = () => { | ||
const API_URL = 'https://shark.ontrack.global'; | ||
const [form, setForm] = useState({author: '', title:'', description: '', subject: '', year: ''}); | ||
|
||
const handleChange = (e) =>{ | ||
setForm({ | ||
...form, | ||
[e.target.name] : e.target.value, | ||
}); | ||
} | ||
|
||
const handleSubmit = (e) =>{ | ||
e.preventDefault() | ||
if (form.title.length > 0 && form.author.length > 0 && form.description.length > 0 && form.subject.length > 0 && form.year.length > 0 && !isNaN(form.year)){ | ||
createBook(form) | ||
setForm({author: '', title:'', description: '', subject: '', year: ''}) | ||
} | ||
} | ||
|
||
const createBook = async (book) => { | ||
const requestOptions = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(book) | ||
}; | ||
console.log(book) | ||
console.log(requestOptions.body) | ||
const response = await fetch(`${API_URL}/book/create`,requestOptions) | ||
const data = await response.text(); | ||
console.log(data) | ||
} | ||
|
||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<label htmlFor = "title" >Titulo: </label> | ||
<input type = "text" id = "title" name = "title" value = {form.title} onChange= {handleChange}></input> | ||
<br/> | ||
<br/> | ||
<label htmlFor = "author" >Autor: </label> | ||
<input type = "text" id = "author" name = "author" value = {form.author} onChange= {handleChange}></input> | ||
<br/> | ||
<br/> | ||
<label htmlFor = "description" >Descripción: </label> | ||
<input type = "text" id = "description" name = "description" value = {form.description} onChange= {handleChange}></input> | ||
<br/> | ||
<br/> | ||
<label htmlFor = "subject" >Tema: </label> | ||
<input type = "text" id = "subject" name = "subject" value = {form.subject} onChange= {handleChange}></input> | ||
<br/> | ||
<br/> | ||
<label htmlFor = "year" >Año de Publicación: </label> | ||
<input type = "text" id = "year" name = "year" value = {form.year} onChange= {handleChange}></input> | ||
<br/> | ||
<input type = "submit"></input> | ||
</form> | ||
) | ||
} | ||
|
||
export default BookForm; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import './index.css'; | ||
import { createRoot } from 'react-dom/client'; | ||
import App from './App'; | ||
import reportWebVitals from './reportWebVitals'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); | ||
const container = document.getElementById('root'); | ||
const root = createRoot(container) | ||
root.render(<App/>); | ||
|
||
// If you want to start measuring performance in your app, pass a function | ||
// to log results (for example: reportWebVitals(console.log)) | ||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
reportWebVitals(); | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.