diff --git a/src/main/java/koreatech/in/repository/MarketPlaceMapper.java b/src/main/java/koreatech/in/repository/MarketPlaceMapper.java index 1005c826..2693bcfe 100644 --- a/src/main/java/koreatech/in/repository/MarketPlaceMapper.java +++ b/src/main/java/koreatech/in/repository/MarketPlaceMapper.java @@ -84,6 +84,9 @@ public interface MarketPlaceMapper { @Select("SELECT COUNT(*) AS totalCount FROM koin.items WHERE IS_DELETED = 0 AND TYPE=#{type}") Integer totalItemCountByType(@Param("type") int type); + @Select("SELECT COUNT(*) AS totalCount FROM koin.items WHERE TYPE=#{type} AND USER_ID = #{user_id} AND IS_DELETED = 0") + Integer totalMyItemCountByType(@Param("type") int type, @Param("user_id") int user_id); + @Select("SELECT COUNT(*) AS totalCount FROM koin.items WHERE TYPE=#{type}") Integer totalItemCountByTypeForAdmin(@Param("type") int type); diff --git a/src/main/java/koreatech/in/schedule/BusTago.java b/src/main/java/koreatech/in/schedule/BusTago.java index 3b148d8f..d7d6ef42 100644 --- a/src/main/java/koreatech/in/schedule/BusTago.java +++ b/src/main/java/koreatech/in/schedule/BusTago.java @@ -105,7 +105,6 @@ private static List> requestBusArrivalInfo(String cityCode, int count = nodeInfo.getAsJsonObject("response").getAsJsonObject("body").get("totalCount").getAsInt(); - Gson gson = new Gson(); if (count <= 1) { BusArrivalInfo col = new BusArrivalInfo(); if (count == 1) { @@ -115,7 +114,6 @@ private static List> requestBusArrivalInfo(String cityCode, } result = con.parseJsonArrayWithObject(nodeInfo.getAsJsonObject("response").getAsJsonObject("body").getAsJsonObject("items").getAsJsonArray("item")); - return result; } diff --git a/src/main/java/koreatech/in/service/CircleServiceImpl.java b/src/main/java/koreatech/in/service/CircleServiceImpl.java index 8fbb850b..29115070 100644 --- a/src/main/java/koreatech/in/service/CircleServiceImpl.java +++ b/src/main/java/koreatech/in/service/CircleServiceImpl.java @@ -7,21 +7,19 @@ import koreatech.in.domain.ErrorMessage; import koreatech.in.domain.Faq.Faq; import koreatech.in.domain.Faq.FaqResponseType; -import koreatech.in.exception.*; +import koreatech.in.exception.ConflictException; +import koreatech.in.exception.NotFoundException; +import koreatech.in.exception.PreconditionFailedException; import koreatech.in.repository.CircleMapper; import koreatech.in.repository.FaqMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; import javax.inject.Inject; import java.util.HashMap; import java.util.List; import java.util.Map; -import static koreatech.in.domain.DomainToMap.domainToMap; -import static koreatech.in.domain.DomainToMap.domainToMapWithExcept; - @Service public class CircleServiceImpl implements CircleService { @Inject @@ -39,8 +37,8 @@ public Map getCirclesForAdmin(Criteria criteria) throws Exceptio double totalCount = circleMapper.totalCount(); double countByLimit = totalCount / criteria.getLimit(); - int totalPage = countByLimit == Double.POSITIVE_INFINITY || countByLimit == Double.NEGATIVE_INFINITY ? 0 : (int)Math.ceil(totalCount / criteria.getLimit()); - if (totalPage<0) + int totalPage = countByLimit == Double.POSITIVE_INFINITY || countByLimit == Double.NEGATIVE_INFINITY ? 0 : (int) Math.ceil(totalCount / criteria.getLimit()); + if (totalPage < 0) throw new PreconditionFailedException(new ErrorMessage("invalid page number", 2)); List circleList = circleMapper.getCircleListForAdmin(criteria.getCursor(), criteria.getLimit()); @@ -64,8 +62,8 @@ public Circle createCircleForAdmin(Circle circle) throws Exception { } //link_urls 체크 - if(!con.isJsonArrayWithOnlyObject(circle.getLink_urls())) - throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); + if (circle.getLink_urls() != null && !con.isJsonArrayWithOnlyObject(circle.getLink_urls())) + throw new PreconditionFailedException(new ErrorMessage("link_urls are not valid", 0)); if (circle.getIs_deleted() == null) { circle.setIs_deleted(false); @@ -82,8 +80,8 @@ public Map getCircles(Criteria criteria) throws Exception { double totalCount = circleMapper.totalCount(); double countByLimit = totalCount / criteria.getLimit(); - int totalPage = countByLimit == Double.POSITIVE_INFINITY || countByLimit == Double.NEGATIVE_INFINITY ? 0 : (int)Math.ceil(totalCount / criteria.getLimit()); - if (totalPage<0) + int totalPage = countByLimit == Double.POSITIVE_INFINITY || countByLimit == Double.NEGATIVE_INFINITY ? 0 : (int) Math.ceil(totalCount / criteria.getLimit()); + if (totalPage < 0) throw new PreconditionFailedException(new ErrorMessage("invalid page number", 2)); List circles = circleMapper.getCircleList(criteria.getCursor(), criteria.getLimit()); @@ -111,7 +109,7 @@ public Map getCircle(int page, int limit, int id) throws Excepti int faqTotalCount = faqMapper.totalCountByCircle(id); int faqTotalPage = (int) Math.ceil(faqTotalCount / (double) limit); - int cursor = (page -1) * limit; + int cursor = (page - 1) * limit; Map faq = new HashMap(); faq.put("items", BeanSerializer.getSerializedResult(Faq.class, new BeanSerializer(FaqResponseType.getArray()), faqMapper.getFaqListByCircle(cursor, limit, id), List.class)); @@ -152,7 +150,7 @@ public Circle updateCircleForAdmin(Circle circle, int id) throws Exception { } //link_urls 체크 - if(!con.isJsonArrayWithOnlyObject(circle.getLink_urls())) + if (circle.getLink_urls() != null && !con.isJsonArrayWithOnlyObject(circle.getLink_urls())) throw new PreconditionFailedException(new ErrorMessage("link_urls are not valid", 0)); selectCircle.update(circle); diff --git a/src/main/java/koreatech/in/service/JsonConstructor.java b/src/main/java/koreatech/in/service/JsonConstructor.java index 7e65f76c..0890e6a2 100644 --- a/src/main/java/koreatech/in/service/JsonConstructor.java +++ b/src/main/java/koreatech/in/service/JsonConstructor.java @@ -38,7 +38,6 @@ public Boolean isJsonArrayWithOnlyString(String jsonString) { return false; JsonArray jsonArray = jsonElement.getAsJsonArray(); - if (jsonArray.size() == 0) return false; for (JsonElement element : jsonArray) { if (element.isJsonObject()) return false; @@ -54,6 +53,9 @@ public List> parseJsonArrayWithObject(JsonArray jsonArray) { if (jsonArray == null) return null; List> list; try { + for (JsonElement element : jsonArray) { + parseJsonObject((element.getAsJsonObject())); + } list = gson.fromJson(jsonArray, new TypeToken>>() {}.getType()); } catch (Exception e) { return null; @@ -88,7 +90,6 @@ public Boolean isJsonArrayWithOnlyObject(String jsonString) { return false; JsonArray jsonArray = jsonElement.getAsJsonArray(); - if (jsonArray.size() == 0) return false; for (JsonElement element : jsonArray) { if (!element.isJsonObject()) return false; diff --git a/src/main/java/koreatech/in/service/LandServiceImpl.java b/src/main/java/koreatech/in/service/LandServiceImpl.java index 6bf831b4..c5060b8a 100644 --- a/src/main/java/koreatech/in/service/LandServiceImpl.java +++ b/src/main/java/koreatech/in/service/LandServiceImpl.java @@ -45,7 +45,7 @@ public Land createLandForAdmin(Land land) throws Exception { land.setInternal_name(land.getName().replace(" ","").toLowerCase()); //image_urls 체크 - if (!con.isJsonArrayWithOnlyObject(land.getImage_urls())) + if (land.getImage_urls() != null && !con.isJsonArrayWithOnlyString(land.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); landMapper.createLandForAdmin(land); @@ -65,7 +65,7 @@ public Land updateLandForAdmin(Land land, int id) throws Exception { } //image_urls 체크 - if (!con.isJsonArrayWithOnlyString(land.getImage_urls())) + if (land.getImage_urls() != null && !con.isJsonArrayWithOnlyString(land.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); land_old.update(land); diff --git a/src/main/java/koreatech/in/service/LostAndFoundServiceImpl.java b/src/main/java/koreatech/in/service/LostAndFoundServiceImpl.java index d66dfbc3..951f0011 100644 --- a/src/main/java/koreatech/in/service/LostAndFoundServiceImpl.java +++ b/src/main/java/koreatech/in/service/LostAndFoundServiceImpl.java @@ -75,7 +75,7 @@ public LostItem createLostItemForAdmin(LostItem lostItem) throws Exception { lostItem.setIp(ip); //image_urls 체크 - if (!con.isJsonArrayWithOnlyObject(lostItem.getImage_urls())) + if (lostItem.getImage_urls() != null && !con.isJsonArrayWithOnlyString(lostItem.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); if (lostItem.getIs_deleted() == null) { @@ -173,7 +173,7 @@ public LostItem updateLostItemForAdmin(LostItem lostItem, int id) throws Excepti lostItem.setIp(ip); //image_urls 체크 - if (!con.isJsonArrayWithOnlyObject(lostItem.getImage_urls())) + if (lostItem.getImage_urls() != null && !con.isJsonArrayWithOnlyString(lostItem.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); //TODO : validator를 사용해 입력된 정보의 유효화 검사 후 입력된 부분만 기존 내용에 반영 @@ -307,7 +307,7 @@ public LostItem createLostItem(LostItem lostItem) throws Exception { lostItem.setIp(ip); //image_urls 체크 - if (!con.isJsonArrayWithOnlyObject(lostItem.getImage_urls())) + if (lostItem.getImage_urls() != null && !con.isJsonArrayWithOnlyString(lostItem.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); lostAndFoundMapper.createLostItem(lostItem); @@ -429,7 +429,7 @@ public LostItem updateLostItem(LostItem lostItem, int id) throws Exception { lostItem.setIp(ip); //image_urls 체크 - if (!con.isJsonArrayWithOnlyString(lostItem.getImage_urls())) + if (lostItem.getImage_urls() != null && !con.isJsonArrayWithOnlyString(lostItem.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); //TODO : validator를 사용해 입력된 정보의 유효화 검사 후 입력된 부분만 기존 내용에 반영 diff --git a/src/main/java/koreatech/in/service/MarketPlaceServiceImpl.java b/src/main/java/koreatech/in/service/MarketPlaceServiceImpl.java index 8c8fa7e6..c7cd5efa 100644 --- a/src/main/java/koreatech/in/service/MarketPlaceServiceImpl.java +++ b/src/main/java/koreatech/in/service/MarketPlaceServiceImpl.java @@ -452,7 +452,7 @@ public Map getMyItemList(int type, Criteria criteria) throws Exc throw new PreconditionFailedException(new ErrorMessage("invalid type", 0)); } - double totalCount = marketPlaceMapper.totalItemCountByType(type); + double totalCount = marketPlaceMapper.totalMyItemCountByType(type, user.getId()); //TODO: paging을 위한 중복코드, 반복코드 개선방법 찾기 int totalPage = (int)Math.ceil(totalCount / criteria.getLimit()); diff --git a/src/main/java/koreatech/in/service/ShopServiceImpl.java b/src/main/java/koreatech/in/service/ShopServiceImpl.java index 0d9b4c17..eb7a3ea3 100644 --- a/src/main/java/koreatech/in/service/ShopServiceImpl.java +++ b/src/main/java/koreatech/in/service/ShopServiceImpl.java @@ -45,7 +45,7 @@ public Shop createShopForAdmin(Shop shop) throws Exception { } //image_urls 체크 - if(!con.isJsonArrayWithOnlyString(shop.getImage_urls())) + if(shop.getImage_urls() != null && !con.isJsonArrayWithOnlyString(shop.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); shop.setInternal_name(shop.getName().replace(" ","").toLowerCase()); @@ -167,7 +167,7 @@ public Shop updateShopForAdmin(Shop shop, int id) throws Exception { } //image_urls 체크 - if(!con.isJsonArrayWithOnlyString(shop.getImage_urls())) + if(shop.getImage_urls() != null && !con.isJsonArrayWithOnlyString(shop.getImage_urls())) throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0)); if (shop.getName() != null) { @@ -198,7 +198,7 @@ public Map deleteShopForAdmin(int id) throws Exception { @Override public Menu createMenuForAdmin(Menu menu, int shop_id) throws Exception { //price_type 검증 - if (!con.isJsonArrayWithOnlyObject(menu.getPrice_type())) + if (menu.getPrice_type() != null && !con.isJsonArrayWithOnlyObject(menu.getPrice_type())) throw new PreconditionFailedException(new ErrorMessage("Price_type is not valid", 0)); menu.setShop_id(shop_id); @@ -234,7 +234,7 @@ public Menu updateMenuForAdmin(Menu menu, int shop_id, int id) throws Exception throw new NotFoundException(new ErrorMessage("There is no such menu", 0)); ///price_type 검증 - if (!con.isJsonArrayWithOnlyObject(menu.getPrice_type())) + if (menu.getPrice_type() != null && !con.isJsonArrayWithOnlyObject(menu.getPrice_type())) throw new PreconditionFailedException(new ErrorMessage("Price_type is not valid", 0));