add leaving group
Co-Authored-By: xxnitram <xxnitram@users.noreply.github.com>
This commit is contained in:
@ -15,13 +15,16 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.ui.Model;
|
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.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@SessionScope
|
||||||
@RequestMapping("/gruppen2")
|
@RequestMapping("/gruppen2")
|
||||||
public class Gruppen2Controller {
|
public class Gruppen2Controller {
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ public class Gruppen2Controller {
|
|||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen", userService.getUserGroups(user.getUser_id()));
|
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||||
model.addAttribute("user",user);
|
model.addAttribute("user",user);
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
@ -125,4 +128,12 @@ public class Gruppen2Controller {
|
|||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@PostMapping("/leaveGroup")
|
||||||
|
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
controllerService.deleteUser(account, id);
|
||||||
|
System.out.println(id);
|
||||||
|
return "redirect:/gruppen2/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import mops.gruppen2.domain.Group;
|
|||||||
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
public class DeleteUserEvent extends Event {
|
public class DeleteUserEvent extends Event {
|
||||||
public DeleteUserEvent(Long group_id, String user_id) {
|
public DeleteUserEvent(Long group_id, String user_id) {
|
||||||
super(group_id, user_id);
|
super(group_id, user_id);
|
||||||
|
|||||||
@ -65,4 +65,10 @@ public class ControllerService {
|
|||||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(group_id,account.getName(),Role.ADMIN);
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(group_id,account.getName(),Role.ADMIN);
|
||||||
eventService.saveEvent(updateRoleEvent);
|
eventService.saveEvent(updateRoleEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteUser(Account account, Long group_id){
|
||||||
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
||||||
|
System.out.println(deleteUserEvent.getGroup_id() + " " + deleteUserEvent.getUser_id());
|
||||||
|
eventService.saveEvent(deleteUserEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,14 @@ package mops.gruppen2.service;
|
|||||||
|
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
//Hallo
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
|
|
||||||
@ -22,10 +23,17 @@ public class UserService {
|
|||||||
|
|
||||||
//Test nötig??
|
//Test nötig??
|
||||||
|
|
||||||
public List<Group> getUserGroups(String user_id) throws EventException {
|
public List<Group> getUserGroups(User user) throws EventException {
|
||||||
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user.getUser_id());
|
||||||
List<Event> events = groupService.getGroupEvents(group_ids);
|
List<Event> events = groupService.getGroupEvents(group_ids);
|
||||||
return groupService.projectEventList(events);
|
List<Group> groups = groupService.projectEventList(events);
|
||||||
|
List<Group> newGroups = new ArrayList<>();
|
||||||
|
for (Group group: groups) {
|
||||||
|
if(group.getMembers().contains(user)){
|
||||||
|
newGroups.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group getGroupById(Long group_id) throws EventException {
|
public Group getGroupById(Long group_id) throws EventException {
|
||||||
|
|||||||
@ -28,20 +28,20 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<form action="/" method="get">
|
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
||||||
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
<p style="font-weight: bold">
|
||||||
<p style="font-weight: bold">
|
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
||||||
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
<span class="badge badge-pill badge-primary" th:if="${group.getVisibility() == group.getVisibility().PUBLIC}">Öffentliche Gruppe</span>
|
||||||
<span class="badge badge-pill badge-primary" th:if="${group.getVisibility() == group.getVisibility().PUBLIC}">Öffentliche Gruppe</span>
|
<span class="badge badge-pill badge-success" style="background: lightseagreen" th:if="${group.getType() == group.getType().LECTURE}"> Veranstaltung</span>
|
||||||
<span class="badge badge-pill badge-success" style="background: lightseagreen" th:if="${group.getType() == group.getType().LECTURE}"> Veranstaltung</span>
|
</p>
|
||||||
</p>
|
<p th:text="${group.getDescription()}"></p>
|
||||||
<p th:text="${group.getDescription()}"></p>
|
<div class="form-group">
|
||||||
<div class="form-group">
|
<div class="text-right">
|
||||||
<div class="text-right">
|
<form method="post" action="/gruppen2/leaveGroup">
|
||||||
<button class="btn btn-danger" type="danger" style="border-style: none;">Gruppe verlassen</button>
|
<button th:value="${group.getId()}" th:name="group_id" class="btn btn-danger" type="submit" style="border-style: none;">Gruppe verlassen</button>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-3" style="white-space: nowrap">
|
<div class="col-3" style="white-space: nowrap">
|
||||||
@ -53,8 +53,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<ul th:each="member : ${group.getMembers()}" class="list-group-flush" style="background: slategrey">
|
<ul th:each="member : ${group.getMembers()}" class="list-group-flush" style="background: slategrey">
|
||||||
<li class="list-group-item" style="background: aliceblue">
|
<li class="list-group-item" style="background: aliceblue">
|
||||||
<span th:text="${member.getUser_id()}"></span>
|
<span th:text="${member.getUser_id()}"></span>
|
||||||
<span th:if="${role == role.ADMIN}" class="badge badge-success">admin</span>
|
<span th:if="${role == role.ADMIN}" class="badge badge-success">admin</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user