Fixed event/all and event/del endpoints
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package res;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.JsonProcessingException;
 | 
			
		||||
import com.fasterxml.jackson.core.type.TypeReference;
 | 
			
		||||
import com.fasterxml.jackson.databind.ObjectMapper;
 | 
			
		||||
import helper.Tuple;
 | 
			
		||||
 | 
			
		||||
@@ -11,6 +12,7 @@ import java.io.OutputStream;
 | 
			
		||||
import java.net.HttpURLConnection;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class DataController {
 | 
			
		||||
@@ -66,34 +68,35 @@ public class DataController {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deleteEvent(int eventId) {
 | 
			
		||||
    public void deleteEvent(int userId, int eventId, LocalDateTime date) {
 | 
			
		||||
        try {
 | 
			
		||||
            System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId, true));
 | 
			
		||||
            System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate());
 | 
			
		||||
            System.out.println(httpRequest.sendPostRequest(
 | 
			
		||||
                    DELETE_EVENT_ENDPOINT,
 | 
			
		||||
                    "userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(),
 | 
			
		||||
                    true
 | 
			
		||||
            ));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ArrayList<Event> getAllVisibleEvents() {
 | 
			
		||||
    public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) {
 | 
			
		||||
        ArrayList<Event> eventList = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            Tuple<Integer, String> response = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true);
 | 
			
		||||
            Tuple<Integer, String> response = httpRequest.sendPostRequest(
 | 
			
		||||
                    ALL_EVENTS_ENDPOINT,
 | 
			
		||||
                    "userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(),
 | 
			
		||||
                    true
 | 
			
		||||
            );
 | 
			
		||||
            String jsonResponse = response.getValue();
 | 
			
		||||
            System.out.println(jsonResponse);
 | 
			
		||||
 | 
			
		||||
            ObjectMapper objectMapper = new ObjectMapper();
 | 
			
		||||
            objectMapper.findAndRegisterModules();
 | 
			
		||||
            eventList = (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>(){});
 | 
			
		||||
 | 
			
		||||
            for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
 | 
			
		||||
                ArrayList<Object> list = new ArrayList<>();
 | 
			
		||||
                if (obj.getClass().isArray()) {
 | 
			
		||||
                    list = (ArrayList<Object>) Arrays.asList((Object[]) obj);
 | 
			
		||||
                } else if (obj instanceof Collection) {
 | 
			
		||||
                    list = new ArrayList<>((Collection<?>) obj);
 | 
			
		||||
                }
 | 
			
		||||
                eventList.add(new Event(list));
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package res;
 | 
			
		||||
 | 
			
		||||
import com.sun.jdi.event.StepEvent;
 | 
			
		||||
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
@@ -43,6 +44,10 @@ public class Event {
 | 
			
		||||
    u.name AS uname
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    public Event() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Event(ArrayList<Object> arr) {
 | 
			
		||||
        id = (int) arr.get(0);
 | 
			
		||||
        name = (String) arr.get(1);
 | 
			
		||||
@@ -59,6 +64,33 @@ public class Event {
 | 
			
		||||
        ownerName = arr.get(8) + " " + arr.get(9);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Event(
 | 
			
		||||
            int id,
 | 
			
		||||
            String name,
 | 
			
		||||
            int priority,
 | 
			
		||||
            boolean isFullDay,
 | 
			
		||||
            boolean isPrivate,
 | 
			
		||||
            String start,
 | 
			
		||||
            String end,
 | 
			
		||||
            String date,
 | 
			
		||||
            int ownerId,
 | 
			
		||||
            String ownerName
 | 
			
		||||
    ) {
 | 
			
		||||
        this.ownerId = ownerId;
 | 
			
		||||
        this.ownerName = ownerName;
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.start = start;
 | 
			
		||||
        this.end = end;
 | 
			
		||||
        this.priority = priority;
 | 
			
		||||
        this.isFullDay = isFullDay;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
 | 
			
		||||
        this.date = LocalDateTime.parse(date + " 00:00", formatter);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Event(String name,
 | 
			
		||||
                 int priority,
 | 
			
		||||
                 boolean isFullDay,
 | 
			
		||||
@@ -174,8 +206,9 @@ public class Event {
 | 
			
		||||
        return date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDate(LocalDateTime date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    public void setDate(String date) {
 | 
			
		||||
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
 | 
			
		||||
        this.date = LocalDateTime.parse(date + " 00:00", formatter);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getOwnerId() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user