Skip to content

Commit

Permalink
Merge pull request #971 from bounswe/main
Browse files Browse the repository at this point in the history
Deployment of recent changes and developments 08.12.2023 21.13
  • Loading branch information
canuzdrn authored Dec 8, 2023
2 parents 1e48d28 + d4a9d77 commit 16fd296
Show file tree
Hide file tree
Showing 80 changed files with 34,633 additions and 3,880 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## CMPE352 Fundamentals of Software Engineering 2023 Spring - GROUP 5
## CMPE451 Project Development in Software Engineering 2023 Fall-GROUP 5

[![Watch on GitHub](https://img.shields.io/github/watchers/bounswe/bounswe2023group5.svg?style=social)](https://github.com/bounswe/bounswe2023group5/watchers)
[![Star on GitHub](https://img.shields.io/github/stars/bounswe/bounswe2023group5.svg?style=social)](https://github.com/bounswe/bounswe2023group5/stargazers)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.app.gamereview.controller;

import com.app.gamereview.dto.request.game.CreateGameRequestDto;
import com.app.gamereview.dto.request.game.GetGameListRequestDto;
import com.app.gamereview.dto.request.game.AddGameTagRequestDto;
import com.app.gamereview.dto.request.game.RemoveGameTagRequestDto;
import com.app.gamereview.dto.request.game.*;
import com.app.gamereview.dto.response.game.GameDetailResponseDto;
import com.app.gamereview.dto.response.game.GetGameListResponseDto;
import com.app.gamereview.dto.response.tag.AddGameTagResponseDto;
Expand All @@ -12,6 +9,7 @@
import com.app.gamereview.service.GameService;
import com.app.gamereview.util.validation.annotation.AdminRequired;
import com.app.gamereview.util.validation.annotation.AuthorizationRequired;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -88,4 +86,22 @@ public ResponseEntity<Game> createGame(@Valid @RequestBody CreateGameRequestDto
Game gameToCreate = gameService.createGame(createGameRequestDto);
return ResponseEntity.ok(gameToCreate);
}

@AuthorizationRequired
@PutMapping("/update")
public ResponseEntity<Game> editGame(@RequestParam String id,
@Valid @RequestBody UpdateGameRequestDto updateGameRequestDto,
@RequestHeader String Authorization, HttpServletRequest request) {
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
@@ -0,0 +1,42 @@
package com.app.gamereview.controller;

import com.app.gamereview.dto.request.home.HomePagePostsFilterRequestDto;
import com.app.gamereview.model.Post;
import com.app.gamereview.model.User;
import com.app.gamereview.service.PostService;
import com.app.gamereview.util.JwtUtil;
import com.app.gamereview.util.validation.annotation.AuthorizationRequired;
import jakarta.servlet.http.HttpServletRequest;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/home")
@Validated
public class HomeController {

private final PostService postService;

@Autowired
public HomeController(PostService postService) {
this.postService = postService;
}

@GetMapping
public ResponseEntity<List<Post>> getHomePagePosts(@ParameterObject HomePagePostsFilterRequestDto filter,
@RequestHeader(name = HttpHeaders.AUTHORIZATION,
required = false) String Authorization){
String email = null;
if (JwtUtil.validateToken(Authorization))
email = JwtUtil.extractSubject(Authorization);
List<Post> postsToShow = postService.getHomepagePosts(filter, email);
return ResponseEntity.ok(postsToShow);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.app.gamereview.dto.request.game;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
public class UpdateGameRequestDto {
@NotEmpty(message = "Game name cannot be null or empty")
private String gameName;

@NotEmpty(message = "Game description cannot be null or empty")
private String gameDescription;

@NotEmpty(message = "Game icon cannot be null or empty")
private String gameIcon;

@NotNull(message = "Release Date cannot be null or empty")
private Date releaseDate;

@NotEmpty(message = "Minimum system requirements cannot be null or empty")
private String minSystemReq;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class CreateGroupRequestDto {
message = "Game has Invalid Id (UUID) format")
private String gameId; // id of related game

private String groupIcon;

@Positive(message = "Quota cannot be negative or zero")
private int quota;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class UpdateGroupRequestDto {
@ValidMemberPolicy(allowedValues = {MembershipPolicy.PUBLIC, MembershipPolicy.PRIVATE})
private String membershipPolicy;

private String groupIcon;

@Positive(message = "Quota cannot be negative or zero")
private int quota;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.app.gamereview.dto.request.home;

import com.app.gamereview.enums.SortDirection;
import com.app.gamereview.enums.SortType;
import com.app.gamereview.util.validation.annotation.ValidSortDirection;
import com.app.gamereview.util.validation.annotation.ValidSortType;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class HomePagePostsFilterRequestDto {
@ValidSortType(allowedValues = {SortType.OVERALL_VOTE, SortType.CREATION_DATE, SortType.VOTE_COUNT})
private String sortBy = SortType.CREATION_DATE.name();

@ValidSortDirection(allowedValues = {SortDirection.ASCENDING, SortDirection.DESCENDING})
private String sortDirection = SortDirection.DESCENDING.name();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GetGroupDetailResponseDto {

private String forumId; // id of the forum of the group

private String groupIcon;

private int quota;

private List<MemberInfo> moderators = new ArrayList<>(); // userIds of the moderators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GetGroupResponseDto {

private String forumId; // id of the forum of the group

private String groupIcon;

private int quota;

private List<String> moderators = new ArrayList<>(); // userIds of the moderators
Expand Down
2 changes: 2 additions & 0 deletions app/backend/src/main/java/com/app/gamereview/model/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class Group extends BaseModel {

private String forumId; // id of the forum of the group

private String groupIcon;

private int quota;

private List<String> moderators = new ArrayList<>(); // userIds of the moderators
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.app.gamereview.model;

import com.app.gamereview.model.common.BaseModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.mongodb.core.mapping.Document;
Expand All @@ -13,6 +15,8 @@
@TypeAlias("Profile")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Profile extends BaseModel {
private String userId; // user the profile is linked to

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import com.app.gamereview.model.Post;

import java.util.List;

public interface PostRepository extends MongoRepository<Post, String> {

List<Post> findByForumAndIsDeletedFalse(String forum);

}
Original file line number Diff line number Diff line change
@@ -1,24 +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.CreateGameRequestDto;
import com.app.gamereview.dto.request.game.AddGameTagRequestDto;
import com.app.gamereview.dto.request.game.RemoveGameTagRequestDto;
import com.app.gamereview.dto.response.group.GetGroupResponseDto;
import com.app.gamereview.dto.request.game.*;
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 @@ -28,11 +23,10 @@
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.app.gamereview.dto.request.game.GetGameListRequestDto;
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 @@ -330,5 +324,37 @@ public Game createGame(CreateGameRequestDto request){
return gameRepository.save(gameToCreate);
}

public Game editGame(String id, UpdateGameRequestDto request){
Optional<Game> findGame = gameRepository.findByIdAndIsDeletedFalse(id);

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

Game gameToUpdate = findGame.get();
gameToUpdate.setGameName(request.getGameName());
gameToUpdate.setGameDescription(request.getGameDescription());
gameToUpdate.setGameIcon(request.getGameIcon());
gameToUpdate.setReleaseDate(request.getReleaseDate());
gameToUpdate.setMinSystemReq(request.getMinSystemReq());
gameRepository.save(gameToUpdate);

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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public Group updateGroup(String groupId, UpdateGroupRequestDto request) {
groupToUpdate.setMembershipPolicy(MembershipPolicy.valueOf(request.getMembershipPolicy()));
groupToUpdate.setQuota(request.getQuota());
groupToUpdate.setAvatarOnly(request.getAvatarOnly());
groupToUpdate.setGroupIcon(request.getGroupIcon());
groupRepository.save(groupToUpdate);
return groupToUpdate;
}
Expand Down
Loading

0 comments on commit 16fd296

Please sign in to comment.