Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
booboosui committed Oct 5, 2023
1 parent b40652a commit b146038
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
pwd
ls -alh
- name: Run Docker Build Script
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKER_REPO: ${{ secrets.DOCKERHUB_REPO }}
run: |
chmod +x docker-build.sh
./docker-build.sh
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__*
9 changes: 9 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import Config

app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)

from app import routes
10 changes: 10 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from app import db

class Demo(db.Model):
id = db.Column(db.Integer, primary_key=True)
info1 = db.Column(db.String(80), unique=True, nullable=False)
info2 = db.Column(db.String(120), unique=True, nullable=False)

def __init__(self, info1, info2):
self.info1 = info1
self.info2 = info2
55 changes: 55 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from flask import request, jsonify
from app import app, db
from app.models import Demo

# 添加用户
@app.route('/demos', methods=['POST'])
def add_demo():
data = request.get_json()
new_demo = Demo(info1=data['info1'], info2=data['info2'])
db.session.add(new_demo)
db.session.commit()
return jsonify({'message': 'Demo added successfully'})

# 获取所有用户
@app.route('/demos', methods=['GET'])
def get_demos():
demos = Demo.query.all()
demo_list = []
for demo in demos:
demo_data = {'id': demo.id, 'info1': demo.info1, 'info2': demo.info2}
demo_list.append(demo_data)
return jsonify({'demos': demo_list})

# 获取单个用户
@app.route('/demos/<int:demo_id>', methods=['GET'])
def get_demo(demo_id):
demo = Demo.query.get(demo_id)
if demo:
demo_data = {'id': demo.id, 'info1': demo.info1, 'info2': demo.info2}
return jsonify(demo_data)
return jsonify({'message': 'Demo not found'}), 404

# 更新用户信息
@app.route('/demos/<int:demo_id>', methods=['PUT'])
def update_demo(demo_id):
demo = Demo.query.get(demo_id)
if not demo:
return jsonify({'message': 'Demo not found'}), 404

data = request.get_json()
demo.info1 = data['info1']
demo.info2 = data['info2']
db.session.commit()
return jsonify({'message': 'Demo updated successfully'})

# 删除用户
@app.route('/demos/<int:demo_id>', methods=['DELETE'])
def delete_demo(demo_id):
demo = Demo.query.get(demo_id)
if not demo:
return jsonify({'message': 'Demo not found'}), 404

db.session.delete(demo)
db.session.commit()
return jsonify({'message': 'Demo deleted successfully'})
3 changes: 3 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

echo "Please complete the compilation script ./build.sh"
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Please complete the compilation script ./build.sh"
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Config:
SQLALCHEMY_DATABASE_URI = 'sqlite:///../data.db'
SQLALCHEMY_TRACK_MODIFICATIONS = False
Binary file added data.db
Binary file not shown.
7 changes: 7 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from app import app, db

if __name__ == '__main__':
with app.app_context():
db.create_all()

app.run(debug=True, port=8061)

0 comments on commit b146038

Please sign in to comment.