diff --git a/__pycache__/database.cpython-37.pyc b/__pycache__/database.cpython-37.pyc index d5df554..5b6bec9 100644 Binary files a/__pycache__/database.cpython-37.pyc and b/__pycache__/database.cpython-37.pyc differ diff --git a/application.py b/application.py index 2b4fbf7..11fcc2b 100644 --- a/application.py +++ b/application.py @@ -2,6 +2,8 @@ from database import DBhandler import hashlib import sys +import math +from flask import jsonify application = Flask(__name__) application.config["SECRET_KEY"] = "helloosp" @@ -16,25 +18,30 @@ def hello(): @application.route("/list") def view_list(): page = request.args.get("page", 0, type=int) + category = request.args.get("category", "all") per_page=6 per_row=3 row_count=int(per_page/per_row) start_idx=per_page*page end_idx=per_page*(page+1) - data = DB.get_items() - print("################333",data) + if category == "all": + data = DB.get_items() + else: + data = DB.get_items_bycategory(category) + data = dict(sorted(data.items(), key=lambda x: x[0], reverse=False)) item_counts = len(data) - data = dict(list(data.items())[start_idx:end_idx]) + if item_counts <= per_page: + data = dict(list(data.items())[:item_counts]) + else: + data = dict(list(data.items())[start_idx:end_idx]) tot_count = len(data) - + for i in range(row_count): if (i == row_count-1) and (tot_count%per_row != 0): locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:]) else: locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:(i+1)*per_row]) - - return render_template( "list.html", datas=data.items(), @@ -42,53 +49,84 @@ def view_list(): row2=locals()['data_1'].items(), limit=per_page, page=page, - page_count=int((item_counts/per_page)+1), - total=item_counts + page_count=int(math.ceil(item_counts/per_page)), + total=item_counts, + category=category ) +@application.route("/reg_review_init//") +def reg_review_init(name): + if 'id' not in session: + return redirect(url_for('login')) + return render_template("reg_reviews.html", name=name) + +@application.route("/reg_review", methods=['POST']) +def reg_review(): + if 'id' not in session: + return redirect(url_for('login')) + data = request.form + image_file = request.files["file"] + img_path = "static/images/{}".format(image_file.filename) + image_file.save(img_path) + DB.reg_review(data, image_file.filename) + return redirect(url_for('view_review')) + @application.route("/review") def view_review(): + if 'id' not in session: + return redirect(url_for('login')) + page = request.args.get("page", 0, type = int) per_page = 6 per_row = 3 row_count = int(per_page/per_row) - start_idx = per_page*per_page + start_idx = per_page*page end_idx = per_page*(page+1) + data = DB.get_reviews() item_counts = len(data) data = dict(list(data.items())[start_idx:end_idx]) tot_count = len(data) + for i in range(row_count): - if(i == row_cont-1) and (tot_count%per_row != 0): + if(i==row_count-1) and (tot_count%per_row!=0): locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:]) - else: + else: locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:(i+1)*per_row]) return render_template( "review.html", - data = data.items(), + datas = data.items(), row1 = locals()['data_0'].items(), row2 = locals()['data_1'].items(), limit = per_page, page = page, page_count = int(item_counts/per_page+1), - total = item_counts) + total = item_counts + ) + +@application.route("/view_review_detail//") +def view_review_detail(name): + if 'id' not in session: + return redirect(url_for('login')) + + review_data = DB.get_review_byname(name) + if review_data: + return render_template("review_detail.html", data=review_data) + else: + return redirect(url_for('view_review')) @application.route("/reg_items") def reg_item(): + if 'id' not in session: + return redirect(url_for('login')) + return render_template("reg_items.html") -@application.route("/reg_review_init//") -def reg_review_init(name): - return render_template("reg_reviews.html", name=name) - -@application.route("/reg_review", methods=['POST']) -def reg_review(): - data = request.form - DB.reg_review(data) - return redirect(url_for('view_review')) - @application.route("/submit_item_post", methods=['POST']) def reg_item_submit_post(): + if 'id' not in session: + return redirect(url_for('login')) + image_file = request.files["file"] image_file.save("static/images/{}".format(image_file.filename)) data = request.form @@ -99,6 +137,9 @@ def reg_item_submit_post(): @application.route("/submit_item") def reg_item_submit(): + if 'id' not in session: + return redirect(url_for('login')) + name = request.args.get("name") seller = request.args.get("seller") addr = request.args.get("addr") @@ -114,11 +155,12 @@ def login(): @application.route("/login_confirm", methods=['POST']) def login_user(): - id_=request.form['id'] - pw=request.form['pw'] + id_ = request.form['id'] + pw = request.form['pw'] pw_hash = hashlib.sha256(pw.encode('utf-8')).hexdigest() + if DB.find_user(id_, pw_hash): - session['id']=id_ + session['id'] = id_ return redirect(url_for('hello')) else: flash("Wrong ID or PW!") @@ -131,17 +173,20 @@ def signup(): @application.route("/signup_post", methods=['POST']) def register_user(): data = request.form - pw = request.form['pw'] + pw = data['pw'] pw_hash = hashlib.sha256(pw.encode('utf-8')).hexdigest() + if DB.insert_user(data, pw_hash): return render_template("login.html") else: - flash("user id already exist!") + flash("User ID already exist") return render_template("signup.html") + #print(name,addr,phone,category,status) #return render_template("reg_item.html") + @application.route("/logout") def logout_user(): session.clear() @@ -154,6 +199,33 @@ def view_item_detail(name): print("####data:",data) return render_template("detail.html", name=name, data=data) +@application.route('/show_heart//', methods=['GET']) +def show_heart(name): + my_heart = DB.get_heart_byname(session['id'],name) + return jsonify({'my_heart': my_heart}) + +@application.route('/like//', methods=['POST']) +def like(name): + my_heart = DB.update_heart(session['id'],'Y',name) + return jsonify({'msg': '좋아요 완료!'}) + +@application.route('/unlike//', methods=['POST']) +def unlike(name): + my_heart = DB.update_heart(session['id'],'N',name) + return jsonify({'msg': '안좋아요 완료!'}) + +@application.route("/search") +def search(): + query = request.args.get("query") + all_items = DB.get_items() + + # Filter items based on item name or seller's ID + filtered_items = {name: details for name, details in all_items.items() + if query.lower() in name.lower() or query.lower() in details.get('seller', '').lower()} + + return render_template("search_result.html", items=filtered_items) + + if __name__ == "__main__": - application.run(host='0.0.0.0', debug=True) + application.run(host='0.0.0.0', debug=True) \ No newline at end of file diff --git a/database.py b/database.py index dabdca5..eb5a84a 100644 --- a/database.py +++ b/database.py @@ -41,7 +41,7 @@ def user_duplicate_check(self, id_string): users = self.db.child("user").get() print("users###", users.val()) - if str(users.val()) == "None": # first registration + if str(users.val()) == "None": return True else: for res in users.each(): @@ -74,16 +74,62 @@ def get_item_byname(self, name): target_value=res.val() return target_value - def reg_review(self, data): + def get_items_bycategory(self, cate): + items = self.db.child("item").get() + target_value = [] + target_key = [] + for res in items.each(): + value = res.val() + key_value = res.key() + + if value['category'] == cate: + target_value.append(value) + target_key.append(key_value) + print("######target_value", target_value) + new_dict = {} + + for k, v in zip(target_key, target_value): + new_dict[k] = v + + return new_dict + + def reg_review(self, data, img_path): review_info ={ "rate": data['reviewStar'], - "review": data['reviewContents'] + "title": data['title'], + "review": data['reviewContents'], + "img_path": img_path } self.db.child("review").child(data['name']).set(review_info) return True - def get_review(self): - review = self.db.child("review").get().val() + def get_review_byname(self,name): + reviews = self.db.child("review").get().val() + for key, value in reviews.items(): + if key == name: + return value + + def get_reviews(self): + reviews = self.db.child("review").get().val() return reviews - + def get_heart_byname(self,uid,name): + hearts = self.db.child("heart").child(uid).get() + target_value="" + if hearts.val() == None: + return target_value + for res in hearts.each(): + key_value = res.key() + + if key_value == name: + target_value=res.val() + return target_value + + def update_heart(self,user_id,isHeart,item): + heart_info={ + "interested":isHeart + } + self.db.child("heart").child(user_id).child(item).set(heart_info) + return True + + \ No newline at end of file diff --git a/static/images/apple_review.jpeg b/static/images/apple_review.jpeg new file mode 100644 index 0000000..e69de29 diff --git a/static/images/apple_review.jpg b/static/images/apple_review.jpg new file mode 100644 index 0000000..630b840 Binary files /dev/null and b/static/images/apple_review.jpg differ diff --git a/static/images/ball_review.jpeg b/static/images/ball_review.jpeg new file mode 100644 index 0000000..4604897 Binary files /dev/null and b/static/images/ball_review.jpeg differ diff --git a/static/images/kiwi_review.jpeg b/static/images/kiwi_review.jpeg new file mode 100644 index 0000000..a681fa8 Binary files /dev/null and b/static/images/kiwi_review.jpeg differ diff --git a/static/images/orange_review.jpeg b/static/images/orange_review.jpeg new file mode 100644 index 0000000..e69de29 diff --git a/static/images/orange_review.jpg b/static/images/orange_review.jpg new file mode 100644 index 0000000..8a86538 Binary files /dev/null and b/static/images/orange_review.jpg differ diff --git a/static/images/potato_review.jpeg b/static/images/potato_review.jpeg new file mode 100644 index 0000000..e69de29 diff --git a/static/images/potato_review.jpg b/static/images/potato_review.jpg new file mode 100644 index 0000000..485c428 Binary files /dev/null and b/static/images/potato_review.jpg differ diff --git a/static/images/sweet_review.jpeg b/static/images/sweet_review.jpeg new file mode 100644 index 0000000..e69de29 diff --git a/static/images/sweet_review.jpg b/static/images/sweet_review.jpg new file mode 100644 index 0000000..46759ad Binary files /dev/null and b/static/images/sweet_review.jpg differ diff --git a/static/main.js b/static/main.js index 8b13789..e69de29 100644 --- a/static/main.js +++ b/static/main.js @@ -1 +0,0 @@ - diff --git a/static/style.css b/static/style.css index c43f138..0d4f42a 100644 --- a/static/style.css +++ b/static/style.css @@ -94,6 +94,15 @@ body { resize: none; } +#heart { + color: grey; + font-size: 50px; +} + +#heart.red { + color: red; +} + /* Responsive layout - when the screen is less than 400px wide, make the navigation links stack on top of each other instead of next to each other */ @media screen and (max-width: 400px) { .navbar__menu li { diff --git a/templates/detail.html b/templates/detail.html index ab6a104..974fe76 100644 --- a/templates/detail.html +++ b/templates/detail.html @@ -1,6 +1,62 @@ {% extends "index.html" %} {% block section %} + + + + + +

