Skip to content

Commit 93d0ad4

Browse files
committed
remarks
1 parent 749861a commit 93d0ad4

File tree

8 files changed

+64
-44
lines changed

8 files changed

+64
-44
lines changed

src/main/java/ru/mystamps/web/config/ControllersConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,3 @@ public SuggestionController getSuggestionController() {
119119
}
120120

121121
}
122-

src/main/java/ru/mystamps/web/dao/CountryDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public interface CountryDao {
3636
List<Object[]> getStatisticsOf(Integer collectionId, String lang);
3737
List<LinkEntityDto> findAllAsLinkEntities(String lang);
3838
LinkEntityDto findOneAsLinkEntity(String slug, String lang);
39-
40-
String suggestCountryForUser(Integer userId);
39+
String findLastCreatedByUser(Integer userId);
40+
String findPopularCountryInCollection(Integer userId);
4141
}

src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ public class JdbcCountryDao implements CountryDao {
7777
@Value("${country.find_country_link_info_by_slug}")
7878
private String findCountryLinkEntityBySlugSql;
7979

80-
@Value("${country.find_last_country_by_id}")
81-
private String findLastCountryByIdSql;
80+
@Value("${country.find_last_created_by_user}")
81+
private String findLastCreatedByUserSql;
8282

83-
@Value("${country.find_popular_country}")
84-
private String findPopularCountrySql;
83+
@Value("${country.find_popular_country_from_user_collection}")
84+
private String findPopularCountryInCollectionSql;
8585

8686
@Override
8787
public Integer add(AddCountryDbDto country) {
@@ -213,25 +213,36 @@ public LinkEntityDto findOneAsLinkEntity(String slug, String lang) {
213213
}
214214
}
215215

216+
/**
217+
* @author Shkarin John
218+
*/
216219
@Override
217-
public String suggestCountryForUser(Integer userId) {
218-
220+
public String findLastCreatedByUser(Integer userId) {
219221
try {
220222
return jdbcTemplate.queryForObject(
221-
findLastCountryByIdSql,
223+
findLastCreatedByUserSql,
222224
Collections.singletonMap("created_by", userId),
223225
String.class);
224226
} catch (EmptyResultDataAccessException ignored) {
225-
try {
226-
return jdbcTemplate.queryForObject(
227-
findPopularCountrySql,
228-
Collections.<String, Object>emptyMap(),
229-
String.class
230-
);
227+
return null;
228+
}
229+
}
230+
231+
/**
232+
* @author Shkarin John
233+
*/
234+
@Override
235+
public String findPopularCountryInCollection(Integer userId) {
236+
try {
237+
return jdbcTemplate.queryForObject(
238+
findPopularCountryInCollectionSql,
239+
Collections.<String, Object>emptyMap(),
240+
String.class
241+
);
231242

232-
} catch (EmptyResultDataAccessException ex) {
233-
return null;
234-
}
243+
} catch (EmptyResultDataAccessException ignored) {
244+
return null;
235245
}
236246
}
247+
237248
}

src/main/java/ru/mystamps/web/service/CountryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@SuppressWarnings("PMD.TooManyMethods")
2727
public interface CountryService {
2828
String add(AddCountryDto dto, Integer userId);
29-
String suggestCountryForUser(Integer userId);
3029
List<LinkEntityDto> findAllAsLinkEntities(String lang);
3130
LinkEntityDto findOneAsLinkEntity(String slug, String lang);
3231
long countAll();
@@ -37,4 +36,5 @@ public interface CountryService {
3736
long countAddedSince(Date date);
3837
long countUntranslatedNamesSince(Date date);
3938
List<Object[]> getStatisticsOf(Integer collectionId, String lang);
39+
String suggestCountryForUser(Integer userId);
4040
}

src/main/java/ru/mystamps/web/service/CountryServiceImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ public List<Object[]> getStatisticsOf(Integer collectionId, String lang) {
173173
public String suggestCountryForUser(Integer userId) {
174174
Validate.isTrue(userId != null, "User id must be non null");
175175

176-
return countryDao.suggestCountryForUser(userId);
176+
String slug = countryDao.findLastCreatedByUser(userId);
177+
if (slug != null) {
178+
LOG.debug("Country {} has been suggested to user #{} as a recently created", slug, userId);
179+
return slug;
180+
}
181+
182+
slug = countryDao.findPopularCountryInCollection(userId);
183+
LOG.debug("Country {} has been suggested to user #{} as popular in his collection", slug, userId);
184+
185+
return slug;
177186
}
178187
}

src/main/javascript/series/add.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@ function initPage(suggestCountryUrl) {
2222
'placement': 'right'
2323
});
2424

25-
if (suggestCountryUrl == null) {
26-
return;
27-
}
28-
29-
$.get(suggestCountryUrl, function (slug) {
30-
if (slug == "")
31-
return;
32-
33-
var country = $("#guess_country");
34-
country.show();
35-
country.click(function() {
36-
$(this).hide();
25+
if (suggestCountryUrl != null) {
26+
$.get(suggestCountryUrl, function handleSuggestedCountry(slug) {
27+
if (slug == "") {
28+
return;
29+
}
30+
31+
var country = $("#js-guess-country-link");
32+
country.show();
33+
country.click(function chooseSuggestedCountry() {
34+
$(this).hide();
3735

38-
var select_country = $("#country").selectize();
39-
var selectize = select_country[0].selectize;
40-
selectize.setValue(slug);
36+
var select_country = $("#country").selectize();
37+
var selectize = select_country[0].selectize;
38+
selectize.setValue(slug);
39+
});
4140
});
42-
});
41+
}
4342
}

src/main/resources/sql/country_dao_queries.properties

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,18 @@ country.find_country_link_info_by_slug = \
8282
WHERE c.slug = :slug \
8383
ORDER BY CASE WHEN 'ru' = :lang THEN COALESCE(c.name_ru, c.name) ELSE c.name END
8484

85-
country.find_last_country_by_id = \
85+
country.find_last_created_by_user = \
8686
SELECT c.slug \
8787
FROM series s \
88-
LEFT JOIN countries c ON c.id = s.country_id \
88+
JOIN countries c ON c.id = s.country_id \
8989
WHERE s.created_by = :created_by \
90-
ORDER BY s.created_at DESC LIMIT 1
90+
ORDER BY s.created_at DESC\
91+
LIMIT 1
9192

92-
country.find_popular_country = \
93+
country.find_popular_country_from_user_collection = \
9394
SELECT c.slug \
9495
FROM series s \
95-
LEFT JOIN countries c ON c.id = s.country_id \
96+
JOIN countries c ON c.id = s.country_id \
9697
GROUP BY country_id \
97-
ORDER BY COUNT(*) DESC LIMIT 1
98+
ORDER BY COUNT(*) DESC\
99+
LIMIT 1

src/main/webapp/WEB-INF/views/series/add.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ <h3 th:text="${#strings.capitalize(add_series)}">
203203
/*/-->
204204
</div>
205205

206-
<small togglz:active="INFO_COUNTRY_SERIES" id="guess_country" th:style="'display: none;'">
206+
<small togglz:active="INFO_COUNTRY_SERIES" id="js-guess-country-link" th:style="'display: none;'">
207207
<a tabindex="-1" th:text="#{t_guess_country}" href="javascript:void(0)">Guess a country</a>
208208
</small>
209209
</div>

0 commit comments

Comments
 (0)