Merge with assign
This commit is contained in:
@ -13,33 +13,48 @@ import org.springframework.context.event.EventListener;
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
public final static String API_VERSION = "v1";
|
||||
public final static String API_VERSION = "v1";
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
public static void main(String[] args) {
|
||||
Logo logo = new Logo("beta");
|
||||
System.out.println(logo.getLogo());
|
||||
System.out.println(
|
||||
"|=============================================================================================|");
|
||||
SpringApplication.run(App.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
Logo logo = new Logo("beta");
|
||||
System.out.println(logo.getLogo());
|
||||
System.out.println(
|
||||
"|=============================================================================================|");
|
||||
SpringApplication.run(App.class, args);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void importData() {
|
||||
User testUser = new User();
|
||||
testUser.setEmail("notexisting@mail.comain");
|
||||
testUser.setName("Tom");
|
||||
testUser.setSurname("Riddle");
|
||||
testUser.setRole(UserRoles.TEST_USER);
|
||||
this.userService.save(testUser);
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void importData() {
|
||||
User filip = new User();
|
||||
filip.setEmail("filizy@st.amu.edu.pl");
|
||||
filip.setName("Filip");
|
||||
filip.setSurname("Izydorczyk");
|
||||
filip.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(filip);
|
||||
|
||||
User filip = new User();
|
||||
filip.setEmail("filizy@st.amu.edu.pl");
|
||||
filip.setName("Filip");
|
||||
filip.setSurname("Izydorczyk");
|
||||
filip.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(filip);
|
||||
}
|
||||
User hub = new User();
|
||||
hub.setEmail("hubwrz1@st.amu.edu.pl");
|
||||
hub.setName("Hubert");
|
||||
hub.setSurname("Wrzesiński");
|
||||
hub.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(hub);
|
||||
|
||||
User mac = new User();
|
||||
mac.setEmail("macglo2@st.amu.edu.pl");
|
||||
mac.setName("Maciej");
|
||||
mac.setSurname("Głowacki");
|
||||
mac.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(mac);
|
||||
|
||||
User mar = new User();
|
||||
mar.setEmail("marwoz16@st.amu.edu.pl");
|
||||
mar.setName("Marcin");
|
||||
mar.setSurname("Woźniak");
|
||||
mar.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(mar);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
||||
public class AssignmentsController extends TokenBasedController {
|
||||
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@GetMapping("/getCurrentAssignments")
|
||||
public ResponseEntity<List<Object>> getCurrentAssignments() throws Exception {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
||||
if (com.isPresent()) {
|
||||
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
|
||||
|
||||
List<Object> finalResponse = new ArrayList<>();
|
||||
for (Assignment a : respone) {
|
||||
Dictionary<String, Object> elem = new Hashtable<>();
|
||||
Dictionary<String, Object> groupInfo = new Hashtable<>();
|
||||
elem.put("id", a.getId());
|
||||
Groups g = a.getGroup();
|
||||
groupInfo.put("id", g.getId());
|
||||
groupInfo.put("day", g.getDay().label);
|
||||
groupInfo.put("time", g.getTimeString());
|
||||
groupInfo.put("lecturer", g.getLecturer().toString());
|
||||
groupInfo.put("room", g.getRoom());
|
||||
groupInfo.put("capacity", g.getCapacity());
|
||||
groupInfo.put("type", g.getType());
|
||||
elem.put("group", groupInfo);
|
||||
finalResponse.add(elem);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(finalResponse, HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(null, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
||||
public class CommisionController extends TokenBasedController {
|
||||
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupServcicxe;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
public CommisionController() {
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<String> addCommision(@RequestBody List<Long> groups) throws UserNotFoundException {
|
||||
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
Commision com = new Commision(user);
|
||||
this.commisionService.save(com);
|
||||
|
||||
groups.stream().forEach((groupId) -> {
|
||||
Groups group = this.groupServcicxe.getGroupById(groupId).orElseThrow(() -> new NullPointerException());
|
||||
Assignment a = new Assignment(group, com);
|
||||
this.assignmentService.save(a);
|
||||
});
|
||||
|
||||
return new ResponseEntity<>("Succes", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getAllCommisions")
|
||||
public ResponseEntity<List<Commision>> getAlCommisions() throws UserNotFoundException {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
List<Commision> result = this.commisionService.getUsersCommisions(user);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
|
||||
public abstract class TokenBasedController {
|
||||
@Autowired
|
||||
protected UserService userService;
|
||||
|
||||
public TokenBasedController() {
|
||||
}
|
||||
|
||||
protected Optional<User> getCurrentUser() throws UserNotFoundException {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (!(authentication instanceof AnonymousAuthenticationToken)) {
|
||||
return Optional.of(this.userService.getUserByEmail(authentication.getName()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ public class AuthenticationProvider extends AbstractUserDetailsAuthenticationPro
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return user.getName() + " " + user.getSurname();
|
||||
return user.getEmail();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user