item name is {{name}} and address is {{data.addr}}

@@ -20,5 +76,16 @@ + + {% endblock section %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 5d745ad..c1ba198 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,7 @@ Home +
{% block section %} - +
+ + +
{% endblock section %}
diff --git a/templates/list.html b/templates/list.html index a7f5080..8ba75a5 100644 --- a/templates/list.html +++ b/templates/list.html @@ -1,6 +1,24 @@ {% extends "index.html" %} {% block section %} + + +
+ +
{% if total > 0 %}

상품 리스트 -- 현재까지 {{total}}개 등록됨 diff --git a/templates/reg_items.html b/templates/reg_items.html index 130e7b4..a49edea 100644 --- a/templates/reg_items.html +++ b/templates/reg_items.html @@ -1,26 +1,8 @@ - - - - - - Home - - +{% extends "index.html" %} + +{% block section %} -

- {% block section %}
@@ -68,7 +50,6 @@

- {% endblock section %}
- \ No newline at end of file +{% endblock section %} \ No newline at end of file diff --git a/templates/reg_reviews.html b/templates/reg_reviews.html index f796566..5bd9061 100644 --- a/templates/reg_reviews.html +++ b/templates/reg_reviews.html @@ -1,18 +1,54 @@ -
- 상품:

- 제목:

-
- 별점을 선택해주세요 - - - - - -
-
- -
- Review Image Upload: -

- -
\ No newline at end of file + + + + + + +
+ 상품:

+ 제목:

+
+ 별점을 선택해주세요 +
+ + + + + +
+
+ +
+ +
+ Review Image Upload: +

+ +
+ + + + \ No newline at end of file diff --git a/templates/review.html b/templates/review.html index ee26bdd..b6347da 100644 --- a/templates/review.html +++ b/templates/review.html @@ -1,29 +1,23 @@ +{% extends "index.html" %} + +{% block section %} {% if total > 0 %}

현재까지 {{total}}개 리뷰 등록됨

+ - {% for key, value in row1 %} - - {% endfor %} - - - {% for key, value in row1 %} - {% endfor %} - {% for key, value in row2 %} - - {% endfor %} - - - {% for key, value in row2 %} - {% endfor %} @@ -40,8 +34,42 @@ + {% else %}

등록된 리뷰가 없습니다

-{% endif %} \ No newline at end of file +{% endif %} + + + +{% endblock section %} \ No newline at end of file diff --git a/templates/review_detail.html b/templates/review_detail.html new file mode 100644 index 0000000..39a8da0 --- /dev/null +++ b/templates/review_detail.html @@ -0,0 +1,15 @@ +{% extends "index.html" %} + +{% block section %} +

+ review title is {{data.title}} and rate is {{data.rate}} points out of 5 points. +

+

+ {{data.review}} + +

+ +
+ + +{% endblock section %} \ No newline at end of file diff --git a/templates/search_result.html b/templates/search_result.html new file mode 100644 index 0000000..296cfda --- /dev/null +++ b/templates/search_result.html @@ -0,0 +1,32 @@ +{% extends "index.html" %} + +{% block section %} +{% if items %} +

+ 검색 결과 -- {{ items|length }}개의 상품이 검색되었습니다. +

+ +
제목: {{value.title}}
- + {% for key, value in row1 %} + 제목: {{value.title}}
+
제목: {{value.title}}
- + {% for key, value in row2 %} + 제목: {{value.title}}
+
+ + {% for key, value in items.items() %} + + {% if loop.index % 3 == 0 %} + + + {% endif %} + {% endfor %} + +
+

상품이름: {{ key }}

+

판매자: {{ value.seller }}

+ +
+ + + +{% else %} +

+ 검색된 상품이 없습니다. +

+{% endif %} +{% endblock section %} \ No newline at end of file diff --git a/templates/submit_item_result.html b/templates/submit_item_result.html index 813a1a7..a65cf19 100644 --- a/templates/submit_item_result.html +++ b/templates/submit_item_result.html @@ -1,26 +1,8 @@ - - +{% extends "index.html" %} - - - - Home - - +{% block section %} -

Seller {{data.seller}} sells {{data.name}} and its category is {{data.category}}. @@ -38,5 +20,4 @@

- - \ No newline at end of file +{% endblock section %} \ No newline at end of file