Commit 05e7ffee authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Merge branch 'event' into 'master'

Basic classes done

See merge request s7_spruge_k/calendar!3
parents 8a3e2d6f 90b8b085
package com.example.models;
import java.util.ArrayList;
import java.util.Date;
public class Calendar {
private int calendar_ID; //Auto generated with JPA?
private static int calendar_counter = 0;
//TODO all calendar arrayList should not be in Calendar class.
private ArrayList<Event> eventList = new ArrayList<>();
public Calendar() {
calendar_ID = calendar_counter;
calendar_counter++;
}
public Calendar(ArrayList<Event> eventList) {
calendar_ID = calendar_counter;
calendar_counter++;
setEventList(eventList);
}
//set&get
public int getCalendar_ID() {
return calendar_ID;
}
public ArrayList<Event> getEventList() {
return eventList;
}
public void setEventList(ArrayList<Event> eventList) {
this.eventList = eventList;
}
//Through controller???
public boolean generateCalendar()
{
return true;
}
//TODO DISCUSS We have 3 different constructors, which one to use here?
public boolean addNewEvent(String name, String description, Date startDate, EventType newEventType, boolean isAllDayEvent)
{
Event tempEvent = new Event(name, description, startDate, isAllDayEvent);
eventList.add(tempEvent);
return true;
}
/**
* Uses getEventsByName() to get all events with the name.
* If there is only 1 event with the same name, deletes it.
*
* @param name
* @return
*/
public boolean deleteEventByName(String name)
{
ArrayList<Event> eventsToDelete = getEventsByName(name);
if(eventsToDelete.size() == 1) //So only 1 event with the name matches
{
for (Event event : eventList) {
if(event.equals(eventsToDelete.get(0))) //We find the event and delete it
{
event = null;
}
}
return true;
}
else if(eventsToDelete.size() > 1)
{
System.out.println("There are multiple events with the name '" + name + "'");
return false;
}
else if(eventsToDelete.size() == 0)
{
System.out.println("Event with the name '" + name + "' does not exist.");
return false;
}
else
{
return false;
}
}
/**
* Finds and returns an ArrayList of all the events with the given name.
*
*
* @param name
* @return
*/
public ArrayList<Event> getEventsByName(String name)
{
ArrayList<Event> allEventsWithEqualName = new ArrayList<>();
for (Event e : eventList) {
if(e.getName().equals(name))
{
allEventsWithEqualName.add(e);
}
}
return allEventsWithEqualName;
}
public boolean deleteEventByID(int id)
{
Event eventToDelete = getEventsByID(id);
if(eventToDelete != null)
{
for (Event e : eventList) {
if(e.getEvent_ID() == id)
{
eventList.remove(e);
}
}
return true;
}
else
{
System.out.println("Event with id: " + id + " doesnt exist");
return false;
}
}
/**
* Finds even by ID.
* Event id is unique to each event so there cant be more than one.
*
*
* @param id
* @return
*/
public Event getEventsByID(int id)
{
Event eventWithTheID = null;
for (Event e : eventList) {
if(e.getEvent_ID() == id)
{
eventWithTheID = e;
}
}
return eventWithTheID;
}
//TODO DISCUSS Better to get event by day? -> how to input day
/**
* returns array list of events at date. (maybe need by day?)
*
*
* @param date
* @return
*/
public ArrayList<Event> getEventsByDate(Date date)
{
ArrayList<Event> allEventsAtDate = new ArrayList<>();
for (Event e : eventList) {
if(e.getStartDate().equals(date))
{
allEventsAtDate.add(e);
}
}
return allEventsAtDate;
}
//TODO DISCUSS deleteEventsByDate necessary?
//TODO get events by Type
/**
* Returns events by EventType enum.
*
*
* @param type
* @return
*/
public ArrayList<Event> getEventsByEventType(EventType type)
{
ArrayList<Event> allEventsByType = new ArrayList<>();
for (Event e : eventList) {
if(e.getEventType().equals(type))
{
allEventsByType.add(e);
}
}
return allEventsByType;
}
//TODO DISCUSS deleteEventsByType neccessary?
}
package com.example.models;
import java.util.ArrayList;
import java.util.Date;
public class Event {
......
package com.example.models;
public class User {
//TODO spring secure auth
private String username;
private String password;
private int user_ID; //Auto generated with JPA?
private static int userCounter = 0;
public User(String username, String password) {
setUsername(username);
setPassword(password);
user_ID = userCounter;
userCounter++;
}
//Set & get
public String getUsername() {
return username;
}
//TODO Username & password cant contain bad characters -> through spring secure auth??
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getUser_ID() {
return user_ID;
}
@Override
public String toString() {
return "User [username=" + username + ", password=" + password + ", user_ID=" + user_ID + "]";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment