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

Notice api #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ dependencies {
asciidoctor 'org.springframework.restdocs:spring-restdocs-asciidoctor:2.0.2.RELEASE'
testCompile("org.springframework.boot:spring-boot-starter-test")
implementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
//이거 문서화때문에 추가함
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:2.0.2.RELEASE'
//
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
Expand All @@ -50,6 +52,7 @@ ext {
}
test {
useJUnitPlatform()
outputs.dir snippetsDir
}

asciidoctor {
Expand Down
199 changes: 199 additions & 0 deletions src/docs/asciidoc/notice.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
= NUTEE REST API Guide(Crawl)
이문혁;
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 4
:sectlinks:
:operation-curl-request-title: Example request
:operation-http-response-title: Example response

[[overview]]
= 개요

[[overview-http-verbs]]
== HTTP 동사

본 REST API에서 사용하는 HTTP 동사(verbs)는 가능한한 표준 HTTP와 REST 규약을 따른다.

|===
| 동사 | 용례

| `GET`
| 리소스를 가져올 때 사용

| `POST`
| 새 리소스를 만들 때 사용

| `PUT`
| 기존 리소스의 전체를 수정할 때 사용

| `PATCH`
| 기존 리소스의 일부를 수정할 때 사용

| `DELETE`
| 기존 리소스를 삭제할 떄 사용
|===

[[overview-http-status-codes]]
== HTTP 상태 코드

본 REST API에서 사용하는 HTTP 상태 코드는 가능한한 표준 HTTP와 REST 규약을 따릅니다.

|===
| 상태 코드 | 용례

| `200 OK`
| 요청을 성공적으로 처리함

| `201 Created`
| 새 리소스를 성공적으로 생성함. 응답의 `Location` 헤더에 해당 리소스의 URI가 담겨있다.

| `204 No Content`
| 기존 리소스를 성공적으로 수정함.

| `400 Bad Request`
| 잘못된 요청을 보낸 경우. 응답 본문에 더 오류에 대한 정보가 담겨있다.

| `404 Not Found`
| 요청한 리소스가 없음.
|===

[[overview-nutee-status-codes]]
== NUTEE 내부 상태코드

NUTEE REST API에서 사용하는 NUTEE 상태 코드입니다.

|===
| 상태 코드 | 용례

| `10`
| 문제 없이 정상 작동함.

| `21`
| 권한이 없는 요청임.

| `22`
| 요청에 해당하는 리소스가 존재하지 않음.

| `23`
| request 에 비어있는 내용이 존재함.

| `51`
| 데이터베이스 중복.

| `52`
| 잘못된 인자를 전달하였음.


|===


[[overview-errors]]
== 오류


[[overview-hypermedia]]
== 하이퍼미디어

본 REST API는 하이퍼미디어와 사용하며 응답에 담겨있는 리소스는 다른 리소스에 대한 링크를 가지고 있다.
응답은 http://stateless.co/hal_specification.html[Hypertext Application from resource to resource. Language (HAL)] 형식을 따른다.
링크는 `_links`라는 키로 제공한다. 본 API의 사용자(클라이언트)는 URI를 직접 생성하지 않아야 하며, 리소스에서 제공하는 링크를 사용해야 한다.


[[api]]
== API(NOTICE)

[[resources-auth]]
== 학교공지

notice는 학교 공지목록을 크롤링한다.

[[resources-get-haksa]]
=== 학사목록

`GET` 요청을 사용 하여 학사공지 목록을 가져온다.

[[http-request]]
==== http-request
include::{snippets}/get-haksa/http-request.adoc[]

[[http-response]]
==== http-response
include::{snippets}/get-haksa/http-response.adoc[]



[[resources-get-sooup]]
=== 수업목록

`GET` 요청을 사용 하여 수업공지 목록을 가져온다.

[[http-request]]
==== http-request
include::{snippets}/get-sooup/http-request.adoc[]

[[http-response]]
==== http-response
include::{snippets}/get-sooup/http-response.adoc[]



[[resources-get-hakjum]]
=== 학점목록

`GET` 요청을 사용 하여 학점공지 목록을 가져온다.

[[http-request]]
==== http-request
include::{snippets}/get-hakjum/http-request.adoc[]

[[http-response]]
==== http-response
include::{snippets}/get-hakjum/http-response.adoc[]



[[resources-get-janghak]]
=== 장학목록

`GET` 요청을 사용 하여 장학공지 목록을 가져온다.

[[http-request]]
==== http-request
include::{snippets}/get-janghak/http-request.adoc[]

[[http-response]]
==== http-response
include::{snippets}/get-janghak/http-response.adoc[]



[[resources-get-illban]]
=== 일반목록

`GET` 요청을 사용 하여 일반공지 목록을 가져온다.

[[http-request]]
==== http-request
include::{snippets}/get-ilban/http-request.adoc[]

[[http-response]]
==== http-response
include::{snippets}/get-ilban/http-response.adoc[]



[[resources-get-hangsa]]
=== 행사목록

`GET` 요청을 사용 하여 행사공지 목록을 가져온다.

[[http-request]]
==== http-request
include::{snippets}/get-hangsa/http-request.adoc[]

[[http-response]]
==== http-response
include::{snippets}/get-hangsa/http-response.adoc[]
106 changes: 57 additions & 49 deletions src/main/java/kr/nutee/crawler/Controller/NoticeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -15,70 +17,76 @@
import java.io.IOException;

@RestController
@RequestMapping(path = "/crawl", consumes = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(path = "/crawl")//, consumes = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@ResponseBody
@Slf4j
public class NoticeController {
@Autowired
NoticeService noticeService;

@GetMapping("/haksa")
public ResponseEntity<ResponseResource> crawlHaksa() throws IOException {
return noticeService.getNoticeApi("학사","haksa");
}

@GetMapping("/sooup")
public ResponseEntity<ResponseResource> crawlSooup() throws IOException {
return noticeService.getNoticeApi("수업","sooup");
}

@GetMapping("/hakjum")
public ResponseEntity<ResponseResource> crawlHakjum() throws IOException {
return noticeService.getNoticeApi("학점","hakjum");
}

@GetMapping("/janghak")
public ResponseEntity<ResponseResource> crawlJanghak() throws IOException {
return noticeService.getNoticeApi("장학","janghak");
}

@GetMapping("/ilban")
public ResponseEntity<ResponseResource> crawlIlban() throws IOException {
return noticeService.getNoticeApi("일반","ilban");
}

@GetMapping("/hangsa")
public ResponseEntity<ResponseResource> crawlHangsa() throws IOException {
return noticeService.getNoticeApi("행사","hangsa");
}
// @GetMapping(path = "/haksa")
// public ResponseEntity<ResponseResource> crawlHaksa(@PageableDefault(size=10) Pageable pageable) throws IOException {
// return noticeService.getNoticeApi("학사","haksa", pageable);
// @GetMapping("/haksa")
// public ResponseEntity<ResponseResource> crawlHaksa() throws IOException {
// return noticeService.getNoticeApi("학사","haksa");
// }
//
// @GetMapping(path = "/sooup")
// public ResponseEntity<ResponseResource> crawlSooup(@PageableDefault(size=10) Pageable pageable) throws IOException {
// return noticeService.getNoticeApi("수업","sooup", pageable);
// @GetMapping("/sooup")
// public ResponseEntity<ResponseResource> crawlSooup() throws IOException {
// return noticeService.getNoticeApi("수업","sooup");
// }
//
// @GetMapping(path = "/hakjum")
// public ResponseEntity<ResponseResource> crawlHakjum(@PageableDefault(size=10) Pageable pageable) throws IOException {
// return noticeService.getNoticeApi("학점","hakjum", pageable);
// @GetMapping("/hakjum")
// public ResponseEntity<ResponseResource> crawlHakjum() throws IOException {
// return noticeService.getNoticeApi("학점","hakjum");
// }
//
// @GetMapping(path = "/janghak")
// public ResponseEntity<ResponseResource> crawlJanghak(@PageableDefault(size=10) Pageable pageable) throws IOException {
// return noticeService.getNoticeApi("장학","janghak", pageable);
// @GetMapping("/janghak")
// public ResponseEntity<ResponseResource> crawlJanghak() throws IOException {
// return noticeService.getNoticeApi("장학","janghak");
// }
//
// @GetMapping(path = "/ilban")
// public ResponseEntity<ResponseResource> crawlIlban(@PageableDefault(size=10) Pageable pageable) throws IOException {
// return noticeService.getNoticeApi("일반","ilban", pageable);
// @GetMapping("/ilban")
// public ResponseEntity<ResponseResource> crawlIlban() throws IOException {
// return noticeService.getNoticeApi("일반","ilban");
// }
//
// @GetMapping(path = "/hangsa")
// public ResponseEntity<ResponseResource> crawlHangsa(@PageableDefault(size=10) Pageable pageable) throws IOException {
// return noticeService.getNoticeApi("행사","hangsa", pageable);
// @GetMapping("/hangsa")
// public ResponseEntity<ResponseResource> crawlHangsa() throws IOException {
// return noticeService.getNoticeApi("행사","hangsa");
// }

// @GetMapping(path = "/test")
// public ResponseEntity<ResponseResource> pageTest(@PageableDefault(size=6,sort="no",direction = Sort.Direction.DESC) Pageable pageable) throws IOException {
// return noticeService.testPage("학사","haksa", pageable);
// }

@GetMapping(path = "/haksa")
public ResponseEntity<ResponseResource> crawlHaksa(@PageableDefault(size=6,sort="no",direction=Sort.Direction.DESC) Pageable pageable) throws IOException {
return noticeService.getNoticePage("학사","haksa", pageable);
}

@GetMapping(path = "/sooup")
public ResponseEntity<ResponseResource> crawlSooup(@PageableDefault(size=6,sort="no",direction=Sort.Direction.DESC) Pageable pageable) throws IOException {
return noticeService.getNoticePage("수업","sooup", pageable);
}

@GetMapping(path = "/hakjum")
public ResponseEntity<ResponseResource> crawlHakjum(@PageableDefault(size=6,sort="no",direction=Sort.Direction.DESC) Pageable pageable) throws IOException {
return noticeService.getNoticePage("학점","hakjum", pageable);
}

@GetMapping(path = "/janghak")
public ResponseEntity<ResponseResource> crawlJanghak(@PageableDefault(size=6,sort="no",direction=Sort.Direction.DESC) Pageable pageable) throws IOException {
return noticeService.getNoticePage("장학","janghak", pageable);
}

@GetMapping(path = "/ilban")
public ResponseEntity<ResponseResource> crawlIlban(@PageableDefault(size=6,sort="no",direction=Sort.Direction.DESC) Pageable pageable) throws IOException {
return noticeService.getNoticePage("일반","ilban", pageable);
}

@GetMapping(path = "/hangsa")
public ResponseEntity<ResponseResource> crawlHangsa(@PageableDefault(size=6,sort="no",direction=Sort.Direction.DESC) Pageable pageable) throws IOException {
return noticeService.getNoticePage("행사","hangsa", pageable);
}
}
Loading