mirror of
https://github.com/sunrin-ana/2025-SSF-dotory-manage.git
synced 2026-03-09 18:10:02 +00:00
jdsflkafjklajfl
This commit is contained in:
parent
bbb2cf8d8d
commit
20c99c6e1c
18 changed files with 119 additions and 26 deletions
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# 디폴트 무시된 파일
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 에디터 기반 HTTP 클라이언트 요청
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
20
.idea/dataSources.xml
generated
Normal file
20
.idea/dataSources.xml
generated
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="dotori" uuid="b8aac1b7-ec75-4a2b-9716-f69ef7adb7bd">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:D:\dotori_test\instance\dotori.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<libraries>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar</url>
|
||||
</library>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar</url>
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
16
.idea/dotori_test.iml
generated
Normal file
16
.idea/dotori_test.iml
generated
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="Flask">
|
||||
<option name="enabled" value="true" />
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.13 (dotori_test)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
|
||||
</component>
|
||||
</module>
|
||||
12
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
12
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="str.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.13 (dotori_test)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (dotori_test)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/dotori_test.iml" filepath="$PROJECT_DIR$/.idea/dotori_test.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/sqldialects.xml
generated
Normal file
6
.idea/sqldialects.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/services/dotori_service.py" dialect="GenericSQL" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -5,14 +5,15 @@ from db import db
|
|||
class UserDotori(db.Model):
|
||||
__tablename__ = 'user_dotori'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
user_id = db.Column(db.Integer, nullable=False)
|
||||
dotori_count = db.Column(db.Integer, default=0)
|
||||
created_at = db.Column(db.DateTime, default=datetime.now)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'user_id': self.id,
|
||||
'user_id': self.user_id,
|
||||
'dotori_count': self.dotori_count,
|
||||
'created_at': self.created_at.isoformat(),
|
||||
'updated_at': self.updated_at.isoformat()
|
||||
|
|
@ -20,7 +21,7 @@ class UserDotori(db.Model):
|
|||
|
||||
def to_response(self):
|
||||
return {
|
||||
'userId': self.id,
|
||||
'userId': self.user_id,
|
||||
'dotory': self.dotori_count
|
||||
}
|
||||
|
||||
|
|
@ -36,4 +37,4 @@ class UserDotori(db.Model):
|
|||
return self.dotori_count
|
||||
return False
|
||||
def __repr__(self):
|
||||
return f"<UserDotori user_id={self.id} dotori_count={self.dotori_count}>"
|
||||
return f"<UserDotori user_id={self.user_id} dotori_count={self.dotori_count}>"
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -4,7 +4,7 @@ from services.dotori_service import DotoriService
|
|||
dotori_ns = Namespace('dotory', description='도토리 관련 API')
|
||||
|
||||
user_model = dotori_ns.model('UserDotori', {
|
||||
'userId': fields.Integer,
|
||||
'user_id': fields.Integer,
|
||||
'dotory': fields.Integer,
|
||||
})
|
||||
|
||||
|
|
@ -17,21 +17,19 @@ class UserDotori(Resource):
|
|||
dotori_ns.abort(404, 'User not found')
|
||||
return user_dotori.to_response()
|
||||
|
||||
@dotori_ns.route('')
|
||||
class InitializeDotori(Resource):
|
||||
@dotori_ns.expect(dotori_ns.model('Initialize', {'userId': fields.Integer(required=True)}))
|
||||
def post(self):
|
||||
data = dotori_ns.payload
|
||||
user_id = data.get('userId')
|
||||
return DotoriService.initialize_user_dotori(user_id)
|
||||
|
||||
@dotori_ns.route('/<int:userId>')
|
||||
class AddDotori(Resource):
|
||||
@dotori_ns.expect(dotori_ns.model('AddDotori', {'num': fields.Integer(required=True)}))
|
||||
def put(self, userId):
|
||||
data = dotori_ns.payload
|
||||
num = data.get('num')
|
||||
return DotoriService.add_dotori(userId, num)
|
||||
return DotoriService.add_dotori(userId, num).to_response()
|
||||
|
||||
@dotori_ns.route('')
|
||||
class InitializeDotori(Resource):
|
||||
@dotori_ns.expect(dotori_ns.model('Initialize', {'user_id': fields.Integer(required=True)}))
|
||||
def post(self):
|
||||
data = dotori_ns.payload
|
||||
user_id = data.get('user_id')
|
||||
return DotoriService.initialize_user_dotori(user_id)
|
||||
|
||||
@dotori_ns.route('/all')
|
||||
class GetAllDotori(Resource):
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class BuyProduct(Resource):
|
|||
@product_ns.response(400, 'Failed')
|
||||
def post(self, productId):
|
||||
data = product_ns.payload
|
||||
user_id = data.get('userId')
|
||||
user_id = data.get('user_id')
|
||||
if not user_id:
|
||||
product_ns.abort(400, 'userId is required')
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ class BuyProduct(Resource):
|
|||
user_dotori = DotoriService.get_user_dotori(user_id)
|
||||
return {
|
||||
'isSuccess': True,
|
||||
'userId': user_id,
|
||||
'user_id': user_id,
|
||||
'dotory': user_dotori if user_dotori else 0
|
||||
}
|
||||
else:
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,27 +1,32 @@
|
|||
from datetime import datetime
|
||||
|
||||
import sqlalchemy
|
||||
|
||||
from models.dotori import UserDotori
|
||||
from flask import current_app
|
||||
from db import db
|
||||
class DotoriService:
|
||||
@staticmethod
|
||||
def get_user_dotori(user_id: int):
|
||||
user_dotori = UserDotori.query.filter_by(id=user_id).first()
|
||||
user_dotori = UserDotori.query.filter_by(user_id=user_id).first()
|
||||
if user_dotori:
|
||||
return user_dotori.dotori_count
|
||||
return user_dotori
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def initialize_user_dotori(user_id: int):
|
||||
user_dotori = UserDotori.query.filter_by(id=user_id).first()
|
||||
print(user_id)
|
||||
user_dotori = UserDotori.query.filter_by(user_id=user_id).first()
|
||||
if not user_dotori:
|
||||
user_dotori = UserDotori(id=user_id, dotori_count=1000000)
|
||||
user_dotori = UserDotori(id=user_id, user_id=user_id, dotori_count=1000000)
|
||||
print(f"초기화 완료, {user_id}님의 도토리: {user_dotori.dotori_count}")
|
||||
db.session.add(user_dotori)
|
||||
db.session.execute(sqlalchemy.text("INSERT INTO user_dotori (user_id, dotori_count, created_at, updated_at) VALUES (:user_id, :dotori_count, :created_at, :updated_at)"), {"user_id":user_id, "dotori_count":1000000, "created_at":datetime.now(), "updated_at":datetime.now()})
|
||||
db.session.commit()
|
||||
return user_dotori.dotori_count
|
||||
|
||||
@staticmethod
|
||||
def buy_product(user_id: int, product_price: int):
|
||||
user_dotori = UserDotori.query.filter_by(id=user_id).first()
|
||||
user_dotori = UserDotori.query.filter_by(user_id=user_id).first()
|
||||
if not user_dotori:
|
||||
return False
|
||||
|
||||
|
|
@ -34,14 +39,14 @@ class DotoriService:
|
|||
|
||||
@staticmethod
|
||||
def add_dotori(user_id: int, amount: int):
|
||||
user_dotori = UserDotori.query.filter_by(id=user_id).first()
|
||||
user_dotori = UserDotori.query.filter_by(user_id=user_id).first()
|
||||
if not user_dotori:
|
||||
user_dotori = UserDotori(id=user_id)
|
||||
user_dotori = UserDotori(user_id=user_id)
|
||||
db.session.add(user_dotori)
|
||||
print(f"도토리 추가, {user_id}님의 도토리: {user_dotori.dotori_count} -> {user_dotori.dotori_count + amount}")
|
||||
user_dotori.increment(amount)
|
||||
db.session.commit()
|
||||
return user_dotori.dotori_count
|
||||
return user_dotori
|
||||
|
||||
@staticmethod
|
||||
def get_all_users_dotori() -> list:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue