# 사용자 API

## &#x20; 사용자 인증

<mark style="color:green;">`POST`</mark> `http://sejabo.com/login`

&#x20;사용자 인증 API이다. 세종대학교에서 사용하는 아이디 및 비밀번호를 입력시,  그 즉시 DB에서 회원 정보를 생성하여 사용자 액세스 토큰을 반환한다.

#### Request Body

| Name | Type   | Description |
| ---- | ------ | ----------- |
| id   | string | 사용자 아이디(학번) |
| pw   | string | 비밀번호        |

{% tabs %}
{% tab title="200 1. 로그인 성공, 액세스 토큰 반환
2\. 해당 입력값이 존재하지 않을 경우, id 입력값이 학번이 아닌 경우
3\. 비밀번호가 일치하지 않을 경우" %}

```javascript
1.
{
    "result":"success",
    "access_token":<string>
}
2.
{
    "result":"your not Sejong"
}
3. 
{
    "result":"password incorrect"
}
```

{% endtab %}
{% endtabs %}

## &#x20; 회원정보 조회&#x20;

<mark style="color:blue;">`GET`</mark> `http://sejabo.com/userinfo`

입력받은 토큰과 일치하는 회원정보를 반환한다. &#x20;

#### Headers

| Name          | Type   | Description               |
| ------------- | ------ | ------------------------- |
| Authorization | string | JWT 토큰: "Bearer " + Token |

{% tabs %}
{% tab title="200 " %}

```coffeescript
{
    "result":"success",
    "student_id":<int>,
    "name":<string>,
    "major_name":<string>,
    "my_post":{
        "post_id":<int>,
        "author_name":<string>,
        "author_id":<int>,
        "author_major":<string>,
        "title":<string>,
        "content"<string>,
        "reg_date":<string>,
        "exp_date":<string>,
        "like_count":<int>,
        "dislike_count":<int>,
        "url":<string>,
        "img_url":<string>,
        "size":<int>,
        "build_yul":<int>,
        "build_dae":<int>,
        "build_hak":<int>,
        "build_gwang":<int>,
        "build_count":<int>,
        "color":<string>
    },
    "like_posts":<array:json>{
        "post_id":<int>,
        "author_name":<string>,
        "author_id":<int>,
        "author_major":<string>,
        "title":<string>,
        "content"<string>,
        "reg_date":<string>,
        "exp_date":<string>,
        "like_count":<int>,
        "dislike_count":<int>,
        "url":<string>,
        "img_url":<string>,
        "size":<int>,
        "build_yul":<int>,
        "build_dae":<int>,
        "build_hak":<int>,
        "build_gwang":<int>,
        "build_count":<int>,
        "color":<string>
    }
    "dislike_posts":<array:json>{
      "post_id":<int>,
        "author_name":<string>,
        "author_id":<int>,
        "author_major":<string>,
        "title":<string>,
        "content"<string>,
        "reg_date":<string>,
        "exp_date":<string>,
        "like_count":<int>,
        "dislike_count":<int>,
        "url":<string>,
        "img_url":<string>,
        "size":<int>,
        "build_yul":<int>,
        "build_dae":<int>,
        "build_hak":<int>,
        "build_gwang":<int>,
        "build_count":<int>,
        "color":<string>
    }
}

```

{% endtab %}

{% tab title="400  유효하지 않은 토큰" %}

```coffeescript
{
    "result":"bad request"
}
```

{% endtab %}
{% endtabs %}

## &#x20;게시물 등록

<mark style="color:green;">`POST`</mark> `http://sejabo.com/add_post`

입력받은 데이터를 이용해 게시물을 등록한다.&#x20;

#### Headers

| Name          | Type   | Description |
| ------------- | ------ | ----------- |
| Authorization | string | JWT 토큰      |

#### Request Body

| Name      | Type   | Description     |
| --------- | ------ | --------------- |
| url       | string | 외부 연결 링크        |
| build     | array  | 게시할 대상 건물 목록    |
| title     | string | 게시물 제목(100자 제한) |
| content   | string | 게시물 내용          |
| size      | number | 게시물 블록 크기       |
| exp\_date | string | 게시물 만료일         |
| img\_url  | object | 첨부 이미지 (1개 제한)  |

{% tabs %}
{% tab title="200 " %}

```coffeescript
{
    "result":"success"
}
```

{% endtab %}

{% tab title="400  1. 게시물 등록 조건에 맞지 않는 요청일 경우
2\. 비로그인 상태이거나 유효하지 않는 토큰일 경우
3\. 이미 해당 계정으로 등록한 게시물이 있을 경우" %}

```coffeescript
{
    "result":"bad request"
}
```

{% endtab %}
{% endtabs %}

## 게시물 수정

<mark style="color:green;">`POST`</mark> `http://sejabo.com/mod_post`

입력받은 데이터를 이용해 기존 게시물을 갱신한다.

#### Headers

| Name          | Type   | Description |
| ------------- | ------ | ----------- |
| Authorization | string | JWT 토큰      |

#### Request Body

| Name    | Type   | Description     |
| ------- | ------ | --------------- |
| title   | string | 게시물 제목(500자 제한) |
| content | string | 게시물 내용          |
| url     | string | 첨부 링크           |

{% tabs %}
{% tab title="200 " %}

```coffeescript
{
    "result":"success"
}
```

{% endtab %}

{% tab title="400  1. 게시물 등록 조건에 맞지 않는 요청일 경우
2\. 비로그인 상태이거나 유효하지 않는 토큰일 경우" %}

```coffeescript
{
    "result":"bad request"
}
```

{% endtab %}
{% endtabs %}

## &#x20;게시물 삭제

<mark style="color:blue;">`GET`</mark> `http://sejabo.com/delete_post/<int:post_id>`

&#x20;로그인된 사용자가 작성한 글인 경우, 해당 게시물을 삭제한다.

#### Path Parameters

| Name     | Type   | Description |
| -------- | ------ | ----------- |
| post\_id | number | 게시물 아이디     |

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | "Bearer " + \<Token> |

{% tabs %}
{% tab title="200 " %}

```coffeescript
{
    "result":"success"
}
```

{% endtab %}

{% tab title="400 해당 게시물의 작성자와 현재 사용자가 다를 경우 " %}

```coffeescript
{
    "result":"bad request"
}
```

{% endtab %}
{% endtabs %}
