@@ -15,16 +15,16 @@ object TargetRepository {
15
15
* @param dataFields Data fields (e.g. "foo", "bar")
16
16
* @return
17
17
*/
18
- def getByTargetFields (dataFields : Seq [String ]): Seq [Target ] = DB .withConnection {
18
+ def getByTargetFields (dataFields : Seq [String ]): Seq [TargetOperators ] = DB .withConnection {
19
19
implicit connection =>
20
- getTargetsAndOperators() map {
20
+ getTargetsAndOperators().toSeq map {
21
21
// If the target is a wildcard, associate that target for all given dataFields
22
- case (TargetModel (target_id, true ), operator ) =>
23
- dataFields.map(dataField => Target .withWildcardTargetId(target_id, dataField, operator ))
22
+ case (TargetModel (target_id, true ), operators ) =>
23
+ dataFields.map(dataField => TargetOperators .withWildcardTargetId(target_id, dataField, operators ))
24
24
25
25
// If the target is not a wildcard (e.g. "data"), use it as-is
26
- case (TargetModel (target_id, false ), operator ) =>
27
- Seq (Target (target_id, operator ))
26
+ case (TargetModel (target_id, false ), operators ) =>
27
+ Seq (TargetOperators (target_id, operators ))
28
28
} flatten
29
29
}
30
30
@@ -37,11 +37,11 @@ object TargetRepository {
37
37
* @param connection SQL connection
38
38
* @return
39
39
*/
40
- def getTargetsAndOperators ()(implicit connection : Connection ): Seq [( TargetModel , OperatorModel ) ] = {
40
+ def getTargetsAndOperators ()(implicit connection : Connection ): Map [ TargetModel , Seq [ OperatorModel ] ] = {
41
41
SQL """
42
42
SELECT * FROM target
43
43
JOIN operator_target USING(target_id)
44
44
JOIN operator USING(operator_id)
45
- """ as(((TargetModel .simple ~ OperatorModel .simple) map flatten) * )
45
+ """ as(((TargetModel .simple ~ OperatorModel .simple) map flatten) * ) groupBy(_._1) mapValues(_.unzip._2)
46
46
}
47
47
}
0 commit comments