Added some team methods
This commit is contained in:
parent
c53fbaf9d5
commit
565bf98432
@ -808,6 +808,18 @@ public class Controller {
|
||||
return ResponseEntity.status(200).body(new Gson().toJson(teamStatus));
|
||||
}
|
||||
|
||||
@RequestMapping("/api/getTeam")
|
||||
public ResponseEntity getTeam(@RequestParam String name){
|
||||
ResponseEntity responseEntity = FinderUtil.findTeamByName(name);
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/getTeamMembers")
|
||||
public ResponseEntity getTeamMembers(@RequestParam String name){
|
||||
return FinderUtil.findTeammemberByTeamName(name);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/api/hello")
|
||||
public ResponseEntity hello(@RequestParam String name) {
|
||||
|
||||
@ -1,8 +1,28 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.Team;
|
||||
import hhn.labsw.bugageocaching.entities.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TeamRepository extends JpaRepository<Team, Integer> {
|
||||
|
||||
Team findByName(String name);
|
||||
|
||||
@Query(value = "SELECT *\n" +
|
||||
"FROM user\n" +
|
||||
"WHERE id = (\n" +
|
||||
" SELECT user_id\n" +
|
||||
" FROM user_info\n" +
|
||||
" WHERE team_id = (SELECT team_id\n" +
|
||||
" FROM team\n" +
|
||||
" WHERE name = ?1\n" +
|
||||
" )\n" +
|
||||
")", nativeQuery = true)
|
||||
List<Object[]> getTeammembers(String name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@ -33,53 +35,6 @@ public class FinderUtil {
|
||||
|
||||
static TeamInviteRepository teamInviteRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setCacheRepository(CacheRepository cacheRepository) {
|
||||
FinderUtil.cacheRepository= cacheRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRewardRepository(RewardRepository rewardRepository) {
|
||||
FinderUtil.rewardRepository = rewardRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStationRepository(StationRepository stationRepository) {
|
||||
FinderUtil.stationRepository = stationRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBearbeitetRepository(BearbeitetRepository bearbeitetRepository) {
|
||||
FinderUtil.bearbeitetRepository = bearbeitetRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCacheAccesDefinitionRepository(CacheAccesDefinitionRepository cacheAccesDefinitionRepository) {
|
||||
FinderUtil.cacheAccesDefinitionRepository = cacheAccesDefinitionRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamRepository(TeamRepository teamRepository) {
|
||||
FinderUtil.teamRepository = teamRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserRepository(UserRepository userRepository) {
|
||||
FinderUtil.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUser_infoRepository(User_InfoRepository user_infoRepository) {
|
||||
FinderUtil.user_infoRepository = user_infoRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamInviteRepository(TeamInviteRepository teamInviteRepository) {
|
||||
FinderUtil.teamInviteRepository = teamInviteRepository;
|
||||
}
|
||||
|
||||
|
||||
public static ResponseEntity findCacheById(String cacheID) {
|
||||
|
||||
Optional<Cache> cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
|
||||
@ -167,4 +122,79 @@ public class FinderUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static ResponseEntity findTeamByName(String name) {
|
||||
|
||||
Team team = teamRepository.findByName(name);
|
||||
if (team != null) {
|
||||
return ResponseEntity.status(200).body(team);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Team with name " + name);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResponseEntity findTeammemberByTeamName(String name) {
|
||||
|
||||
List<Object[]> list = teamRepository.getTeammembers(name);
|
||||
if (list != null) {
|
||||
|
||||
List<User> sendBack = new LinkedList<>();
|
||||
|
||||
for (Object[] obj :
|
||||
list) {
|
||||
User tmp = new User();
|
||||
tmp.setUsername((String) obj[3]);
|
||||
sendBack.add(tmp);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(200).body(sendBack);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Team member of Team " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCacheRepository(CacheRepository cacheRepository) {
|
||||
FinderUtil.cacheRepository = cacheRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRewardRepository(RewardRepository rewardRepository) {
|
||||
FinderUtil.rewardRepository = rewardRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStationRepository(StationRepository stationRepository) {
|
||||
FinderUtil.stationRepository = stationRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBearbeitetRepository(BearbeitetRepository bearbeitetRepository) {
|
||||
FinderUtil.bearbeitetRepository = bearbeitetRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCacheAccesDefinitionRepository(CacheAccesDefinitionRepository cacheAccesDefinitionRepository) {
|
||||
FinderUtil.cacheAccesDefinitionRepository = cacheAccesDefinitionRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamRepository(TeamRepository teamRepository) {
|
||||
FinderUtil.teamRepository = teamRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserRepository(UserRepository userRepository) {
|
||||
FinderUtil.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUser_infoRepository(User_InfoRepository user_infoRepository) {
|
||||
FinderUtil.user_infoRepository = user_infoRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamInviteRepository(TeamInviteRepository teamInviteRepository) {
|
||||
FinderUtil.teamInviteRepository = teamInviteRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user