Skip to content

Commit

Permalink
Merge pull request #777 from support-project/feature/issue760_delete_…
Browse files Browse the repository at this point in the history
…article

#760 Add a web api to delete article
  • Loading branch information
koda-masaru authored Jul 1, 2017
2 parents e69e02c + c714545 commit cf84713
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import org.support.project.knowledge.vo.api.Knowledge;
import org.support.project.knowledge.vo.api.KnowledgeDetail;
import org.support.project.web.bean.ApiParams;
import org.support.project.web.bean.Msg;
import org.support.project.web.bean.NameId;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.control.ApiControl;
import org.support.project.web.control.service.Delete;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.control.service.Put;
Expand Down Expand Up @@ -96,7 +98,7 @@ public Boundary put() {
KnowledgeDetail data = getJsonObject(KnowledgeDetail.class);
data.setKnowledgeId(id);
KnowledgeDataEditLogic.get().update(data, getLoginedUser());
return send(HttpStatus.SC_200_OK, new NameId(data.getTitle(), String.valueOf(id)));
return send(HttpStatus.SC_200_OK, new Msg("updated"));
} catch (JSONException e) {
LOG.debug("json parse error", e);
return sendError(HttpStatus.SC_400_BAD_REQUEST);
Expand All @@ -107,5 +109,27 @@ public Boundary put() {
return sendError(HttpStatus.SC_500_INTERNAL_SERVER_ERROR);
}
}


/**
* Delete knowledges
*/
@Delete(path="api/knowledges", checkReferer=false)
public Boundary delete() {
try {
Long id = getPathLong();
KnowledgeDataEditLogic.get().delete(id, getLoginedUser());
return send(HttpStatus.SC_200_OK, new Msg("deleted"));
} catch (JSONException e) {
LOG.debug("json parse error", e);
return sendError(HttpStatus.SC_400_BAD_REQUEST);
} catch (InvalidParamException e) {
return sendError(e);
} catch (Exception e) {
LOG.error("error", e);
return sendError(HttpStatus.SC_500_INTERNAL_SERVER_ERROR);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,43 @@ public void update(KnowledgeDetail data, LoginedUser loginedUser) throws Excepti
throw new InvalidParamException(new MessageResult(
MessageStatus.Warning, HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND", ""));
}
// 画面での登録と形をあわせる
KnowledgeData knowledge = conv(data);
// 編集権限チェック
Resources resources = Resources.getInstance(Locale.ENGLISH);
List<LabelValue> editors = TargetLogic.get().selectEditorsOnKnowledgeId(data.getKnowledgeId());
if (!KnowledgeLogic.get().isEditor(loginedUser, check, editors)) {
throw new InvalidParamException(new MessageResult(
MessageStatus.Warning, HttpStatus.SC_403_FORBIDDEN, resources.getResource("knowledge.edit.noaccess"), ""));
}
// 画面での登録と形をあわせる
KnowledgeData knowledge = conv(data);
KnowledgeLogic.get().update(knowledge, loginedUser);
}

/**
* WebAPIからの Knowledge削除
* @param data
* @param loginedUser
* @return
* @throws Exception
*/
public void delete(Long id, LoginedUser loginedUser) throws Exception {
LOG.trace("delete");
KnowledgesEntity check = KnowledgesDao.get().selectOnKey(id);
if (check == null) {
throw new InvalidParamException(new MessageResult(
MessageStatus.Warning, HttpStatus.SC_404_NOT_FOUND, "NOT_FOUND", ""));
}
// 編集権限チェック
Resources resources = Resources.getInstance(Locale.ENGLISH);
List<LabelValue> editors = TargetLogic.get().selectEditorsOnKnowledgeId(id);
if (!KnowledgeLogic.get().isEditor(loginedUser, check, editors)) {
throw new InvalidParamException(new MessageResult(
MessageStatus.Warning, HttpStatus.SC_403_FORBIDDEN, resources.getResource("knowledge.edit.noaccess"), ""));
}
KnowledgeLogic.get().delete(id);

}




Expand Down

0 comments on commit cf84713

Please sign in to comment.