Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/java/koreatech/in/schedule/BusTago.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private static List<Map<String, Object>> 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) {
Expand All @@ -115,7 +114,6 @@ private static List<Map<String, Object>> requestBusArrivalInfo(String cityCode,
}

result = con.parseJsonArrayWithObject(nodeInfo.getAsJsonObject("response").getAsJsonObject("body").getAsJsonObject("items").getAsJsonArray("item"));

return result;
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/java/koreatech/in/service/CircleServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,8 +37,8 @@ public Map<String, Object> 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<Circle> circleList = circleMapper.getCircleListForAdmin(criteria.getCursor(), criteria.getLimit());
Expand All @@ -64,7 +62,7 @@ public Circle createCircleForAdmin(Circle circle) 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("Image_urls are not valid", 0));

if (circle.getIs_deleted() == null) {
Expand All @@ -82,8 +80,8 @@ public Map<String, Object> 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<Circle> circles = circleMapper.getCircleList(criteria.getCursor(), criteria.getLimit());
Expand Down Expand Up @@ -111,7 +109,7 @@ public Map<String, Object> 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<String, Object> faq = new HashMap<String, Object>();
faq.put("items", BeanSerializer.getSerializedResult(Faq.class, new BeanSerializer(FaqResponseType.getArray()), faqMapper.getFaqListByCircle(cursor, limit, id), List.class));
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/koreatech/in/service/JsonConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +53,9 @@ public List<Map<String, Object>> parseJsonArrayWithObject(JsonArray jsonArray) {
if (jsonArray == null) return null;
List<Map<String, Object>> list;
try {
for (JsonElement element : jsonArray) {
parseJsonObject((element.getAsJsonObject()));
}
list = gson.fromJson(jsonArray, new TypeToken<List<Map<String, Object>>>() {}.getType());
} catch (Exception e) {
return null;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/koreatech/in/service/LandServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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를 사용해 입력된 정보의 유효화 검사 후 입력된 부분만 기존 내용에 반영
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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를 사용해 입력된 정보의 유효화 검사 후 입력된 부분만 기존 내용에 반영
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/koreatech/in/service/ShopServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -198,7 +198,7 @@ public Map<String, Object> 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);
Expand Down Expand Up @@ -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));


Expand Down