Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Temporarily fix show ticket crash (#1292)
Browse files Browse the repository at this point in the history
download ticketTypes explicitly when trying to view an a ticket
  • Loading branch information
jacqueline8711 authored Apr 22, 2019
1 parent 354c4d8 commit e041063
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package de.tum.in.tumcampusapp.component.ui.ticket;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.List;

import de.tum.in.tumcampusapp.component.ui.ticket.model.TicketType;

@Dao
Expand All @@ -18,8 +17,8 @@ public interface TicketTypeDao {
@Query("SELECT * FROM ticket_types")
List<TicketType> getAll();

@Query("SELECT * FROM ticket_types WHERE id = :id")
TicketType getById(int id);
@Query("SELECT * FROM ticket_types tt, tickets t WHERE tt.id = t.ticket_type_id AND t.event_id = :eventId")
List<TicketType> getByEventId(int eventId);

@Query("DELETE FROM ticket_types")
void flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import de.tum.in.tumcampusapp.component.ui.ticket.model.Event;
import de.tum.in.tumcampusapp.component.ui.ticket.model.Ticket;
import de.tum.in.tumcampusapp.component.ui.ticket.model.TicketInfo;
import de.tum.in.tumcampusapp.component.ui.ticket.model.TicketType;
import de.tum.in.tumcampusapp.component.ui.ticket.repository.EventsLocalRepository;
import de.tum.in.tumcampusapp.component.ui.ticket.repository.TicketsLocalRepository;
import de.tum.in.tumcampusapp.component.ui.ticket.repository.TicketsRemoteRepository;
Expand Down Expand Up @@ -155,6 +156,10 @@ private void handleTicketRefreshFailure() {
}

private void loadTicketData(int eventId) {
List<TicketType> ticketTypes = ticketsLocalRepo.getTicketTypesByEventId(eventId);
if (ticketTypes.isEmpty()) {
ticketsLocalRepo.addTicketTypes(ticketsRemoteRepo.fetchTicketTypesForEvent(eventId).blockingSingle());
}
ticketInfoList = ticketsLocalRepo.getTicketsByEventId(eventId);
event = eventsLocalRepo.getEventById(eventId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TicketsLocalRepository @Inject constructor(

fun getTicketsByEventId(eventId: Int): List<TicketInfo> = database.ticketDao().getByEventId(eventId)

fun getTicketTypeById(id: Int): TicketType = database.ticketTypeDao().getById(id)
fun getTicketTypesByEventId(eventId: Int): List<TicketType> = database.ticketTypeDao().getByEventId(eventId)

fun addTicketTypes(ticketTypes: List<TicketType>) {
database.ticketTypeDao().insert(ticketTypes)
Expand Down

0 comments on commit e041063

Please sign in to comment.