Skip to content

Commit

Permalink
#110 and #111: create FieldRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed May 25, 2016
1 parent a823b76 commit f056718
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
37 changes: 37 additions & 0 deletions src/main/java/alfio/repository/FieldRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* This file is part of alf.io.
*
* alf.io is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* alf.io is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with alf.io. If not, see <http://www.gnu.org/licenses/>.
*/
package alfio.repository;

import alfio.model.TicketFieldConfiguration;
import ch.digitalfondue.npjt.*;

@QueryRepository
interface FieldRepository {

@Query("insert into ticket_field_configuration(event_id_fk, field_name, field_order, field_type, field_restricted_values, field_maxlength, field_minlength, field_required, context) " +
" values (:eventId, :name, :order, :type, :restrictedValues, :maxLength, :minLength, :required, :context)")
@AutoGeneratedKey("id")
AffectedRowCountAndKey<Integer> insertConfiguration(@Bind("eventId") int eventId, @Bind("name") String name, @Bind("order") int order, @Bind("type") String type, @Bind("restrictedValues") String restrictedValues,
@Bind("maxLength") Integer maxLength, @Bind("minLength") Integer minLength, @Bind("required") boolean required, @Bind("context") TicketFieldConfiguration.Context context);

@Query("insert into ticket_field_description(ticket_field_configuration_id_fk, field_locale, description) values (:ticketConfigurationId, :locale, :description)")
int insertDescription(@Bind("ticketConfigurationId") int ticketConfigurationId, @Bind("locale") String locale, @Bind("description") String description);

@Query("update ticket_field_description set description = :description where ticket_field_configuration_id_fk = :ticketConfigurationId and field_locale = :locale")
int updateDescription(@Bind("ticketConfigurationId") int ticketConfigurationId, @Bind("locale") String locale, @Bind("description") String description);

}
19 changes: 4 additions & 15 deletions src/main/java/alfio/repository/TicketFieldRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,24 @@
package alfio.repository;

import alfio.model.*;
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.Bind;
import ch.digitalfondue.npjt.Query;
import ch.digitalfondue.npjt.QueryRepository;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@QueryRepository
public interface TicketFieldRepository {
public interface TicketFieldRepository extends FieldRepository {

@Query("select count(*) from ticket_field_value where ticket_id_fk = :ticketId and field_value is not null and field_value <> '' and context = 'ATTENDEE'")
Integer countFilledOptionalData(@Bind("ticketId") int id);

@Query("select a.ticket_id_fk, a.ticket_field_configuration_id_fk, b.field_name, a.field_value from ticket_field_value a, ticket_field_configuration b where a.ticket_id_fk = :ticketId and a.ticket_field_configuration_id_fk = b.id and b.context = 'ATTENDEE'")
List<TicketFieldValue> findAllByTicketId(@Bind("ticketId") int id);

@Query("insert into ticket_field_configuration(event_id_fk, field_name, field_order, field_type, field_restricted_values, field_maxlength, field_minlength, field_required, context) " +
" values (:eventId, :name, :order, :type, :restrictedValues, :maxLength, :minLength, :required, :context)")
@AutoGeneratedKey("id")
AffectedRowCountAndKey<Integer> insertConfiguration(@Bind("eventId") int eventId, @Bind("name") String name, @Bind("order") int order, @Bind("type") String type, @Bind("restrictedValues") String restrictedValues,
@Bind("maxLength") Integer maxLength, @Bind("minLength") Integer minLength, @Bind("required") boolean required, @Bind("context")TicketFieldConfiguration.Context context);


@Query("insert into ticket_field_description(ticket_field_configuration_id_fk, field_locale, description) values (:ticketConfigurationId, :locale, :description)")
int insertDescription(@Bind("ticketConfigurationId") int ticketConfigurationId, @Bind("locale") String locale, @Bind("description") String description);

@Query("update ticket_field_description set description = :description where ticket_field_configuration_id_fk = :ticketConfigurationId and field_locale = :locale")
int updateDescription(@Bind("ticketConfigurationId") int ticketConfigurationId, @Bind("locale") String locale, @Bind("description") String description);

@Query("update ticket_field_value set field_value = :value where ticket_id_fk = :ticketId and ticket_field_configuration_id_fk = :fieldConfigurationId")
int updateValue(@Bind("ticketId") int ticketId, @Bind("fieldConfigurationId") int fieldConfigurationId, @Bind("value") String value);

Expand Down

0 comments on commit f056718

Please sign in to comment.