Skip to content

Commit

Permalink
Merge pull request #1075 from bounswe/main
Browse files Browse the repository at this point in the history
Deploy recent changes 23.12.2023 17.26
  • Loading branch information
canuzdrn authored Dec 23, 2023
2 parents e6f1b2b + d290e0f commit 0788616
Show file tree
Hide file tree
Showing 107 changed files with 38,153 additions and 32,414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public ResponseEntity<List<GetGameListResponseDto>> getAllGames(@RequestBody(req
}

@GetMapping("get-game-list")
public ResponseEntity<List<Game>> getGames(@ParameterObject GetGameListRequestDto filter) {
List<Game> gameList = gameService.getGames(filter);
public ResponseEntity<List<GetGameListResponseDto>> getGames(@ParameterObject GetGameListRequestDto filter) {
List<GetGameListResponseDto> gameList = gameService.getGames(filter);
return ResponseEntity.ok(gameList);
}

Expand Down Expand Up @@ -121,4 +121,13 @@ public ResponseEntity<List<Game>> getRecommendedGames(@RequestHeader(name = Http
List<Game> games = gameService.getRecommendedGames(email);
return ResponseEntity.ok(games);
}

@AuthorizationRequired
@AdminRequired
@PostMapping("/promote")
public ResponseEntity<Game> changePromotionStatus(@RequestParam String id,@RequestHeader String Authorization,
HttpServletRequest request){
Game gameToPromote = gameService.changePromotionStatusOfGame(id);
return ResponseEntity.ok(gameToPromote);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.app.gamereview.dto.response.home;

import com.app.gamereview.enums.ForumType;
import com.app.gamereview.enums.VoteChoice;
import com.app.gamereview.model.Achievement;
import com.app.gamereview.model.Character;
import com.app.gamereview.model.Tag;
import com.app.gamereview.model.User;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -22,7 +26,13 @@ public class HomePagePostResponseDto {

private String postImage;

private String poster;
private User poster;

private Achievement achievement;

private Character character;

private VoteChoice userVote;

@NotNull
private String forum;
Expand Down
2 changes: 2 additions & 0 deletions app/backend/src/main/java/com/app/gamereview/model/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class Game extends BaseModel {

private String minSystemReq;

private Boolean isPromoted = false;

public Game(String gameName, String gameDescription, Date releaseDate, String minSystemReq) {
this.gameName = gameName;
this.gameDescription = gameDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.app.gamereview.model.Post;

import java.util.List;
import java.util.Optional;

public interface PostRepository extends MongoRepository<Post, String> {
Optional<Post> findByIdAndIsDeletedFalse(String postId);

List<Post> findByForumAndIsDeletedFalse(String forum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.MatchOperation;
import org.springframework.data.mongodb.core.aggregation.SampleOperation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -65,8 +68,20 @@ protected void configure() {
});
}

public List<Game> getGames(GetGameListRequestDto filter) {
public List<GetGameListResponseDto> getGames(GetGameListRequestDto filter) {

MatchOperation matchStage = Aggregation.match(Criteria.where("isPromoted").is(true));
SampleOperation sampleStage = Aggregation.sample(2);

Aggregation aggregation = Aggregation.newAggregation(matchStage, sampleStage);

List<Game> randomPromotedGames = new ArrayList<>(mongoTemplate.aggregate(aggregation, "Game", Game.class).getMappedResults());
List<String> randomPromotedGamesIds = randomPromotedGames.stream().map(Game::getId).collect(Collectors.toList());

Query query = new Query();

query.addCriteria(Criteria.where("_id").nin(randomPromotedGamesIds));

if(filter != null) {
if (filter.getFindDeleted() == null || !filter.getFindDeleted()) {
query.addCriteria(Criteria.where("isDeleted").is(false));
Expand All @@ -91,11 +106,26 @@ public List<Game> getGames(GetGameListRequestDto filter) {
}
}

return mongoTemplate.find(query, Game.class);
List<Game> gamesList = mongoTemplate.find(query, Game.class);

randomPromotedGames.addAll(gamesList);

return randomPromotedGames.stream().map(this::mapToGetGameListResponseDto).collect(Collectors.toList());

}

public List<GetGameListResponseDto> getAllGames(GetGameListRequestDto filter) {
MatchOperation matchStage = Aggregation.match(Criteria.where("isPromoted").is(true));
SampleOperation sampleStage = Aggregation.sample(2);

Aggregation aggregation = Aggregation.newAggregation(matchStage, sampleStage);

List<Game> randomPromotedGames = new ArrayList<>(mongoTemplate.aggregate(aggregation, "Game", Game.class).getMappedResults());
List<String> randomPromotedGamesIds = randomPromotedGames.stream().map(Game::getId).collect(Collectors.toList());

Query query = new Query();

query.addCriteria(Criteria.where("_id").nin(randomPromotedGamesIds));
if(filter != null) {
if (filter.getFindDeleted() == null || !filter.getFindDeleted()) {
query.addCriteria(Criteria.where("isDeleted").is(false));
Expand Down Expand Up @@ -125,7 +155,9 @@ public List<GetGameListResponseDto> getAllGames(GetGameListRequestDto filter) {

List<Game> gamesList = mongoTemplate.find(query, Game.class);

return gamesList.stream().map(this::mapToGetGameListResponseDto).collect(Collectors.toList());
randomPromotedGames.addAll(gamesList);

return randomPromotedGames.stream().map(this::mapToGetGameListResponseDto).collect(Collectors.toList());
}

private GetGameListResponseDto mapToGetGameListResponseDto(Game game) {
Expand Down Expand Up @@ -475,6 +507,19 @@ else if(findTag.get().getTagType().equals(TagType.GENRE)){
}
return score;
}

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

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

Game game = findGame.get();
game.setIsPromoted(!game.getIsPromoted());
gameRepository.save(game);
return game;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,17 @@ else if(forumOfPost.getType().equals(ForumType.GAME)){
typeName = findGame.get().getGameName();
}

Optional<User> findPoster = userRepository.findByIdAndIsDeletedFalse(post.getPoster());
findPoster.ifPresent(dto::setPoster);

Optional<Achievement> findAchievement = achievementRepository.findByIdAndIsDeletedFalse(post.getAchievement());
findAchievement.ifPresent(dto::setAchievement);

Optional<Character> findCharacter = characterRepository.findByIdAndIsDeletedFalse(post.getCharacter());
findCharacter.ifPresent(dto::setCharacter);

dto.setUserVote(null);

dto.setTypeName(typeName);

first20dto.add(dto);
Expand Down Expand Up @@ -673,6 +684,17 @@ else if(forumOfPost.getType().equals(ForumType.GAME)){
typeName = findGame.get().getGameName();
}

Optional<User> findPoster = userRepository.findByIdAndIsDeletedFalse(post.getPoster());
findPoster.ifPresent(dto::setPoster);

Optional<Achievement> findAchievement = achievementRepository.findByIdAndIsDeletedFalse(post.getAchievement());
findAchievement.ifPresent(dto::setAchievement);

Optional<Character> findCharacter = characterRepository.findByIdAndIsDeletedFalse(post.getCharacter());
findCharacter.ifPresent(dto::setCharacter);

dto.setUserVote(getUserVote(post.getId(), user.getId()));

dto.setTypeName(typeName);

first20dto.add(dto);
Expand All @@ -681,6 +703,16 @@ else if(forumOfPost.getType().equals(ForumType.GAME)){
return first20dto;
}

public VoteChoice getUserVote(String postId, String userId){
Optional<Post> findPost = postRepository.findByIdAndIsDeletedFalse(postId);

if(findPost.isEmpty()) return null;

Optional<Vote> userVote = voteRepository.findByTypeIdAndVotedBy(postId,userId);

return userVote.map(Vote::getChoice).orElse(null);
}

public List<Tag> populatedTags(List<String> tagIds){
List<Tag> res = new ArrayList<>();

Expand Down
9 changes: 8 additions & 1 deletion app/frontend/src/Pages/Admin/Game/CreateGame/CreateGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { NotificationUtil } from "../../../../Library/utils/notification";
import { handleAxiosError } from "../../../../Library/utils/handleError";

function CreateGame() {
// add gameIcon, duration, min system, developer and othertags req field
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [releaseDate, setReleaseDate] = useState<Date | null>(new Date());
const [minReq, setMinReq] = useState("");
const [selectedTags, setSelectedTags] = useState<any>({
playerTypes: [],
genre: [],
Expand Down Expand Up @@ -78,6 +78,7 @@ function CreateGame() {
description,
releaseDate,
gameIcon,
minReq,
...selectedTags,
});
};
Expand Down Expand Up @@ -145,6 +146,12 @@ function CreateGame() {
className={styles.datePicker}
/>
<br></br>
<Input
placeholder="Min System Requirements"
value={minReq}
className={styles.input}
onChange={(event) => setMinReq(event.target.value)}
/>
<MultipleSelect
title="Player Types"
filterKey="playerTypes"
Expand Down
11 changes: 9 additions & 2 deletions app/frontend/src/Pages/Admin/Game/UpdateGame/UpdateGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function UpdateGame() {
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [releaseDate, setReleaseDate] = useState<Date | null>(new Date());
const [minSystemReq, setMinSystemReq] = useState("");
const [fileList, setFileList] = useState<any[]>([]);

const { data: games } = useQuery(["games"], () => getGames());
Expand Down Expand Up @@ -57,7 +58,7 @@ function UpdateGame() {
description,
releaseDate,
gameIcon: gameIcon || game?.gameIcon,
minSystemReq: game.minSystemReq,
minSystemReq,
});
};

Expand Down Expand Up @@ -86,9 +87,9 @@ function UpdateGame() {
updatedGame = await getGame(updatedGame.id);
setId(updatedGame.id);
setGame(updatedGame);
console.log(updatedGame);
setName(updatedGame.gameName);
setDescription(updatedGame.gameDescription);
setMinSystemReq(updatedGame.minSystemReq);

const dateObject = new Date(Date.parse(updatedGame.releaseDate));

Expand Down Expand Up @@ -149,6 +150,12 @@ function UpdateGame() {
className={styles.datePicker}
/>
<br></br>
<Input
placeholder="Min System Requirements"
value={minSystemReq}
className={styles.input}
onChange={(event) => setMinSystemReq(event.target.value)}
/>
<Button className={styles.filterButton} onClick={handleClick}>
Update Game
</Button>
Expand Down
4 changes: 3 additions & 1 deletion app/frontend/src/Services/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export const createGame = async ({
name,
description,
releaseDate,
minReq,
gameIcon,
...tags
}: {
name: string;
description: string;
releaseDate: Date | null;
minReq: string;
gameIcon: any;
tags: any;
}) => {
Expand All @@ -29,7 +31,7 @@ export const createGame = async ({
releaseDate,
...tags,
platforms: tags.platform,
minSystemReq: "4GBRAM", // will be changed
minSystemReq: minReq,
gameIcon,
}
);
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export default defineConfig({
localsConvention: "camelCaseOnly",
},
},
optimizeDeps: {
exclude: ["js-big-decimal"],
},
});
8 changes: 8 additions & 0 deletions app/mobile/Assets/Button.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added app/mobile/Assets/Button/Bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0788616

Please sign in to comment.