pull/882/head^2
chanhengseang 2025-05-26 17:56:59 -07:00
parent 5d6a859214
commit 707cd002f8
4 changed files with 194 additions and 0 deletions

View File

@ -26,4 +26,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
**/
public interface TeamPlayerRepository extends JpaRepository<TeamPlayer, Long>, JpaSpecificationExecutor<TeamPlayer> {
boolean existsByTeamIdAndPlayerId(Long teamId, Long playerId);
TeamPlayer findByTeamIdAndPlayerId(Long teamId, Long playerId);
}

View File

@ -0,0 +1,69 @@
/*
* Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.srr.rest;
import com.srr.dto.TeamPlayerDto;
import com.srr.service.TeamPlayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
* @author Chanheng
* @website https://eladmin.vip
* @date 2025-05-26
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "Team Player Management")
@RequestMapping("/api/team-player")
public class TeamPlayerController {
private final TeamPlayerService teamPlayerService;
@GetMapping("/{id}")
@ApiOperation("Get team player details")
@PreAuthorize("@el.check('event:list')")
public ResponseEntity<TeamPlayerDto> getTeamPlayer(@PathVariable Long id) {
return new ResponseEntity<>(teamPlayerService.findById(id), HttpStatus.OK);
}
@PutMapping("/{id}/check-in")
@Log("Check in player")
@ApiOperation("Check in player for an event")
@PreAuthorize("@el.check('event:edit')")
public ResponseEntity<TeamPlayerDto> checkIn(@PathVariable Long id) {
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);
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.srr.service;
import com.srr.domain.TeamPlayer;
import com.srr.dto.TeamPlayerDto;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageResult;
/**
* @author Chanheng
* @website https://eladmin.vip
* @description Service interface for TeamPlayer
* @date 2025-05-26
**/
public interface TeamPlayerService {
/**
* Get a specific TeamPlayer by ID
* @param id TeamPlayer ID
* @return TeamPlayerDto
*/
TeamPlayerDto findById(Long id);
/**
* Check in a player for an event
* @param id TeamPlayer ID
* @return The updated TeamPlayerDto
*/
TeamPlayerDto checkIn(Long id);
/**
* Find TeamPlayer by teamId and playerId
* @param teamId the team ID
* @param playerId the player ID
* @return TeamPlayerDto if found, null otherwise
*/
TeamPlayerDto findByTeamIdAndPlayerId(Long teamId, Long playerId);
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.srr.service.impl;
import com.srr.domain.TeamPlayer;
import com.srr.dto.TeamPlayerDto;
import com.srr.dto.mapstruct.TeamPlayerMapper;
import com.srr.repository.TeamPlayerRepository;
import com.srr.service.TeamPlayerService;
import lombok.RequiredArgsConstructor;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.exception.EntityNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author Chanheng
* @website https://eladmin.vip
* @date 2025-05-26
**/
@Service
@RequiredArgsConstructor
public class TeamPlayerServiceImpl implements TeamPlayerService {
private final TeamPlayerRepository teamPlayerRepository;
private final TeamPlayerMapper teamPlayerMapper;
@Override
@Transactional(readOnly = true)
public TeamPlayerDto findById(Long id) {
TeamPlayer teamPlayer = teamPlayerRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(TeamPlayer.class, "id", id.toString()));
return teamPlayerMapper.toDto(teamPlayer);
}
@Override
@Transactional
public TeamPlayerDto checkIn(Long id) {
TeamPlayer teamPlayer = teamPlayerRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(TeamPlayer.class, "id", id.toString()));
if (teamPlayer.isCheckedIn()) {
throw new BadRequestException("Player is already checked in");
}
teamPlayer.setCheckedIn(true);
teamPlayerRepository.save(teamPlayer);
return teamPlayerMapper.toDto(teamPlayer);
}
@Override
@Transactional(readOnly = true)
public TeamPlayerDto findByTeamIdAndPlayerId(Long teamId, Long playerId) {
TeamPlayer teamPlayer = teamPlayerRepository.findByTeamIdAndPlayerId(teamId, playerId);
return teamPlayer != null ? teamPlayerMapper.toDto(teamPlayer) : null;
}
}