Checkpoint: return all exchanges works

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2021-01-07 16:51:35 +01:00
parent 56120c4724
commit 842e38898a
6 changed files with 109 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
/**
* Entity that keeps user exchange offer.
* Entity that keeps user exchange offer.
*/
@Entity
public class Exchange {
@ -20,29 +20,49 @@ public class Exchange {
@OneToOne
@JoinColumn(name = "owned_id", unique = true)
private Assignment ownedAssignment;
@OneToOne
@JoinColumn(name = "desired_id")
private Groups desiredAssignment;
public Exchange() {
private Long ownerId;
public Exchange(){
}
public Exchange(Assignment ownedAssignment, Groups desiredAssignment){
/**
* @return Long ID of exchange trader
*/
public Long getOwnerId() {
return ownerId;
}
/**
* @param ownerId ID of exchange trader
*/
public void setOwnerId(Long ownerId) {
this.ownerId = ownerId;
}
/**
*
* @param ownedAssignment Assignment which owner would like to trade
* @param desiredAssignment Groups instance that trader wants
*/
public Exchange(Assignment ownedAssignment, Groups desiredAssignment) {
this.ownedAssignment = ownedAssignment;
this.desiredAssignment = desiredAssignment;
this.ownerId = this.ownedAssignment.getCommision().getCommisionOwner().getId();
}
/**
* @return Long ID in database
*/
public Long getId(){
return this.id;
}
/**
* @return Groups Target group
*/
@ -50,7 +70,6 @@ public class Exchange {
return desiredAssignment;
}
/**
* @param desiredAssignment Target group
*/
@ -58,7 +77,6 @@ public class Exchange {
this.desiredAssignment = desiredAssignment;
}
/**
* @return Assignment Owned assignment
*/
@ -66,7 +84,6 @@ public class Exchange {
return ownedAssignment;
}
/**
* @param ownedAssignment Owned assignment
*/

View File

@ -1,5 +1,6 @@
package com.plannaplan.repositories;
import java.util.List;
import java.util.Optional;
import com.plannaplan.entities.Assignment;
@ -16,5 +17,8 @@ public interface ExchangeRepository extends JpaRepository<Exchange, Long>{
@Query("FROM Exchange WHERE owned_id = ?1 AND desired_id = ?2")
Optional<Exchange> checkForExchange(@Param("owned_id") Assignment assignment, @Param("desired_id") Groups group);
@Query("FROM Exchange WHERE ownerId = ?1")
List<Exchange> getByUserId(@Param("id") Long id);
}

View File

@ -1,5 +1,6 @@
package com.plannaplan.services;
import java.util.List;
import java.util.Optional;
import com.plannaplan.entities.Assignment;
@ -32,6 +33,14 @@ public class ExchangeService {
return this.repo.findById(id);
}
/**
* @param id Id of user
* @return List of exchanges that belong to user
*/
public List<Exchange> getByUserId(Long id){
return this.repo.getByUserId(id);
}
/**
* @param entity Exchange entity which we would like to delete
*/