Skip to content

Commit 5350d35

Browse files
committed
Guess Country
Guess Country gh571_prediction_country add guess country fixes after merge fix query cleaning and return String check style check style fixes fixes fixes
1 parent 0f1a51f commit 5350d35

File tree

15 files changed

+122
-4
lines changed

15 files changed

+122
-4
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public final class Url {
5151
public static final String INFO_SERIES_PAGE = "/series/{id}";
5252
public static final String ADD_IMAGE_SERIES_PAGE = "/series/{id}/image";
5353
public static final String SEARCH_SERIES_BY_CATALOG = "/series/search/by_catalog";
54+
public static final String INFO_COUNTRY_SERIES_PAGE = "/suggest/series_country";
5455

5556
public static final String ADD_CATEGORY_PAGE = "/category/add";
5657
public static final String LIST_CATEGORIES_PAGE = "/category/list";
@@ -125,6 +126,7 @@ public static Map<String, String> asMap(boolean serveContentFromSingleHost) {
125126
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
126127
map.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);
127128
map.put("SEARCH_SERIES_BY_CATALOG", SEARCH_SERIES_BY_CATALOG);
129+
map.put("INFO_COUNTRY_SERIES_PAGE", INFO_COUNTRY_SERIES_PAGE);
128130
map.put("ADD_CATEGORY_PAGE", ADD_CATEGORY_PAGE);
129131
map.put("INFO_CATEGORY_PAGE", INFO_CATEGORY_PAGE);
130132
map.put("LIST_CATEGORIES_PAGE", LIST_CATEGORIES_PAGE);

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.springframework.web.bind.annotation.PathVariable;
4848
import org.springframework.web.bind.annotation.PostMapping;
4949
import org.springframework.web.bind.annotation.RequestParam;
50+
import org.springframework.web.bind.annotation.ResponseBody;
5051
import org.springframework.web.servlet.View;
5152
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
5253
import org.springframework.web.servlet.view.RedirectView;
@@ -133,6 +134,7 @@ public void showForm(
133134
model.addAttribute("countries", countries);
134135

135136
model.addAttribute("years", YEARS);
137+
model.addAttribute("urlSuggest", Url.INFO_COUNTRY_SERIES_PAGE);
136138

137139
AddSeriesForm addSeriesForm = new AddSeriesForm();
138140
addSeriesForm.setPerforated(true);
@@ -420,6 +422,15 @@ public String searchSeriesByCatalog(
420422

421423
return "series/search_result";
422424
}
425+
426+
/**
427+
* @author Shkarin John
428+
*/
429+
@ResponseBody
430+
@GetMapping(Url.INFO_COUNTRY_SERIES_PAGE)
431+
public String suggestCountryForUser(@CurrentUser Integer currentUserId) {
432+
return countryService.suggestCountryForUser(currentUserId);
433+
}
423434

424435
// CheckStyle: ignore LineLength for next 1 line
425436
private Map<String, ?> prepareCommonAttrsForSeriesInfo(SeriesDto series, Integer currentUserId) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ public interface CountryDao {
3535
List<Object[]> getStatisticsOf(Integer collectionId, String lang);
3636
List<LinkEntityDto> findAllAsLinkEntities(String lang);
3737
LinkEntityDto findOneAsLinkEntity(String slug, String lang);
38+
39+
String suggestCountryForUser(Integer userId);
3840
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@SuppressWarnings("PMD.TooManyMethods")
3131
public interface SeriesDao {
3232
Integer add(AddSeriesDbDto series);
33+
3334
void markAsModified(Integer seriesId, Date updateAt, Integer updatedBy);
3435
List<SitemapInfoDto> findAllForSitemap();
3536
List<SeriesInfoDto> findLastAdded(int quantity, String lang);

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public class JdbcCountryDao implements CountryDao {
7676

7777
@Value("${country.find_country_link_info_by_slug}")
7878
private String findCountryLinkEntityBySlugSql;
79+
80+
@Value("${series.find_last_country_by_id}")
81+
private String findLastCountryByIdSql;
82+
83+
@Value("${series.find_popular_country}")
84+
private String findPopularCountrySql;
7985

8086
@Override
8187
public Integer add(AddCountryDbDto country) {
@@ -206,5 +212,20 @@ public LinkEntityDto findOneAsLinkEntity(String slug, String lang) {
206212
return null;
207213
}
208214
}
209-
215+
216+
@Override
217+
public String suggestCountryForUser(Integer userId) {
218+
String result = jdbcTemplate.queryForObject(findLastCountryByIdSql,
219+
Collections.singletonMap("created_by", userId),
220+
String.class);
221+
if (result != null) {
222+
return result;
223+
}
224+
225+
return jdbcTemplate.queryForObject(
226+
findPopularCountrySql,
227+
Collections.<String, Object>emptyMap(),
228+
String.class
229+
);
230+
}
210231
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
public interface CountryService {
2727
String add(AddCountryDto dto, Integer userId);
28+
String suggestCountryForUser(Integer userId);
2829
List<LinkEntityDto> findAllAsLinkEntities(String lang);
2930
LinkEntityDto findOneAsLinkEntity(String slug, String lang);
3031
long countAll();

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,15 @@ public List<Object[]> getStatisticsOf(Integer collectionId, String lang) {
162162

163163
return countryDao.getStatisticsOf(collectionId, lang);
164164
}
165-
165+
166+
/**
167+
* @author Shkarin John
168+
*/
169+
@Override
170+
@Transactional(readOnly = true)
171+
public String suggestCountryForUser(Integer userId) {
172+
Validate.isTrue(userId != null, "UserId must be non null");
173+
174+
return countryDao.suggestCountryForUser(userId);
175+
}
166176
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@SuppressWarnings("PMD.TooManyMethods")
3232
public interface SeriesService {
3333
Integer add(AddSeriesDto dto, Integer userId, boolean userCanAddComments);
34+
3435
void addImageToSeries(AddImageDto dto, Integer seriesId, Integer userId);
3536
long countAll();
3637
long countAllStamps();

src/main/javascript/series/add.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// IMPORTANT:
33
// You have to update Url.RESOURCES_VERSION each time whenever you're modified this file!
44
//
5-
function initPage() {
5+
function initPage(urlSuggest) {
66
$('#country').selectize();
77

88
$('.js-catalog-numbers').on('blur', function() {
@@ -21,4 +21,19 @@ function initPage() {
2121
$('.js-with-tooltip').tooltip({
2222
'placement': 'right'
2323
});
24+
25+
$.get(urlSuggest, function (slug){
26+
if (slug == null)
27+
return;
28+
29+
var country = $("#guess_country");
30+
country[0].style.display = "block";
31+
country.click(function() {
32+
$(this)[0].style.display = "none";
33+
34+
var select_country = $("#country").selectize();
35+
var selectize = select_country[0].selectize;
36+
selectize.setValue(slug);
37+
});
38+
});
2439
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--
2+
-- Auto-generated by Maven, based on values from src/main/resources/test/spring/test-data.properties
3+
--
4+
5+
INSERT INTO countries(name, created_at, created_by, updated_at, updated_by, name_ru, slug) VALUES
6+
('Russia', NOW(), 3, NOW(), 3, 'Россия', 'russia');
7+
8+
INSERT INTO countries(name, created_at, created_by, updated_at, updated_by, name_ru, slug) VALUES
9+
('Germany', NOW(), 3, NOW(), 3, 'Германия', 'germany');
10+
11+
INSERT INTO countries(name, created_at, created_by, updated_at, updated_by, name_ru, slug) VALUES
12+
('France', NOW(), 3, NOW(), 3, 'Франция', 'france');

0 commit comments

Comments
 (0)