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

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

refactoring and response dto

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