Add createLecture feature
also add private checkbox again and delete the uploadCsv methods in APIController Co-Authored-By: tomvahl <tomvahl@users.noreply.github.com> Co-Authored-By: andibuls <andibuls@users.noreply.github.com> Co-Authored-By: Lukas Ettel <lukasettel@users.noreply.github.com>
This commit is contained in:
@ -60,13 +60,4 @@ public class APIController {
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/uploadcsv", consumes = "text/csv")
|
||||
public void uploadCsv(@RequestBody InputStream body) throws IOException {
|
||||
System.out.println(CsvService.read(body));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/uploadcsv", consumes = "multipart/form-data")
|
||||
public void uploadMultipart(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
System.out.println(CsvService.read(file.getInputStream()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,9 +17,11 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -71,13 +73,18 @@ public class Gruppen2Controller {
|
||||
return "createLecture";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/createLecture")
|
||||
public String pCreateLecture(KeycloakAuthenticationToken token,
|
||||
@RequestParam(value = "title") String title,
|
||||
@RequestParam(value = "beschreibung") String beschreibung) {
|
||||
@RequestParam(value = "beschreibung") String beschreibung,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("file") MultipartFile file) throws IOException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
controllerService.createGroup(account, title, beschreibung, true);
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
visibility = visibility == null;
|
||||
controllerService.createLecture(account, title, beschreibung, visibility, userList);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
@ -109,11 +116,7 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
if (visibility == null) {
|
||||
visibility = true;
|
||||
}else{
|
||||
visibility = false;
|
||||
}
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, beschreibung, visibility);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.*;
|
||||
import mops.gruppen2.domain.event.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -31,9 +28,9 @@ public class ControllerService {
|
||||
Visibility visibility1;
|
||||
Long group_id = eventService.checkGroup();
|
||||
|
||||
if (visibility){
|
||||
if(visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
}else{
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
@ -51,6 +48,13 @@ public class ControllerService {
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
public void addUserList(List<User> users, Long group_id) {
|
||||
for (User user : users) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(group_id, user.getUser_id(), user.getGivenname(), user.getFamilyname(), user.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTitle(Account account, Long group_id, String title){
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
@ -70,4 +74,24 @@ public class ControllerService {
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
||||
eventService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
|
||||
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) {
|
||||
Visibility visibility1;
|
||||
Long group_id = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, group_id);
|
||||
updateTitle(account, group_id, title);
|
||||
updateDescription(account, group_id, description);
|
||||
updateRole(account, group_id);
|
||||
addUserList(users, group_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user