source: src/main/java/it/finki/tinki/web/controller/RegisterController.java@ 31fc5c8

Last change on this file since 31fc5c8 was 31fc5c8, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

finalized register logic

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[723994f]1package it.finki.tinki.web.controller;
[7edede9]2
[4a15c9c]3import it.finki.tinki.model.Skill;
4import it.finki.tinki.model.Users.Account;
[31fc5c8]5import it.finki.tinki.model.dto.CompanyRegisterDTO;
6import it.finki.tinki.model.dto.TeamRegisterDTO;
[b31afbd]7import it.finki.tinki.model.dto.UserRegisterDTO;
[4a15c9c]8import it.finki.tinki.service.AccountService;
[509cb95]9import it.finki.tinki.service.MatchmakerService;
[4a15c9c]10import it.finki.tinki.service.SkillService;
[509cb95]11import it.finki.tinki.service.WorkService;
[4a15c9c]12import org.springframework.web.bind.annotation.*;
13
14import java.util.HashMap;
15import java.util.List;
16import java.util.Map;
[7edede9]17
18@RestController
19@CrossOrigin(origins = "http://localhost:3000")
20@RequestMapping("/api/register")
21public class RegisterController {
22
[4a15c9c]23 AccountService accountService;
24 SkillService skillService;
[509cb95]25 WorkService workService;
26 MatchmakerService matchmakerService;
[4a15c9c]27
[509cb95]28 public RegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
[4a15c9c]29 this.accountService = accountService;
30 this.skillService = skillService;
[509cb95]31 this.workService = workService;
32 this.matchmakerService = matchmakerService;
[4a15c9c]33 }
34
35 @RequestMapping(path = "/user", method = RequestMethod.POST)
[b31afbd]36 private Map<String, String> registerUser(@RequestBody UserRegisterDTO body){
[4a15c9c]37
[b31afbd]38 List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
39 List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
[4a15c9c]40
[b31afbd]41 Account k = this.accountService.registerUser(body.getEmail(), body.getPassword(), body.getName(), body.getSurname(), retained, toLearn);
[4a15c9c]42
43 Map<String, String> response = new HashMap<>();
44
[509cb95]45 if(k==null){
[4a15c9c]46 response.put("error", "There was an error when trying to register user.");
47 }else{
48 response.put("success", "Registration completed successfully.");
49 }
[7edede9]50
[4a15c9c]51 return response;
52 }
[7edede9]53
[9d4220d]54 @RequestMapping(path = "/team", method = RequestMethod.POST)
[31fc5c8]55 private Map<String, String> registerTeam(@RequestBody TeamRegisterDTO body){
[7edede9]56
[31fc5c8]57 Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
[9d4220d]58
59 Map<String, String> response = new HashMap<>();
60
[509cb95]61 if(k==null){
[9d4220d]62 response.put("error", "There was an error when trying to register team.");
63 }else{
64 response.put("success", "Registration completed successfully.");
65 }
66
67 return response;
68 }
69
70 @RequestMapping(path = "/company", method = RequestMethod.POST)
[31fc5c8]71 private Map<String, String> registeCompany(@RequestBody CompanyRegisterDTO body){
72
73 Account k = this.accountService.registerCompany(body.getEmail(),
74 body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
[9d4220d]75
76 Map<String, String> response = new HashMap<>();
77
[509cb95]78 if(k==null){
[9d4220d]79 response.put("error", "There was an error when trying to register company.");
80 }else{
81 response.put("success", "Registration completed successfully.");
82 }
83
84 return response;
85 }
[7edede9]86}
Note: See TracBrowser for help on using the repository browser.