package org.example.tampoposerverdtram.resources;
import java.util.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.client.*;
import jakarta.ws.rs.core.*;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
@Path("/friendRequests")
@Component
public class FriendRequests {
private List<Map<String, Object>> value = new ArrayList<>();
private Client client = ClientBuilder.newClient();
@Produces(MediaType.APPLICATION_JSON)
@GET
public List<Map<String, Object>> getValue() {
return new ArrayList<>(this.value);
}
@DELETE
public void deleteFriendRequest(@QueryParam("friendRequestId") int friendRequestId) {
List<Map<String, Object>> temp_if35;
if ((friendRequestId<this.value.size())) {
this.value.remove(friendRequestId);
temp_if35 = this.value;
} else {
temp_if35 = this.value;
}
this.value = temp_if35;
}
@POST
public void postFriendRequest(@FormParam("receiverId") String receiverId, @FormParam("senderId") String senderId) {
Map<String, Map<String, Object>> users_json = client.target("http://localhost:8080").path("/users").request().get(HashMap.class);
Map<String, Map<String, Object>> users = new HashMap<>();
users = users_json;
List<Map<String, Object>> temp_if37;
if (senderId.equals(receiverId)) {
temp_if37 = this.value;
} else {
List<Map<String, Object>> temp_if36;
if ((users.containsKey(senderId)&&users.containsKey(receiverId))) {
Map<String, Object> temp_json0 = new HashMap<>();
temp_json0.put("senderId", senderId);
temp_json0.put("receiverId", receiverId);
this.value.add(temp_json0);
temp_if36 = this.value;
} else {
temp_if36 = this.value;
}
temp_if37 = temp_if36;
}
this.value = temp_if37;
}
}