1. DB 연결 함수 생성 - 팔로우
def insert_follow(user_follow) :
return current_app.database.execute(text("""
INSERT INTO users_follow_list(
user_id,
follow_user_id
)VALUES (
:id,
:follow
)
"""), user_follow).rowcount
def insert_unfollow(user_unfollow) :
return current_app.database.execute(text("""
DELETE FROM users_follow_list
WHERE user_id = :id
AND follow_user_id = :unfollow
"""), user_unfollow).rowcount
- INSERT : users_follow_list 테이블의 컬럼 user_id에 id값, follow_user_id에 follow 값 넣어줌
- DELETE : users_follow_list 테이블의 user_id에서 unfollow값을 찾아 삭제
2. HTTP 요청 - 팔로우
http -v POST 127.0.0.1:5000/follow id=1 follow=3
DB 확인
3. HTTP 요청 - 언팔로우
http -v POST 127.0.0.1:5000/unfollow id=1 unfollow=4
DB 확인
'Python > Flask' 카테고리의 다른 글
[미니터] 인증 (0) | 2022.07.14 |
---|---|
[미니터] DB연결 - 타임라인 (0) | 2022.07.14 |
[미니터] DB연결 - tweet 올리기 (0) | 2022.07.14 |
[미니터] DB 연결 - 회원가입 (0) | 2022.07.12 |
[미니터] sqlalchemy를 사용한 API와 DB 연결 (0) | 2022.07.12 |