---
# System prepended metadata

title: Untitled

---

## 方針
- マップをビューのベースに持ってくる
- 時間、距離、いいね、評価関数
- リストをなくしてマップに表示

- 周囲?m以内で評価関数で表示
- 差分だけ送る
- 離れたらそっちで破棄
- この辺で何件（遠いとこ）

- twitterとgoogleでログイン

## page
- 

## DB

### post
| column          | type     |
| :--             | :--      |
| ==id==(primary) | integer  |
| longitude       | integer  |
| latitude        | integer  |
| url             | string   |
| body            | text     |
| created_at      | datetime |
| updated_at      | datetime |

### user
| column          | type     |
| :--             | :--      |
| ==id==(primary) | integer  |
|name|strnig|
| email | string   |
| password_digest   | string  |
| token   | string |
| created_at   | datetime |
| updated_at   | datetime |

## API

base_url: `https://monu-geometry.herokkuapp.com/v1/`


### get /posts

#### Request

##### params



| param     | value       |
| --------  | --------    |
| longitude | 34.684860   |
| latitude  | 135.1994354 |
| delta     | 0.003       |

#### Response

##### 正常系

post のリスト
距離近い順

```jsonld
{
    "posts": [
        {
            "distance": 12, // number: メートル単位
            "body": "this is body", // string: ツイート本文
            "url": "https://<slug>", // string: ツイートに含まれるURL
            "created_at": 1571454012 // number: UNIX時間
        },
        {
            "distance": 13, // number: メートル単位
            "body": "this is body", // string
            "url": "https://<slug>", // string
            "created_at": 1571454012 // number
        },
    ]
}
```

##### 異常系

| failure mode                                     | HTTP status               |
| --------                                         | --------                  |
| longitude or latitude が未指定 or numberじゃない | 400 Bad Request           |
| 上記以外                                         | 500 internal server error |

```jsonld
{
    msg: "error message"
}
```

### post /posts

新しいpostを作成

#### Request

##### body

```jsonld
{
    "longitude": 34.684860, // number
    "latitude": 135.1994354, // number
    "url": "http://hogehoge",
    "body": "this is body"
}
```

#### Response

##### 正常系

post のリスト
距離近い順

```jsonld
{
    post: {
        "body": "this is body", // string: ツイート本文
        "url": "https://<slug>", // string: ツイートに含まれるURL
        "created_at": 1571454012 // number: UNIX時間
    }
}
```

#### 異常系

| failure mode   | HTTP status               |
| --------       | --------                  |
| どれかが未指定 | 400 Bad Request           |
| 上記以外       | 500 internal server error |

```jsonld
{
    msg: "error message"
}
```


## apilists
```
v1_users GET    /v1/users(.:format)           v1/users#index
         POST   /v1/users(.:format)           v1/users#create
 v1_user GET    /v1/users/:id(.:format)       v1/users#show
         PATCH  /v1/users/:id(.:format)       v1/users#update
         PUT    /v1/users/:id(.:format)       v1/users#update
         DELETE /v1/users/:id(.:format)       v1/users#destroy
   v1_me GET    /v1/me(.:format)              v1/users#me
v1_login POST   /v1/login(.:format)           v1/users#log_in
v1_posts GET    /v1/posts(.:format)           v1/posts#index
         POST   /v1/posts(.:format)           v1/posts#create
 v1_post GET    /v1/posts/:id(.:format)       v1/posts#show
         PATCH  /v1/posts/:id(.:format)       v1/posts#update
         PUT    /v1/posts/:id(.:format)       v1/posts#update
         DELETE /v1/posts/:id(.:format)       v1/posts#destroy
      v1 POST   /v1/images/:post_id(.:format) v1/images#create
         GET    /v1/images/:post_id(.:format) v1/images#show
         POST   /v1/posts/:id/good(.:format)  v1/posts#good
v2_users GET    /v2/users(.:format)           v2/users#index
         POST   /v2/users(.:format)           v2/users#create
 v2_user GET    /v2/users/:id(.:format)       v2/users#show
         PATCH  /v2/users/:id(.:format)       v2/users#update
         PUT    /v2/users/:id(.:format)       v2/users#update
         DELETE /v2/users/:id(.:format)       v2/users#destroy
   v2_me GET    /v2/me(.:format)              v2/users#me
v2_login POST   /v2/login(.:format)           v2/users#log_in
v2_posts GET    /v2/posts(.:format)           v2/posts#index
         POST   /v2/posts(.:format)           v2/posts#create
 v2_post GET    /v2/posts/:id(.:format)       v2/posts#show
         PATCH  /v2/posts/:id(.:format)       v2/posts#update
         PUT    /v2/posts/:id(.:format)       v2/posts#update
         DELETE /v2/posts/:id(.:format)       v2/posts#destroy
      v2 POST   /v2/images/:post_id(.:format) v2/images#create
         GET    /v2/images/:post_id(.:format) v2/images#show
         POST   /v2/posts/:id/good(.:format)  v2/posts#good
```
### Auth方法
1. (GET)/login または (POST)/usersでログインかユーザー作成
2. json形式の`{"token": "huahkdailno"}`がもらえる
3. headerに`Authorization`と`Bearer {token}`を追加し、送信
4. 簡単にauthできてるかの確認として(GET)/meにアクセス（ユーザーオブジェクトがもらえる）


