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);
|
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.bind.annotation.*;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.context.annotation.SessionScope;
|
import org.springframework.web.context.annotation.SessionScope;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -71,13 +73,18 @@ public class Gruppen2Controller {
|
|||||||
return "createLecture";
|
return "createLecture";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||||
@PostMapping("/createLecture")
|
@PostMapping("/createLecture")
|
||||||
public String pCreateLecture(KeycloakAuthenticationToken token,
|
public String pCreateLecture(KeycloakAuthenticationToken token,
|
||||||
@RequestParam(value = "title") String title,
|
@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);
|
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/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
@ -109,11 +116,7 @@ public class Gruppen2Controller {
|
|||||||
@RequestParam(value = "visibility", required = false) Boolean visibility) {
|
@RequestParam(value = "visibility", required = false) Boolean visibility) {
|
||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
if (visibility == null) {
|
visibility = visibility == null;
|
||||||
visibility = true;
|
|
||||||
}else{
|
|
||||||
visibility = false;
|
|
||||||
}
|
|
||||||
controllerService.createGroup(account, title, beschreibung, visibility);
|
controllerService.createGroup(account, title, beschreibung, visibility);
|
||||||
|
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.*;
|
||||||
import mops.gruppen2.domain.GroupType;
|
|
||||||
import mops.gruppen2.domain.Role;
|
|
||||||
import mops.gruppen2.domain.Visibility;
|
|
||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -51,6 +48,13 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(addUserEvent);
|
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){
|
public void updateTitle(Account account, Long group_id, String title){
|
||||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
|
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
|
||||||
eventService.saveEvent(updateGroupTitleEvent);
|
eventService.saveEvent(updateGroupTitleEvent);
|
||||||
@ -70,4 +74,24 @@ public class ControllerService {
|
|||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
||||||
eventService.saveEvent(deleteUserEvent);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,6 +43,10 @@
|
|||||||
<label for="beschreibung">Beschreibung</label>
|
<label for="beschreibung">Beschreibung</label>
|
||||||
<textarea th:name="beschreibung" class="form-control" id="beschreibung" rows="3" required></textarea>
|
<textarea th:name="beschreibung" class="form-control" id="beschreibung" rows="3" required></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="custom-control custom-checkbox">
|
||||||
|
<input type="checkbox" id="visibility" class="custom-control-input" th:name="visibility">
|
||||||
|
<label class="custom-control-label" for="visibility">Private Gruppe</label>
|
||||||
|
</div>
|
||||||
<div class="form-group pt-4">
|
<div class="form-group pt-4">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
|
|||||||
Reference in New Issue
Block a user