Skip to content

Commit

Permalink
Merge pull request #968 from bounswe/backend/delete-game
Browse files Browse the repository at this point in the history
Delete game functionality is implemented
  • Loading branch information
Ardakacd authored Dec 8, 2023
2 parents aaa2653 + da7d177 commit 8885b6b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ public ResponseEntity<Game> editGame(@RequestParam String id,
Game updatedGame = gameService.editGame(id, updateGameRequestDto);
return ResponseEntity.ok(updatedGame);
}

@AuthorizationRequired
@AdminRequired
@DeleteMapping("/delete")
public ResponseEntity<Boolean> deleteGame(@RequestParam String id, @RequestHeader String Authorization,
HttpServletRequest request) {
Boolean isDeleted = gameService.deleteGame(id);
return ResponseEntity.ok(isDeleted);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.app.gamereview.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.app.gamereview.dto.request.game.*;
import com.app.gamereview.dto.response.group.GetGroupResponseDto;
import com.app.gamereview.dto.response.game.GameDetailResponseDto;
import com.app.gamereview.dto.response.game.GetGameListResponseDto;
import com.app.gamereview.dto.response.tag.AddGameTagResponseDto;
import com.app.gamereview.dto.response.tag.GetAllTagsOfGameResponseDto;
import com.app.gamereview.enums.ForumType;
import com.app.gamereview.enums.TagType;
import com.app.gamereview.exception.BadRequestException;
import com.app.gamereview.exception.ResourceNotFoundException;
import com.app.gamereview.model.Forum;
import com.app.gamereview.model.Group;
import com.app.gamereview.model.Game;
import com.app.gamereview.model.Tag;
import com.app.gamereview.repository.ForumRepository;
import com.app.gamereview.repository.GameRepository;
import com.app.gamereview.repository.TagRepository;
import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
Expand All @@ -26,10 +23,10 @@
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.app.gamereview.dto.response.game.GetGameListResponseDto;
import com.app.gamereview.model.Game;
import com.app.gamereview.repository.GameRepository;
import com.app.gamereview.dto.response.game.GameDetailResponseDto;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public class GameService {
Expand Down Expand Up @@ -345,5 +342,19 @@ public Game editGame(String id, UpdateGameRequestDto request){
return gameToUpdate;
}

public Boolean deleteGame(String id){
Optional<Game> findGame = gameRepository.findByIdAndIsDeletedFalse(id);

if(findGame.isEmpty()){
throw new ResourceNotFoundException("Game is not found");
}

Game gameToDelete = findGame.get();
gameToDelete.setIsDeleted(true);
gameRepository.save(gameToDelete);

return true;
}


}

0 comments on commit 8885b6b

Please sign in to comment.