Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichailVlasopoulos committed Jan 23, 2021
1 parent ac51167 commit ab3ad80
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getAllRequests () throws JSONException, AdminServiceException, Res
}

@GetMapping(path="/admin/filterRequests")
public String filterRequestsByRequest(String requestType) throws JSONException, AdminServiceException, ResourceNotFoundException{
public String filterRequestsByRequest(@RequestParam String requestType) throws JSONException, AdminServiceException, ResourceNotFoundException{
try{
String response = adminService.filterRequests(requestType).toString();
if (response==null) throw new ResourceNotFoundException("Error retrieving all requests");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gr.hua.DistSysApp.ritoAPI.Controllers.UserControllers;

import com.fasterxml.jackson.core.JsonProcessingException;
import gr.hua.DistSysApp.ritoAPI.Models.GoPremiumRequest;
import gr.hua.DistSysApp.ritoAPI.Models.RegisterRequest;
import gr.hua.DistSysApp.ritoAPI.Repositories.UserRepository;
import gr.hua.DistSysApp.ritoAPI.Services.AdminServiceException;
import gr.hua.DistSysApp.ritoAPI.Services.PremiumUserServiceException;
import gr.hua.DistSysApp.ritoAPI.Services.UserService;
import gr.hua.DistSysApp.ritoAPI.exceptionHandling.ResourceNotFoundException;
Expand Down Expand Up @@ -58,6 +60,17 @@ public String goPremium (@RequestBody GoPremiumRequest goPremiumRequest) throws
}
}

@GetMapping(path="/user/getMyRequests")
public String getMyRequests (@RequestParam String requestStatus) throws JSONException, ResourceNotFoundException, PremiumUserServiceException {
try{
String response = userService.getMyRequests(requestStatus);
if (response==null) throw new ResourceNotFoundException("Error while making the request");
return response;
} catch (JsonProcessingException | AdminServiceException e) {
throw new PremiumUserServiceException("Internal Server Exception while getting exception");
}
}

@GetMapping(path="/user/requestMatchHistory")
public String requestMatchHistory () throws JSONException, PremiumUserServiceException, ResourceNotFoundException {
try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public interface RequestRepository extends JpaRepository<Request, Long> {
@Query(value = "SELECT * FROM Request WHERE user_id=?1 AND request_type=?2 ORDER BY created_at DESC LIMIT 1",nativeQuery = true)
Request findRequestByUseridAndRequestTypeOrdered(int UserId, String RequestType);

@Query(value = "SELECT * FROM Request WHERE user_id=?1 AND request_type=?2",nativeQuery = true)
List <Request> findRequestByUseridAndRequestType(int UserId, String RequestType);
@Query(value = "SELECT * FROM Request WHERE user_id=?",nativeQuery = true)
List <Request> findRequestByUserid(int UserId);

@Query(value = "SELECT * FROM Request WHERE request_type=?1",nativeQuery = true)
List <Request> findRequestsByRequestType(String RequestType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package gr.hua.DistSysApp.ritoAPI.Repositories;

import gr.hua.DistSysApp.ritoAPI.Models.Entities.Request;
import gr.hua.DistSysApp.ritoAPI.Models.Entities.RequestResults;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface RequestResultsRepository extends JpaRepository<RequestResults,Integer> {

@Query(value = "SELECT * FROM Requests_Results WHERE request_id=?",nativeQuery = true)
RequestResults findRequestResultsByRequest_id(int request_id);


@Query(value = "SELECT * FROM Request_Results WHERE request_status=?",nativeQuery = true)
List<Request> findRequestsByRequestStatus(String RequestStatus);

@Modifying(clearAutomatically = true)
@Transactional
@Query(value = "UPDATE Requests_Results SET request_status=?1,results=?2 WHERE request_id=?3",nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public Iterable<User> getAllUsers() {

//TODO CREATE filterRequests

public JSONObject filterRequests(String requestType) throws JSONException, AdminServiceException{
public JSONObject filterRequests(String requestStatus) throws JSONException, AdminServiceException{
List<Request> requests;
requests = requestRepository.findRequestsByRequestType(requestType);
requests = requestResultsRepository.findRequestsByRequestStatus(requestStatus);
JSONObject listOfRequests = new JSONObject(requests.toString());
if(listOfRequests==null) return JsonUtils.stringToJsonObject("Status", "There are no requests");
return listOfRequests;
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/gr/hua/DistSysApp/ritoAPI/Services/UserService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gr.hua.DistSysApp.ritoAPI.Services;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import gr.hua.DistSysApp.ritoAPI.Models.Entities.*;
import gr.hua.DistSysApp.ritoAPI.Repositories.*;
import gr.hua.DistSysApp.ritoAPI.Utilities.JsonUtils;
Expand All @@ -16,6 +18,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

@Service
public class UserService {
Expand Down Expand Up @@ -187,6 +190,32 @@ public JSONObject createSubscriptionRequest(User user, String request_type, Stri

}

public String getMyRequests(String requestStatus) throws JSONException, AdminServiceException, JsonProcessingException {

authentication = SecurityContextHolder.getContext().getAuthentication();
username = authentication.getName();
User user = userRepository.findByUsername(username);

List<Request> requests = user.getRequests();
List<RequestResults> pendingRequests = null;
RequestResults requestResults;

for (Request request:requests) {
requestResults = requestResultsRepository.findRequestResultsByRequest_id(request.getRequest_id());
if (requestResults.getRequest_status().equals(requestStatus)) {
pendingRequests.add(requestResults);
} else if (requestStatus.equals("RESOLVED")) {
pendingRequests.add(requestResults);
} else {
return "There are no such requests";
}
}

ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(pendingRequests);
return json;
}

@Transactional
public JSONObject Register(String username,String password, String firstName,String lastName, String email, String summonerName) throws PremiumUserServiceException, JSONException {

Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://2.tcp.ngrok.io:11469/hua?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=thanos
spring.datasource.password=thanos
#spring.datasource.url=jdbc:mysql://2.tcp.ngrok.io:11204/hua?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=thanos
#spring.datasource.password=thanos
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# LOCAL DATABASE

#spring.datasource.url=jdbc:mysql://localhost:3306/springtestV2?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/springtestV2?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root

0 comments on commit ab3ad80

Please sign in to comment.