Browse code

make passgrid unique by name

devnewton authored on 16/12/2015 at 16:37:29
Showing 4 changed files
... ...
@@ -1,12 +1,16 @@
1 1
 package im.bci.passgrid.data;
2 2
 
3 3
 import org.springframework.data.annotation.Id;
4
+import org.springframework.data.mongodb.core.index.Indexed;
5
+import org.springframework.data.mongodb.core.mapping.Document;
4 6
 
7
+@Document
5 8
 public class Passgrid {
6 9
 
7 10
     @Id
8 11
     private String id;
9 12
 
13
+    @Indexed(unique = true)
10 14
     private String name;
11 15
 
12 16
     private Character[][] grid;
... ...
@@ -11,11 +11,14 @@ import pl.allegro.tech.boot.autoconfigure.handlebars.HandlebarsHelper;
11 11
 public class PassgridHelper {
12 12
 
13 13
     public String passgridColspan(Passgrid context) {
14
-        Character[][] grid = context.getGrid();
15
-        if (null != grid && grid.length > 0) {
16
-            Character[] row = grid[0];
17
-            if (null != row && row.length > 0) {
18
-                return String.valueOf(row.length + 1);
14
+        if (null != context) {
15
+            Character[][] grid = context.getGrid();
16
+
17
+            if (null != grid && grid.length > 0) {
18
+                Character[] row = grid[0];
19
+                if (null != row && row.length > 0) {
20
+                    return String.valueOf(row.length + 1);
21
+                }
19 22
             }
20 23
         }
21 24
         return "";
... ...
@@ -1,5 +1,5 @@
1 1
 <h2>Create grid</h2>
2
-<form action="create" method="POST">
2
+<form action="/create" method="POST">
3 3
     <label for="create-passgrid-name" >Name: </label>
4 4
     <input id="create-passgrid-name" type="text" name="name">
5 5
     <label for="create-passgrid-allowed-characters" >Lines: </label>
... ...
@@ -1,4 +1,4 @@
1
-<form action="search">
1
+<form action="/search">
2 2
     <label for="search-passgrid-name" >Search grid: </label>
3 3
     <input id="search-passgrid-name" type="text" name="name">
4 4
     <input type="submit" >