- Timestamp:
- 01/11/21 18:57:03 (3 years ago)
- Branches:
- master
- Children:
- 8f1f460
- Parents:
- fc8421e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/tinki/web/controller/AccountEditController.java
rfc8421e r5f9d25a 13 13 import it.finki.tinki.model.enumerator.AccountType; 14 14 import it.finki.tinki.service.AccountService; 15 import it.finki.tinki.service.BuilderService; 15 16 import it.finki.tinki.service.SkillService; 16 17 import org.springframework.web.bind.annotation.*; … … 26 27 AccountService accountService; 27 28 SkillService skillService; 29 BuilderService builderService; 28 30 29 public AccountEditController(AccountService accountService, SkillService skillService ) {31 public AccountEditController(AccountService accountService, SkillService skillService, BuilderService builderService) { 30 32 this.accountService = accountService; 31 33 this.skillService = skillService; 34 this.builderService = builderService; 32 35 } 33 36 34 @PostMapping(path = "/user/{id} /{email}")37 @PostMapping(path = "/user/{id}") 35 38 public UserResponseDTO editUser(@PathVariable(name = "id") Long id, 36 @PathVariable(name = "email") String email,37 39 @RequestBody UserRegisterDTO body){ 38 40 39 Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.USER);41 Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.USER); 40 42 41 43 if(a.isPresent()){ 42 44 List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills()); 43 45 List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn()); 44 45 46 User u = this.accountService.editUser(id, body.getEmail(), body.getName(), body.getSurname(), retained, toLearn); 46 47 UserResponseDTO userResponseDTO = new UserResponseDTO(); 48 49 userResponseDTO.setId(u.getId()); 50 userResponseDTO.setEmail(u.getEmail()); 51 userResponseDTO.setType(AccountType.USER); 52 userResponseDTO.setError(null); 53 userResponseDTO.setName(u.getName()); 54 userResponseDTO.setSurname(u.getSurname()); 55 userResponseDTO.setRetained(u.getRetainedSkills()); 56 userResponseDTO.setToLearn(u.getSkillsToLearn()); 57 58 return userResponseDTO; 47 return this.builderService.buildUserResponseDTO(u); 59 48 } 60 49 61 return n ull;50 return new UserResponseDTO(); 62 51 } 63 52 64 @PostMapping(path = "/company/{id} /{email}")53 @PostMapping(path = "/company/{id}") 65 54 public CompanyResponseDTO editCompany(@PathVariable(name = "id") Long id, 66 @PathVariable(name = "email") String email,67 55 @RequestBody CompanyRegisterDTO body){ 68 56 69 Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.COMPANY);57 Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.COMPANY); 70 58 71 59 if(a.isPresent()){ 72 60 Company c = this.accountService.editCompany(id, body.getEmail(), body.getName(), body.getCountry(), body.getCity(), body.getStreet()); 73 74 CompanyResponseDTO companyResponseDTO = new CompanyResponseDTO(); 75 76 companyResponseDTO.setId(c.getId()); 77 companyResponseDTO.setEmail(c.getEmail()); 78 companyResponseDTO.setError(null); 79 companyResponseDTO.setType(AccountType.COMPANY); 80 companyResponseDTO.setName(c.getName()); 81 companyResponseDTO.setAddress(c.getAddress()); 82 83 return companyResponseDTO; 61 return this.builderService.buildCompanyResponseDTO(c); 84 62 } 85 63 86 return n ull;64 return new CompanyResponseDTO(); 87 65 } 88 66 89 @PostMapping(path = "/team/{id} /{email}")67 @PostMapping(path = "/team/{id}") 90 68 public TeamResponseDTO editTeam(@PathVariable(name = "id") Long id, 91 @PathVariable(name = "email") String email,92 69 @RequestBody TeamRegisterDTO body){ 93 70 94 Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.TEAM);71 Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.TEAM); 95 72 96 73 if(a.isPresent()){ 97 74 Team t = this.accountService.editTeam(id, body.getEmail(), body.getName(), body.getMembers()); 98 99 TeamResponseDTO teamResponseDTO = new TeamResponseDTO(); 100 101 teamResponseDTO.setId(t.getId()); 102 teamResponseDTO.setEmail(t.getEmail()); 103 teamResponseDTO.setError(null); 104 teamResponseDTO.setType(AccountType.TEAM); 105 teamResponseDTO.setName(t.getName()); 106 teamResponseDTO.setMembers(t.getMembers()); 107 108 return teamResponseDTO; 75 return this.builderService.buildTeamResponseDTO(t); 109 76 } 110 77 111 return n ull;78 return new TeamResponseDTO(); 112 79 } 113 80 }
Note:
See TracChangeset
for help on using the changeset viewer.