Rival Delete functionality

This commit is contained in:
Wanich Keatkajonjumroen 2023-09-02 07:40:57 +09:00
parent 147d7adaaf
commit 16d801aff5
5 changed files with 32 additions and 8 deletions

View File

@ -4,6 +4,7 @@
<title>{{ title }}</title> <title>{{ title }}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<style> <style>
html { html {
background-color: #181a1b !important; background-color: #181a1b !important;

View File

@ -65,12 +65,15 @@ class OngekiFrontend(FE_Base):
if uri == "/game/ongeki/rival.add": if uri == "/game/ongeki/rival.add":
rival_id = request.args[b"rivalUserId"][0].decode() rival_id = request.args[b"rivalUserId"][0].decode()
self.data.profile.put_rival(usr_sesh.userId, rival_id) self.data.profile.put_rival(usr_sesh.userId, rival_id)
self.logger.info(f"{usr_sesh.userId} added a rival") # self.logger.info(f"{usr_sesh.userId} added a rival")
return redirectTo(b"/game/ongeki/", request) return redirectTo(b"/game/ongeki/", request)
elif uri == "/game/ongeki/rival.delete": elif uri == "/game/ongeki/rival.delete":
return b"" rival_id = request.args[b"rivalUserId"][0].decode()
self.data.profile.delete_rival(usr_sesh.userId, rival_id)
# self.logger.info(f"{response}")
return redirectTo(b"/game/ongeki/", request)
else: else:
return b"" return b"Something went wrong"
else: else:
return b"User is not logged in" return b"User is not logged in"

View File

@ -0,0 +1,12 @@
function deleteRival(rivalUserId){
$(document).ready(function () {
$.post("/game/ongeki/rival.delete",
{
rivalUserId
},
function(data,status){
window.location.replace("/game/ongeki/")
})
});
}

View File

@ -32,10 +32,10 @@
</thead> </thead>
<tbody> <tbody>
{% for rival in rival_info%} {% for rival in rival_info%}
<tr> <tr id="{{rival.rivalUserId}}">
<td>{{rival.rivalUserId}}</td> <td>{{rival.rivalUserId}}</td>
<td>{{rival.rivalUserName}}</td> <td>{{rival.rivalUserName}}</td>
<td><button class="btn-danger btn btn-sm">Delete</button></td> <td><button class="btn-danger btn btn-sm" onclick="deleteRival({{rival.rivalUserId}})">Delete</button></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -65,8 +65,9 @@
</div> </div>
</div> </div>
{# <script> <script>
</script> #} {% include 'titles/ongeki/frontend/js/rival_scripts.js' %}
</script>
{% else %} {% else %}
<h2>Not Currently Logged In</h2> <h2>Not Currently Logged In</h2>
{% endif %} {% endif %}

View File

@ -3,7 +3,7 @@ from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, an
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, BigInteger from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, BigInteger
from sqlalchemy.engine.base import Connection from sqlalchemy.engine.base import Connection
from sqlalchemy.schema import ForeignKey from sqlalchemy.schema import ForeignKey
from sqlalchemy.sql import func, select from sqlalchemy.sql import func, select, delete
from sqlalchemy.engine import Row from sqlalchemy.engine import Row
from sqlalchemy.dialects.mysql import insert from sqlalchemy.dialects.mysql import insert
@ -519,3 +519,10 @@ class OngekiProfileData(BaseData):
) )
return None return None
return result.lastrowid return result.lastrowid
def delete_rival(self, aime_id: int, rival_id: int) -> Optional[int]:
sql = delete(rival).where(rival.c.user==aime_id, rival.c.rivalUserId==rival_id)
result = self.execute(sql)
if result is None:
self.logger.error(f"delete_rival: failed to delete! aime_id: {aime_id}, rival_id: {rival_id}")
else:
return result.rowcount