API測試表:

設計Twitter RESTful API

查詢可用"control+F",輸入(測試表左側當中的對應index)找到對應規格

有任何問題或優化建議歡迎請隨時提出~感恩!

User有關

// 取得當前使用者資料  (這條是希望可以加的)
GET('api/get_current_user')

response.data: {
	id, // 當前使用者id   → ok
	name, // 當前使用者名稱    → ok
	account, // 當前使用者帳號    → ok
	avatar, // 當前使用者照片    → ok
	role // 當前使用者角色    → ok
}
// sign up(2)
POST('api/users', payLoad)

payLoad: {
	account, // 使用者帳號    → ok
	name, // 使用者名稱   → ok
	email, // 使用者email   → ok
	password, // 使用者密碼   → ok
	checkPassword // 使用者密碼確認   → ok
}
// sign in(3)
POST('api/signin', payLoad)
**admin 不能從這邊登入**  → ok
payLoad: {
	account, // 使用者帳號   → ok
	password // 使用者密碼    → ok
}

response.data: { // 成功狀態    → ok
  token, // 識別碼   → ok
  user: {
      id, // 使用者id  → ok
      name, // 使用者名稱  → ok
			account, // 使用者帳號  → ok
			email, // 使用者email  → ok
			avatar, // 使用者照片  → ok
			role // 使用者角色  → ok
}
// setting(4)
PUT(`api/users/${userId}`, fromData)  

fromData: {
	account, // 使用者帳號   → ok
	name, // 使用者名稱   → ok
	email, // 使用者email   → ok
	password, // 使用者密碼   → ok
	checkPassword // 使用者密碼確認   → ok
}
// 編輯使用者頁面資料(4)
PUT(`api/users/${userId}`, formData) //因為有上傳圖片所以需用formData

formData: {             
	cover, // 封面圖片   → ok
	avatar, // 使用者照片 → ok
	name, // 使用者名稱   → ok
	introduction // 使用者簡介  → ok
}
// 取得使用者資料(5)
GET(`api/users/${userId}`)

response.data: {
		
		id, // 使用者id   → ok
		name, // 使用者名稱   → ok
		account, // 使用者帳號   → ok
		email, // 使用者email   → ok
		tweetsNumber, // 使用者推文數   → ok
		avatar, // 使用者照片   → ok
		cover, // 使用者封面照片   → ok
		introduction, // 使用者簡介  → ok
		followingsNumber, // 使用者追蹤數   → ok,數量正確
		followersNumber, // 使用者跟隨數  → ok,數量正確
		isFollowed, // 是否追蹤中    → ok

}
// 自己發的推文串(6)  
GET(`api/users/${userId}/tweets`)
**排序依日期,最新的在前** → ok
response.data: [
		{
			TweetId, // 推文id   → ok
			description, // 推文內容   → ok
			likesNumber, // 推文like數    → ok,數量正確
			repliesNumber, // 推文回覆數   → ok,數量正確
			isLiked, // 是否按過like    → ok
			createdAt, // 推文發布時間   → 
			User: { // 推主資料    → ok
				id, // 推主連結用user.id    → ok
				name, // 推主名稱    → ok
				account, // 推主帳號    → ok
				avatar, // 推主照片   → ok
			}
		},
		{},{},{}...
]
// 使用者reply過的推文串(7) 
GET(`api/users/${userId}/replied_tweets`)
**排序依日期,最新的在前**→ ok
response.data: [
		{
			TweetId, // 推文id   → ok
			description, // 推文內容   → ok
			likesNumber, // 推文like數   → ok,數量正確
			repliesNumber, // 推文回覆數  → ok,數量正確
			isLiked, // 是否按過like  → ok
			createdAt, // 推文發布時間   → ok
			User: { // 推主資料   → ok
				id, // 推主連結用user.id   → ok
				name, // 推主名稱   → ok
				account, // 推主帳號   → ok
				avatar, // 推主照片   → ok
			}
		},
		{},{},{}...
]
// 取得該使用者的追蹤者(8)
GET(`api/users/${userId}/followings`)
**排序依日期,最新的在前**    → ok
response.data: [
			{
				followingId, // 追蹤者id → ok
				name, // 追蹤者名稱 → ok
				account, // 追蹤者帳號 → ok
				avatar, // 追蹤者照片 → ok
				introduction, // 追蹤者簡介 → ok
				isFollowed // 是否已追蹤 → ok
			},
			{},{},{}...
]

// 取得使用者資料與其追隨者(9)
GET(`api/users/${userId}/followers`)
**排序依日期,最新的在前**  → ok
response.data: [
			{
				followerId, // 跟隨者id  → ok 
				name, // 跟隨者名稱   → ok
				account, // 跟隨者帳號  → ok
				avatar, // 跟隨者照片   → ok
				introduction, // 跟隨者簡介   → ok
				isFollowed // 是否已追蹤   → ok
			},
			{},{},{}...
]
// 使用者like過的推文串(10)
GET(`api/users/${userId}/likes`)
**排序依日期,最新的在前**  → ok
response.data: [
		{
			TweetId, // 推文id    → ok
			description, // 推文內容    → ok
			likesNumber, // 推文like數  → ok,數量正確
			repliesNumber, // 推文回覆數  → ok,數量正確
			isLiked, // 是否按過like  → ok
			createdAt, // 推文發布時間   → ok
			User: { // 推主資料    → ok
				id, // 推主連結用user.id  → ok
				name, // 推主名稱  → ok
				account, // 推主帳號  → ok
				avatar, // 推主照片  → ok
			}
		},
		{},{},{}...
]
// 取得前10名熱門使用者名單(11)
GET('api/topuser')

response.data: [
		{
			id, // 使用者id → ok
			name, // 使用者名稱 → ok
			avatar, // 使用者照片 → ok
			account, // 使用者帳號 → ok
			isFollowed // 是否追蹤中 → ok
		},
		{},{},{}...
]

Follow(追蹤)有關

// 追蹤使用者(12)
**不能追蹤自己** → 待確認
POST(`api/followships`, payLoad)    → ok

payLoad: {
	id // 追蹤的使用者id
}
// 退追使用者(13)
DELETE(`api/followships/${userId}`)   → ok

Tweet(貼文)有關

// 取得主推文串(14) ok
GET('api/tweets')
	
response.tweetsData: [
		{
			TweetId, // 推文id
			UserId, // 推文作者
			description, // 推文內容
			createdAt, // 推文發布時間
			repliesNumber, // 推文回復數
			likesNumber, // 推文like數			
			isLiked, // 是否按過like
			User: { 
				id, // 連結用user.id
				name, // 推主名稱
				account, // 推主帳號
				avatar // 推主照片
			}
		},
		{},{},{}...
]
// 取得單一推文資料(15) ok
GET(`api/tweets/${tweetId}`)

response.tweetData: {

	TweetId, // 推文id
	UserId, // 推文作者 
	description, // 推文內容
	likesNumber, // 推文like數
	repliesNumber, // 推文回覆數	
	createdAt, // 推文發布時間
	isLiked, // 是否按過like
	User: { // 推主資料
		id, // 連結用user.id
		name, // 推主名稱
		account, // 推主帳號
		avatar, // 推主照片
	},
	Likes:[ // 推文被按讚
					{
						Id, // Like_id
						UserId, //按讚的人
						TweetId, //讚的推文編號
						createdAt, //建立時間
					}
				],
	Replies: [ //推文回覆串
		{
			id, // 回覆id
			UserId, // Replies作者
			comment, // 回覆內容
			createdAt, // 回覆發布時間
			name, // 回覆者名稱
			User: { // 回覆者資料
				id, // 連結用user.id
				name, // 回覆者名稱
				account, // 回覆者帳號
				avatar // 回覆者照片
			}
		},
		{},{},{}...
	]

}
// 取得該推文回覆資料(16-1) 沒用到 Allen哥回傳陣列是為了過測試嗎?(沒錯..自動測試不准只有數字...)
GET(`api/tweets/${tweet_id}/replies`)

response.data: [
	{
		id, // 推文回覆串
		UserId, // 關聯使用者id,
		TweetId, // 關聯推文id
		comment, // 回覆內容
		createdAt, // 回覆建立時間        
		User: {
	  				name, // 關聯使用者名稱
	  				account // 關聯使用者帳號        				}
					},	
	},
	{},{},{}...
]

// 取得該推文回覆數(16-2)
GET(`api/tweets/${tweet_id}/replies/count`)

response.data: {
 repliesNumber // 推文回覆數
}
//取得該推文按讚數(17) 沒用到 Allen哥回傳陣列是為了過測試嗎?
GET(`api/tweets/${tweet_id}/likes`)

response.data: {
	likesNumber// 按讚數量
}
// 新增推文(18) ok
POST('api/tweets', payLoad)
	
payLoad: {
	description // 推文內容
}

Response: 
{ status: 'success', message: 'Created Tweet success' }
{ status: 'error', message: 'Description can not empty' }
{ status: 'error', message: 'Word is over 140' }
{ status: 'error', message: 'Post Tweet Fail' }
// 編輯推文內容(19) 沒用到
PUT(`api/tweets/${tweet_id}`, payLoad)

payLoad: {
	description // 推文內容
}

Response: 
{ status: 'success', message: 'Tweet was successfully to update' }
{ status: 'error', message: 'Description can not empty' }
{ status: 'error', message: 'Word is over 140' }
{ status: 'error', message: 'Put Tweet Fail' }

Replies(回覆)有關

// 新增回覆(20) ok
POST(`api/tweets/${tweet_id}/replies`, payLoad)

payLoad: {
	comment // 回覆內容
}

Response: 
{ status: 'success', message: 'Created Reply Success' }
{ status: 'error', message: 'Comment can not empty' }
{ status: 'error', message: 'Post Reply Fail' }
// 修改回覆內容(21) 沒用到
PUT(`api/replies/${reply_id}`, payLoad)

payLoad: {
	comment // 回覆內容
}

Response: 
{ status: 'success', message: 'Reply was successfully to update' }
{ status: 'error', message: 'Comment can not empty' }
{ status: 'error', message: 'Put Reply Fail' }
// 刪除回覆(22) 沒用到
DELETE(`api/replies/${reply_id}`)

Response: 
{ status: 'success', message: 'Delete Reply Success' }
{ status: 'error', message: 'Reply was not exist' }
{ status: 'error', message: 'Delete Tweet Fail' }

Like(按讚)有關

// 推文按讚(23) ok
POST(`api/tweets/${tweet_id}/like`, null)

Response: 
{ status: 'success', message: 'AddLike Success' }
{ status: 'error', message: 'AddLike To Tweet Fail' }
// 推文收回讚(24) ok
POST(`api/tweets/${tweet_id}/unlike`, null)

Response: 
{ status: 'success', message: 'RemoveLike Success' }
{ status: 'error', message: 'RemoveLike To Tweet Fail' }

Admin有關