Skip to content

Commit

Permalink
Merge branch 'main' into frontend-user-agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardakacd authored Nov 20, 2023
2 parents 4565867 + 2782da4 commit 1b35a26
Show file tree
Hide file tree
Showing 169 changed files with 14,298 additions and 711 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.app.gamereview.controller;

import com.app.gamereview.dto.request.game.CreateGameRequestDto;
import com.app.gamereview.dto.request.tag.AddGameTagRequestDto;
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.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.model.Game;
import com.app.gamereview.service.GameService;
import com.app.gamereview.util.validation.annotation.AdminRequired;
import com.app.gamereview.util.validation.annotation.AuthorizationRequired;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.app.gamereview.dto.request.game.GetGameListRequestDto;
import com.app.gamereview.dto.response.game.GetGameListResponseDto;
import com.app.gamereview.service.GameService;

import java.util.List;

@RestController
Expand All @@ -33,12 +34,24 @@ public GameController(GameService gameService) {
}

@PostMapping("get-game-list")
public ResponseEntity<List<GetGameListResponseDto>> getGames(@RequestBody(required = false) GetGameListRequestDto filter) {
public ResponseEntity<List<GetGameListResponseDto>> getAllGames(@RequestBody(required = false) GetGameListRequestDto filter) {

List<GetGameListResponseDto> gameList = gameService.getAllGames(filter);
return ResponseEntity.ok().body(gameList);
}

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

@GetMapping("game-by-name")
public ResponseEntity<GameDetailResponseDto> getGameByName(String name) {
GameDetailResponseDto game = gameService.getGameByName(name);
return ResponseEntity.ok(game);
}

@AuthorizationRequired
@AdminRequired
@PostMapping("/add-tag")
Expand All @@ -48,6 +61,15 @@ public ResponseEntity<AddGameTagResponseDto> addGameTag(
return ResponseEntity.ok(response);
}

@AuthorizationRequired
@AdminRequired
@DeleteMapping("/remove-tag")
public ResponseEntity<Boolean> removeGameTag(
@Valid @RequestBody RemoveGameTagRequestDto removeGameTagRequestDto) {
Boolean response = gameService.removeGameTag(removeGameTagRequestDto);
return ResponseEntity.ok(response);
}

@GetMapping("/get-all-tags")
public ResponseEntity<GetAllTagsOfGameResponseDto> getAllTags(@RequestParam String gameId){
GetAllTagsOfGameResponseDto response = gameService.getGameTags(gameId);
Expand All @@ -61,7 +83,8 @@ public ResponseEntity<GameDetailResponseDto> getGameDetail(@RequestParam String

@AuthorizationRequired
@PostMapping("/create")
public ResponseEntity<Game> createGame(@Valid @RequestBody CreateGameRequestDto createGameRequestDto, String Authorization) {
public ResponseEntity<Game> createGame(@Valid @RequestBody CreateGameRequestDto createGameRequestDto,
@RequestHeader String Authorization) {
Game gameToCreate = gameService.createGame(createGameRequestDto);
return ResponseEntity.ok(gameToCreate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.app.gamereview.controller;

import com.app.gamereview.dto.request.group.*;
import com.app.gamereview.dto.response.group.GetGroupResponseDto;
import com.app.gamereview.dto.response.tag.AddGroupTagResponseDto;
import com.app.gamereview.model.Group;
import com.app.gamereview.model.User;
import com.app.gamereview.service.GroupService;
import com.app.gamereview.service.ReviewService;
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;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/group")
@Validated
public class GroupController {

@Value("${SECRET_KEY}")
private String secret_key = "${SECRET_KEY}";

private final GroupService groupService;

@Autowired
public GroupController(
GroupService groupService
) {
this.groupService = groupService;
}

@GetMapping("/get-all")
public ResponseEntity<List<GetGroupResponseDto>> getReviews(
@ParameterObject GetAllGroupsFilterRequestDto filter) {
List<GetGroupResponseDto> groups = groupService.getAllGroups(filter);
return ResponseEntity.ok(groups);
}

@GetMapping("/get")
public ResponseEntity<GetGroupResponseDto> getGroup(@RequestParam String id) {
GetGroupResponseDto group = groupService.getGroupById(id);

return ResponseEntity.ok(group);
}

@AuthorizationRequired
@PostMapping("/create")
public ResponseEntity<Group> createGroup(@Valid @RequestBody CreateGroupRequestDto createGroupRequestDto,
@RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Group groupToCreate = groupService.createGroup(createGroupRequestDto, user);
return ResponseEntity.ok(groupToCreate);
}

@AuthorizationRequired
@PutMapping("/update")
public ResponseEntity<Group> editGroup(@RequestParam String id,
@Valid @RequestBody UpdateGroupRequestDto updateGroupRequestDto,
@RequestHeader String Authorization, HttpServletRequest request) {
Group updatedGroup = groupService.updateGroup(id,updateGroupRequestDto);
return ResponseEntity.ok(updatedGroup);
}

@AuthorizationRequired
@DeleteMapping("/delete")
public ResponseEntity<Boolean> deleteGroup(String identifier,
@RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Boolean response = groupService.deleteGroup(identifier);
return ResponseEntity.ok(response);
}

@AuthorizationRequired
@PostMapping("/add-tag")
public ResponseEntity<AddGroupTagResponseDto> addGroupTag(
@Valid @RequestBody AddGroupTagRequestDto addGroupTagRequestDto) {
AddGroupTagResponseDto response = groupService.addGroupTag(addGroupTagRequestDto);
return ResponseEntity.ok(response);
}

@AuthorizationRequired
@DeleteMapping("/remove-tag")
public ResponseEntity<Boolean> removeGroupTag(
@Valid @RequestBody RemoveGroupTagRequestDto removeGroupTagRequestDto) {
Boolean response = groupService.removeGroupTag(removeGroupTagRequestDto);
return ResponseEntity.ok(response);
}

@AuthorizationRequired
@PostMapping("/join")
public ResponseEntity<Boolean> joinGroup(@RequestParam String id,
@RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Boolean joined = groupService.joinGroup(id, user);
return ResponseEntity.ok(joined);
}

@AuthorizationRequired
@PostMapping("/leave")
public ResponseEntity<Boolean> leaveGroup(@RequestParam String id,
@RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Boolean leave = groupService.leaveGroup(id, user);
return ResponseEntity.ok(leave);
}

@AuthorizationRequired
@PutMapping("/ban-user")
public ResponseEntity<Boolean> banUser(@RequestParam String groupId, @RequestParam String userId, @RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Boolean result = groupService.banUser(groupId, userId, user);
return ResponseEntity.ok(result);
}
@AuthorizationRequired
@PutMapping("/add-moderator")
public ResponseEntity<Boolean> addModerator(@RequestParam String groupId, @RequestParam String userId, @RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Boolean result = groupService.addModerator(groupId, userId, user);
return ResponseEntity.ok(result);
}

@AuthorizationRequired
@AdminRequired
@PutMapping("/remove-moderator")
public ResponseEntity<Boolean> removeModerator(@RequestParam String groupId, @RequestParam String userId, @RequestHeader String Authorization, HttpServletRequest request) {
Boolean result = groupService.removeModerator(groupId, userId);
return ResponseEntity.ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package com.app.gamereview.controller;

import com.app.gamereview.service.FileStorageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.*;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class ImageController {

private final FileStorageService fileService;
@Value("${image.base-directory}")
private String imageBaseDirectory;

public ImageController(FileStorageService fileService) {
this.fileService = fileService;
}

@GetMapping("/api/{folder}/{fileName:.+}")
public ResponseEntity<Resource> serveImage(@PathVariable String folder, @PathVariable String fileName) {
try {
Expand All @@ -41,4 +48,9 @@ public ResponseEntity<Resource> serveImage(@PathVariable String folder, @PathVar
}
}

@PostMapping("/api/image/upload")
public ResponseEntity<String> uploadImage(@RequestParam String folder, @RequestPart MultipartFile image) throws IOException {
return ResponseEntity.ok(folder + "/" + fileService.storeFile(image, folder));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public ResponseEntity<List<GetPostCommentsResponseDto>> getPostComments(@Request

@AuthorizationRequired
@PostMapping("/create")
public ResponseEntity<Post> createPost(@Valid @RequestBody CreatePostRequestDto post, @RequestHeader String Authorization, HttpServletRequest request) {
public ResponseEntity<Post> createPost(@Valid @RequestBody CreatePostRequestDto post,
@RequestHeader String Authorization, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
Post postToCreate = postService.createPost(post, user);
return ResponseEntity.ok(postToCreate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
import com.app.gamereview.model.Review;
import com.app.gamereview.model.User;
import com.app.gamereview.service.ReviewService;
import com.app.gamereview.util.validation.annotation.AdminRequired;
import com.app.gamereview.util.validation.annotation.AuthorizationRequired;
import io.jsonwebtoken.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.apache.tomcat.util.http.parser.Authorization;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.Date;
import java.util.List;

@RestController
@RequestMapping("/api/review")
@Validated
public class ReviewController {

@Value("${SECRET_KEY}")
private String secret_key = "${SECRET_KEY}";

private final ReviewService reviewService;

@Autowired
Expand All @@ -36,8 +41,28 @@ public ReviewController(

@GetMapping("/get-all")
public ResponseEntity<List<GetAllReviewsResponseDto>> getReviews(
@ParameterObject GetAllReviewsFilterRequestDto filter) {
List<GetAllReviewsResponseDto> reviews = reviewService.getAllReviews(filter);
@ParameterObject GetAllReviewsFilterRequestDto filter,
@RequestHeader(name = HttpHeaders.AUTHORIZATION, required = false) String Authorization) {

String email = "";
try {
Claims claims = Jwts.parser().setSigningKey(secret_key).parseClaimsJws(String.valueOf(Authorization)).getBody();

Date expirationDate = claims.getExpiration();
Date now = new Date();
if (expirationDate.after(now)) {
email = claims.getSubject();
}
}
catch (SignatureException | ExpiredJwtException | IllegalArgumentException | MalformedJwtException e) {
// SignatureException: Token signature is invalid
// ExpiredJwtException: Token has expired
// IllegalArgumentException: Token is not correctly formatted
// MalformedJwtException: Token is not correctly formatted (eg. empty string)
// In any of these cases, the token is considered invalid
}

List<GetAllReviewsResponseDto> reviews = reviewService.getAllReviews(filter, email);
return ResponseEntity.ok(reviews);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.app.gamereview.dto.request.tag;
package com.app.gamereview.dto.request.game;


import jakarta.validation.constraints.NotEmpty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
@NoArgsConstructor
public class GetGameListRequestDto {

private Boolean findDeleted;
private Boolean findDeleted = false;

private String gameName;

private List<String> playerTypes;

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


import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class RemoveGameTagRequestDto {

@NotEmpty(message = "Game Id field cannot be null or empty")
@Pattern(regexp = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
message = "Game Id has Invalid Id (UUID) format")
private String gameId;

@NotEmpty(message = "Tag Id field cannot be null or empty")
@Pattern(regexp = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
message = "Tag Id has Invalid Id (UUID) format")
private String tagId;
}
Loading

0 comments on commit 1b35a26

Please sign in to comment.