Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@
/** A class to represent the details of an event. */
public class EventDetails extends ApiDto {
private String description;
private String privateDescription;
private String location;
private Timestamp start;
private Timestamp end;

public EventDetails(String description, String location, Timestamp start, Timestamp end) {
public EventDetails(
String description,
String privateDescription,
String location,
Timestamp start,
Timestamp end) {
this.description = description;
this.privateDescription = privateDescription;
this.location = location;
this.start = start;
this.end = end;
Expand All @@ -41,6 +48,24 @@ public void setDescription(String description) {
this.description = description;
}

/**
* Gets the event's private description.
*
* @return the event's private description
*/
public String getPrivateDescription() {
return privateDescription;
}

/**
* Sets the given private description as the description of the event
*
* @param privateDescription the private description to be set
*/
public void setPrivateDescription(String privateDescription) {
this.privateDescription = privateDescription;
}

/**
* Gets the location of the event.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public GetUserEventsRequest(
this.count = count;
}

public GetUserEventsRequest() {
this.endDate = Optional.empty();
this.startDate = Optional.empty();
this.count = Optional.empty();
}

/**
* Gets the end date of the event.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE events
ADD COLUMN private_description TEXT DEFAULT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void updateSystemProperties() {

/** Connect to the database and create a DSLContext so jOOQ can interact with it. */
private void createDatabaseConnection() throws ClassNotFoundException {

// Load configuration from db.properties file
String databaseDriver = PropertiesLoader.loadProperty("database_driver");
String databaseUrl = PropertiesLoader.loadProperty("database_url");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public UserInformation getUserInformation(Users user) {
AddressData locationData = extractAddressDataFromUser(user);
PrivilegeLevel privilegeLevel = user.getPrivilegeLevel();

return new UserInformation(mainContact, additionalContacts, children, locationData, privilegeLevel);
return new UserInformation(
mainContact, additionalContacts, children, locationData, privilegeLevel);
}

/**
Expand Down Expand Up @@ -180,9 +181,9 @@ public UsersRecord createNewUser(NewUserRequest request) {
public void addToBlackList(String signature) {
Timestamp expirationTimestamp = Timestamp.from(Instant.now().plusMillis(msRefreshExpiration));
db.insertInto(Tables.BLACKLISTED_REFRESHES)
.values(signature, expirationTimestamp)
.onDuplicateKeyIgnore()
.execute();
.values(signature, expirationTimestamp)
.onDuplicateKeyIgnore()
.execute();
}

/** Given a JWT signature return true if it is stored in the BLACKLISTED_REFRESHES table. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ public SingleEventResponse getSingleEvent(int eventId, JWTData userData) {
throw new EventDoesNotExistException(eventId);
}

// getting all of the users registered for this event
EventRegistrations registrations = this.getEventRegisteredUsers(eventId);
boolean userRegisteredForEvent = false;
for (Registration reg : registrations.getRegistrations()) {
if (reg.getUserId() == userData.getUserId()) {
userRegisteredForEvent = true;
break;
}
}

// hide the private description if the user isn't registered and they're not an admin
if (!userRegisteredForEvent && userData.getPrivilegeLevel() != PrivilegeLevel.ADMIN) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunthakkar1 This line should allow admins to always see the private description

event.setPrivateDescription(null);
}

return eventPojoToResponse(event, userData);
}

Expand Down Expand Up @@ -191,6 +206,9 @@ public SingleEventResponse modifyEvent(
if (details.getDescription() != null) {
record.setDescription(details.getDescription());
}
if (details.getPrivateDescription() != null) {
record.setPrivateDescription(details.getPrivateDescription());
}
if (details.getLocation() != null) {
record.setLocation(details.getLocation());
}
Expand Down Expand Up @@ -230,6 +248,16 @@ public EventRegistrations getEventRegisteredUsers(int eventId, JWTData userData)
throw new AdminOnlyRouteException();
}

return this.getEventRegisteredUsers(eventId);
}

/**
* Returns an EventRegistrations object containing all of the users registered for this event
*
* @param eventId id of the event
* @return an EventRegistrations object containing all of the users registered for this event
*/
private EventRegistrations getEventRegisteredUsers(int eventId) {
if (!db.fetchExists(EVENTS.where(EVENTS.ID.eq(eventId)))) {
throw new EventDoesNotExistException(eventId);
}
Expand Down Expand Up @@ -357,6 +385,7 @@ private List<SingleEventResponse> listOfEventsToListOfSingleEventResponse(
EventDetails details =
new EventDetails(
event.getDescription(),
event.getPrivateDescription(),
event.getLocation(),
event.getStartTime(),
event.getEndTime());
Expand All @@ -381,7 +410,11 @@ private SingleEventResponse eventPojoToResponse(Events event, JWTData userData)

EventDetails details =
new EventDetails(
event.getDescription(), event.getLocation(), event.getStartTime(), event.getEndTime());
event.getDescription(),
event.getPrivateDescription(),
event.getLocation(),
event.getStartTime(),
event.getEndTime());
return new SingleEventResponse(
event.getId(),
event.getTitle(),
Expand All @@ -399,6 +432,7 @@ private EventsRecord eventRequestToRecord(CreateEventRequest request) {
EventsRecord newRecord = db.newRecord(EVENTS);
newRecord.setTitle(request.getTitle());
newRecord.setDescription(request.getDetails().getDescription());
newRecord.setPrivateDescription(request.getDetails().getPrivateDescription());
newRecord.setThumbnail(request.getThumbnail());
newRecord.setCapacity(request.getCapacity());
newRecord.setLocation(request.getDetails().getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private List<PublicSingleEventResponse> listOfEventsToListOfPublicSingleEventRes
EventDetails details =
new EventDetails(
event.getDescription(),
null,
event.getLocation(),
event.getStartTime(),
event.getEndTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void testCreateEvent1() {
EventDetails myEventDetails =
new EventDetails(
"my event",
"please arrive 5 min early",
"boston",
new Timestamp(START_TIMESTAMP_TEST),
new Timestamp(END_TIMESTAMP_TEST));
Expand All @@ -117,6 +118,7 @@ public void testCreateEvent2() {
EventDetails myEventDetails =
new EventDetails(
"my event",
null,
"boston",
new Timestamp(START_TIMESTAMP_TEST),
new Timestamp(END_TIMESTAMP_TEST));
Expand Down Expand Up @@ -174,6 +176,7 @@ public void testGetSingleEvent2() {
EventDetails myEventDetails =
new EventDetails(
"my event",
null,
"boston",
new Timestamp(START_TIMESTAMP_TEST),
new Timestamp(END_TIMESTAMP_TEST));
Expand All @@ -188,10 +191,15 @@ public void testGetSingleEvent2() {
eventRecord.setCapacity(myEventRequest.getCapacity());
eventRecord.setLocation(myEventDetails.getLocation());
eventRecord.setDescription(myEventDetails.getDescription());
eventRecord.setPrivateDescription(myEventDetails.getPrivateDescription());
eventRecord.setStartTime(myEventDetails.getStart());
eventRecord.setEndTime(myEventDetails.getEnd());
eventRecord.setPrice(myEventRequest.getPrice());
myJooqMock.addReturn(OperationType.SELECT, eventRecord);
// mocking db for getting users registered for the event
myJooqMock.addExistsReturn(true);
myJooqMock.addReturn(OperationType.SELECT, eventRecord);


// mock the DB for getting ticket counts
Record2<Integer, Integer> registrationRecord =
Expand Down Expand Up @@ -703,6 +711,7 @@ public void testModifyEvent2() {
null,
new EventDetails(
"new description",
"remember to bring a jacket ;)",
"new location",
new Timestamp(START_TIMESTAMP_TEST),
new Timestamp(END_TIMESTAMP_TEST)),
Expand All @@ -714,6 +723,7 @@ public void testModifyEvent2() {
myEvent.setTitle("old title");
myEvent.setCapacity(5);
myEvent.setDescription("old description");
myEvent.setPrivateDescription("old private description");
myEvent.setLocation("old location");
myEvent.setPrice(500);
myEvent.setStartTime(new Timestamp(0));
Expand All @@ -733,6 +743,9 @@ public void testModifyEvent2() {

myJooqMock.addReturn(OperationType.UPDATE, myEvent);
myJooqMock.addReturn(OperationType.SELECT, myEvent);
// mocking db for getting users registered for the event
myJooqMock.addExistsReturn(true);
myJooqMock.addReturn(OperationType.SELECT, myEvent);

// mock the ticket count
Record2<Integer, Integer> ticketCount =
Expand All @@ -744,15 +757,17 @@ public void testModifyEvent2() {

Object[] updateBindings = myJooqMock.getSqlOperationBindings().get(OperationType.UPDATE).get(0);

assertEquals(8, updateBindings.length);
assertEquals(9, updateBindings.length);
// TODO: create a method assertBindingsEqual() to check if the bindings are equal without caring about order
assertEquals(req.getTitle(), updateBindings[0]);
assertEquals(req.getDetails().getDescription(), updateBindings[1]);
assertEquals(req.getCapacity(), updateBindings[2]);
assertEquals(req.getDetails().getLocation(), updateBindings[3]);
assertEquals(req.getDetails().getStart(), updateBindings[4]);
assertEquals(req.getDetails().getEnd(), updateBindings[5]);
assertEquals(myEvent.getPrice(), updateBindings[6]);
assertEquals(myEvent.getId(), updateBindings[7]);
assertEquals(req.getDetails().getPrivateDescription(), updateBindings[7]);
assertEquals(myEvent.getId(), updateBindings[8]);
}

// modifying an event with the event details null
Expand All @@ -768,6 +783,7 @@ public void testModifyEvent3() {
myEvent.setTitle("old title");
myEvent.setCapacity(5);
myEvent.setDescription("old description");
myEvent.setPrivateDescription("old private description");
myEvent.setLocation("old location");
myEvent.setStartTime(new Timestamp(0));
myEvent.setEndTime(new Timestamp(0));
Expand All @@ -787,6 +803,9 @@ public void testModifyEvent3() {

myJooqMock.addReturn(OperationType.UPDATE, myEvent);
myJooqMock.addReturn(OperationType.SELECT, myEvent);
// mocking db for getting users registered for the event
myJooqMock.addExistsReturn(true);
myJooqMock.addReturn(OperationType.SELECT, myEvent);

// mock the ticket count
Record2<Integer, Integer> ticketCount =
Expand Down Expand Up @@ -818,13 +837,17 @@ public void testModifyEvent4() {
myEvent.setTitle("old title");
myEvent.setCapacity(5);
myEvent.setDescription("old description");
myEvent.setPrivateDescription("old private description");
myEvent.setLocation("old location");
myEvent.setPrice(20);
myEvent.setStartTime(new Timestamp(0));
myEvent.setEndTime(new Timestamp(0));
myJooqMock.addReturn(OperationType.SELECT, myEvent);
myJooqMock.addReturn(OperationType.SELECT, myEvent);
myJooqMock.addReturn(OperationType.UPDATE, myEvent);
// mocking db for getting users registered for the event
myJooqMock.addExistsReturn(true);
myJooqMock.addReturn(OperationType.SELECT, myEvent);

// mock the ticket count
Record2<Integer, Integer> ticketCount =
Expand Down Expand Up @@ -855,6 +878,7 @@ public void testModifyEvent5() {
myEvent.setTitle("old title");
myEvent.setCapacity(5);
myEvent.setDescription("old description");
myEvent.setPrivateDescription("old private description");
myEvent.setLocation("old location");
myEvent.setPrice(65);
myEvent.setStartTime(new Timestamp(0));
Expand All @@ -863,6 +887,10 @@ public void testModifyEvent5() {
myJooqMock.addReturn(OperationType.SELECT, myEvent);
myJooqMock.addReturn(OperationType.UPDATE, myEvent);

// mocking db for getting users registered for the event
myJooqMock.addExistsReturn(true);
myJooqMock.addReturn(OperationType.SELECT, myEvent);

// mock the ticket count
Record2<Integer, Integer> ticketCount =
myJooqMock.getContext().newRecord(EVENTS.ID, EVENT_REGISTRATIONS.TICKET_QUANTITY);
Expand All @@ -886,14 +914,15 @@ public void testModifyEvent6() {
"edited title",
null,
null,
new EventDetails("new description", "new location", null, null),
new EventDetails("new description", null, "new location", null, null),
50);

EventsRecord myEvent = myJooqMock.getContext().newRecord(EVENTS);
myEvent.setId(0);
myEvent.setTitle("old title");
myEvent.setCapacity(5);
myEvent.setDescription("old description");
myEvent.setPrivateDescription("old private description");
myEvent.setLocation("old location");
myEvent.setPrice(50);
myEvent.setStartTime(new Timestamp(0));
Expand All @@ -902,6 +931,10 @@ public void testModifyEvent6() {
myJooqMock.addReturn(OperationType.SELECT, myEvent);
myJooqMock.addReturn(OperationType.UPDATE, myEvent);

// mocking db for getting users registered for the event
myJooqMock.addExistsReturn(true);
myJooqMock.addReturn(OperationType.SELECT, myEvent);

// mock the ticket count
Record2<Integer, Integer> ticketCount =
myJooqMock.getContext().newRecord(EVENTS.ID, EVENT_REGISTRATIONS.TICKET_QUANTITY);
Expand Down