Merge with assign
This commit is contained in:
37
buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java
Executable file
37
buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java
Executable file
@ -0,0 +1,37 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Assignment {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "group_id")
|
||||
private Groups group;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "commision_id")
|
||||
private Commision commision;
|
||||
|
||||
public Assignment(Groups group, Commision commision) {
|
||||
this.commision = commision;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public Assignment() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Groups getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
}
|
47
buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java
Executable file
47
buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java
Executable file
@ -0,0 +1,47 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class Commision {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "owner_id")
|
||||
private User commisionOwner;
|
||||
private Timestamp commisionDate;
|
||||
|
||||
@OneToMany(mappedBy = "commision")
|
||||
private List<Assignment> assignments;
|
||||
|
||||
public Commision(User user) {
|
||||
this.commisionDate = new Timestamp(System.currentTimeMillis());
|
||||
this.commisionOwner = user;
|
||||
}
|
||||
|
||||
public Commision() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Timestamp getCommisionDate() {
|
||||
return commisionDate;
|
||||
}
|
||||
|
||||
public User getCommisionOwner() {
|
||||
return commisionOwner;
|
||||
}
|
||||
|
||||
}
|
@ -77,4 +77,7 @@ public class User {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
@ -4,22 +4,16 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
//dictionary is deprecated use hashmap instead
|
||||
public class FileData {
|
||||
|
||||
private HashMap<String, Integer> keys;
|
||||
private Iterator<Row> rows;
|
||||
|
||||
//why variable is called keys2, could it be more specific???
|
||||
//why use setters in constructor here instead of assignments???
|
||||
// thought that setters are used to change values in runtime
|
||||
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
|
||||
this.keys = keys;
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Iterator<Row> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AssignmentRepository extends JpaRepository<Assignment, Long> {
|
||||
|
||||
@Query("FROM Assignment WHERE commision_id = ?1")
|
||||
List<Assignment> getByCommision(@Param("commision_id") Long id);
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CommisionRepository extends JpaRepository<Commision, Long> {
|
||||
@Query("FROM Commision WHERE owner_id = ?1")
|
||||
List<Commision> getUsers(@Param("owner_id") Long id);
|
||||
|
||||
@Query("FROM Commision WHERE owner_id = ?1 order by commisionDate desc")
|
||||
List<Commision> getNewestCommision(@Param("owner_id") Long id);
|
||||
|
||||
}
|
28
buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java
Executable file
28
buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java
Executable file
@ -0,0 +1,28 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AssignmentService {
|
||||
@Autowired
|
||||
private AssignmentRepository repo;
|
||||
|
||||
public AssignmentService() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void save(Assignment assignment) {
|
||||
this.repo.save(assignment);
|
||||
}
|
||||
|
||||
public List<Assignment> getCommisionAssignments(Commision com) {
|
||||
return this.repo.getByCommision(com.getId());
|
||||
}
|
||||
}
|
35
buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java
Executable file
35
buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java
Executable file
@ -0,0 +1,35 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class CommisionService {
|
||||
@Autowired
|
||||
private CommisionRepository repo;
|
||||
|
||||
public CommisionService() {
|
||||
}
|
||||
|
||||
public Commision save(Commision commision) {
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
||||
}
|
||||
|
||||
public List<Commision> getUsersCommisions(User user) {
|
||||
Long id = user.getId();
|
||||
return this.repo.getUsers(id);
|
||||
}
|
||||
|
||||
public Optional<Commision> getNewestCommision(User user) {
|
||||
return Optional.of(this.repo.getNewestCommision(user.getId()).get(0));
|
||||
}
|
||||
}
|
@ -37,4 +37,8 @@ public class GroupService {
|
||||
public int getGroupsAmmount() {
|
||||
return (int) this.repo.count();
|
||||
}
|
||||
|
||||
public Optional<Groups> getGroupById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user