|
| 1 | +package koreatech.in.controller; |
| 2 | + |
| 3 | +import io.swagger.annotations.*; |
| 4 | +import koreatech.in.annotation.Auth; |
| 5 | +import koreatech.in.annotation.AuthExcept; |
| 6 | +import koreatech.in.annotation.ParamValid; |
| 7 | +import koreatech.in.annotation.ValidationGroups; |
| 8 | +import koreatech.in.domain.Criteria.Criteria; |
| 9 | +import koreatech.in.domain.ErrorMessage; |
| 10 | +import koreatech.in.domain.Event.EventArticle; |
| 11 | +import koreatech.in.domain.Event.EventComment; |
| 12 | +import koreatech.in.exception.PreconditionFailedException; |
| 13 | +import koreatech.in.service.EventService; |
| 14 | +import koreatech.in.util.StringXssChecker; |
| 15 | +import org.springframework.http.HttpStatus; |
| 16 | +import org.springframework.http.ResponseEntity; |
| 17 | +import org.springframework.stereotype.Controller; |
| 18 | +import org.springframework.validation.BindingResult; |
| 19 | +import org.springframework.validation.annotation.Validated; |
| 20 | +import org.springframework.web.bind.annotation.*; |
| 21 | +import org.springframework.web.multipart.MultipartFile; |
| 22 | +import org.springframework.web.multipart.MultipartHttpServletRequest; |
| 23 | + |
| 24 | +import javax.inject.Inject; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Map; |
| 27 | + |
| 28 | +@Auth(role = Auth.Role.OWNER) |
| 29 | +@Controller |
| 30 | +public class EventController { |
| 31 | + @Inject |
| 32 | + private EventService eventService; |
| 33 | + |
| 34 | + @AuthExcept |
| 35 | + @ApiOperation(value = "전체 홍보글 조회") |
| 36 | + @RequestMapping(value = "/events", method = RequestMethod.GET) |
| 37 | + public @ResponseBody |
| 38 | + ResponseEntity<Map<String, Object>> getEventArticles(@ModelAttribute("criteria") Criteria criteria) throws Exception { |
| 39 | + |
| 40 | + return new ResponseEntity<>(eventService.getEventArticles(criteria), HttpStatus.OK); |
| 41 | + } |
| 42 | + |
| 43 | + @ParamValid |
| 44 | + @ApiOperation(value = "홍보글 작성", authorizations = {@Authorization(value = "Authorization")}) |
| 45 | + @RequestMapping(value = "/events", method = RequestMethod.POST) |
| 46 | + public @ResponseBody |
| 47 | + ResponseEntity<EventArticle> createEventArticle(@ApiParam(value = "(required: title, event_title, content, shop_id, start_date, end_date), (optional: thumbnail)", required = true) @RequestBody @Validated(ValidationGroups.Create.class) EventArticle eventArticle, BindingResult result) throws Exception { |
| 48 | + EventArticle clear = new EventArticle(); |
| 49 | + |
| 50 | + return new ResponseEntity<>(eventService.createEventArticle((EventArticle) StringXssChecker.xssCheck(eventArticle, clear)), HttpStatus.CREATED); |
| 51 | + } |
| 52 | + |
| 53 | + @AuthExcept |
| 54 | + @ApiOperation(value = "특정 홍보글 조회") |
| 55 | + @RequestMapping(value = "/events/{id}", method = RequestMethod.GET) |
| 56 | + public @ResponseBody |
| 57 | + ResponseEntity<Map<String, Object>> getEventArticle(@ApiParam(required = true) @PathVariable int id) throws Exception { |
| 58 | + |
| 59 | + return new ResponseEntity<>(eventService.getEventArticle(id), HttpStatus.OK); |
| 60 | + } |
| 61 | + |
| 62 | + @ParamValid |
| 63 | + @ApiOperation(value = "홍보글 수정", authorizations = {@Authorization(value = "Authorization")}) |
| 64 | + @RequestMapping(value = "/events/{id}", method = RequestMethod.PUT) |
| 65 | + public @ResponseBody |
| 66 | + ResponseEntity<EventArticle> updateEventArticle(@ApiParam(value = "(optional: title, event_title, content, start_date, end_date)", required = false) @RequestBody @Validated(ValidationGroups.Update.class) EventArticle eventArticle, BindingResult bindingResult, @ApiParam(required = true) @PathVariable int id) throws Exception { |
| 67 | + EventArticle clear = new EventArticle(); |
| 68 | + return new ResponseEntity<>(eventService.updateEventArticle((EventArticle) StringXssChecker.xssCheck(eventArticle, clear), id), HttpStatus.CREATED); |
| 69 | + } |
| 70 | + |
| 71 | + @ApiOperation(value = "홍보글 삭제", authorizations = {@Authorization(value = "Authorization")}) |
| 72 | + @RequestMapping(value = "/events/{id}", method = RequestMethod.DELETE) |
| 73 | + public @ResponseBody |
| 74 | + ResponseEntity<Map<String, Object>> deleteEventArticle(@ApiParam(required = true) @PathVariable int id) throws Exception { |
| 75 | + |
| 76 | + return new ResponseEntity<>(eventService.deleteEventArticle(id), HttpStatus.OK); |
| 77 | + } |
| 78 | + |
| 79 | + @Auth(role = Auth.Role.USER) |
| 80 | + @ParamValid |
| 81 | + @ApiOperation(value = "홍보글 댓글 작성", authorizations = {@Authorization(value = "Authorization")}) |
| 82 | + @RequestMapping(value = "/events/{articleId}/comments", method = RequestMethod.POST) |
| 83 | + public @ResponseBody |
| 84 | + ResponseEntity<EventComment> createEventComment(@ApiParam(value = "(required: content)", required = true) @RequestBody @Validated(ValidationGroups.Create.class) EventComment comment, BindingResult bindingResult, @ApiParam(required = true) @PathVariable(value = "articleId") int articleId) throws Exception { |
| 85 | + EventComment clear = new EventComment(); |
| 86 | + return new ResponseEntity<>(eventService.createEventComment((EventComment) StringXssChecker.xssCheck(comment, clear), articleId), HttpStatus.CREATED); |
| 87 | + } |
| 88 | + |
| 89 | +// @AuthExcept |
| 90 | +// @ApiOperation(value = "특정 홍보글 댓글 조회", authorizations = {@Authorization(value = "Authorization")}) |
| 91 | +// @RequestMapping(value = "/events/{articleId}/comments/{commentId}", method = RequestMethod.GET) |
| 92 | +// public @ResponseBody |
| 93 | +// ResponseEntity<EventComment> getEventComment(@ApiParam(required = true) @PathVariable int articleId, @ApiParam(required = true) @PathVariable int commentId) throws Exception { |
| 94 | +// |
| 95 | +// return new ResponseEntity<>(eventService.getEventComment(articleId, commentId), HttpStatus.OK); |
| 96 | +// } |
| 97 | + |
| 98 | + @Auth(role = Auth.Role.USER) |
| 99 | + @ParamValid |
| 100 | + @ApiOperation(value = "홍보글 댓글 수정", authorizations = {@Authorization(value = "Authorization")}) |
| 101 | + @RequestMapping(value = "/events/{articleId}/comments/{commentId}", method = RequestMethod.PUT) |
| 102 | + public @ResponseBody |
| 103 | + ResponseEntity<EventComment> updateEventComment(@ApiParam(value = "(optional: content)", required = false) @RequestBody @Validated(ValidationGroups.Update.class) EventComment comment, BindingResult bindingResult, @ApiParam(required = true) @PathVariable int articleId, @ApiParam(required = true) @PathVariable int commentId) throws Exception { |
| 104 | + EventComment clear = new EventComment(); |
| 105 | + return new ResponseEntity<>(eventService.updateEventComment((EventComment) StringXssChecker.xssCheck(comment, clear), articleId, commentId), HttpStatus.CREATED); |
| 106 | + } |
| 107 | + |
| 108 | + @Auth(role = Auth.Role.USER) |
| 109 | + @ApiOperation(value = "홍보글 댓글 삭제", authorizations = {@Authorization(value = "Authorization")}) |
| 110 | + @RequestMapping(value = "/events/{articleId}/comments/{commentId}", method = RequestMethod.DELETE) |
| 111 | + public @ResponseBody |
| 112 | + ResponseEntity<Map<String, Object>> deleteEventComment(@ApiParam(required = true) @PathVariable int articleId, @ApiParam(required = true) @PathVariable int commentId) throws Exception { |
| 113 | + |
| 114 | + return new ResponseEntity<>(eventService.deleteEventComment(articleId, commentId), HttpStatus.OK); |
| 115 | + } |
| 116 | + |
| 117 | + @ApiOperation(value = "점주의 가게 조회", authorizations = {@Authorization(value = "Authorization")}) |
| 118 | + @RequestMapping(value = "/events/my/shops", method = RequestMethod.GET) |
| 119 | + public @ResponseBody |
| 120 | + ResponseEntity<Map<String, Object>> getMyShops() { |
| 121 | + |
| 122 | + return new ResponseEntity<>(eventService.getMyShops(), HttpStatus.OK); |
| 123 | + } |
| 124 | + |
| 125 | + @ApiOperation(value = "점주의 진행 중인 홍보 조회", authorizations = {@Authorization(value = "Authorization")}) |
| 126 | + @RequestMapping(value = "/events/pending/my", method = RequestMethod.GET) |
| 127 | + public @ResponseBody |
| 128 | + ResponseEntity<Map<String, Object>> getMyPendingEvent(@ModelAttribute("criteria") Criteria criteria) throws Exception { |
| 129 | + |
| 130 | + return new ResponseEntity<>(eventService.getMyPendingEvent(criteria), HttpStatus.OK); |
| 131 | + } |
| 132 | + |
| 133 | + @AuthExcept |
| 134 | + @ApiOperation(value = "진행 중인 전체 홍보글 조회") |
| 135 | + @RequestMapping(value = "/events/pending", method = RequestMethod.GET) |
| 136 | + public @ResponseBody |
| 137 | + ResponseEntity<Map<String, Object>> getPendingEvents(@ModelAttribute("criteria") Criteria criteria) throws Exception { |
| 138 | + |
| 139 | + return new ResponseEntity<>(eventService.getPendingEvents(criteria), HttpStatus.OK); |
| 140 | + } |
| 141 | + |
| 142 | + @AuthExcept |
| 143 | + @ApiOperation(value = "마감된 전체 홍보글 조회") |
| 144 | + @RequestMapping(value = "/events/closed", method = RequestMethod.GET) |
| 145 | + public @ResponseBody |
| 146 | + ResponseEntity<Map<String, Object>> getClosedEvents(@ModelAttribute("criteria") Criteria criteria) throws Exception { |
| 147 | + |
| 148 | + return new ResponseEntity<>(eventService.getClosedEvents(criteria), HttpStatus.OK); |
| 149 | + } |
| 150 | + |
| 151 | + @ApiOperation(value = "특정 홍보글 수정 권한 확인", authorizations = {@Authorization(value = "Authorization")}) |
| 152 | + @RequestMapping(value = "/events/grant/check", method = RequestMethod.POST) |
| 153 | + public @ResponseBody |
| 154 | + ResponseEntity<Map<String, Boolean>> checkGrantEditEvent(@ApiParam(required = true) @RequestBody Map<String, Integer> article_id) throws Exception { |
| 155 | + if (article_id == null || !article_id.containsKey("article_id")) |
| 156 | + throw new PreconditionFailedException(new ErrorMessage("올바르지 않은 데이터입니다.", 0)); |
| 157 | + |
| 158 | + return new ResponseEntity<>(eventService.checkGrantEditEvent(article_id.get("article_id")), HttpStatus.OK); |
| 159 | + } |
| 160 | + |
| 161 | + @AuthExcept |
| 162 | + @ApiOperation(value = "진행 중인 이벤트 랜덤 조회") |
| 163 | + @RequestMapping(value = "/events/pending/random", method = RequestMethod.GET) |
| 164 | + public @ResponseBody |
| 165 | + ResponseEntity<EventArticle> getRandomPendingEvent() { |
| 166 | + |
| 167 | + return new ResponseEntity<>(eventService.getRandomPendingEvent(), HttpStatus.OK); |
| 168 | + } |
| 169 | +} |
0 commit comments