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

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

fixed some bugs and finalized user registration

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