[Notice] Announcing the End of Demo Server [Read me]

#HIVE-40 마일스톤 이름 중복되지 않도록 처리
@643d85e2f5034d90d1e551f71aa10db746ccce54
--- app/controllers/MilestoneApp.java
+++ app/controllers/MilestoneApp.java
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 |
import models.enumeration.*; |
5 | 5 |
import play.data.*; |
6 | 6 |
import play.mvc.*; |
7 |
+import utils.Constants; |
|
7 | 8 |
import views.html.milestone.*; |
8 | 9 |
|
9 | 10 |
import java.util.*; |
... | ... | @@ -56,6 +57,7 @@ |
56 | 57 |
if(project == null ) { |
57 | 58 |
return notFound(); |
58 | 59 |
} |
60 |
+ validate(project, milestoneForm); |
|
59 | 61 |
if (milestoneForm.hasErrors()) { |
60 | 62 |
return ok(create.render("title.newMilestone", milestoneForm, project)); |
61 | 63 |
} else { |
... | ... | @@ -63,6 +65,14 @@ |
63 | 65 |
newMilestone.project = project; |
64 | 66 |
Milestone.create(newMilestone); |
65 | 67 |
return redirect(routes.MilestoneApp.manageMilestones(userName, projectName)); |
68 |
+ } |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ private static void validate(Project project, Form<Milestone> milestoneForm) { |
|
72 |
+ // 중복된 title로 만들 수 없다. |
|
73 |
+ if (!Milestone.isUniqueProjectIdAndTitle(project.id, milestoneForm.field("title").value())) { |
|
74 |
+ milestoneForm.reject("title", "milestone.title.duplicated"); |
|
75 |
+ flash(Constants.WARNING, "milestone.title.duplicated"); |
|
66 | 76 |
} |
67 | 77 |
} |
68 | 78 |
|
... | ... | @@ -95,8 +105,11 @@ |
95 | 105 |
if(project == null ) { |
96 | 106 |
return notFound(); |
97 | 107 |
} |
98 |
- |
|
99 | 108 |
Form<Milestone> milestoneForm = new Form<Milestone>(Milestone.class).bindFromRequest(); |
109 |
+ Milestone original = Milestone.findById(milestoneId); |
|
110 |
+ if(!original.title.equals(milestoneForm.field("title").value())) { |
|
111 |
+ validate(project, milestoneForm); |
|
112 |
+ } |
|
100 | 113 |
if (milestoneForm.hasErrors()) { |
101 | 114 |
return ok(edit.render("title.editMilestone", milestoneForm, milestoneId, project)); |
102 | 115 |
} else { |
--- app/models/Milestone.java
+++ app/models/Milestone.java
... | ... | @@ -23,6 +23,7 @@ |
23 | 23 |
public Long id; |
24 | 24 |
|
25 | 25 |
@Constraints.Required |
26 |
+ @Column(unique = true) |
|
26 | 27 |
public String title; |
27 | 28 |
|
28 | 29 |
@Constraints.Required |
... | ... | @@ -63,7 +64,7 @@ |
63 | 64 |
public int getNumOpenIssues() { |
64 | 65 |
return Issue.finder.where().eq("milestone", this).eq("state", State.OPEN).findRowCount(); |
65 | 66 |
} |
66 |
- |
|
67 |
+ |
|
67 | 68 |
public int getNumTotalIssues() { |
68 | 69 |
return issues.size(); |
69 | 70 |
} |
... | ... | @@ -167,4 +168,9 @@ |
167 | 168 |
} |
168 | 169 |
return options; |
169 | 170 |
} |
171 |
+ |
|
172 |
+ public static boolean isUniqueProjectIdAndTitle(Long projectId, String title) { |
|
173 |
+ int count = find.where().eq("project.id", projectId).eq("title", title).findRowCount(); |
|
174 |
+ return (count == 0); |
|
175 |
+ } |
|
170 | 176 |
} |
--- conf/messages.en
+++ conf/messages.en
... | ... | @@ -97,6 +97,7 @@ |
97 | 97 |
milestone.menu.new = New |
98 | 98 |
sort.by.dueDate = Due Date |
99 | 99 |
sort.by.completionRate = Completeness |
100 |
+milestone.title.duplicated = Title is duplicated. |
|
100 | 101 |
|
101 | 102 |
#Issue |
102 | 103 |
issue.stateType.all = All |
... | ... | @@ -279,7 +280,7 @@ |
279 | 280 |
user.logout.success = Logout successfully |
280 | 281 |
user.isAlreadySignupUser = HAVE AN ACCOUNT ALREADY? |
281 | 282 |
user.signupId = ID (lower case) |
282 |
-user.signupBtn = Sign Up |
|
283 |
+user.signupBtn = Sign Up |
|
283 | 284 |
|
284 | 285 |
#Time |
285 | 286 |
time.just = just now |
--- conf/messages.ko
+++ conf/messages.ko
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 |
menu.wiki = 위키 |
40 | 40 |
menu.admin = 프로젝트 관리 |
41 | 41 |
menu.siteAdmin = 사이트 관리 |
42 |
-menu.task = 작업 |
|
42 |
+menu.task = 작업 |
|
43 | 43 |
|
44 | 44 |
message.warning = 경고 |
45 | 45 |
message.success = 성공 |
... | ... | @@ -99,6 +99,7 @@ |
99 | 99 |
milestone.none = 없음 |
100 | 100 |
sort.by.dueDate = 완료일 순 |
101 | 101 |
sort.by.completionRate = 완료율 순 |
102 |
+milestone.title.duplicated = 마일스톤 제목이 다른것과 중복 됩니다. 다른 제목을 사용하세요. |
|
102 | 103 |
|
103 | 104 |
#Issue |
104 | 105 |
issue.state = 상태 |
... | ... | @@ -355,7 +356,7 @@ |
355 | 356 |
validation.invalidEmail = 올바른 이메일을 입력해 주세요. |
356 | 357 |
validation.required = 필수 항목 입니다. |
357 | 358 |
validation.duplicated = 이미 존재합니다! |
358 |
-validation.allowedCharsForLoginId = 아이디는 알파벳 숫자 - _ . 를 포함할 수 있으나 _ . 로 시작하거나 끝날 수 없습니다. |
|
359 |
+validation.allowedCharsForLoginId = 아이디는 알파벳 숫자 - _ . 를 포함할 수 있으나 _ . 로 시작하거나 끝날 수 없습니다. |
|
359 | 360 |
|
360 | 361 |
#Unauthorized |
361 | 362 |
auth.unauthorized.title = 접근 권한 오류 |
--- test/models/MilestoneTest.java
+++ test/models/MilestoneTest.java
... | ... | @@ -242,4 +242,19 @@ |
242 | 242 |
assertThat(m5.getNumTotalIssues()).describedAs("number of total issues should be 1").isEqualTo(1); |
243 | 243 |
assertThat(m5.getCompletionRate()).isEqualTo(100); |
244 | 244 |
} |
245 |
+ |
|
246 |
+ @Test |
|
247 |
+ public void isUniqueProjectIdAndTitle() { |
|
248 |
+ //Given |
|
249 |
+ //When |
|
250 |
+ boolean isUnique = Milestone.isUniqueProjectIdAndTitle(1l, "v.0.1"); |
|
251 |
+ //Then |
|
252 |
+ assertThat(isUnique == false); |
|
253 |
+ |
|
254 |
+ //Given |
|
255 |
+ //When |
|
256 |
+ isUnique = Milestone.isUniqueProjectIdAndTitle(1l, "unique milestone"); |
|
257 |
+ //Then |
|
258 |
+ assertThat(isUnique == true); |
|
259 |
+ } |
|
245 | 260 |
} |
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?