1 | package it.finki.tinki.controller;
|
---|
2 |
|
---|
3 | import it.finki.tinki.model.Skill;
|
---|
4 | import it.finki.tinki.model.Users.Account;
|
---|
5 | import it.finki.tinki.model.Users.User;
|
---|
6 | import it.finki.tinki.service.AccountService;
|
---|
7 | import it.finki.tinki.service.SkillService;
|
---|
8 | import org.springframework.http.ResponseEntity;
|
---|
9 | import org.springframework.web.bind.annotation.*;
|
---|
10 |
|
---|
11 | import java.util.ArrayList;
|
---|
12 | import java.util.HashMap;
|
---|
13 | import java.util.List;
|
---|
14 | import java.util.Map;
|
---|
15 |
|
---|
16 | @RestController
|
---|
17 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
18 | @RequestMapping("/api/register")
|
---|
19 | public class RegisterController {
|
---|
20 |
|
---|
21 | AccountService accountService;
|
---|
22 | SkillService skillService;
|
---|
23 |
|
---|
24 | public RegisterController(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(@RequestParam String email,
|
---|
31 | @RequestParam String password,
|
---|
32 | @RequestParam String name,
|
---|
33 | @RequestParam String surname,
|
---|
34 | @RequestParam List<Integer> retainedSkills,
|
---|
35 | @RequestParam List<Integer> skillsToLearn){
|
---|
36 |
|
---|
37 | List<Skill> retained = this.skillService.returnSkillsBasedOnId(retainedSkills);
|
---|
38 | List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(skillsToLearn);
|
---|
39 |
|
---|
40 | Account k = this.accountService.registerUser(email, password, name, surname, retained, toLearn);
|
---|
41 |
|
---|
42 | Map<String, String> response = new HashMap<>();
|
---|
43 |
|
---|
44 | if(k!=null){
|
---|
45 | response.put("error", "There was an error when trying to register user.");
|
---|
46 | }else{
|
---|
47 | response.put("success", "Registration completed successfully.");
|
---|
48 | }
|
---|
49 |
|
---|
50 | return response;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | }
|
---|