Esempio n. 1
0
    def patch(self):
        try:
            parser.add_argument('employee_code', type=str, help='Employee code')
            params = parser.parse_args()
            logger.info_log("params : " + str(params))

            data = request.get_json(silent=True, force=True)

            logger.info_log("Request data : " + str(data))

            sql = """\
            update Employee set 
                employee_name = %s,
                address = %s,
                salary = %s,
                phone_number = %s,                
                where employee_code = %s

            """            
            rows = db_class.execute(sql, (data["employee_name"], data["address"], data["salary"], data["phone_number"], data["employee_code"]))
            
            db_class.commit()
            db_class.close()

            logger.info_log("commit complete")
            
            return {"status" : "200", "message": "Data update success..."}

        except Exception as e:
            logger.error_log(str(e))
        finally:
            db_class.close()
Esempio n. 2
0
    def post(self):
        try:
            parser.add_argument('employee_code', type=str, help='employee code')
            parser.add_argument('employee_name', type=str, help='employee name')
            parser.add_argument('address', type=str, help='address')
            parser.add_argument('salary', type=str, help='salary')
            parser.add_argument('phone_number', type=str, help='phone_number')     
            params = parser.parse_args()
            logger.info_log("params : " + str(params))

            data = request.get_json(silent=True, force=True)
            logger.info_log("Request data : " + str(data))

            sql = """\
            insert into Employee (employee_code, employee_name, address, salary, phone_number, date) 
                    values ( %s, %s, %s, %s, %s, now())
            """

            rows = db_class.execute(sql, (data["employee_code"], data["employee_name"], data["address"], data["salary"], data["phone_number"]))
            
            db_class.commit()
            db_class.close()

            logger.info_log("commit complete")
            
            return {"status" : "200", "message": "Data insert success..."}

        except Exception as e:
            logger.error_log(str(e))
        finally:
            db_class.close()
Esempio n. 3
0
    def post(self):
        db_class = dbConnector.Database()

        try:
            sql = 'insert into employee_code values(%s, %s, %s, %s, %s, %s)'

            wb = load_workbook(path + filename, data_only=True)
            ws = wb['Sheet']

            iter_rows = iter(ws.rows)
            next(iter_rows)

            for row in iter_rows:
                db_class.execute(sql,
                                 (row[0].value, row[1].value, row[2].value,
                                  row[3].value, row[4].value, row[5].value))

            wb.close()
            db_class.commit()

            return {"status": "200", "message": "Data insert success..."}

        except Exception as e:
            logger.error_log(str(e))
        finally:
            db_class.close()
            wb.close()
Esempio n. 4
0
    def get(self):
        try:            
            parser.add_argument('Date', type=str, help='admisstion date')
            params = parser.parse_args()
            logger.info_log("params : " + str(params))

            sql = "select employee_name from Employee where employee_code = %s"
            convert_date = datetime.datetime.strptime(params['Date'], "%Y-%m-%d").date()
            rows = db_class.executeAll(sql, convert_date)

            logger.info_log("[User List Data] : " + str(rows))
            
            return {"status" : "200", "message": "Data select success..."}

        except Exception as e:            
            logger.error_log(str(e))           
Esempio n. 5
0
    def delete(self):
        try:
            data = request.get_json(silent=True, force=True)

            logger.info_log("Request data : " + str(data))

            sql = """\
            delete from Employee where employee_code = %s
            """            
            rows = db_class.execute(sql, data["employee_code"])
            
            db_class.commit()
            db_class.close()

            logger.info_log("commit complete")
            
            return {"status" : "200", "message": "Data delete success..."}

        except Exception as e:
            logger.error_log(str(e))            
        finally:
            db_class.close()
Esempio n. 6
0
    logger.info_log("request get user list...")


class HttpStatusResponse(Resource):
    @app.errorhandler(404)
    def notFoundError(self):
        return "[404] Page Not Found..."

    @app.errorhandler(400)
    def uncaughtError(self):
        return "[400] Bad request..."

    @app.errorhandler(401)
    def unauthorize(self):
        return "[401] Not unauthorized..."

    @app.errorhandler(500)
    def serverError(self):
        return "[500] Server Error..."


if __name__ == '__main__':
    try:
        models.db.init_app(app)
        # 테이블 삭제 후 생성
        models.db.drop_all()
        models.db.create_all()
    except Exception as e:
        logger.error_log(str(e))

    app.run(host='127.0.0.1', port=5002, debug=True)