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
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;
[509cb95]9import it.finki.tinki.service.MatchmakerService;
[4a15c9c]10import it.finki.tinki.service.SkillService;
[509cb95]11import it.finki.tinki.service.WorkService;
[4a15c9c]12import org.springframework.web.bind.annotation.*;
13
14import java.util.HashMap;
15import java.util.List;
16import java.util.Map;
[7edede9]17
18@RestController
19@CrossOrigin(origins = "http://localhost:3000")
20@RequestMapping("/api/register")
[297bd16]21public class AccountRegisterController {
[7edede9]22
[4a15c9c]23 AccountService accountService;
24 SkillService skillService;
[509cb95]25 WorkService workService;
26 MatchmakerService matchmakerService;
[4a15c9c]27
[297bd16]28 public AccountRegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
[4a15c9c]29 this.accountService = accountService;
30 this.skillService = skillService;
[509cb95]31 this.workService = workService;
32 this.matchmakerService = matchmakerService;
[4a15c9c]33 }
34
35 @RequestMapping(path = "/user", method = RequestMethod.POST)
[b31afbd]36 private Map<String, String> registerUser(@RequestBody UserRegisterDTO body){
[4a15c9c]37
[b31afbd]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);
[4a15c9c]41 Map<String, String> response = new HashMap<>();
42
[509cb95]43 if(k==null){
[4a15c9c]44 response.put("error", "There was an error when trying to register user.");
45 }else{
46 response.put("success", "Registration completed successfully.");
47 }
[7edede9]48
[4a15c9c]49 return response;
50 }
[7edede9]51
[9d4220d]52 @RequestMapping(path = "/team", method = RequestMethod.POST)
[31fc5c8]53 private Map<String, String> registerTeam(@RequestBody TeamRegisterDTO body){
[7edede9]54
[31fc5c8]55 Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
[9d4220d]56 Map<String, String> response = new HashMap<>();
57
[509cb95]58 if(k==null){
[9d4220d]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)
[14b648e]68 private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){
[31fc5c8]69
70 Account k = this.accountService.registerCompany(body.getEmail(),
71 body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
[9d4220d]72 Map<String, String> response = new HashMap<>();
73
[509cb95]74 if(k==null){
[9d4220d]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 }
[7edede9]82}
Note: See TracBrowser for help on using the repository browser.