### POST /v2/users
```jsonld
//request
{
    "name": "hoge1",
    "email": "kooala",
    "password": "password",
    "image": "url_to_image"
}

//response: user_obj(include token)
{
"id": 6,
"name": "hoge",
"email": "a21ala@s.q",
"token": "GtvXPzfyK2KVJ2fNkUSYC28n"
}
```

### GET /v2/me (==need Auth==)
```jsonld
//response: user_obj(include token) 
{
"id": 5,
"name": "json野郎",
"email": "imjson",
"token": "WzW2aqrSthsbhhx4dJ64LB2K",
"image": null
}
```

### POST /v2/login
```jsonld
//request
{
  "email": "a21ala@s.q",
  "password": "hgehoelaal"
}
//response: user_obj(include token)
{
"id": 6,
"name": "hoge",
"email": "a21ala@s.q",
"token": "GtvXPzfyK2KVJ2fNkUSYC28n",
"image": "http://kakka"
}
```
### GET /v2/users/:id
```jsonld
//response: user_obj
{
"id": 1,
"name": "hoge",
"email": "aaa@a.a",
"image": null
}
```

### POST /v2/posts (==need Auth==)
```jsonld
//request
{
    "longitude": 34.684860, 
    "latitude": 135.1994354, 
    "url": "http://hogehoge",
    "body": "this is body"
}
//response: post_obj
{
"id": 76,
"url": "http://hogehkakkakkkkoge",
"body": "this is body",
"created_at": "2019-10-20T01:15:24.797Z"
}
```

### POST /v2/posts/:post_id/good (==need Auth==)
```jsonld
//response good_obj
{"id":3,
"post_id":72,
"user_id":5,
"created_at":"2019-10-20T01:16:45.620Z",
"updated_at":"2019-10-20T01:16:45.620Z"
}
```

### GET /v2/posts
```jsonld
//request => /v2/posts?longitude=34.684860&latitude=135.1994354&delta=0.05
//response: arrayof posts_obj
 [{
  {
"id": 5,
"body": "this is body",
"url": "http://hogehkakkakkkkoge",
"distance": 0.004452779394415685,
"created_at": "2019-10-20T03:03:31.892Z",
"latitude": 34.6941384,
"longitude": 135.1961528,
"user": "hhha",
"user_id": 8,
"already": true,
"good": 1
}]
```

### GET /v2/posts/:id
```jsonld
//response: posts_obj
{
"id": 1,
"longitude": 34.68486,
"latitude": 135.1994354,
"url": "http://hogehoge",
"body": "this is body",
"created_at": "2019-10-19T06:59:10.460Z",
"updated_at": "2019-10-19T06:59:10.460Z",
"user_id": null
}
```


