[14b648e] | 1 | package it.finki.tinki.web.controller;
|
---|
| 2 |
|
---|
| 3 | import it.finki.tinki.model.Skill;
|
---|
| 4 | import it.finki.tinki.model.Users.Company;
|
---|
| 5 | import it.finki.tinki.model.Users.Team;
|
---|
| 6 | import it.finki.tinki.model.Users.User;
|
---|
[bd46dbb] | 7 | import it.finki.tinki.model.dto.register.account.CompanyRegisterDTO;
|
---|
| 8 | import it.finki.tinki.model.dto.register.account.TeamRegisterDTO;
|
---|
| 9 | import it.finki.tinki.model.dto.register.account.UserRegisterDTO;
|
---|
| 10 | import it.finki.tinki.model.dto.response.account.CompanyResponseDTO;
|
---|
| 11 | import it.finki.tinki.model.dto.response.account.TeamResponseDTO;
|
---|
| 12 | import it.finki.tinki.model.dto.response.account.UserResponseDTO;
|
---|
[14b648e] | 13 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
| 14 | import it.finki.tinki.service.AccountService;
|
---|
[5f9d25a] | 15 | import it.finki.tinki.service.BuilderService;
|
---|
[14b648e] | 16 | import it.finki.tinki.service.SkillService;
|
---|
[bd46dbb] | 17 | import org.springframework.web.bind.annotation.*;
|
---|
[14b648e] | 18 |
|
---|
| 19 | import java.util.List;
|
---|
| 20 | import java.util.Optional;
|
---|
| 21 |
|
---|
| 22 | @RestController
|
---|
[17abe5e] | 23 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
[bd38a55] | 24 | @RequestMapping(path = "/api/edit/account")
|
---|
| 25 | public class AccountEditController {
|
---|
[14b648e] | 26 |
|
---|
| 27 | AccountService accountService;
|
---|
| 28 | SkillService skillService;
|
---|
[5f9d25a] | 29 | BuilderService builderService;
|
---|
[14b648e] | 30 |
|
---|
[5f9d25a] | 31 | public AccountEditController(AccountService accountService, SkillService skillService, BuilderService builderService) {
|
---|
[14b648e] | 32 | this.accountService = accountService;
|
---|
| 33 | this.skillService = skillService;
|
---|
[5f9d25a] | 34 | this.builderService = builderService;
|
---|
[14b648e] | 35 | }
|
---|
| 36 |
|
---|
[33d4f5d] | 37 | @PostMapping(path = "/user/{id}/{email}")
|
---|
[14b648e] | 38 | public UserResponseDTO editUser(@PathVariable(name = "id") Long id,
|
---|
[33d4f5d] | 39 | @PathVariable(name = "email") String email,
|
---|
[14b648e] | 40 | @RequestBody UserRegisterDTO body){
|
---|
| 41 |
|
---|
[33d4f5d] | 42 | Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.USER);
|
---|
[14b648e] | 43 |
|
---|
| 44 | if(a.isPresent()){
|
---|
| 45 | List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
|
---|
| 46 | List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
|
---|
[bd38a55] | 47 | User u = this.accountService.editUser(id, body.getEmail(), body.getName(), body.getSurname(), retained, toLearn);
|
---|
[5f9d25a] | 48 | return this.builderService.buildUserResponseDTO(u);
|
---|
[14b648e] | 49 | }
|
---|
| 50 |
|
---|
[5f9d25a] | 51 | return new UserResponseDTO();
|
---|
[14b648e] | 52 | }
|
---|
| 53 |
|
---|
[33d4f5d] | 54 | @PostMapping(path = "/company/{id}/{email}")
|
---|
[14b648e] | 55 | public CompanyResponseDTO editCompany(@PathVariable(name = "id") Long id,
|
---|
[33d4f5d] | 56 | @PathVariable(name = "email") String email,
|
---|
[14b648e] | 57 | @RequestBody CompanyRegisterDTO body){
|
---|
| 58 |
|
---|
[33d4f5d] | 59 | Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.COMPANY);
|
---|
[14b648e] | 60 |
|
---|
| 61 | if(a.isPresent()){
|
---|
| 62 | Company c = this.accountService.editCompany(id, body.getEmail(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
|
---|
[5f9d25a] | 63 | return this.builderService.buildCompanyResponseDTO(c);
|
---|
[14b648e] | 64 | }
|
---|
| 65 |
|
---|
[5f9d25a] | 66 | return new CompanyResponseDTO();
|
---|
[14b648e] | 67 | }
|
---|
| 68 |
|
---|
[33d4f5d] | 69 | @PostMapping(path = "/team/{id}/{email}")
|
---|
[14b648e] | 70 | public TeamResponseDTO editTeam(@PathVariable(name = "id") Long id,
|
---|
[33d4f5d] | 71 | @PathVariable(name = "email") String email,
|
---|
[14b648e] | 72 | @RequestBody TeamRegisterDTO body){
|
---|
| 73 |
|
---|
[33d4f5d] | 74 | Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.TEAM);
|
---|
[14b648e] | 75 |
|
---|
| 76 | if(a.isPresent()){
|
---|
| 77 | Team t = this.accountService.editTeam(id, body.getEmail(), body.getName(), body.getMembers());
|
---|
[5f9d25a] | 78 | return this.builderService.buildTeamResponseDTO(t);
|
---|
[14b648e] | 79 | }
|
---|
| 80 |
|
---|
[5f9d25a] | 81 | return new TeamResponseDTO();
|
---|
[14b648e] | 82 | }
|
---|
| 83 | }
|
---|