Skip to content

Commit

Permalink
post, matching exe
Browse files Browse the repository at this point in the history
  • Loading branch information
sosschs9 committed Dec 3, 2022
1 parent aabba8d commit 6c702dc
Show file tree
Hide file tree
Showing 26 changed files with 870 additions and 1,030 deletions.
Binary file modified __pycache__/basic.cpython-39.pyc
Binary file not shown.
Binary file modified __pycache__/database.cpython-39.pyc
Binary file not shown.
Binary file modified __pycache__/matching.cpython-39.pyc
Binary file not shown.
Binary file modified __pycache__/post.cpython-39.pyc
Binary file not shown.
Binary file modified __pycache__/user.cpython-39.pyc
Binary file not shown.
185 changes: 149 additions & 36 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,37 @@
from post import *
from user import *
from matching import *
from database import findUser

app = Flask(__name__)

# default user 불러오기
userID = "testUser"
user = findUser(userID)
# Test user 불러오기
# 일반 사용자 1
# userID = "testUser"
# user = DB_getUser(userID)
# 일반 사용자 2
# userID = "testUser2"
# user = DB_getUser(userID)
# 병원동행 도우미
# userID = "helper1"
# user = DB_getUser(userID)
# 심리상담 도우미
userID = "helper2"
user = DB_getUser(userID)
# 안전점검 도우미
# userID = "helper4"
# user = DB_getUser(userID)

# checkType을 통해 matchingBoard 접근 권한 확인
isHelper = isHelper(userID)
if isHelper == False:
checkType = 0
else:
checkType = user.getHelperType()

# 메인페이지
@app.route('/')
def home():
return render_template("main.html")
return render_template("main.html", checkType=checkType)

# 의뢰 게시판 보기
@app.route('/post_board/<int:page>', methods=['GET'])
Expand All @@ -28,8 +47,8 @@ def post_board(page):
block_start = (block_size * block_num) + 1
block_end = block_start + (block_size - 1)

return render_template('Post/postBoard.html',
page_list=page_list, max_page=max_page, this_page = page, start=block_start, end=block_end)
return render_template('Post/postBoard.html', checkType=checkType,
page_list=page_list, max_page=max_page, this_page=page, start=block_start, end=block_end)

# 의뢰 게시글 작성하기
@app.route('/write_post', methods=['GET', 'POST'])
Expand All @@ -49,7 +68,7 @@ def writing_post():

return redirect('/post_board/1')
else:
return render_template('Post/newPost.html')
return render_template('Post/newPost.html', checkType=checkType,)

# 의뢰 게시글 보기
@app.route('/post/<int:post_id>', methods=['GET', 'POST'])
Expand All @@ -61,7 +80,7 @@ def view_post(post_id):
createComment(post_id, userID, comment)

post = getPost(post_id)
return render_template('Post/readPost.html', post=post, userID=userID)
return render_template('Post/readPost.html', checkType=checkType, post=post, userID=userID)

# 의뢰 게시글 삭제하기
@app.route('/delete_post/<int:post_id>')
Expand All @@ -87,7 +106,7 @@ def modify_post(post_id):
flash("해당 게시물이 존재하지 않습니다.")
return redirect('/post_board/1')
else:
return render_template("Post/modifyPost.html", post=post)
return render_template("Post/modifyPost.html", checkType=checkType, post=post)

else:
title = request.form['title']
Expand All @@ -102,68 +121,162 @@ def modify_post(post_id):
modifyPost(post_id, title, contents, reqDate, addr, pay, contact)
return redirect('/post_board/1')

# 댓글 삭제하기
@app.route('/delete_comment/<int:post_id>/<int:comment_id>', methods=['GET', 'POST'])
def delete_comment(post_id, comment_id):
post = getPost(post_id)

deleteComment(post_id, comment_id)
post = getPost(post_id)
return render_template('Post/readPost.html', post=post, userID=userID)

# 도우미 매칭
@app.route('/select_helper', methods=['GET'])
def request_matching():
return render_template('Matching/newMatching.html')
return render_template('Matching/newMatching.html', checkType=checkType)

# 병원동행 도우미 신청
@app.route('/select_helper/accompany', methods=['GET', 'POST'])
def accompany_matching():
if request.method == 'POST':
# 유저 정보 불러오기
reqDate = request.form['date']
time = request.form['time']
hospital = request.form['hospital']
# userinfo = user.getUserInfo()
reqDate = request.form['date'] + " " + request.form['time']
# 출발지 주소
address = request.form['address']
start_addr = Address(address, "", "")
# 병원 주소
address = request.form['hospital']
hospital_addr = Address(address, "", "")
reason = request.form['reason']

#reqMatching
createAccompany(userID, reqDate, start_addr, hospital_addr, reason)
user = DB_getUser(userID)

return redirect(url_for('check_request', ))
matchingList = user.getMyRequest()
matchingID = matchingList[-1]

return redirect(url_for('check_request', helpType=HelperType.ACCOMPANY, matchingID=matchingID))
else:
return render_template("Matching/accompanyMatching.html")
return render_template("Matching/accompanyMatching.html", checkType=checkType)

# 심리상담 도우미 요청
@app.route('/select_helper/counsel', methods=['GET', 'POST'])
def counsel_matching():
if request.method == 'POST':
# 유저 정보 불러오기
# userinfo = user.getUserInfo()
reqDate = request.form['date'] + " " + request.form['time']
address = request.form['address'] + " " + request.form['detailAddress']
addr = Address(address, "", "")
category = request.form['category']

createCounsel(userID, reqDate, addr, category)
user = DB_getUser(userID)

matchingList = user.getMyRequest()
matchingID = matchingList[-1]

