Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
BackEnd-V2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joel Andres Molina Velez
BackEnd-V2
Commits
c9dc2578
Commit
c9dc2578
authored
Jun 26, 2023
by
Joel Andres Molina Velez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se corrigen los servicios de ModelUzyTLineaOperativa
parent
f085138d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
52 deletions
+101
-52
UzyTavCabComcaController.java
...idad/MovilidadWS/Controller/UzyTavCabComcaController.java
+16
-10
UzyTavCabComcaMapper.java
...lidadWS/Mapper/Components_Class/UzyTavCabComcaMapper.java
+30
-3
ModelUzyTavCabComca.java
...espe/movilidad/MovilidadWS/Model/ModelUzyTavCabComca.java
+4
-10
IServiceUzyTavCabComca.java
...idadWS/Service/UzyTavCabComca/IServiceUzyTavCabComca.java
+7
-6
ServiceUzyTavCabComca.java
...lidadWS/Service/UzyTavCabComca/ServiceUzyTavCabComca.java
+44
-23
No files found.
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Controller/UzyTavCabComcaController.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Controller
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavCabComca.IServiceUzyTavCabComca
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -22,31 +23,36 @@ public class UzyTavCabComcaController {
@GetMapping
(
"/exampleFindId/{id}"
)
public
ResponseEntity
<
Model
UzyTavCabComca
>
ListarPorID
(
@PathVariable
Long
id
)
{
public
ResponseEntity
<
Dto
UzyTavCabComca
>
ListarPorID
(
@PathVariable
Long
id
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
ListarPorID
(
id
),
HttpStatus
.
OK
);
}
@GetMapping
(
"/getAll"
)
public
ResponseEntity
<
List
<
Model
UzyTavCabComca
>>
ListarRegistros
()
{
public
ResponseEntity
<
List
<
Dto
UzyTavCabComca
>>
ListarRegistros
()
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
ListarRegistros
(),
HttpStatus
.
OK
);
}
@PostMapping
(
"/guardar"
)
public
ResponseEntity
<
ModelUzyTavCabComca
>
guardar
(
@RequestBody
ModelUzyTavCabComca
model
UzyTavCabComca
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
guardar
(
model
UzyTavCabComca
),
HttpStatus
.
OK
);
public
ResponseEntity
<
DtoUzyTavCabComca
>
guardar
(
@RequestBody
DtoUzyTavCabComca
dto
UzyTavCabComca
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
guardar
(
dto
UzyTavCabComca
),
HttpStatus
.
OK
);
}
@PutMapping
(
"/editar/{id}"
)
public
ResponseEntity
<
ModelUzyTavCabComca
>
editar
(
@PathVariable
Long
id
,
@RequestBody
ModelUzyTavCabComca
model
UzyTavCabComca
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
editar
(
id
,
model
UzyTavCabComca
),
HttpStatus
.
OK
);
public
ResponseEntity
<
DtoUzyTavCabComca
>
editar
(
@PathVariable
Long
id
,
@RequestBody
DtoUzyTavCabComca
dto
UzyTavCabComca
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
editar
(
id
,
dto
UzyTavCabComca
),
HttpStatus
.
OK
);
}
@DeleteMapping
(
"/eliminar/{id}"
)
public
ResponseEntity
<
Void
>
eliminar
(
@PathVariable
Long
id
)
{
serviceUzyTavCabComca
.
eliminar
(
id
);
return
ResponseEntity
.
ok
().
build
();
public
ResponseEntity
<
String
>
eliminar
(
@PathVariable
Long
id
){
boolean
eliminado
=
serviceUzyTavCabComca
.
eliminar
(
id
);
if
(
eliminado
)
{
return
ResponseEntity
.
ok
(
"El registro se eliminó exitosamente."
);
}
else
{
return
ResponseEntity
.
notFound
().
build
();
}
}
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Mapper/Components_Class/UzyTavCabComcaMapper.java
View file @
c9dc2578
...
...
@@ -2,15 +2,23 @@ package ec.edu.espe.movilidad.MovilidadWS.Mapper.Components_Class;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavConsolca
;
import
org.modelmapper.ModelMapper
;
import
org.modelmapper.PropertyMap
;
import
org.springframework.stereotype.Component
;
import
javax.persistence.EntityManager
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Component
public
class
UzyTavCabComcaMapper
{
private
final
ModelMapper
modelMapper
;
public
UzyTavCabComcaMapper
(
ModelMapper
modelMapper
)
{
private
final
EntityManager
entityManager
;
public
UzyTavCabComcaMapper
(
ModelMapper
modelMapper
,
EntityManager
entityManager
)
{
this
.
modelMapper
=
modelMapper
;
this
.
entityManager
=
entityManager
;
configureMappings
();
}
public
DtoUzyTavCabComca
entityToDto
(
ModelUzyTavCabComca
entity
)
{
...
...
@@ -18,6 +26,25 @@ public class UzyTavCabComcaMapper {
}
public
ModelUzyTavCabComca
dtoToEntity
(
DtoUzyTavCabComca
dto
)
{
return
modelMapper
.
map
(
dto
,
ModelUzyTavCabComca
.
class
);
ModelUzyTavCabComca
entity
=
modelMapper
.
map
(
dto
,
ModelUzyTavCabComca
.
class
);
Long
consolcaID
=
dto
.
getUzytavconsolca_id
();
ModelUzyTavConsolca
valorPar
=
entityManager
.
find
(
ModelUzyTavConsolca
.
class
,
consolcaID
);
entity
.
setUzytavconsolca
(
valorPar
);
return
entity
;
}
public
List
<
DtoUzyTavCabComca
>
entitiesToDtos
(
List
<
ModelUzyTavCabComca
>
entities
)
{
return
entities
.
stream
()
.
map
(
this
::
entityToDto
)
.
collect
(
Collectors
.
toList
());
}
private
void
configureMappings
()
{
modelMapper
.
addMappings
(
new
PropertyMap
<
ModelUzyTavCabComca
,
DtoUzyTavCabComca
>()
{
@Override
protected
void
configure
()
{
map
().
setUzytavcabcomca_id
(
source
.
getUzytavcabcomca_id
());
map
().
setUzytavconsolca_id
(
source
.
getUzytavconsolca
().
getUzytavconsolca_id
());
}
});
}
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Model/ModelUzyTavCabComca.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
import
javax.persistence.*
;
import
java.util.Date
;
import
java.util.Set
;
@Data
@Getter
@Setter
@Entity
@Table
(
name
=
"uzytavcabcomca"
,
schema
=
"UTIC1"
)
public
class
ModelUzyTavCabComca
{
...
...
@@ -27,28 +29,20 @@ public class ModelUzyTavCabComca {
//RELACION CON PROYECT- cabcomca es la padre
//@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
//@JoinColumn(name = "uzytavcabcomca_id", referencedColumnName = "uzytavcabcomca_id")
//Set<ModelUzyTavProyec> modelUzyTavProyecss = new HashSet<>();
@JsonIgnore
@OneToMany
(
mappedBy
=
"uzytavcabcomca"
,
cascade
=
CascadeType
.
ALL
)
private
Set
<
ModelUzyTavProyec
>
modelUzyTavProyecs
;
//RELACION CON DETCOMCA-Tabla Hija
//
@JsonIgnore
@OneToMany
(
mappedBy
=
"uzytavcabcomca"
,
cascade
=
CascadeType
.
ALL
)
private
Set
<
ModelUzyTavDetComca
>
modelUzyTavDetComcas
;
///fetch = FetchType.LAZY
//RELACIÓN CON CONSOLCA- TABLA PADRE
@JsonIgnore
@ManyToOne
@JoinColumn
(
name
=
"uzytavconsolca_id"
)
private
ModelUzyTavConsolca
uzytavconsolca
;
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/UzyTavCabComca/IServiceUzyTavCabComca.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
UzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
java.util.List
;
public
interface
IServiceUzyTavCabComca
{
public
Model
UzyTavCabComca
ListarPorID
(
Long
id
);
Dto
UzyTavCabComca
ListarPorID
(
Long
id
);
public
List
<
Model
UzyTavCabComca
>
ListarRegistros
();
List
<
Dto
UzyTavCabComca
>
ListarRegistros
();
public
ModelUzyTavCabComca
guardar
(
ModelUzyTavCabComca
model
UzyTavCabComca
);
DtoUzyTavCabComca
guardar
(
DtoUzyTavCabComca
dto
UzyTavCabComca
);
public
ModelUzyTavCabComca
editar
(
Long
id
,
ModelUzyTavCabComca
model
UzyTavCabComca
);
DtoUzyTavCabComca
editar
(
Long
id
,
DtoUzyTavCabComca
dto
UzyTavCabComca
);
void
eliminar
(
Long
id
);
boolean
eliminar
(
Long
id
);
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/UzyTavCabComca/ServiceUzyTavCabComca.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
UzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dao.DaoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Exceptions.ResourceNotFoundException
;
import
ec.edu.espe.movilidad.MovilidadWS.Mapper.Components_Class.UzyTavCabComcaMapper
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
...
@@ -10,40 +12,59 @@ import java.util.List;
@Service
public
class
ServiceUzyTavCabComca
implements
IServiceUzyTavCabComca
{
@Autowired
DaoUzyTavCabComca
daoUzyTavCabComca
;
private
final
DaoUzyTavCabComca
daoUzyTavCabComca
;
private
final
UzyTavCabComcaMapper
mapper
;
public
ServiceUzyTavCabComca
(
DaoUzyTavCabComca
daoUzyTavCabComca
,
UzyTavCabComcaMapper
mapper
)
{
this
.
daoUzyTavCabComca
=
daoUzyTavCabComca
;
this
.
mapper
=
mapper
;
}
@Override
public
ModelUzyTavCabComca
ListarPorID
(
@PathVariable
Long
id
)
{
return
daoUzyTavCabComca
.
findById
(
id
).
get
();
public
DtoUzyTavCabComca
ListarPorID
(
@PathVariable
Long
id
)
{
ModelUzyTavCabComca
entity
=
daoUzyTavCabComca
.
findById
(
id
)
.
orElseThrow
(()
->
new
ResourceNotFoundException
(
"No se encontró el registro con ID: "
+
id
));
return
mapper
.
entityToDto
(
entity
);
}
@Override
public
List
<
ModelUzyTavCabComca
>
ListarRegistros
()
{
return
daoUzyTavCabComca
.
findAll
();
public
List
<
DtoUzyTavCabComca
>
ListarRegistros
()
{
List
<
ModelUzyTavCabComca
>
entities
=
daoUzyTavCabComca
.
findAll
();
return
mapper
.
entitiesToDtos
(
entities
);
}
@Override
public
ModelUzyTavCabComca
guardar
(
ModelUzyTavCabComca
modelUzyTavCabComca
)
{
return
daoUzyTavCabComca
.
save
(
modelUzyTavCabComca
);
public
DtoUzyTavCabComca
guardar
(
DtoUzyTavCabComca
dtoUzyTavCabComca
)
{
ModelUzyTavCabComca
entity
=
mapper
.
dtoToEntity
(
dtoUzyTavCabComca
);
ModelUzyTavCabComca
nuevoEntity
=
daoUzyTavCabComca
.
save
(
entity
);
return
mapper
.
entityToDto
(
nuevoEntity
);
}
@Override
public
ModelUzyTavCabComca
editar
(
@PathVariable
Long
id
,
ModelUzyTavCabComca
modelUzyTavCabComca
)
{
ModelUzyTavCabComca
dato
=
daoUzyTavCabComca
.
findById
(
id
).
get
();
//.orElseThrow(()->new ControlExcepciones("No existe el registro con el ID : " + id));
//Seteamos los nuevos datos del registro
dato
.
setUzytavcabcomca_id
(
modelUzyTavCabComca
.
getUzytavcabcomca_id
());
dato
.
setUzytavcabcomca_decsrip
(
modelUzyTavCabComca
.
getUzytavcabcomca_decsrip
());
dato
.
setUzytavcabcomca_fech_crea
(
modelUzyTavCabComca
.
getUzytavcabcomca_fech_crea
());
ModelUzyTavCabComca
datoActualizado
=
daoUzyTavCabComca
.
save
(
dato
);
return
datoActualizado
;
public
DtoUzyTavCabComca
editar
(
@PathVariable
Long
id
,
DtoUzyTavCabComca
dtoUzyTavCabComca
)
{
try
{
ModelUzyTavCabComca
entity
=
daoUzyTavCabComca
.
findById
(
id
).
get
();
if
(
entity
!=
null
)
{
entity
.
setUzytavcabcomca_decsrip
(
dtoUzyTavCabComca
.
getUzytavcabcomca_decsrip
());
entity
.
setUzytavcabcomca_fech_crea
(
dtoUzyTavCabComca
.
getUzytavcabcomca_fech_crea
());
ModelUzyTavCabComca
updatedEntity
=
daoUzyTavCabComca
.
save
(
entity
);
return
mapper
.
entityToDto
(
updatedEntity
);
}
else
{
throw
new
ResourceNotFoundException
(
"No se encontró el registro con ID: "
+
id
);
}
}
catch
(
Exception
e
)
{
throw
new
ResourceNotFoundException
(
"Error al editar el registro: "
+
e
.
getMessage
());
}
}
@Override
public
void
eliminar
(
@PathVariable
Long
id
)
{
ModelUzyTavCabComca
dato
=
daoUzyTavCabComca
.
findById
(
id
).
get
();
//.orElseThrow(() -> new ControlExcepciones("No existe el registro con el ID : " + id));
daoUzyTavCabComca
.
delete
(
dato
);
public
boolean
eliminar
(
Long
id
)
{
ModelUzyTavCabComca
entity
=
daoUzyTavCabComca
.
findById
(
id
).
orElse
(
null
);
if
(
entity
!=
null
)
{
daoUzyTavCabComca
.
delete
(
entity
);
return
true
;
}
return
false
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment