diff options
author | Vitaly Takmazov | 2023-07-19 23:50:14 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-07-19 23:59:40 +0300 |
commit | c576c003716851863c832b5e0dacb9186516f167 (patch) | |
tree | 420c517806d28db3c8f448eacbc3d61f01106629 /src/main/java/com/juick/service/UserServiceImpl.java | |
parent | 128753a9bd11e09940d58d97c67db59a15251b71 (diff) |
Migrate to Twitter API 2.0
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/UserServiceImpl.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index d19af067..7f73e6d1 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -523,10 +523,24 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional @Override public boolean linkTwitterAccount( - final User user, final String accessToken, final String accessTokenSecret, final String screenName) { - return getJdbcTemplate().update("INSERT INTO twitter(user_id,access_token,access_token_secret,uname) " + - "VALUES (?,?,?,?)", - user.getUid(), accessToken, accessTokenSecret, screenName) > 0; + final User user, final String accessToken, final String refreshToken, final String screenName) { + return getJdbcTemplate().update("INSERT INTO twitter(user_id,access_token,access_token_secret,refresh_token,uname) " + + "VALUES (?,?,'',?,?)", + user.getUid(), accessToken, refreshToken, screenName) > 0; + } + + @Transactional + @Override + public boolean refreshTwitterToken( + final User user, final String accessToken, final String refreshToken) { + return getJdbcTemplate().update("UPDATE twitter SET access_token=?, refresh_token=?" + + " WHERE user_id=?", + accessToken, refreshToken, user.getUid()) > 0; + } + @Transactional(readOnly = true) + @Override + public boolean isTwitter1User(User user) { + return jdbcTemplate.queryForList("SELECT user_id FROM twitter WHERE user_id=? AND refresh_token=''", Integer.class, user.getUid()).size() > 0; } @Transactional(readOnly = true) @@ -612,7 +626,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Override public Optional<ExternalToken> getTwitterToken(final int uid) { List<ExternalToken> list = getJdbcTemplate().query( - "SELECT uname, access_token, access_token_secret FROM twitter WHERE user_id = ? AND crosspost = true", + "SELECT uname, access_token, refresh_token FROM twitter WHERE user_id = ? AND crosspost = true", (rs, num) -> new ExternalToken(rs.getString(1), "twitter", rs.getString(2), rs.getString(3)), uid); |