return render_template('check.html')
return redirect(url_for('check_request', helpType=HelperType.COUNSEL, matchingID=matchingID))
else:
return render_template("Matching/counselMatching.html")
return render_template("Matching/counselMatching.html", checkType=checkType)

# 안전점검 도우미 요청
@app.route('/select_helper/safe', methods=['GET', 'POST'])
def safe_matching():
if request.method == 'POST':
# 유저 정보 불러오기
# userinfo = user.getUserInfo()
reqDate = request.form['date'] + " " + request.form['time']
address = request.form['address'] + " " + request.form['detailAddress']
addr = Address(address, "", "")
category = request.form['category']

createSafetyCheck(userID, reqDate, addr, category)
user = DB_getUser(userID)

matchingList = user.getMyRequest()
matchingID = matchingList[-1]

return render_template('check.html')
return redirect(url_for('check_request', helpType=HelperType.SAFETYCHECK, matchingID=matchingID))
else:
return render_template("Matching/safeMatching.html")
return render_template("Matching/safeMatching.html", checkType=checkType)

# @app.route('/select_helper/check_request/<str:param_userID>', methods=['GET', 'POST'])
# def check_request(param_userID):
# if request.method == 'POST':
# # DB 저장
# return render_template('')
# else:
# check_data = {}
# return render_template('check.html', userID=param_userID, check_data=check_data)
@app.route('/check_request/<int:helpType>/<int:matchingID>', methods=['GET', 'POST'])
def check_request(helpType, matchingID):
check = {}
if request.method == 'POST':
# 신청 취소
flash("매칭 신청이 완료되었습니다.")
return redirect(url_for('home'))
else:
matching = getMatching(matchingID)
check['username'] = user.getUserInfo().NAME
# 작성자, 날짜, 장소, 상세 내용
if type(matching) is Accompany:
check['helpType'] = "병원동행"
check['date'] = matching.getRequestDate()
check['address'] = "[출발지] " + matching.getAddress().detailAddress + " [병원위치] " + matching.getHospitalLocation().detailAddress
check['detail'] = "[동행사유] " + matching.getReason()

elif type(matching) is Counsel:
check['helpType'] = "심리상담"
check['date'] = matching.getRequestDate()
check['address'] = matching.getAddress().detailAddress
check['detail'] = "[상담분야] " + matching.getCategory()

elif type(matching) is SafetyCheck:
check['helpType'] = "안전점검"
check['date'] = matching.getRequestDate()
check['address'] = matching.getAddress().detailAddress
check['detail'] = "[점검부분] " + matching.getCheckPart()

return render_template('check.html', matchingID=matchingID, check=check)

# 매칭 취소/삭제하기
@app.route('/delete_matching/<int:matchingID>')
def delete_matching(matchingID):
deleteMatching(matchingID)
return redirect(url_for('home'))

# 도우미 신청 목록 보기
@app.route('/matching_board/<int:page>', methods=['GET'])
def matching_board(page):
@app.route('/matching_board/<int:helperType>/<int:page>', methods=['GET'])
def matching_board(helperType, page):
if (helperType == 0):
flash("도우미만 해당 페이지에 접근할 수 있습니다.", 'error')
return redirect(url_for('home'))

# 목록 리스트 불러오기
return render_template('Matching/matchingBoard.html')
page_list = getMatchingList(page, helperType)
max_page = getAllMatchingPageCount(helperType)

block_size = 5
block_num = int((page - 1)/block_size)
block_start = (block_size * block_num) + 1
block_end = block_start + (block_size - 1)

return render_template('Matching/matchingBoard.html', checkType=checkType,
page_list=page_list, max_page=max_page, this_page=page, start=block_start, end=block_end)

# 개별 매칭 보기
@app.route('/matching/<int:matching_id>', methods=['GET'])
def view_matching(matching_id):
# 매칭 내용 불러오기
return render_template('Matching/readMatching.html')
matching = getMatching(matching_id)

if type(matching) is Accompany:
helpType = "병원동행 "
elif type(matching) is Counsel:
helpType = "심리상담 "
elif type(matching) is SafetyCheck:
helpType = "안전점검 "

return render_template('Matching/readMatching.html', checkType=checkType, helpType=helpType, matching=matching)

@app.route('/consent_matching/<int:matchingID>')
def consent_matching(matchingID):
requestMatching(matchingID, userID)
# 메시지 전송 + 메시지 전송 예약
return redirect(url_for('home'))

if __name__ == '__main__':
app.secret_key = '1234'
app.config['SESSION_TYPE'] = 'filesystem'
app.run()
14 changes: 12 additions & 2 deletions basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import requests
import datetime

class HelperType:
ACCOMPANY = 1
COUNSEL = 2
SAFETYCHECK = 4

class UserCommonInfo:
def __init__(self, id:str, name:str, phoneNumber:str, gender:bool):
self.ID = id
Expand All @@ -20,4 +24,10 @@ def __init__(self, detailAddress:str, placeName:str, region:str):

# 현재 시간 > str / ret:str
def getNowTime():
return datetime.datetime.now().strftime('%y.%m.%d')
return datetime.datetime.now().strftime('%y.%m.%d')

# DB 불러올 때 변환용
def data_to_UserInfo(result:dict, indexHead:str):
return UserCommonInfo(result[indexHead]['ID'], result[indexHead]['NAME'], result[indexHead]['PHONENUMBER'], result[indexHead]['GENDER'])
def data_to_Address(result:dict, indexHead:str):
return Address(result[indexHead]['detailAddress'], result[indexHead]['placeName'], result[indexHead]['region'])
2 changes: 2 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# user / post / matching 수정 완료.

import pymongo
from user import *
from matching import *
Expand Down
Loading

0 comments on commit 6c702dc

Please sign in to comment.