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

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

bugfixes and refactoring

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