Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

게시물 목록api 구현 #79

Merged
merged 1 commit into from
Jul 10, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.mobile.device.Device;
import org.springframework.mobile.device.DeviceUtils;
import org.springframework.security.web.util.UrlUtils;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;

import com.jakduk.authentication.common.CommonPrincipal;
import com.jakduk.common.CommonConst;
import com.jakduk.dao.BoardDAO;
Expand Down Expand Up @@ -54,23 +72,6 @@
import com.jakduk.repository.BoardFreeOnListRepository;
import com.jakduk.repository.BoardFreeRepository;
import com.jakduk.repository.GalleryRepository;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.mobile.device.Device;
import org.springframework.mobile.device.DeviceUtils;
import org.springframework.security.web.util.UrlUtils;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;

@Service
@Slf4j
Expand Down Expand Up @@ -552,15 +553,13 @@ public Integer edit(HttpServletRequest request, BoardFreeWrite boardFreeWrite) {

return HttpServletResponse.SC_OK;
}

/**
* 자유게시판 목록 페이지
* @param model
* @param boardListInfo
* @return
*/
public Model getFreePostsList(Model model, Locale locale, BoardListInfo boardListInfo) {

public Map<String, Object> getFreePostsList(Locale locale, BoardListInfo boardListInfo) {
Map<String, Date> createDate = new HashMap<String, Date>();
List<BoardFreeOnList> posts = new ArrayList<BoardFreeOnList>();
ArrayList<Integer> seqs = new ArrayList<Integer>();
Expand All @@ -570,12 +569,12 @@ public Model getFreePostsList(Model model, Locale locale, BoardListInfo boardLis
Integer page = boardListInfo.getPage();
Integer size = boardListInfo.getSize();
String categoryName = boardListInfo.getCategory();

if (categoryName == null || commonService.isNumeric(categoryName)) {
categoryName = CommonConst.BOARD_CATEGORY_ALL;
boardListInfo.setCategory(categoryName);
}

if (page < 1) {
page = 1;
boardListInfo.setPage(page);
Expand All @@ -584,8 +583,8 @@ public Model getFreePostsList(Model model, Locale locale, BoardListInfo boardLis
Sort sort = new Sort(Sort.Direction.DESC, Arrays.asList("seq"));
Pageable pageable = new PageRequest(page - 1, size, sort);

if (categoryName != null &&
(categoryName.equals(CommonConst.BOARD_CATEGORY_NONE) || categoryName.equals(CommonConst.BOARD_CATEGORY_ALL))) {
if (categoryName != null &&
(categoryName.equals(CommonConst.BOARD_CATEGORY_NONE) || categoryName.equals(CommonConst.BOARD_CATEGORY_ALL))) {
posts = boardFreeOnListRepository.findAll(pageable).getContent();
totalPosts = boardFreeOnListRepository.count();
} else {
Expand Down Expand Up @@ -630,16 +629,23 @@ public Model getFreePostsList(Model model, Locale locale, BoardListInfo boardLis
Map<String, Integer> commentCount = boardDAO.getBoardFreeCommentCount(seqs);
Map<String, BoardFeelingCount> feelingCount = boardDAO.getBoardFreeUsersFeelingCount(ids);

model.addAttribute("posts", posts);
model.addAttribute("notices", notices);
model.addAttribute("categorys", categorys);
model.addAttribute("boardListInfo", boardListInfo);
model.addAttribute("totalPosts", totalPosts);
model.addAttribute("commentCount", commentCount);
model.addAttribute("feelingCount", feelingCount);
model.addAttribute("createDate", createDate);
model.addAttribute("dateTimeFormat", commonService.getDateTimeFormat(locale));
Map<String, Object> data = new HashMap<>();
data.put("posts", posts);
data.put("notices", notices);
data.put("categorys", categorys);
data.put("boardListInfo", boardListInfo);
data.put("totalPosts", totalPosts);
data.put("commentCount", commentCount);
data.put("feelingCount", feelingCount);
data.put("createDate", createDate);
data.put("dateTimeFormat", commonService.getDateTimeFormat(locale));

return data;
}

public Model getFreePostsList(Model model, Locale locale, BoardListInfo boardListInfo) {
Map<String, Object> data = getFreePostsList(locale, boardListInfo);
data.forEach(model::addAttribute);
return model;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package com.jakduk.restcontroller;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mobile.device.Device;
import org.springframework.mobile.device.DeviceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.LocaleResolver;

import com.jakduk.authentication.common.CommonPrincipal;
import com.jakduk.common.CommonConst;
import com.jakduk.exception.UnauthorizedAccessException;
Expand All @@ -8,27 +28,12 @@
import com.jakduk.model.embedded.BoardItem;
import com.jakduk.model.simple.BoardFreeOfMinimum;
import com.jakduk.model.web.BoardListInfo;
import com.jakduk.restcontroller.vo.BoardPaging;
import com.jakduk.service.BoardFreeService;
import com.jakduk.service.CommonService;
import com.jakduk.service.UserService;
import com.jakduk.vo.BoardCommentRequest;
import com.jakduk.vo.BoardCommentsResponse;
import com.jakduk.vo.UserFeelingResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mobile.device.Device;
import org.springframework.mobile.device.DeviceUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.LocaleResolver;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

/**
* Created by pyohwan on 16. 3. 26.
Expand All @@ -51,12 +56,19 @@ public class BoardRestController {
@Autowired
private CommonService commonService;

@ApiOperation(value = "게시물 목록(미구현)")
@ApiOperation(value = "게시물 목록")
@RequestMapping(value = "/free/posts", method = RequestMethod.GET)
public void freeList(@ModelAttribute BoardPaging boardPaging,
HttpServletRequest request) {

public Map<String, Object> freeList(@RequestParam(required = false) String page,
@RequestParam(required = false) String size,
@RequestParam(required = false) String category,
HttpServletRequest request) {

BoardListInfo paging = new BoardListInfo();
paging.setPage(Objects.isNull(page) ? 1 : Integer.parseInt(page));
paging.setSize(Objects.isNull(size) ? CommonConst.BOARD_MAX_LIMIT : Integer.parseInt(size));
paging.setCategory(Objects.isNull(category) ? CommonConst.BOARD_CATEGORY_NONE : category);
Locale locale = localeResolver.resolveLocale(request);
return boardFreeService.getFreePostsList(locale, paging);
}

@ApiOperation(value = "게시판 댓글 목록")
Expand Down