refactored project.members to be map of userId → member
This commit is contained in:
@@ -12,7 +12,7 @@ import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Project implements Mappable {
|
||||
private final Collection<Member> members;
|
||||
private final Map<Long,Member> members;
|
||||
private final boolean showClosed;
|
||||
private final Long companyId;
|
||||
private Status status;
|
||||
@@ -21,7 +21,7 @@ public class Project implements Mappable {
|
||||
private String description;
|
||||
private final Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Project(long id, String name, String description, Status status, Long companyId, boolean showClosed, Collection<Member> members) {
|
||||
public Project(long id, String name, String description, Status status, Long companyId, boolean showClosed, Map<Long,Member> members) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -44,17 +44,14 @@ public class Project implements Mappable {
|
||||
}
|
||||
|
||||
public boolean hasMember(UmbrellaUser user) {
|
||||
for (var member : members){
|
||||
if (member.user().id() == user.id()) return true;
|
||||
}
|
||||
return false;
|
||||
return members.containsKey(user.id());
|
||||
}
|
||||
|
||||
public long id(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public Collection<Member> members(){
|
||||
public Map<Long,Member> members(){
|
||||
return members;
|
||||
}
|
||||
|
||||
@@ -64,7 +61,7 @@ public class Project implements Mappable {
|
||||
|
||||
public static Project of(ResultSet rs) throws SQLException {
|
||||
var companyId = rs.getLong(COMPANY_ID);
|
||||
return new Project(rs.getLong(ID),rs.getString(NAME),rs.getString(DESCRIPTION),Status.of(rs.getInt(STATUS)),companyId == 0 ? null : companyId,rs.getBoolean(SHOW_CLOSED),new ArrayList<>());
|
||||
return new Project(rs.getLong(ID),rs.getString(NAME),rs.getString(DESCRIPTION),Status.of(rs.getInt(STATUS)),companyId == 0 ? null : companyId,rs.getBoolean(SHOW_CLOSED),new HashMap<>());
|
||||
}
|
||||
|
||||
public Project patch(JSONObject json) {
|
||||
@@ -91,13 +88,15 @@ public class Project implements Mappable {
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var map = new HashMap<String, Object>();
|
||||
var memberMap = new HashMap<Long,Map<String,Object>>();
|
||||
for (var entry : members.entrySet()) memberMap.put(entry.getKey(),entry.getValue().toMap());
|
||||
map.put(ID,id);
|
||||
map.put(NAME,name);
|
||||
map.put(DESCRIPTION,Map.of(SOURCE,description,RENDERED,markdown(description)));
|
||||
map.put(STATUS,Map.of(STATUS_CODE,status.code(), NAME,status.name()));
|
||||
map.put(COMPANY_ID,companyId);
|
||||
map.put(SHOW_CLOSED,showClosed);
|
||||
map.put(MEMBERS,members == null ? List.of() : members.stream().map(Member::toMap).toList());
|
||||
map.put(MEMBERS,memberMap);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user