add 2 new Queries and 2 Methods for UserService
This commit is contained in:
@ -1,9 +1,18 @@
|
||||
package mops.gruppen2.repository;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
@Query("select distinct group_id where user_id =:id")
|
||||
List<Long> findGroup_idsWhereUser_id(@Param("id") Long user_id);
|
||||
|
||||
@Query("select * where group_id =:id")
|
||||
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id);
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -18,9 +19,20 @@ import java.util.Map;
|
||||
public class GroupService {
|
||||
|
||||
private final EventService eventService;
|
||||
private final EventRepository eventRepository;
|
||||
|
||||
public GroupService(EventService eventService) {
|
||||
public GroupService(EventService eventService, EventRepository eventRepository) {
|
||||
this.eventService = eventService;
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
|
||||
public List<Event> getGroupEvents(List<Long> group_ids) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
List<Event> events = new ArrayList<>();
|
||||
for (Long group_id: group_ids) {
|
||||
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) throws EventException {
|
||||
|
||||
25
src/main/java/mops/gruppen2/service/UserService.java
Normal file
25
src/main/java/mops/gruppen2/service/UserService.java
Normal file
@ -0,0 +1,25 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
final EventRepository eventRepository;
|
||||
|
||||
public UserService(EventRepository eventRepository) {
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
|
||||
public List<Long> getUserGroups(Long user_id) {
|
||||
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user