mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2025-12-22 22:41:59 +00:00
various updates
This commit is contained in:
@@ -1,33 +1,42 @@
|
||||
package de.pnreichmuth.timekeep_backend.controllers;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import de.pnreichmuth.timekeep_backend.repositories.TeamRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.rmi.NoSuchObjectException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/teams")
|
||||
@Slf4j
|
||||
public class TeamRestController {
|
||||
@Autowired
|
||||
private TeamRepository teamRepository;
|
||||
|
||||
TeamService teamService;
|
||||
@PostMapping("createTeam")
|
||||
public Team createTeam(){
|
||||
Team team = new Team();
|
||||
teamRepository.save(team);
|
||||
public Team createTeam(@RequestBody Team team){
|
||||
teamService.createTeam(team);
|
||||
return team;
|
||||
}
|
||||
|
||||
@GetMapping("all")
|
||||
public List<Team> findAllTeams(){
|
||||
return teamRepository.findAll();
|
||||
return teamService.getTeams();
|
||||
}
|
||||
|
||||
@DeleteMapping("all")
|
||||
public void deleteAllTeams(){
|
||||
teamRepository.deleteAll();
|
||||
teamService.deleteAllTeams();
|
||||
}
|
||||
|
||||
@DeleteMapping("deleteTeam")
|
||||
public void deleteTeam(@RequestBody Team team){
|
||||
try{
|
||||
teamService.deleteTeam(team.getTeamName());
|
||||
} catch (NoSuchObjectException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import lombok.Setter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package de.pnreichmuth.timekeep_backend.repositories;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Racer;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Repository
|
||||
public interface RacerRepository extends JpaRepository<Racer, UUID> {
|
||||
public interface RacerRepository extends JpaRepository<@NonNull Racer,@NonNull UUID> {
|
||||
Racer findByName(String name);
|
||||
List<Racer> findAllByName(String name);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package de.pnreichmuth.timekeep_backend.repositories;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Station;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface StationRepository extends JpaRepository<Station, UUID> {
|
||||
public Station findByLocation(String location);
|
||||
public Station findByName(String name);
|
||||
public Station findByPasswordHash(String passwordHash);
|
||||
public interface StationRepository extends JpaRepository<@NonNull Station, @NonNull UUID> {
|
||||
Station findByLocation(String location);
|
||||
Station findByName(String name);
|
||||
Station findByPasswordHash(String passwordHash);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.pnreichmuth.timekeep_backend.repositories;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Station;
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -9,9 +10,11 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface TeamRepository extends JpaRepository<Team, UUID> {
|
||||
Team getTeamById(UUID id);
|
||||
public interface TeamRepository extends JpaRepository<@NonNull Team, @NonNull UUID> {
|
||||
Team getTeamByTeamName(String name);
|
||||
List<Team> getTeamsByFirstSemesterTeamIsTrue();
|
||||
List<Team> getTeamsByPassedStationsContains(Station station);
|
||||
void deleteTeamByTeamName(String name);
|
||||
|
||||
boolean existsByTeamName(String name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package de.pnreichmuth.timekeep_backend.services;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import de.pnreichmuth.timekeep_backend.repositories.TeamRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.rmi.NoSuchObjectException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("LoggingSimilarMessage")
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TeamService {
|
||||
private final TeamRepository teamRepository;
|
||||
|
||||
public Team getTeam(UUID id){
|
||||
return teamRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Team getTeam(String name){
|
||||
return teamRepository.getTeamByTeamName(name);
|
||||
}
|
||||
|
||||
public List<Team> getTeams(){
|
||||
return teamRepository.findAll();
|
||||
}
|
||||
|
||||
public void createTeam(){
|
||||
Team team = new Team();
|
||||
teamRepository.save(team);
|
||||
log.info("Team created: {}", team);
|
||||
}
|
||||
|
||||
public void createTeam(Team team){
|
||||
teamRepository.save(team);
|
||||
log.info("Team created: {}", team);
|
||||
}
|
||||
|
||||
public void createTeam(String name){
|
||||
Team tempTeam = new Team();
|
||||
tempTeam.setTeamName(name);
|
||||
teamRepository.save(tempTeam);
|
||||
log.info("Team created: {}", tempTeam);
|
||||
}
|
||||
|
||||
public void deleteTeam(UUID id) throws NoSuchObjectException{
|
||||
if(!teamRepository.existsById(id)) throw new NoSuchObjectException("Team not found");
|
||||
teamRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteTeam(String name) throws NoSuchObjectException{
|
||||
if(!teamRepository.existsByTeamName(name)) throw new NoSuchObjectException("Team not found");
|
||||
teamRepository.deleteTeamByTeamName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* DANGER ZONE
|
||||
*/
|
||||
public void deleteAllTeams(){
|
||||
teamRepository.deleteAll();
|
||||
log.warn("All teams deleted. Database is now empty.");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.pnreichmuth.timekeep_backend;
|
||||
package de.pnreichmuth.timekeep_backend.spring_configs;
|
||||
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
Reference in New Issue
Block a user