mirror of https://github.com/elunez/eladmin
team pl
parent
707cd002f8
commit
d181fb2e63
|
@ -18,6 +18,10 @@ package com.srr.repository;
|
||||||
import com.srr.domain.TeamPlayer;
|
import com.srr.domain.TeamPlayer;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
|
@ -28,4 +32,7 @@ public interface TeamPlayerRepository extends JpaRepository<TeamPlayer, Long>, J
|
||||||
boolean existsByTeamIdAndPlayerId(Long teamId, Long playerId);
|
boolean existsByTeamIdAndPlayerId(Long teamId, Long playerId);
|
||||||
|
|
||||||
TeamPlayer findByTeamIdAndPlayerId(Long teamId, Long playerId);
|
TeamPlayer findByTeamIdAndPlayerId(Long teamId, Long playerId);
|
||||||
|
|
||||||
|
@Query("SELECT tp FROM TeamPlayer tp JOIN tp.team t JOIN t.event e WHERE e.id = :eventId")
|
||||||
|
List<TeamPlayer> findByEventId(@Param("eventId") Long eventId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,10 @@ import com.srr.domain.Event;
|
||||||
import com.srr.dto.EventDto;
|
import com.srr.dto.EventDto;
|
||||||
import com.srr.dto.EventQueryCriteria;
|
import com.srr.dto.EventQueryCriteria;
|
||||||
import com.srr.dto.JoinEventDto;
|
import com.srr.dto.JoinEventDto;
|
||||||
|
import com.srr.dto.TeamPlayerDto;
|
||||||
import com.srr.enumeration.EventStatus;
|
import com.srr.enumeration.EventStatus;
|
||||||
import com.srr.service.EventService;
|
import com.srr.service.EventService;
|
||||||
|
import com.srr.service.TeamPlayerService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
@ -36,6 +38,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Chanheng
|
* @author Chanheng
|
||||||
|
@ -49,6 +52,7 @@ import java.io.IOException;
|
||||||
public class EventController {
|
public class EventController {
|
||||||
|
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final TeamPlayerService teamPlayerService;
|
||||||
|
|
||||||
@ApiOperation("Export Data")
|
@ApiOperation("Export Data")
|
||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
|
@ -104,6 +108,13 @@ public class EventController {
|
||||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/players")
|
||||||
|
@ApiOperation("Find all team players in an event")
|
||||||
|
@PreAuthorize("@el.check('event:list')")
|
||||||
|
public ResponseEntity<List<TeamPlayerDto>> findEventPlayers(@PathVariable("id") Long eventId) {
|
||||||
|
return new ResponseEntity<>(teamPlayerService.findByEventId(eventId), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@Log("Delete event")
|
@Log("Delete event")
|
||||||
@ApiOperation("Delete event")
|
@ApiOperation("Delete event")
|
||||||
|
|
|
@ -53,17 +53,4 @@ public class TeamPlayerController {
|
||||||
public ResponseEntity<TeamPlayerDto> checkIn(@PathVariable Long id) {
|
public ResponseEntity<TeamPlayerDto> checkIn(@PathVariable Long id) {
|
||||||
return new ResponseEntity<>(teamPlayerService.checkIn(id), HttpStatus.OK);
|
return new ResponseEntity<>(teamPlayerService.checkIn(id), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/find")
|
|
||||||
@ApiOperation("Find team player by team and player IDs")
|
|
||||||
@PreAuthorize("@el.check('event:list')")
|
|
||||||
public ResponseEntity<TeamPlayerDto> findByTeamAndPlayer(
|
|
||||||
@RequestParam Long teamId,
|
|
||||||
@RequestParam Long playerId) {
|
|
||||||
TeamPlayerDto teamPlayer = teamPlayerService.findByTeamIdAndPlayerId(teamId, playerId);
|
|
||||||
if (teamPlayer == null) {
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(teamPlayer, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import com.srr.dto.TeamPlayerDto;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import me.zhengjie.utils.PageResult;
|
import me.zhengjie.utils.PageResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Chanheng
|
* @author Chanheng
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
|
@ -43,10 +45,9 @@ public interface TeamPlayerService {
|
||||||
TeamPlayerDto checkIn(Long id);
|
TeamPlayerDto checkIn(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find TeamPlayer by teamId and playerId
|
* Find all TeamPlayers by event ID
|
||||||
* @param teamId the team ID
|
* @param eventId the event ID
|
||||||
* @param playerId the player ID
|
* @return List of TeamPlayerDto objects
|
||||||
* @return TeamPlayerDto if found, null otherwise
|
|
||||||
*/
|
*/
|
||||||
TeamPlayerDto findByTeamIdAndPlayerId(Long teamId, Long playerId);
|
List<TeamPlayerDto> findByEventId(Long eventId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ import me.zhengjie.exception.EntityNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Chanheng
|
* @author Chanheng
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
|
@ -64,8 +67,10 @@ public class TeamPlayerServiceImpl implements TeamPlayerService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public TeamPlayerDto findByTeamIdAndPlayerId(Long teamId, Long playerId) {
|
public List<TeamPlayerDto> findByEventId(Long eventId) {
|
||||||
TeamPlayer teamPlayer = teamPlayerRepository.findByTeamIdAndPlayerId(teamId, playerId);
|
List<TeamPlayer> teamPlayers = teamPlayerRepository.findByEventId(eventId);
|
||||||
return teamPlayer != null ? teamPlayerMapper.toDto(teamPlayer) : null;
|
return teamPlayers.stream()
|
||||||
|
.map(teamPlayerMapper::toDto)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue