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

LightHouse 名稱 : Leo chiang、Keiko、Hanna Lin、子裔 #900

Open
wants to merge 123 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
093c203
project init
mmm999xp Aug 21, 2023
910e9b6
add process.env.PORT
mmm999xp Aug 21, 2023
c3b03ba
feat: add error-handler
keitakeiko Aug 22, 2023
6067532
feat: add multer function
keitakeiko Aug 22, 2023
3f70eb4
feat: modify model
mmm999xp Aug 22, 2023
2b71773
Merge pull request #1 from mmm999xp/R01
mmm999xp Aug 22, 2023
f7365d1
Merge pull request #2 from mmm999xp/R02
mmm999xp Aug 22, 2023
a78f14f
feat: add-banner-to-users
mmm999xp Aug 22, 2023
93d906f
Merge pull request #4 from mmm999xp/R04
keitakeiko Aug 22, 2023
9f2510d
feat: passport Strategy
mmm999xp Aug 22, 2023
8b1048f
Merge pull request #5 from mmm999xp/R05
keitakeiko Aug 22, 2023
451a1d1
feat: add user signup
mmm999xp Aug 22, 2023
b2b3b49
Merge pull request #6 from mmm999xp/R06
keitakeiko Aug 23, 2023
6da7fd6
feat: add signin & api-error-handler (#7)
mmm999xp Aug 23, 2023
43a276b
feat: add getTweets function
keitakeiko Aug 25, 2023
125773f
Merge pull request #10 from mmm999xp/R08
mmm999xp Aug 25, 2023
565ed0e
R10 (#12)
mmm999xp Aug 25, 2023
18fd743
fix: amend getTweets function
keitakeiko Aug 25, 2023
1f9b723
Merge pull request #13 from mmm999xp/R08
mmm999xp Aug 25, 2023
eb12369
feat: add postTweet
keitakeiko Aug 25, 2023
1c00107
Merge branch 'main' into R11-1
mmm999xp Aug 26, 2023
8c85bc6
Merge pull request #14 from mmm999xp/R11-1
mmm999xp Aug 26, 2023
a303cfa
feat: add getTweet
keitakeiko Aug 26, 2023
0b05206
fix: amend router
keitakeiko Aug 26, 2023
084ebba
Merge branch 'main' into R12
mmm999xp Aug 26, 2023
74f7aca
Merge pull request #16 from mmm999xp/R12
mmm999xp Aug 26, 2023
159fa58
fix: amend function in getTweets & postTweet
keitakeiko Aug 26, 2023
80c2014
fix: amend function in getTweets & postTweet
keitakeiko Aug 26, 2023
93e2448
Merge pull request #17 from mmm999xp/R12
mmm999xp Aug 26, 2023
367ecff
feat: add likeTweet function and fix datetime-helper
keitakeiko Aug 26, 2023
272de57
Merge branch 'main' into R13
mmm999xp Aug 26, 2023
188e363
Merge pull request #18 from mmm999xp/R13
mmm999xp Aug 26, 2023
c82d388
feat: modify config for heroku (#19)
mmm999xp Aug 26, 2023
0a7c8a6
fix: seed bug fixed (#20)
mmm999xp Aug 26, 2023
6bdfaa6
feat: add unlikeTweet function
keitakeiko Aug 26, 2023
80d6289
feat: add getReplies
keitakeiko Aug 26, 2023
1e27afb
feat: add test function
keitakeiko Aug 27, 2023
b9e2aec
feat: add postReply
keitakeiko Aug 27, 2023
291ff4b
Merge branch 'main' into R14
mmm999xp Aug 27, 2023
c04e629
Merge pull request #21 from mmm999xp/R14
mmm999xp Aug 27, 2023
b9ce168
Merge pull request #22 from mmm999xp/R15
mmm999xp Aug 27, 2023
20655d5
Merge branch 'main' into R25
mmm999xp Aug 27, 2023
a6d2863
Merge pull request #23 from mmm999xp/R25
mmm999xp Aug 27, 2023
0baf00a
fix: adapt unlike function method to fit the test file
keitakeiko Aug 27, 2023
7439644
Merge pull request #24 from mmm999xp/R26
mmm999xp Aug 27, 2023
bd952e3
R16 (#25)
mmm999xp Aug 27, 2023
33e5f4d
R17 (#26)
mmm999xp Aug 27, 2023
efcd407
fix: adapt Reply, Like, Tweet function to fit the test file
keitakeiko Aug 27, 2023
3053079
R29 modify: passport config and helper (#28)
mmm999xp Aug 27, 2023
738d6c2
Merge branch 'main' into R27
keitakeiko Aug 27, 2023
78765fe
Merge pull request #27 from mmm999xp/R27
mmm999xp Aug 27, 2023
f7852a6
fix: amend function for signin & pass the getTweets
keitakeiko Aug 27, 2023
4963ba7
Merge pull request #29 from mmm999xp/R30
mmm999xp Aug 27, 2023
5ba7336
R21 (#30)
mmm999xp Aug 28, 2023
5c4e55e
feat: addFollowing function & CORS
keitakeiko Aug 28, 2023
2bed8ba
feat: add removeFollowing
keitakeiko Aug 28, 2023
f5771a4
Merge pull request #31 from mmm999xp/R31
mmm999xp Aug 28, 2023
9387b76
Merge pull request #32 from mmm999xp/R32
mmm999xp Aug 28, 2023
42b8cbc
feat: install cors
mmm999xp Aug 28, 2023
b9c0002
fix: error-msg in tweet-controller & followship-controller & add note
keitakeiko Aug 28, 2023
c0a6279
Merge pull request #33 from mmm999xp/R33
mmm999xp Aug 28, 2023
75eb517
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
mmm999xp Aug 28, 2023
ad57514
feat: add imgur & multer function
keitakeiko Aug 28, 2023
6f4a7e8
R36 (#35)
mmm999xp Aug 29, 2023
cbd2d38
Merge branch 'main' into R34
keitakeiko Aug 29, 2023
29f09b6
feat: add getTopFollow
keitakeiko Aug 29, 2023
a61bb47
Merge branch 'main' into R37
mmm999xp Aug 29, 2023
0ff0d9c
Merge pull request #37 from mmm999xp/R37
mmm999xp Aug 29, 2023
7d7de77
Merge branch 'main' into R34
mmm999xp Aug 29, 2023
699fadd
Merge pull request #36 from mmm999xp/R34
mmm999xp Aug 29, 2023
253e365
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
mmm999xp Aug 29, 2023
da88dc4
fix: npm install imgur
mmm999xp Aug 29, 2023
efb29f5
R38 fix: npm i imgur (#38)
mmm999xp Aug 29, 2023
7402934
fix: add front-end data
keitakeiko Aug 29, 2023
1133bf1
Merge pull request #39 from mmm999xp/R39
mmm999xp Aug 29, 2023
f9f78a5
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
mmm999xp Aug 29, 2023
3fa9d14
R40 (#40)
mmm999xp Aug 29, 2023
b20e989
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
mmm999xp Aug 29, 2023
6702894
R40 -fix: cors web address (#41)
mmm999xp Aug 29, 2023
7ab5132
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
mmm999xp Aug 29, 2023
6790224
R42 (#43)
mmm999xp Aug 30, 2023
a7766fe
fix req.params.id data type
keitakeiko Aug 31, 2023
1eec8bb
Merge branch 'main' into R43
mmm999xp Aug 31, 2023
9b77178
Merge pull request #44 from mmm999xp/R43
mmm999xp Aug 31, 2023
cec0505
modify: getUserReplies 、getUserLikes
mmm999xp Sep 1, 2023
7824da7
Merge pull request #45 from mmm999xp/R44
mmm999xp Sep 1, 2023
0ee4d61
fix: user -> User
mmm999xp Sep 1, 2023
e88f16c
Merge pull request #46 from mmm999xp/R44
mmm999xp Sep 1, 2023
c34e3a5
modify: getUserLikes add tweet description
mmm999xp Sep 2, 2023
b0532a9
Merge pull request #47 from mmm999xp/R44
mmm999xp Sep 2, 2023
27c6119
modify: res User & Tweet
mmm999xp Sep 2, 2023
3c80693
Merge pull request #48 from mmm999xp/R44
mmm999xp Sep 2, 2023
edb83cc
modify: add order DESC
mmm999xp Sep 2, 2023
2259e4b
fix: amend params code (#49)
keitakeiko Sep 2, 2023
04cd509
modify: add admin tweet
mmm999xp Sep 2, 2023
e0953da
fix: debug Number()
keitakeiko Sep 2, 2023
cc00d1b
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
keitakeiko Sep 2, 2023
498ce48
modify admin getTweets
mmm999xp Sep 3, 2023
94ffe72
Merge pull request #50 from mmm999xp/R45
mmm999xp Sep 3, 2023
a2436e7
fix: getTweets order
mmm999xp Sep 3, 2023
388ab70
Merge pull request #51 from mmm999xp/R45
mmm999xp Sep 3, 2023
023999b
fix: err handler
mmm999xp Sep 3, 2023
12f947d
fix:get admin tweets createdAt
mmm999xp Sep 3, 2023
7ed3839
modify: get admin tweets
mmm999xp Sep 3, 2023
4a42fb7
modify: get admin users order
mmm999xp Sep 3, 2023
4b90878
fix:get admin users order
mmm999xp Sep 3, 2023
d43a38a
fix:get admin users order
mmm999xp Sep 3, 2023
29795aa
modify : getUserTweets add replycount likecount
mmm999xp Sep 3, 2023
2c34e61
Create README.md
mmm999xp Sep 3, 2023
7516975
FIX : Build ci (#52)
mmm999xp Sep 3, 2023
eb075b8
fix:createdAt time
keitakeiko Sep 3, 2023
cf5beb2
Merge branch 'main' of https://github.com/mmm999xp/twitter-api-2023
keitakeiko Sep 3, 2023
a7c7379
fix: admin get tweets createdAt
mmm999xp Sep 3, 2023
471deb5
fix: admin get tweets createdAt
mmm999xp Sep 3, 2023
e1f5bf5
fix: meeting user story
mmm999xp Sep 3, 2023
5a08252
fix env config
mmm999xp Sep 3, 2023
0224606
fix: admin don't use user function
mmm999xp Sep 4, 2023
7eac6d4
fix: dateformat and likecount and replycount
mmm999xp Sep 4, 2023
0e87ec1
fix: test
mmm999xp Sep 4, 2023
4f8c029
fix:test
mmm999xp Sep 4, 2023
1cc5400
fix:test
mmm999xp Sep 4, 2023
1c302ac
fix:test getUserReplies
mmm999xp Sep 4, 2023
903098f
fix: getUserLike and reply
mmm999xp Sep 4, 2023
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
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ const session = require('express-session')
const app = express()
const port = process.env.PORT || 3000
const apis = require('./routes')
const routes = require('./routes')

const SESSION_SECRET = 'secret'
// use helpers.getUser(req) to replace req.user
32 changes: 32 additions & 0 deletions controllers/tweet-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { Tweet, User, Like, Reply, sequelize } = require('../models')
const helpers = require('../_helpers')

const tweetController = {
getTweets: (req, res, next) => {

// 當下登入使用者能取得的頁面
const loginUser = helpers.getUser(req).id

return Tweet.findAll({
nest: true,
raw: true,
include: {
model: User,
attributes: ['id', 'name', 'avatar', 'account']
},
attributes: [
'id',
[sequelize.literal('(SELECT COUNT(id) FROM Replies WHERE Replies.TweetId = Tweet.id)'), 'replyCount'],
[sequelize.literal('(SELECT COUNT(id) FROM Likes WHERE Likes.TweetId = Tweet.id)'), 'likeCount'],
[sequelize.literal(`EXISTS (SELECT id FROM Likes WHERE Likes.UserId = ${loginUser} AND Likes.TweetId = Tweet.id)`), 'isLiked']
],
order: [['createdAt', 'DESC']]
})
.then(tweet => {
res.status(200).json(tweet)
})
.catch(err => next(err))
}
}

module.exports = tweetController
2 changes: 2 additions & 0 deletions middleware/api-auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const passport = require('../config/passport') // 引入 passport
const authenticated = passport.authenticate('jwt', { session: false })

const authenticatedAdmin = (req, res, next) => {
if (req.user && req.user.isAdmin) return next()
return res.status(403).json({ status: 'error', message: 'permission denied' })
}

module.exports = {
authenticated,
authenticatedAdmin
9 changes: 8 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const express = require('express')
// 待確認,passport.authenticate 是他內建的,不是載入這個config裡的
// const { authenticate } = require('../config/passport')
const router = express.Router()
const passport = require('../config/passport')
// const admin = require('./modules/admin')
// const { authenticated, authenticatedAdmin } = require('../middleware/api-auth')
const { authenticated, authenticatedAdmin } = require('../middleware/api-auth')
const userController = require('../controllers/user-controller')
const { apiErrorHandler } = require('../middleware/error-handler')
const tweet = require('./modules/tweet')


// router.use('/admin', authenticated, authenticatedAdmin, admin)

// users
router.post('/users/signin', passport.authenticate('local', { session: false }), userController.signIn) // 登入
router.post('/users/', userController.signUp) // 註冊

// modules
router.use('/tweets', authenticated, tweet)

router.use('/', apiErrorHandler)
module.exports = router
9 changes: 9 additions & 0 deletions routes/modules/tweet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require('express')
const router = express.Router()

const tweetController = require('../../controllers/tweet-controller')
const upload = require('../../middleware/multer')

router.get('/', tweetController.getTweets)

module.exports = router