Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dylan/hoja de vida #48

Merged
merged 3 commits into from
Jun 9, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.entrevistador.orquestador.dominio.model.enums;

import lombok.Getter;

@Getter
public enum EstadoHojaDeVidaEnum {
US("USADO"),
NU("NO USADO");

private String descripcion;

EstadoHojaDeVidaEnum(String descripcion) {
this.descripcion = descripcion;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.entrevistador.orquestador.infrastructure.adapter.dao;

import com.entrevistador.orquestador.dominio.model.Perfil;
import com.entrevistador.orquestador.dominio.model.enums.EstadoHojaDeVidaEnum;
import com.entrevistador.orquestador.infrastructure.adapter.mapper.HojaDeVidaMapper;
import com.entrevistador.orquestador.dominio.excepciones.IdHojaDeVidaRagNuloException;
import com.entrevistador.orquestador.dominio.excepciones.UsernameNoEncontradoException;
Expand All @@ -19,8 +20,10 @@ public class HojaDeVidaBdDao implements HojaDeVidaDao {
private final HojaDeVidaMapper mapper;

public Mono<Void> guardarHojaDeVida(HojaDeVidaModel hojaDeVidaModel){
return Mono.just(this.mapper.mapHojaDeVidaModelToHojaDeVidaEntity(hojaDeVidaModel))
.flatMap(this.hojaDeVidaRepository::save)
HojaDeVidaEntity entity = this.mapper.mapHojaDeVidaModelToHojaDeVidaEntity(hojaDeVidaModel);

return this.hojaDeVidaRepository.actualizarEstadoHojadeVidaPorUsername(entity.getUsername(), EstadoHojaDeVidaEnum.NU.name())
.then(this.hojaDeVidaRepository.save(entity))
.then();
}

Expand All @@ -34,7 +37,7 @@ public Mono<String> obtenerIdHojaDeVidaRag(String username){
}

public Mono<HojaDeVidaModel> obtenerHojaDeVidaPorNombreUsuario(String username){
return this.hojaDeVidaRepository.findFirstByUsernameOrderByFechaCreacionDesc(username)
return this.hojaDeVidaRepository.findFirstByUsernameAndEstadoHojaDeVida(username,EstadoHojaDeVidaEnum.US.name())
.map(this.mapper::mapHojaDeVidaEntityToHojaDeVida);
}

Expand All @@ -56,6 +59,7 @@ public Mono<Void> actualizarDatosPerfil(String uuid, Perfil perfil) {
.nivelIngles(perfil.getNivelIngles())
.otrasHabilidades(perfil.getOtrasHabilidades())
.fechaCreacion(hojaDeVidaEntity.getFechaCreacion())
.estadoHojaDeVida(hojaDeVidaEntity.getEstadoHojaDeVida())
.build())).then();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public class HojaDeVidaEntity {
private List<String> proyectos;
private String nivelIngles;
private List<String> otrasHabilidades;
private String estadoHojaDeVida;
private LocalDateTime fechaCreacion;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.entrevistador.orquestador.infrastructure.adapter.mapper;

import com.entrevistador.orquestador.dominio.model.enums.EstadoHojaDeVidaEnum;
import com.entrevistador.orquestador.infrastructure.adapter.dto.EntrevistaDto;
import com.entrevistador.orquestador.infrastructure.adapter.dto.FeedbackDto;
import com.entrevistador.orquestador.infrastructure.adapter.dto.HojaDeVidaDto;
Expand Down Expand Up @@ -32,8 +33,12 @@ public interface HojaDeVidaMapper {

@Mapping(target = "uuid", ignore = true)
@Mapping(target = "fechaCreacion", expression = "java(defaultFechaCreacion())")
@Mapping(target = "estadoHojaDeVida", expression = "java(defaultEstadoHojaDeVida())")
HojaDeVidaEntity mapHojaDeVidaModelToHojaDeVidaEntity(HojaDeVidaModel hojaDeVidaModel);

default String defaultEstadoHojaDeVida(){
return EstadoHojaDeVidaEnum.US.name();
}
default LocalDateTime defaultFechaCreacion() {
return LocalDateTime.now(ZoneOffset.UTC);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.entrevistador.orquestador.infrastructure.adapter.repository;

import com.entrevistador.orquestador.infrastructure.adapter.entity.HojaDeVidaEntity;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.data.mongodb.repository.Update;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;

@Repository
public interface HojaDeVidaRepository extends ReactiveMongoRepository<HojaDeVidaEntity, String> {
Mono<HojaDeVidaEntity> findFirstByUsernameOrderByFechaCreacionDesc(String username);

Mono<HojaDeVidaEntity> findFirstByUsernameAndEstadoHojaDeVida(String username, String estadoHojaDeVida);

@Query("{ 'username' : ?0, 'estadoHojaDeVida' : { $ne: 'AT' } }")
@Update("{'$set': {'estadoHojaDeVida': ?1 }}")
Mono<Void> actualizarEstadoHojadeVidaPorUsername(String username, String estadoHojaDeVida);
}