Skip to content

Commit

Permalink
event description: load only locale and description
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Aug 20, 2019
1 parent 98680ee commit 71480f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ public ResponseEntity<EventWithAdditionalInfo> getEvent(@PathVariable("eventName

var messageSource = messageSourceManager.getMessageSourceForEvent(event);

var descriptions = applyCommonMark(eventDescriptionRepository.findByEventIdAndType(event.getId(), EventDescription.EventDescriptionType.DESCRIPTION)
.stream()
.collect(Collectors.toMap(EventDescription::getLocale, EventDescription::getDescription)));
var descriptions = applyCommonMark(eventDescriptionRepository.findDescriptionByEventIdAsMap(event.getId()));

var organization = organizationRepository.getContactById(event.getOrganizationId());

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/alfio/model/EventDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ public EventDescription(@Column("event_id_fk") Integer eventId, @Column("locale"
this.eventDescriptionType = eventDescriptionType;
this.description = description;
}

@Getter
public static class LocaleDescription {
private final String locale;
private final String description;

public LocaleDescription(@Column("locale") String locale, @Column("description") String description) {
this.locale = locale;
this.description = description;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ public interface EventDescriptionRepository {
@Query("select * from event_description_text where event_id_fk = :eventId")
List<EventDescription> findByEventId(@Bind("eventId") int eventId);

@Query("select * from event_description_text where event_id_fk = :eventId and type = :type")
List<EventDescription> findByEventIdAndType(@Bind("eventId") int eventId, @Bind("type")EventDescription.EventDescriptionType type);
@Query("select locale, description from event_description_text where event_id_fk = :eventId and type = 'DESCRIPTION'")
List<EventDescription.LocaleDescription> findDescriptionByEventId(@Bind("eventId") int eventId);

default Map<String, String> findByEventIdAsMap(int eventId) {
return findByEventId(eventId).stream().collect(Collectors.toMap(EventDescription::getLocale, EventDescription::getDescription));
}

default Map<String, String> findDescriptionByEventIdAsMap(int eventId) {
return findDescriptionByEventId(eventId).stream().collect(Collectors.toMap(EventDescription.LocaleDescription::getLocale, EventDescription.LocaleDescription::getDescription));
}

@Query("select description from event_description_text where event_id_fk = :eventId and type = :type and locale = :locale")
Optional<String> findDescriptionByEventIdTypeAndLocale(@Bind("eventId") int eventId, @Bind("type") EventDescription.EventDescriptionType type, @Bind("locale") String locale);

Expand Down

0 comments on commit 71480f9

Please sign in to comment.