Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import drip.competition.feedback.entities.Game;
import drip.competition.feedback.repository.CompetitionRepository;
import drip.competition.feedback.repository.GameRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


@RestController
@RequestMapping("/admin")
@RequestMapping("/api/v1/admin")
@PreAuthorize("hasRole('ADMIN')")
public class AdminController {

Expand All @@ -27,14 +26,15 @@ public AdminController(GameRepository gameRepository,
this.competitionRepository = competitionRepository;
}

@GetMapping("/user")
@GetMapping("/users/{id}/matches")
@Transactional(readOnly = true)
public Page<Game> getUserMatches(@PathVariable("id") UUID iduser, Pageable pageable) {
return gameRepository.findByIduser(iduser, pageable);
}

@GetMapping("/users/{id}/tournaments")
@Transactional(readOnly = true)
public List<Object> getByUser(@RequestParam UUID iduser) {
List<Game> games = gameRepository.findByIduser(iduser);
List<Competition> competitions = competitionRepository.findByIduser(iduser);
List<Object> result = new ArrayList<>();
result.addAll(games);
result.addAll(competitions);
return result;
public Page<Competition> getUserTournaments(@PathVariable("id") UUID iduser, Pageable pageable) {
return competitionRepository.findByIduser(iduser, pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import drip.competition.feedback.entities.Game;
import drip.competition.feedback.repository.CompetitionRepository;
import drip.competition.feedback.repository.GameRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.List;
import java.net.URI;
import java.util.UUID;

@RestController
@RequestMapping("/user")
@RequestMapping("/api/v1/feedback")
@PreAuthorize("isAuthenticated()")
public class UserController {

Expand All @@ -25,25 +29,29 @@ public UserController(GameRepository gameRepository,
this.competitionRepository = competitionRepository;
}

@PostMapping("/add/game")
@PostMapping("/matches")
@Transactional
public Game addGame(@RequestBody Game game) {
return gameRepository.save(game);
public ResponseEntity<Void> createMatch(@RequestBody Game game, UriComponentsBuilder builder) {
Game saved = gameRepository.save(game);
URI location = builder.path("/api/v1/feedback/matches/{id}").buildAndExpand(saved.getId()).toUri();
return ResponseEntity.created(location).build(); // 201 Created
}

@PostMapping("/add/competition")
@PostMapping("/tournaments")
@Transactional
public Competition addCompetition(@RequestBody Competition competition) {
return competitionRepository.save(competition);
public ResponseEntity<Void> createTournament(@RequestBody Competition competition, UriComponentsBuilder builder) {
Competition saved = competitionRepository.save(competition);
URI location = builder.path("/api/v1/feedback/tournaments/{id}").buildAndExpand(saved.getId()).toUri();
return ResponseEntity.created(location).build(); // 201 Created
}

@GetMapping("/game")
public List<Game> getAllGame(@RequestParam UUID idgame) {
return gameRepository.findByIdgame(idgame);
@GetMapping("/matches")
public Page<Game> getMatches(@RequestParam UUID idgame, Pageable pageable) {
return gameRepository.findByIdgame(idgame, pageable);
}

@GetMapping("/competition")
public List<Competition> getAllCompetition(@RequestParam UUID idcompetition) {
return competitionRepository.findByIdcompetition(idcompetition);
@GetMapping("/tournaments")
public Page<Competition> getTournaments(@RequestParam UUID idcompetition, Pageable pageable) {
return competitionRepository.findByIdcompetition(idcompetition, pageable);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package drip.competition.feedback.repository;

import drip.competition.feedback.entities.Competition;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface CompetitionRepository extends JpaRepository<Competition, UUID> {

List<Competition> findByIdcompetition(UUID idcompetition);

List<Competition> findByIduser(UUID iduser);

Page<Competition> findByIduser(UUID iduser, Pageable pageable);
Page<Competition> findByIdcompetition(UUID idcompetition, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package drip.competition.feedback.repository;

import drip.competition.feedback.entities.Game;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface GameRepository extends JpaRepository<Game, UUID> {

List<Game> findByIdgame(UUID idgame);

List<Game> findByIduser(UUID iduser);

Page<Game> findByIduser(UUID iduser, Pageable pageable);
Page<Game> findByIdgame(UUID idgame, Pageable pageable);
}