
CommentThread: find by commitId
@e45b15ac86467539ecc626e3c18ebd99b0f372f5
--- app/models/CommentThread.java
+++ app/models/CommentThread.java
... | ... | @@ -1,8 +1,11 @@ |
1 | 1 |
package models; |
2 | 2 |
|
3 |
+import play.data.format.Formats; |
|
4 |
+import play.data.validation.Constraints; |
|
3 | 5 |
import play.db.ebean.Model; |
4 | 6 |
|
5 | 7 |
import javax.persistence.*; |
8 |
+import java.util.Date; |
|
6 | 9 |
import java.util.List; |
7 | 10 |
|
8 | 11 |
/** |
... | ... | @@ -13,6 +16,8 @@ |
13 | 16 |
public class CommentThread extends Model { |
14 | 17 |
|
15 | 18 |
private static final long serialVersionUID = 1L; |
19 |
+ |
|
20 |
+ public static final Finder<Long, CommentThread> find = new Finder<>(Long.class, CommentThread.class); |
|
16 | 21 |
|
17 | 22 |
@Id |
18 | 23 |
public Long id; |
... | ... | @@ -26,6 +31,17 @@ |
26 | 31 |
@Enumerated(EnumType.STRING) |
27 | 32 |
public ThreadState state; |
28 | 33 |
|
34 |
+ @Constraints.Required |
|
35 |
+ @Formats.DateTime(pattern = "YYYY/MM/DD/hh/mm/ss") |
|
36 |
+ public Date createdDate; |
|
37 |
+ |
|
38 |
+ public static List<CommentThread> findByCommitId(String commitId) { |
|
39 |
+ return find.where() |
|
40 |
+ .eq("commitId", commitId) |
|
41 |
+ .order().desc("createdDate") |
|
42 |
+ .findList(); |
|
43 |
+ } |
|
44 |
+ |
|
29 | 45 |
enum ThreadState { |
30 | 46 |
OPEN, CLOSED; |
31 | 47 |
} |
+++ conf/evolutions/default/69.sql
... | ... | @@ -0,0 +1,7 @@ |
1 | +# --- !Ups | |
2 | + | |
3 | +alter table comment_thread add created_date timestamp; | |
4 | + | |
5 | +# --- !Downs | |
6 | + | |
7 | +alter table comment_thread drop column created_date; |
--- test/models/CommentThreadTest.java
+++ test/models/CommentThreadTest.java
... | ... | @@ -1,6 +1,11 @@ |
1 | 1 |
package models; |
2 | 2 |
|
3 | 3 |
import org.junit.Test; |
4 |
+import utils.JodaDateUtil; |
|
5 |
+ |
|
6 |
+import java.util.List; |
|
7 |
+ |
|
8 |
+import static org.fest.assertions.Assertions.assertThat; |
|
4 | 9 |
|
5 | 10 |
/** |
6 | 11 |
* @author Keesun Baik |
... | ... | @@ -14,4 +19,63 @@ |
14 | 19 |
thread.save(); |
15 | 20 |
} |
16 | 21 |
|
22 |
+ @Test |
|
23 |
+ public void findByCommitId() { |
|
24 |
+ // given |
|
25 |
+ String commitId = "123123"; |
|
26 |
+ addTestData(commitId); |
|
27 |
+ |
|
28 |
+ // when |
|
29 |
+ List<CommentThread> threadList = CommentThread.findByCommitId(commitId); |
|
30 |
+ |
|
31 |
+ // then |
|
32 |
+ assertThat(threadList.size()).isEqualTo(2); |
|
33 |
+ assertThat(threadList.get(0).createdDate).isEqualTo(JodaDateUtil.before(2)); |
|
34 |
+ assertThat(threadList.get(1).createdDate).isEqualTo(JodaDateUtil.before(3)); |
|
35 |
+ } |
|
36 |
+ |
|
37 |
+ /** |
|
38 |
+ * {@code commitId}를 가지는 {@link models.NonRangedCodeCommentThread} 한 개 저장. |
|
39 |
+ * - state: OPEN |
|
40 |
+ * - createDate: 3일전 |
|
41 |
+ * {@code commitId}를 가지는 {@link models.CodeCommentThread} 한 개 저장. |
|
42 |
+ * - state: CLOSED |
|
43 |
+ * - path: "readme.md" |
|
44 |
+ * - createdDate: 2일전 |
|
45 |
+ * 123321을 커밋 ID로 가지는 {@link models.NonRangedCodeCommentThread} 한 개 저장. |
|
46 |
+ * - state: OPEN |
|
47 |
+ * - createdDate: 1일전 |
|
48 |
+ * |
|
49 |
+ * @param commitId |
|
50 |
+ */ |
|
51 |
+ private void addTestData(String commitId) { |
|
52 |
+ NonRangedCodeCommentThread thread1 = new NonRangedCodeCommentThread(); |
|
53 |
+ thread1.commitId = commitId; |
|
54 |
+ thread1.state = CommentThread.ThreadState.OPEN; |
|
55 |
+ thread1.createdDate = JodaDateUtil.before(3); |
|
56 |
+ thread1.save(); |
|
57 |
+ |
|
58 |
+ CodeCommentThread thread2 = new CodeCommentThread(); |
|
59 |
+ thread2.commitId = commitId; |
|
60 |
+ thread2.state = CommentThread.ThreadState.CLOSED; |
|
61 |
+ CodeRange codeRange = new CodeRange(); |
|
62 |
+ codeRange.path = "readme.md"; |
|
63 |
+ codeRange.startColumn = 0; |
|
64 |
+ codeRange.startLine = 1; |
|
65 |
+ codeRange.startSide = CodeRange.Side.A; |
|
66 |
+ codeRange.endColumn = 100; |
|
67 |
+ codeRange.endLine = 10; |
|
68 |
+ codeRange.endSide = CodeRange.Side.B; |
|
69 |
+ thread2.codeRange = codeRange; |
|
70 |
+ thread2.createdDate = JodaDateUtil.before(2); |
|
71 |
+ thread2.save(); |
|
72 |
+ |
|
73 |
+ NonRangedCodeCommentThread thread3 = new NonRangedCodeCommentThread(); |
|
74 |
+ thread3.commitId = "123321"; |
|
75 |
+ thread3.state = CommentThread.ThreadState.OPEN; |
|
76 |
+ thread3.createdDate = JodaDateUtil.before(1); |
|
77 |
+ thread3.save(); |
|
78 |
+ } |
|
79 |
+ |
|
80 |
+ |
|
17 | 81 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?