Commit d708fd2a authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

types.

parent bfc727e2
......@@ -2,4 +2,224 @@
add description of real-world-conduit here
Just go ahead to this (write up)[siskam.link/2018-07-02-thinkster-s-realworld---backend.html].
Just go ahead to this [write up](siskam.link/2018-07-02-thinkster-s-realworld---backend.html).
### Backend Endpoints
```
Endpoint | Method | What | Auth? | Req. Body | Return
---------------------------------|--------|------------------------------|----------|-------------------|----------
/api/user | GET | Current user's information | Yes | | user.json
/api/user | PUT | Update user's information | Yes | requpdtuser.json | user.json
/api/users | POST | Registration | No | reqregister.json | user.json
/api/users/login | POST | Login | No | reqlogin.json | user.json
/api/profiles/:username | GET | :username's profile | Opt | | profile.json
/api/profiles/:username/follow | DELETE | Follow :username | Yes | | profile.json
/api/profiles/:username/follow | POST | Follow :username | Yes | | profile.json
/api/articles | GET | Latest articles | Opt | | articles.json
| | Params: | | |
| | - tag: Text | | |
| | - author: Text | | |
| | - favorited: Text | | |
| | - limit: Int (20) | | |
| | - offset: Int (0) | | |
/api/articles | POST | Create article | Yes | reqcreartic.json | article.json
/api/articles/:slug | DELETE | Delete article :slug | Yes | |
/api/articles/:slug | GET | Article with slug :slug | No | | article.json
/api/articles/:slug | PUT | Update article :slug | Yes | requpdtartic.json | article.json
/api/articles/:slug/comments | GET | Comment on article :slug | Opt | | comments.json
/api/articles/:slug/comments | POST | Comment on article :slug | Yes | reqcomment.json | comment.json
/api/articles/:slug/comments/:id | DELETE | Comment on article :slug :id | Yes | |
/api/articles/:slug/favorite | DELETE | Unfavorite article :slug | Yes | | article.json
/api/articles/:slug/favorite | POST | Favorite article :slug | Yes | | article.json
/api/articles/feed | GET | Latest articles by followed | Yes | | articles.json
| | - limit: Int (20) | | |
| | - offset: Int (0) | | |
/api/tags | GET | List of tags | No | | tags.json
```
#### Example reqregister.json
```
{
"user":{
"username": "Jacob",
"email": "[email protected]",
"password": "jakejake"
}
}
```
#### Example reqlogin.json
```
{
"user":{
"email": "[email protected]",
"password": "jakejake"
}
}
```
#### Example requpdtuser.json
```
{
"user":{
"email": "[email protected]", // nullable
"bio": "I like to skateboard", // nullable
"image": "https://i.stack.imgur.com/xHWG8.jpg", // nullable
"username": null, // nullable
"password": null // nullable
}
}
```
#### Example reqcreartic.json
```
{
"article": {
"title": "How to train your dragon",
"description": "Ever wonder how?",
"body": "You have to believe",
"tagList": ["reactjs", "angularjs", "dragons"] // nullable
}
}
```
#### Example requpdtartic.json
```
{
"article": {
"title": "How to train your dragon", // nullable
"description": "Ever wonder how?", // nullable
"body": "You have to believe", // nullable
}
}
```
#### Example reqcomment.json
```
{
"comment": {
"body": "His name was my name too."
}
}
```
#### Example user.json
```
{
"user": {
"email": "[email protected]",
"token": "jwt.token.here",
"username": "jake",
"bio": "I work at statefarm", // nullable
"image": null
}
}
```
### Example profile.json
```
{
"profile": {
"username": "jake",
"bio": "I work at statefarm", // nullable
"image": "https://static.productionready.io/images/smiley-cyrus.jpg", // nullable
"following": false
}
}
```
### Example article.json
```
{
"article": {
"slug": "how-to-train-your-dragon",
"title": "How to train your dragon",
"description": "Ever wonder how?",
"body": "It takes a Jacobian",
"tagList": ["dragons", "training"], // nullable
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z", // nullable
"favorited": false,
"favoritesCount": 0,
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}
}
```
### Example articles.json
```
{
"articles":[{
"slug": "how-to-train-your-dragon",
"title": "How to train your dragon",
"description": "Ever wonder how?",
"body": "It takes a Jacobian",
"tagList": ["dragons", "training"],
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z",
"favorited": false,
"favoritesCount": 0,
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}, {
"slug": "how-to-train-your-dragon-2",
"title": "How to train your dragon 2",
"description": "So toothless",
"body": "It a dragon",
"tagList": ["dragons", "training"],
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z",
"favorited": false,
"favoritesCount": 0,
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}],
"articlesCount": 2
}
```
### Example comment.json
```
{
"comment": {
"id": 1,
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:22:56.637Z",
"body": "It takes a Jacobian",
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}
}
```
### Example comments.json
```
{
"comments": [{
"id": 1,
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:22:56.637Z",
"body": "It takes a Jacobian",
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}]
}
```
### Example tags.json
```
{
"tags": [
"reactjs",
"angularjs"
]
}
```
......@@ -17,6 +17,7 @@ library
hs-source-dirs: src
ghc-options: -Wall
exposed-modules: Lib
, Types
other-modules: Lib.Prelude
build-depends: base >= 4.7 && < 5
, protolude
......
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TemplateHaskell #-}
module Types where
import Protolude
import Data.Aeson
import Data.Aeson.Casing
import Data.Time
-- | Body of the registration request.
data RequestRegistrationBody = RequestRegistrationBody
{ reqregbodyUsername :: Text -- ^ Username field.
, reqregbodyEmail :: Text -- ^ Email field.
, reqregbodyPassword :: Text -- ^ Password field.
} deriving (Generic)
instance FromJSON RequestRegistrationBody where
parseJSON = genericParseJSON (aesonPrefix camelCase)
-- | Request for the registration.
data RequestRegistration = RequestRegistration
{ reqregUser :: RequestRegistrationBody
} deriving (Generic)
instance FromJSON RequestRegistration where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestLoginBody = RequestLoginBody
{ reqloginbodyEmail :: Text
, reqloginbodyPassword :: Text
} deriving (Generic)
instance FromJSON RequestLoginBody where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestLogin = RequestLogin
{ reqloginUser :: RequestLoginBody
} deriving (Generic)
instance FromJSON RequestLogin where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestUpdateUserBody = RequestUpdateUserBody
{ requpdtuserbodyEmail :: Maybe Text
, requpdtuserbodyBio :: Maybe Text
, requpdtuserbodyImage :: Maybe Text
, requpdtuserbodyUsername :: Maybe Text
, requpdtuserbodyPassword :: Maybe Text
} deriving (Generic)
instance FromJSON RequestUpdateUserBody where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestUpdateUser = RequestUpdateUser
{ requpdtuserUser :: RequestUpdateUserBody
} deriving (Generic)
instance FromJSON RequestUpdateUser where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestCreateArticleBody = RequestCreateArticleBody
{ reqcrtarticlTitle :: Text
, reqcrtarticlDescription :: Text
, reqcrtarticlBody :: Text
, reqcrtarticlTagList :: Maybe [Text]
} deriving Generic
instance FromJSON RequestCreateArticleBody where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestCreateArticle = RequestCreateArticle
{ reqcrtarticArticle :: RequestCreateArticleBody
} deriving (Generic)
instance FromJSON RequestCreateArticle where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestUpdateArticleBody = RequestUpdateArticleBody
{ requpdtarticbodyTitle :: Maybe Text
, requpdtarticbodyDescription :: Maybe Text
, requpdtarticbodyBody :: Maybe Text
} deriving Generic
instance FromJSON RequestUpdateArticleBody where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestUpdateArticle = RequestUpdateArticle
{ requpdtarticArticle :: RequestUpdateArticleBody
} deriving (Generic)
instance FromJSON RequestUpdateArticle where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestCommentBody = RequestCommentBody
{ reqcmtbodyBody :: Text
} deriving (Generic)
instance FromJSON RequestCommentBody where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data RequestComment = RequestComment
{ reqcmtComment :: RequestCommentBody
} deriving (Generic)
instance FromJSON RequestComment where
parseJSON = genericParseJSON (aesonPrefix camelCase)
data ResponseUserBody = ResponseUserBody
{ respuserbodyEmail :: Text
, respuserbodyToken :: Maybe Text
, respuserbodyUsername :: Text
, respuserbodyBio :: Maybe Text
, respuserbodyImage :: Maybe Text
} deriving (Generic)
instance ToJSON ResponseUserBody where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseUser = ResponseUser
{ responseuserUser :: ResponseUserBody
} deriving (Generic)
instance ToJSON ResponseUser where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseProfileBody = ResponseProfileBody
{ respprofbodyUsername :: Text
, respprofbodyBio :: Maybe Text
, respprofbodyImage :: Maybe Text
, respprofbodyFollowing :: Bool
} deriving (Generic)
instance ToJSON ResponseProfileBody where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseProfile = ResponseProfile
{ respprofProfile :: ResponseProfileBody
} deriving (Generic)
instance ToJSON ResponseProfile where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseArticleBody = ResponseArticleBody
{ resparticbodySlug :: Text
, resparticbodyTitle :: Text
, resparticbodyDescription :: Text
, resparticbodyBody :: Text
, resparticbodyTagList :: Maybe [Text]
, resparticbodyCreatedAt :: UTCTime
, resparticbodyUpdatedAt :: Maybe UTCTime
, resparticbodyFavorited :: Bool
, resparticbodyFavoritesCount :: Int64
, resparticbodyAuthor :: ResponseProfileBody
} deriving (Generic)
instance ToJSON ResponseArticleBody where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseArticle = ResponseArticle
{ resparticArticle :: ResponseArticleBody
} deriving (Generic)
instance ToJSON ResponseArticle where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseMultiArticle = ResponseMultiArticle
{ respmultiarticArticles :: [ResponseArticleBody]
, respmultiarticArticlesCount :: Int
} deriving (Generic)
instance ToJSON ResponseMultiArticle where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseCommentBody = ResponseCommentBody
{ respcomtbodyId :: Int64
, respcomtbodyCreatedAt :: UTCTime
, respcomtbodyUpdatedAtt :: Maybe UTCTime
, respcomtbodyBody :: Text
, respcomtbodyAuthor :: ResponseProfileBody
} deriving (Generic)
instance ToJSON ResponseCommentBody where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseComment = ResponseComment
{ respcomtComment :: ResponseCommentBody
} deriving (Generic)
instance ToJSON ResponseComment where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseMultiComment = ResponseMultiComment
{ respmulticomtComments :: [ResponseCommentBody]
} deriving (Generic)
instance ToJSON ResponseMultiComment where
toJSON = genericToJSON (aesonPrefix camelCase)
data ResponseTags = ResponseTags
{ resptagsTags :: [Text]
} deriving (Generic)
instance ToJSON ResponseTags where
toJSON = genericToJSON (aesonPrefix camelCase)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment