Toda la vida use el patrón DTO para lectura/escritura.... la pregunta es ¿Solo se usa para lectura verdad? :'(
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
const Item = require('../models/item');
const ItemCtlr = {}
ItemCtlr.getiIems = async(req, res) => {
console.log("entro a obtener items");
items = await Item.find();
res.json(items);
}
module.exports = ItemCtlr;
export class miClase {
_id: string;
name: string;
constructor(id?: string, name?: string) {
this._id = id;
this.name = name;
}
}
deleteObject(req, res) {
Obecjt.findByIdAndRemove({ _id: req.body.id }).then(doc => {
res.json({
ok: true
})
}, err => {
res.status(500).json({
error: 'Error al borrar ' + req.body.id
})
})
}
</a>
<div class="myFormUpdate">
<form th:action="@{/producto/guardar}" method="POST"
class="form_content" enctype="multipart/form-data">
<div class="modal fade" th:id="updateModal+${producto.codigo}"
id="updateModal" tabindex="-1" role="dialog"
aria-labelledby="updateModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="updateModalLabel">Update
Producto</h4>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="alert alert-info">Input data to the fields</p>
<div class="form-group">
<!--<label for="id" class="col-form-label">User id:</th:text></label>-->
<input type="hidden" class="form-control" id="id"
th:name="codigo" th:value="*{producto.codigo}" />
</div>
<div class="form-group">
<label for="titulo" class="col-form-label">Nombre</label>
<input type="text" class="form-control" id="titulo"
th:name="nombre" th:value="*{producto.nombre}" />
</div>
<div class="form-group">
<label for="marca" class="col-form-label">Marca</label>
<input type="text" class="form-control" id="marca"
th:name="marca" th:value="*{producto.marca}">
</div>
<div class="form-group">
<label for="marca" class="col-form-label">Precio</label>
<input type="number" class="form-control" id="precio"
th:name="precio" th:value="*{producto.precio}" step="any">
</div>
<div class="form-group">
<label for="descripcion" class="col-form-label">Descripcion</label>
<input type="text" class="form-control" id="descripcion"
th:name="descripcion" th:value="*{producto.descripcion}" />
</div>
<div class="form-group">
<label for="fecha" class="col-form-label">Stock</label>
<input type="number" class="form-control" id="fecha"
th:name="stock" th:value="*{producto.stock}" />
</div>
<div class="form-group">
<img width="100px" class="card-img-top m-auto"
th:src="*{'data:image/png;base64,'+producto.imagen}">
<label for="file" class="bttn">
<i class="fa fa-cloud-upload" aria-hidden="true"></i>
Subir archivo
</label>
<input type="file" name="file" class="form-control-file"
id="imagen" th:name="file"
accept="image/x-png,image/gif,image/jpeg,image/png,image/jpeg"
style='display: none;'>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Save" />
</div>
</div>
</div>
</div>
</form>
</div></td>
<td>
<td><a data-toggle="modal" data-target="#removeModalNoticias"
class="btn btn-danger delBtn"
th:attr="data-target='#removeModalNoticias'+${noticia.id}">Eliminar
<i class="fa fa-trash"></i>
</a> <!-- #Modal for removing noticias -->
<div class="modal fade" th:id="removeModalNoticias+${noticia.id}"
id="removeModalNoticias" tabindex="-1" role="dialog"
aria-labelledby="removeModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="removeModalCenterTitle">Eliminar
Noticia</h4>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="alert alert-danger">Are You sure You want to
delete this Noticia?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<a th:href="@{/delete/(id=${noticia.id})}"
class="btn btn-danger" id="delRef">Delete</a>
</div>
</div>
</div>
</div></td>
</td>
@GetMapping("/delete/{id}")
public String delete(Long id) {
noticia.deleteById(id);
return "redirect://noticias";
}
@GetMapping(value = "/noticias")
public String findAll(@RequestParam Map<String, Object> params, Model model) {
int page = params.get("page") != null ? Integer.valueOf(params.get("page").toString()) - 1 : 0;
PageRequest pageRequest = PageRequest.of(page, 5);
Page<Noticia> pageNoticia = noticia.findAll(pageRequest);
int totalPage = pageNoticia.getTotalPages();
if (totalPage > 0) {
List<Integer> pages = IntStream.rangeClosed(1, totalPage).boxed().collect(Collectors.toList());
model.addAttribute("pages", pages);
}
model.addAttribute("list", pageNoticia.getContent());
model.addAttribute("current", page + 1);
model.addAttribute("next", page + 2);
model.addAttribute("prev", page);
model.addAttribute("last", totalPage);
return "noticias";
}
<td><a data-toggle="modal" data-target="#updateModal"
class="btn btn-warning"
th:attr="data-target='#updateModal'+${noticia.id}">Editar <i
class="fa fa-edit"></i>
</a></td>
<!--#Modal form for noticia update-->
<div class="myFormUpdate">
<form th:action="@{/save}" method="post">
<div class="modal fade"
id="updateModal" tabindex="-1" role="dialog"
aria-labelledby="updateModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="updateModalLabel">Modificar
Noticia</h4>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="alert alert-info">Input data to the fields</p>
<div class="form-group">
<!--<label for="id" class="col-form-label">User id:</th:text></label>-->
<input type="hidden" class="form-control" id="id" th:name="id"
value="" />
</div>
<div class="form-group">
<label for="titulo" class="col-form-label">Titulo:</label> <input
type="text" class="form-control" id="titulo" th:name="titulo"
value="" />
</div>
<div class="form-group">
<label for="descripcion" class="col-form-label">Descripcion:</label>
<input type="text" class="form-control" id="descripcion"
th:name="descripcion" value="" />
</div>
<div class="form-group">
<label for="fecha" class="col-form-label">Fecha:</label> <input
type="date" class="form-control" id="fecha" th:name="fecha"
value="" />
</div>
<div class="form-group">
<label for="fileUpload">Imagen:</label>
<fieldset style="margin-left: 10px;">
<input id="fileUpload" type="file" style="margin-left: 20px"
value="" th:name="imagen" />
</fieldset>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Save" />
</div>
</div>
</div>
</div>
</form>
</div>
<!--End update form-->
@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
public String edit(@PathVariable("id") Long id, Model model) {
Optional<Noticia> noticia = this.noticia.findById(id);
model.addAttribute("noticia", noticia);
return "redirect:/noticias";
}
<body>
<div th:insert="layout/header :: header"></div>
<div class="col-12">
<h2>Noticias</h2>
<div class="alert"></div>
<button type="button" class="btn btn-success" data-toggle="modal"
data-target="#agregarNoticiaModal">Agregar</button>
<div class="modal fade" id="agregarNoticiaModal" tabindex="-1"
role="dialog" aria-labelledby="addClassModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="agregarNoticiaModalLabel">Agregar
Noticia</h4>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="#" method="POST" th:action="@{/save}"
th:object="${noticia}">
<div class="form-group">
<label for="titulo">Titulo:</label> <input type="text"
class="form-control" id="titulo" value="" th:name="titulo" />
</div>
<div class="form-group">
<label for="descripcion">Descripcion:</label> <input type="text"
class="form-control" id="descripcion" value=""
th:name="descripcion" />
</div>
<div class="form-group">
<label for="fileUpload">Imagen:</label>
<fieldset style="margin-left: 10px;">
<input id="fileUpload" type="file" style="margin-left: 20px"
value="" th:name="imagen" />
</fieldset>
</div>
<input type="submit" value="Aceptar" />
</form>
</div>
</div>
</div>
</div>
<table class="table table-bordered table-responsive p-3">
<thead class="thead-dark">
<tr class="text-center">
<th style="width: 6%">ID</th>
<th>Titulo</th>
<th>Descripción</th>
<th style="width: 10%">Imagen</th>
<th style="width: 11%">Fecha</th>
<th style="width: 10%">Editar</th>
<th style="width: 10%">Eliminar</th>
</tr>
</thead>
<tbody>
<tr class="text-center" th:each="noticia : ${list}">
<td th:text="${noticia.id}"></td>
<td th:text="${noticia.titulo}"></td>
<td th:text="${noticia.descripcion}"></td>
<td><img class="card-img-top m-auto"
th:src="${noticia.imagen}"></td>
<td th:text="${noticia.fecha}"></td>
<td><a class="btn btn-warning">Editar <i
class="fa fa-edit"></i></a></td>
<td>
<form method="post">
<input type="hidden" name="id" />
<button type="submit" class="btn btn-danger">
Eliminar <i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<nav aria-label="Pagination">
<ul class="pagination justify-content-center">
<li class="page-item"
th:classappend="${prev == 0 ? 'disabled': ''}"><a
class="page-link" th:href="@{|/noticias/?page=${prev}|}">Anterior</a></li>
<li class="page-item" th:each="page : ${pages}"
th:classappend="${current == page ? 'active': ''}"><a
class="page-link" th:href="@{|/noticias/?page=${page}|}"
th:text="${page}"></a></li>
<li class="page-item"
th:classappend="${current == last ? 'disabled': ''}"><a
class="page-link" th:href="@{|/noticias/?page=${next}|}">Siguiente</a></li>
</ul>
</nav>
</div>
<div class="col-md-2"></div>
</div>
</div>
<div th:insert="layout/footer :: footer"></div>
</body>
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@ModelAttribute("noticia") Noticia noticia) {
this.noticia.save(noticia);
return "redirect:/";
}
<ul class="navbar-nav mr-auto">
<li class="nav-item active"><a class="nav-link" href="inicio">Inicio<span
class="sr-only">(current)</span></a></li>
<li class="nav-item"><a class="nav-link" href="noticias">Noticias</a></li>
<li class="nav-item"><a class="nav-link" href="noticias">Usuarios</a></li>
</ul>
import 'package:flutter/material.dart';
//Agrego esta weas de librerias
import 'package:barcode_scan/barcode_scan.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
void main() => runApp(MaterialApp(
theme: ThemeData(primarySwatch: Colors.green),
home: MyHomePage(),
));
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ScanResult _scanResult;
//Acá va la magía
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Lector códigos QR'),
),
body: Center(
child: _scanResult == null
? Text('Esperando datos de código')
: Column(
children: [
Text('Contenido: ${_scanResult.rawContent}'),
Text('Estado: ${_validado}'),
],
)),
floatingActionButton: FloatingActionButton(
onPressed: () {
_scanCode();
},
child: Icon(Icons.camera),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
//Método para escanear el codigo Qr
Future<void> _scanCode() async {
var result = await BarcodeScanner.scan();
recibirRespuestaGET(result.toString());
if (this._id == result.toString() && this._estado == "CONFIRMADO") {
setState(() {
_validado = "CONFIRMADO";
});
} else {
setState(() {
_validado = "DENEGADO";
});
}
}
Future<void> recibirRespuestaGET(String result) async {
final respuesta = await http
.get('https://mi-sitio.com/algo/?id=' + result);
if (respuesta.statusCode == 200) {
setState(() {
var parsedJson = json.decode(respuesta.body);
_id = parsedJson["_id"];
_estado = parsedJson["estado"];
});
} else {
throw Exception("Fallo");
}
}
String _id;
String _estado;
String _validado = "";
}
{_id: "1",
nombre: "Ana Keldysh",
nacionalidad: "Argentina",
edad: "17",
profesion: "Desarrollador Web Full Stack, pero la verdad hago de todo.",
"__v": 0
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
EventManager.RegisterClassHandler(typeof(Window), Window.MouseMoveEvent, new RoutedEventHandler(Window_MouseDown));
}
void Window_MouseMove(object sender, RoutedEventArgs e)
{
//tu evento aquí >.<
}