Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
s7_spruge_k
calendar
Commits
b48e89cf
Commit
b48e89cf
authored
May 11, 2019
by
s7_spruge_k
Browse files
Added User and Calendar classes
parent
39b9682d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
212 additions
and
1 deletion
+212
-1
src/main/java/com/example/models/Calendar.java
src/main/java/com/example/models/Calendar.java
+161
-0
src/main/java/com/example/models/Event.java
src/main/java/com/example/models/Event.java
+0
-1
src/main/java/com/example/models/User.java
src/main/java/com/example/models/User.java
+51
-0
No files found.
src/main/java/com/example/models/Calendar.java
0 → 100644
View file @
b48e89cf
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 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 get events byDate
//TODO get events by Type
}
src/main/java/com/example/models/Event.java
View file @
b48e89cf
package
com.example.models
;
import
java.util.ArrayList
;
import
java.util.Date
;
public
class
Event
{
...
...
src/main/java/com/example/models/User.java
0 → 100644
View file @
b48e89cf
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
+
"]"
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment