Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/example/project/dto/TipoReclamoDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.project.dto;

import lombok.Data;

@Data
public class TipoReclamoDTO {
private Long id;
private String nombre;

public TipoReclamoDTO(Long id, String nombre) {
this.id = id;
this.nombre = nombre;
}

}
17 changes: 17 additions & 0 deletions src/main/java/com/example/project/dto/reclamo/CrearReclamoDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.project.dto.reclamo;

import lombok.Data;

@Data
public class CrearReclamoDTO {

private Long tipoReclamoId;
private String descripcion;
private boolean critico;

public CrearReclamoDTO(Long tipoReclamoId, String descripcion, boolean critico) {
this.tipoReclamoId = tipoReclamoId;
this.descripcion = descripcion;
this.critico = critico;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.project.dto.reclamo;



import com.example.project.models.TipoReclamo;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class ResponseReclamoDTO {
private Long id;

private TipoReclamo tipoReclamo;

private String descripcion;

private boolean critico;



public ResponseReclamoDTO(Long id, TipoReclamo tipoReclamo, String descripcion, boolean critico) {
this.id = id;
this.tipoReclamo = tipoReclamo;
this.descripcion = descripcion;
this.critico = critico;

}
}
35 changes: 35 additions & 0 deletions src/main/java/com/example/project/mapper/ReclamoMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.project.mapper;

import java.util.List;

import com.example.project.dto.reclamo.CrearReclamoDTO;
import com.example.project.dto.reclamo.ResponseReclamoDTO;
import com.example.project.models.Reclamo;
import com.example.project.models.TipoReclamo;

public class ReclamoMapper {

public static ResponseReclamoDTO toDto(Reclamo reclamo){
return ResponseReclamoDTO.builder()
.id(reclamo.getId())
.tipoReclamo(reclamo.getTipoReclamo())
.descripcion(reclamo.getDescripcion())
.critico(reclamo.isCritico())
.build();
}

public static Reclamo toEntity(CrearReclamoDTO reclamoDto, TipoReclamo tipoReclamo){
return Reclamo.builder()
.tipoReclamo(tipoReclamo)
.descripcion(reclamoDto.getDescripcion())
.critico(reclamoDto.isCritico())
.build();
}

public static List<ResponseReclamoDTO> toDtoList(List<Reclamo> reclamos){
return reclamos
.stream()
.map(ReclamoMapper::toDto)
.toList();
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/example/project/models/Reclamo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.project.models;



import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;

import lombok.Builder;
import lombok.Data;

@Data
@Entity
@Builder
public class Reclamo {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "tipo_reclamo_id")
private TipoReclamo tipoReclamo;

private String descripcion;

private boolean critico;

public Reclamo() {

}

public Reclamo(Long id, TipoReclamo tipoReclamo, String descripcion, boolean critico) {
this.id = id;
this.tipoReclamo = tipoReclamo;
this.descripcion = descripcion;
this.critico = critico;
}


}
29 changes: 29 additions & 0 deletions src/main/java/com/example/project/models/TipoReclamo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.project.models;



import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

import lombok.Data;

@Data
@Entity
public class TipoReclamo {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String nombre;

public TipoReclamo() {

}

public TipoReclamo(String nombre) {
this.nombre = nombre;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.project.repositories;

import org.springframework.data.repository.CrudRepository;

import com.example.project.models.Reclamo;

public interface IReclamoRepository extends CrudRepository<Reclamo , Long>{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.project.services.reclamoServices;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

import com.example.project.mapper.ReclamoMapper;
import com.example.project.models.Reclamo;
import com.example.project.models.TipoReclamo;
import com.example.project.repositories.IReclamoRepository;
import com.example.project.services.reclamoServices.interfaces.IBuscarReclamoService;

public class BuscarReclamoService implements IBuscarReclamoService{

@Autowired
private IReclamoRepository repository;

@Override
public ResponseEntity<?> buscarReclamo(Long id) {

Optional<Reclamo> optionalReclamo = repository.findById(id);
if (optionalReclamo.isEmpty()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(ReclamoMapper.toDto(optionalReclamo.get()));

}

@Override
public ResponseEntity<?> buscarReclamos() {
return ResponseEntity
.ok()
.body(
ReclamoMapper.toDtoList((List<Reclamo>) repository.findAll())
);
}

@Override
public ResponseEntity<?> buscarReclamosPorTipo(TipoReclamo tipoReclamo) {
//Metodo no implementado
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.project.services.reclamoServices.interfaces;

import org.springframework.http.ResponseEntity;

import com.example.project.models.TipoReclamo;

public interface IBuscarReclamoService {

ResponseEntity<?> buscarReclamo(Long id);

ResponseEntity<?> buscarReclamos();

ResponseEntity<?> buscarReclamosPorTipo(TipoReclamo tipoReclamo);
}
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
spring.application.name=project.management

spring.datasource.url = jdbc:mysql://localhost:3306/e_commerce_db
spring.datasource.username = root
spring.datasource.password = admin
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true