-
Notifications
You must be signed in to change notification settings - Fork 3
Adicionar profissionais a uma empresa #112
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
Open
TaisHryssai
wants to merge
12
commits into
develop
Choose a base branch
from
feature/add_professionals_company
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b231788
Adicionar profissionais a uma empresa
TaisHryssai 1bf39c6
método delete, na lista de profissionais da empresa
TaisHryssai 4146998
Adicionar profissional em uma empresa
TaisHryssai bd77b80
Merge branch 'develop' of https://github.com/utfpr-gp/servicebook int…
TaisHryssai 5511823
Atualizando branch e corrigindo conflitos
TaisHryssai e194a8c
Adicionar profissional em um empresa atraves de link por email
TaisHryssai 087ab17
Merge branch 'develop' into feature/add_professionals_company
ronifabio 06bba17
refactor: importações
ronifabio 23a0cf5
Correções ao adicionar profissional em uma empresa
TaisHryssai 2b1d3ce
Merge branch 'feature/add_professionals_company' of https://github.co…
TaisHryssai a0709fe
Correções ao adicionar profissional em uma empresa
TaisHryssai a9e0edd
Ajustes na inclusão do profissional em uma empresa
TaisHryssai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
232 changes: 232 additions & 0 deletions
232
src/main/java/br/edu/utfpr/servicebook/controller/CompanyProfessionalController.java
This file contains hidden or 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,232 @@ | ||
| package br.edu.utfpr.servicebook.controller; | ||
|
|
||
| import br.edu.utfpr.servicebook.model.dto.*; | ||
| import br.edu.utfpr.servicebook.model.entity.*; | ||
| import br.edu.utfpr.servicebook.model.mapper.*; | ||
| import br.edu.utfpr.servicebook.model.repository.UserRepository; | ||
| import br.edu.utfpr.servicebook.security.IAuthentication; | ||
| import br.edu.utfpr.servicebook.security.RoleType; | ||
| import br.edu.utfpr.servicebook.service.*; | ||
| import br.edu.utfpr.servicebook.sse.EventSSE; | ||
| import br.edu.utfpr.servicebook.sse.EventSSEDTO; | ||
| import br.edu.utfpr.servicebook.sse.EventSseMapper; | ||
| import br.edu.utfpr.servicebook.sse.SSEService; | ||
| import br.edu.utfpr.servicebook.util.TemplateUtil; | ||
| import br.edu.utfpr.servicebook.util.UserTemplateInfo; | ||
| import br.edu.utfpr.servicebook.util.UserTemplateStatisticInfo; | ||
| import com.cloudinary.utils.StringUtils; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.validation.BindingResult; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import org.springframework.web.servlet.ModelAndView; | ||
| import org.springframework.web.servlet.mvc.support.RedirectAttributes; | ||
| import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
|
||
| import javax.annotation.security.RolesAllowed; | ||
| import javax.persistence.EntityNotFoundException; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpSession; | ||
| import javax.validation.Valid; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
| @RequestMapping("/minha-conta/empresa/profissionais") | ||
| @Controller | ||
| public class CompanyProfessionalController { | ||
| public static final Logger log = LoggerFactory.getLogger(CompanyProfessionalController.class); | ||
| @Autowired | ||
| private UserService userService; | ||
|
|
||
| @Autowired | ||
| private CompanyProfessionalService companyProfessionalService; | ||
|
|
||
| @Autowired | ||
| private IAuthentication authentication; | ||
|
|
||
| @Autowired | ||
| private UserMapper userMapper; | ||
|
|
||
| @Autowired | ||
| private CompanyProfessionalMapper companyProfessionalMapper; | ||
|
|
||
| @Autowired | ||
| private TemplateUtil templateUtil; | ||
|
|
||
| @Autowired | ||
| private UserRepository userRepository; | ||
|
|
||
| @Autowired | ||
| private QuartzService quartzService; | ||
|
|
||
| @Autowired | ||
| private UserCodeMapper userCodeMapper; | ||
|
|
||
| @Autowired | ||
| private UserCodeService userCodeService; | ||
|
|
||
| @Autowired | ||
| private UserTokenMapper userTokenMapper; | ||
|
|
||
| @Autowired | ||
| private UserTokenService userTokenService; | ||
|
|
||
| @Autowired | ||
| private StateService stateService; | ||
|
|
||
| @Autowired | ||
| private SSEService sseService; | ||
|
|
||
| @Autowired | ||
| private EventSseMapper eventSseMapper; | ||
| @Autowired | ||
| private ProfessionalExpertiseService professionalExpertiseService; | ||
| @Autowired | ||
| private ExpertiseService expertiseService; | ||
|
|
||
| @Autowired | ||
| private ExpertiseMapper expertiseMapper; | ||
|
|
||
| /** | ||
| * Apresenta a tela para a empresa adicionar profissionais. | ||
| * @param id | ||
| * @return | ||
| * @throws Exception | ||
| */ | ||
| @GetMapping() | ||
| @RolesAllowed({RoleType.COMPANY}) | ||
| public ModelAndView showProfessionals(@RequestParam(required = false, defaultValue = "0") Optional<Long> expertiseId) throws Exception { | ||
|
|
||
| User company = this.getCompany(); | ||
| UserDTO professionalMinDTO = userMapper.toDto(company); | ||
|
|
||
| ModelAndView mv = new ModelAndView("company/new-professional"); | ||
|
|
||
| UserTemplateInfo userTemplateInfo = templateUtil.getUserInfo(professionalMinDTO); | ||
| UserTemplateStatisticInfo sidePanelStatisticDTO = templateUtil.getCompanyStatisticInfo(company, expertiseId.get()); | ||
|
|
||
| mv.addObject("statisticInfo", sidePanelStatisticDTO); | ||
|
|
||
| mv.addObject("id", expertiseId.orElse(0L)); | ||
|
|
||
| List<User> professionals = userService.findProfessionalsNotExist(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Está buscando todos os profissionais, não é o correto para o auto-complete. Imagine se tiver 100k de usuários. Deveria usar um like do SQL para buscar de acordo com os termos digitados. Limitar, trazer apenas umas 5 sugestões. |
||
|
|
||
| List<CompanyProfessional> companyProfessionals = companyProfessionalService.findByCompany(company.getId()); | ||
|
|
||
| List<CompanyProfessionalDTO2> companyProfessionalDTO2s = companyProfessionals.stream() | ||
| .map(s -> companyProfessionalMapper.toResponseDTO(s)) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| Optional<User> oProfessional = (userService.findByEmail(authentication.getEmail())); | ||
|
|
||
| UserTemplateInfo individualInfo = templateUtil.getUserInfo(professionalMinDTO); | ||
|
|
||
| //envia a notificação ao usuário | ||
| List<EventSSE> eventSsesList = sseService.findPendingEventsByEmail(authentication.getEmail()); | ||
| List<EventSSEDTO> eventSSEDTOs = eventSsesList.stream() | ||
| .map(eventSse -> { | ||
| return eventSseMapper.toFullDto(eventSse); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
| List<ProfessionalExpertise> professionalExpertises = professionalExpertiseService.findByProfessional(oProfessional.get()); | ||
|
|
||
| List<ExpertiseDTO> expertiseDTOs = professionalExpertises.stream() | ||
| .map(professionalExpertise -> professionalExpertise.getExpertise()) | ||
| .map(expertise -> expertiseMapper.toDto(expertise)) | ||
| .collect(Collectors.toList()); | ||
|
|
||
|
|
||
| mv.addObject("professionals", professionals); | ||
| mv.addObject("professionalCompanies", companyProfessionalDTO2s); | ||
| mv.addObject("statisticInfo", sidePanelStatisticDTO); | ||
| mv.addObject("eventsse", eventSSEDTOs); | ||
| mv.addObject("expertises", expertiseDTOs); | ||
| mv.addObject("company", true); | ||
|
|
||
| return mv; | ||
| } | ||
|
|
||
| @PostMapping() | ||
| @RolesAllowed({RoleType.COMPANY}) | ||
| public ModelAndView saveProfessionals(@Valid CompanyProfessionalDTO dto, BindingResult errors, RedirectAttributes redirectAttributes) throws Exception { | ||
|
|
||
| ModelAndView mv = new ModelAndView("redirect:profissionais"); | ||
| String ids = dto.getIds(); | ||
| User company = this.getCompany(); | ||
| Optional<User> company_name = userService.findById(company.getId()); | ||
| Optional<User> oCompany = (userService.findByEmail(authentication.getEmail())); | ||
|
|
||
| Optional<User> oProfessional = userService.findByEmail(ids); | ||
| if(!oProfessional.isPresent()){ | ||
| Random random = new Random(); | ||
| int numberRandom = random.nextInt(100 - 1) + 1; | ||
|
|
||
| String token = "RP0"+company.getId()+numberRandom; | ||
| UserTokenDTO userTokenDTO = new UserTokenDTO(); | ||
| userTokenDTO.setUser(company); | ||
| userTokenDTO.setEmail(ids); | ||
| userTokenDTO.setToken(token); | ||
| UserToken userToken = userTokenMapper.toEntity(userTokenDTO); | ||
|
|
||
| userTokenService.save(userToken); | ||
|
|
||
| String tokenLink = ServletUriComponentsBuilder.fromCurrentContextPath().build().toString() | ||
| + "/cadastrar-se?passo-1&code="+token; | ||
|
|
||
| quartzService.sendEmailToRegisterUser(dto.getIds(), company.getName(), tokenLink); | ||
| Optional<UserToken> optionalUserToken = userTokenService.findByEmail(ids); | ||
|
|
||
| // CompanyProfessional p = companyProfessionalService.save(new CompanyProfessional(company, dto.getIds())); | ||
| // redirectAttributes.addFlashAttribute("msg", "Convite enviado para usuário, aguardando confirmação!"); | ||
|
|
||
| } else { | ||
| String tokenLink = ServletUriComponentsBuilder.fromCurrentContextPath().build().toString() + "/confirmar?empresa=" + company_name.get().getName() +"&email=" + dto.getIds(); | ||
| quartzService.sendEmailWithConfirmationUser(dto.getIds(), company.getName(), tokenLink); | ||
|
|
||
| Optional<CompanyProfessional> optionalCompanyProfessional = companyProfessionalService.findByCompanyAndProfessional(company, oProfessional.get()); | ||
|
|
||
| if(!optionalCompanyProfessional.isPresent()){ | ||
| CompanyProfessional p = companyProfessionalService.save(new CompanyProfessional(company, oProfessional.get(), false)); | ||
| redirectAttributes.addFlashAttribute("msg", "Convite enviado para usuário, aguardando confirmação!"); | ||
| } else { | ||
| redirectAttributes.addFlashAttribute("msg", "Usuário ja está na empresa!"); | ||
| } | ||
| } | ||
| return mv; | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| @RolesAllowed({RoleType.COMPANY}) | ||
| @Transactional | ||
| public String delete(@PathVariable User id, RedirectAttributes redirectAttributes) throws Exception { | ||
| User company = this.getCompany(); | ||
| Optional<User> oProfessional = userService.findById(id.getId()); | ||
|
|
||
| Optional<CompanyProfessional> optionalCompanyProfessional = companyProfessionalService.findByCompanyAndProfessional(company, oProfessional.get()); | ||
|
|
||
| if (optionalCompanyProfessional.get().getProfessional().getId().equals(id.getId())) { | ||
| this.companyProfessionalService.delete(optionalCompanyProfessional.get().getId()); | ||
| } | ||
| return "redirect:/minha-conta/empresa/profissionais"; | ||
| } | ||
|
|
||
| /** | ||
| * Retorna a empresa logado. | ||
| * @return | ||
| * @throws Exception | ||
| */ | ||
| private User getCompany() throws Exception { | ||
| Optional<User> oCompany = (userService.findByEmail(authentication.getEmail())); | ||
|
|
||
| if (!oCompany.isPresent()) { | ||
| throw new Exception("Opss! Não foi possivel encontrar seus dados, tente fazer login novamente"); | ||
| } | ||
|
|
||
| return oCompany.get(); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.