source: src/main/java/it/finki/tinki/web/controller/AccountRegisterController.java@ 5f9d25a

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

refactoring controllers

  • 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 AccountRegisterController {
22
23 AccountService accountService;
24 SkillService skillService;
25 WorkService workService;
26 MatchmakerService matchmakerService;
27
28 public AccountRegisterController(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 Account k = this.accountService.registerUser(body.getEmail(), body.getPassword(), body.getName(), body.getSurname(), retained, toLearn);
41 Map<String, String> response = new HashMap<>();
42
43 if(k==null){
44 response.put("error", "There was an error when trying to register user.");
45 }else{
46 response.put("success", "Registration completed successfully.");
47 }
48
49 return response;
50 }
51
52 @RequestMapping(path = "/team", method = RequestMethod.POST)
53 private Map<String, String> registerTeam(@RequestBody TeamRegisterDTO body){
54
55 Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
56 Map<String, String> response = new HashMap<>();
57
58 if(k==null){
59 response.put("error", "There was an error when trying to register team.");
60 }else{
61 response.put("success", "Registration completed successfully.");
62 }
63
64 return response;
65 }
66
67 @RequestMapping(path = "/company", method = RequestMethod.POST)
68 private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){
69
70 Account k = this.accountService.registerCompany(body.getEmail(),
71 body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
72 Map<String, String> response = new HashMap<>();
73
74 if(k==null){
75 response.put("error", "There was an error when trying to register company.");
76 }else{
77 response.put("success", "Registration completed successfully.");
78 }
79
80 return response;
81 }
82}
Note: See TracBrowser for help on using the repository browser.