Skip to content

Commit

Permalink
Merge pull request #59 from FH-Joanneum-Iron-Road-for-Children/develo…
Browse files Browse the repository at this point in the history
…p-#58-fix-db-and-picture

Develop #58 fix db and picture
  • Loading branch information
PhilipMoser authored Jun 5, 2023
2 parents 0bf3017 + dbfeb5f commit 3a2a0c8
Show file tree
Hide file tree
Showing 32 changed files with 421 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package at.fh.joanneum.irfc.model.VotingResult;

import at.fh.joanneum.irfc.model.votingPartialResult.VotingPartialResultDTO;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
* @author https://github.com/GoldNova
**/
Expand All @@ -15,8 +18,8 @@
public class VotingResultDTO {

private Long votingResultId;
String title;
long endDate;
///List<VotingPartialResult> partialResults;
private String title;
private long endDate;
private List<VotingPartialResultDTO> partialResults;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ public class EventDTO {
private long endDateTimeInUTC;
private EventLocationDTO eventLocation;
private EventCategoryDTO eventCategory;
//private bool isEditable; //TODO check if we need this
}
7 changes: 5 additions & 2 deletions src/main/java/at/fh/joanneum/irfc/model/vote/VoteDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package at.fh.joanneum.irfc.model.vote;

import at.fh.joanneum.irfc.model.event.EventDTO;
import at.fh.joanneum.irfc.model.voting.VotingDTO;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -13,7 +15,8 @@
@Setter
@RegisterForReflection
public class VoteDTO {
private Long votingId;
private Long eventId;
private Long voteId;
private VotingDTO voting;
private EventDTO event;
private String deviceId;
}
6 changes: 4 additions & 2 deletions src/main/java/at/fh/joanneum/irfc/model/voting/VotingDTO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.fh.joanneum.irfc.model.voting;


import at.fh.joanneum.irfc.model.VotingResult.VotingResultDTO;
import at.fh.joanneum.irfc.model.event.EventDTO;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jdk.jfr.Event;
import lombok.Getter;
Expand All @@ -22,6 +24,6 @@ public class VotingDTO {
private String title;
private boolean isActive;
private boolean isEditable;
private List<Event> events;
// private VotingResult votingResult;
private List<EventDTO> events;
private VotingResultDTO votingResult;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.fh.joanneum.irfc.model.event;
package at.fh.joanneum.irfc.model.votingPartialResult;

import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.fh.joanneum.irfc.model.event;
package at.fh.joanneum.irfc.model.votingPartialResult;

import at.fh.joanneum.irfc.persistence.entiy.VotingPartialResultEntity;
import org.mapstruct.InheritInverseConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.Setter;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
* @author [email protected]
Expand All @@ -26,10 +28,10 @@ public class EventEntity {
strategy = GenerationType.SEQUENCE,
generator = "event_id_seq"
)
@Column(name = "event_id")
@Column(name = "event_id", nullable = false)
private Long eventId;

@Column
@Column(nullable = false)
private String title;

@OneToOne(cascade = CascadeType.ALL)
Expand All @@ -40,10 +42,10 @@ public class EventEntity {
@JoinColumn(name = "fk_picture", referencedColumnName = "picture_id")
private PictureEntity picture;

@Column(name = "start_date_time_in_utc")
@Column(name = "start_date_time_in_utc", nullable = false)
private long startDateTimeInUTC;

@Column(name = "end_date_time_in_utc")
@Column(name = "end_date_time_in_utc", nullable = false)
private long endDateTimeInUTC;

@ManyToOne
Expand All @@ -54,6 +56,9 @@ public class EventEntity {
@JoinColumn(name = "fk_event_category", nullable = false)
private EventCategoryEntity eventCategory;

//@Column(name = "is_editable")
// private boolean isEditable; //TODO create Task and Implement
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "events")
private Set<VotingEntity> votings = new HashSet<>();

@OneToMany(mappedBy = "event")
private Set<VoteEntity> votes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;

/**
* @author [email protected]
Expand All @@ -17,12 +18,28 @@
public class VoteEntity {

@Id
@Column(name = "vote_id")
private Long votingId;
@SequenceGenerator(
name = "vote_id_seq",
sequenceName = "vote_id_seq",
allocationSize = 1
)
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "vote_id_seq"
)
@Column(name = "vote_id", nullable = false)
private Long voteId;

@Column(name = "event_id")
private Long eventId;

@ManyToOne
@JoinColumn(name = "fk_voting", nullable = false)
private VotingEntity voting;

@ManyToOne
@JoinColumn(name = "fk_event", nullable = false)
private EventEntity event;

@Column(name = "device_id")
private String deviceId;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.Setter;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
* @author https://github.com/GoldNova
Expand All @@ -26,25 +28,27 @@ public class VotingEntity {
strategy = GenerationType.SEQUENCE,
generator = "voting_id_seq"
)
@Column(name = "voting_id")
@Column(name = "voting_id", nullable = false)
private Long votingId;

@Column(name = "title")
@Column(name = "title", nullable = false)
private String title;

@Column(name = "is_active")
@Column(name = "is_active", nullable = false)
private boolean isActive;

@Column(name = "is_editable")
@Column(name = "is_editable", nullable = false)
private boolean isEditable;

//@ManyToMany //TODO check if we need many to many here
//@Column(name = "events")
//private List<EventEntity> events;

//TODO check if we need EventCategory
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "fk_voting_result", referencedColumnName = "voting_result_id")
private VotingResultEntity votingResult;

// @Column(name = "votingResult")
// private VotingResult votingResult;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "voting_event", joinColumns = @JoinColumn(name = "voting_id"), inverseJoinColumns = @JoinColumn(name = "event_id"))
private Set<EventEntity> events = new HashSet<>();

@OneToMany(mappedBy = "voting")
private Set<VoteEntity> votes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public class VotingPartialResultEntity {

@Column
private Double percentage;

@ManyToOne
@JoinColumn(name = "fk_voting_result", nullable = false)
private VotingResultEntity votingResult;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;

import javax.persistence.*;
import java.util.Set;

/**
* @author https://github.com/GoldNova
Expand Down Expand Up @@ -34,11 +35,9 @@ public class VotingResultEntity {
@Column(name = "end_date")
private long endDate;

// @Column(nullable = false,
// name = "partial-results-id")
// @NotNull
// @OneToOne
// private List<parialResults> partialResults;

@OneToOne(mappedBy="votingResult", cascade = CascadeType.ALL)
private VotingEntity voting;

@OneToMany(mappedBy = "votingResult")
private Set<VotingPartialResultEntity> partialResults;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
**/
@RequestScoped
public class EventRepository implements PanacheRepository<EventEntity> {
public boolean hasActiveVoting(Long eventId) {
return find("id = ?1 and votings.isActive = true", eventId)
.firstResultOptional()
.isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
**/
@RequestScoped
public class VoteRepository implements PanacheRepository<VoteEntity> {
public long countVotesByEventAndVoting(Long eventId, Long votingId) {
return count("event.id = ?1 and voting.id = ?2", eventId, votingId);
}

public long countVotesByVoting(Long votingId) {
return count("voting.id = ?1", votingId);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package at.fh.joanneum.irfc.persistence.repository;

import at.fh.joanneum.irfc.persistence.entiy.EventEntity;
import at.fh.joanneum.irfc.persistence.entiy.VotingEntity;
import io.quarkus.hibernate.orm.panache.PanacheRepository;

import javax.enterprise.context.RequestScoped;
import java.util.Set;

/**
* @author https://github.com/GoldNova
**/
@RequestScoped
public class VotingRepository implements PanacheRepository<VotingEntity> {
public boolean containsEventId(VotingEntity voting, Long eventId) {
Set<EventEntity> events = voting.getEvents();
for (EventEntity event : events) {
if (event.getEventId().equals(eventId)) {
return true;
}
}
return false;
}
}
8 changes: 8 additions & 0 deletions src/main/java/at/fh/joanneum/irfc/rest/EventInfoApi.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package at.fh.joanneum.irfc.rest;

import at.fh.joanneum.irfc.model.eventInfo.EventInfoDTO;
import at.fh.joanneum.irfc.model.picture.PictureDTO;
import at.fh.joanneum.irfc.service.EventInfoService;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;

/**
* @author [email protected]
Expand All @@ -25,6 +27,12 @@ public EventInfoDTO get(@PathParam("id") Long id){
return eventInfoService.get(id);
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public List<EventInfoDTO> getAll(){
return eventInfoService.getAll();
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/at/fh/joanneum/irfc/rest/EventLocationApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
@RequestScoped
@Path("event-locations")
public class EventLocationApi {

@Inject
EventLocationService eventLocationService;


@GET
@Produces(MediaType.APPLICATION_JSON)
public List<EventLocationDTO> getAll() {
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/at/fh/joanneum/irfc/rest/PictureApi.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package at.fh.joanneum.irfc.rest;

import at.fh.joanneum.irfc.model.event.EventDTO;
import at.fh.joanneum.irfc.model.event.EventMapper;
import at.fh.joanneum.irfc.model.multipartbody.MultipartBody;
import at.fh.joanneum.irfc.model.picture.PictureDTO;
import at.fh.joanneum.irfc.service.PictureService;
Expand All @@ -11,6 +13,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author [email protected]
Expand All @@ -27,21 +30,27 @@ public class PictureApi {
public PictureDTO get(@PathParam("id") Long id){ return pictureService.get(id); }

@GET
@Path("/search/{searchString}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public List<PictureDTO> getByTitle(@PathParam("searchString") String searchString){
return pictureService.search(searchString);
public List<PictureDTO> getAll(){
return pictureService.getAll();
}

// @GET
// @Path("/search/{searchString}")
// @Produces(MediaType.APPLICATION_JSON)
// @Consumes(MediaType.APPLICATION_JSON)
// public List<PictureDTO> getByTitle(@PathParam("searchString") String searchString){
// return pictureService.search(searchString);
// }

@GET
@Path("rootpath")
@Produces(MediaType.TEXT_PLAIN)
public String getRootPath(){
return pictureService.getRootpath();
}

//TODO: there will be only MULTIPART as input with file and altText
// there will be only MULTIPART as input with file and altText
// (see: https://quarkus.io/guides/rest-client-multipart)
@POST
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Loading

0 comments on commit 3a2a0c8

Please sign in to comment.