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
RevLine 
[723994f]1package it.finki.tinki.web.controller;
[7edede9]2
[4a15c9c]3import it.finki.tinki.model.Skill;
4import it.finki.tinki.model.Users.Account;
[bd46dbb]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;
[4a15c9c]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;
[7edede9]15
16@RestController
17@CrossOrigin(origins = "http://localhost:3000")
18@RequestMapping("/api/register")
[297bd16]19public class AccountRegisterController {
[7edede9]20
[4a15c9c]21 AccountService accountService;
22 SkillService skillService;
23
[33d4f5d]24 public AccountRegisterController(AccountService accountService, SkillService skillService) {
[4a15c9c]25 this.accountService = accountService;
26 this.skillService = skillService;
27 }
28
29 @RequestMapping(path = "/user", method = RequestMethod.POST)
[b31afbd]30 private Map<String, String> registerUser(@RequestBody UserRegisterDTO body){
[4a15c9c]31
[b31afbd]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);
[4a15c9c]35 Map<String, String> response = new HashMap<>();
36
[509cb95]37 if(k==null){
[4a15c9c]38 response.put("error", "There was an error when trying to register user.");
39 }else{
40 response.put("success", "Registration completed successfully.");
41 }
[7edede9]42
[4a15c9c]43 return response;
44 }
[7edede9]45
[9d4220d]46 @RequestMapping(path = "/team", method = RequestMethod.POST)
[31fc5c8]47 private Map<String, String> registerTeam(@RequestBody TeamRegisterDTO body){
[7edede9]48
[31fc5c8]49 Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
[9d4220d]50 Map<String, String> response = new HashMap<>();
51
[509cb95]52 if(k==null){
[9d4220d]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)
[14b648e]62 private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){
[31fc5c8]63
64 Account k = this.accountService.registerCompany(body.getEmail(),
65 body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
[9d4220d]66 Map<String, String> response = new HashMap<>();
67
[509cb95]68 if(k==null){
[9d4220d]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 }
[7edede9]76}
Note: See TracBrowser for help on using the repository browser.