def index(): try: dosen = Dosen.query.all() data = formatarray(dosen) return response.success(data, "succes") except Exception as e: print(e)
def createBook(): req_data = request.get_json() nomor_buku = req_data.get('nomor_buku') judul = req_data.get('judul') pengarang = req_data.get('pengarang') tahun_terbit = req_data.get('tahun_terbit') penerbit = req_data.get('penerbit') create_at = datetime.utcnow() update_at = datetime.utcnow() buku = Buku.query.filter_by(nomor_buku=nomor_buku).first() if buku == None: book = Buku(nomor_buku=nomor_buku, judul=judul, pengarang=pengarang, tahun_terbit=tahun_terbit, penerbit=penerbit, created_at=create_at, update_at=update_at) try: db.session.add(book) db.session.commit() return response.success('', 'Berhasil Mebambahkan Buku') except Exception as e: return response.badRequest('', 'Gagal menambahkan Buku !!!') else: return response.badRequest( '', f'Buku dengan nomor #{nomor_buku} sudah ada')
def login(): try: email = request.form.get('email') password = request.form.get('password') user = User.query.filter_by(email=email).first() if not user: return response.badRequest([], 'Email Tidak Terdaftar') if not user.checkPassword(password): return response.badRequest([], 'Kombinasi Password Salah !') data = singleObject(user) expires = datetime.timedelta(days=1) expires_refresh = datetime.timedelta(days=3) access_token = create_access_token(data, fresh=True, expires_delta=expires) refresh_token = create_refresh_token(data, expires_delta=expires_refresh) return response.success( { "data": data, "access_token": access_token, "refresh_token": refresh_token, }, "Success") except Exception as e: print(e)
def index(): '''Menampilkan daftar buku yang terdapar pada table buku ''' try: books = Buku.query.all() data_buku = fromatArrayBooks(books) return response.success(data_buku, 'Success') except Exception as e: return response.badRequest('', 'Gagal Menampilkan')
def tampilUser(): '''Tampil User ini digunakan untuk Menampilkan keseluruhan user yang terdaftar pada table user ''' try: users = User.query.all() data = formatArray(users) return response.success(data, 'Success') except Exception as e: # return response.badRequest('', 'Gagal Menampilkan') print(e)
def tampilMahasiswa(): try: mhs = Mahasiswa.query.all() if data is None: return response.badRequest("", "Tidak ada data mahasiswa") data = [serializeMahasiswa(data) for data in mhs] return response.success(data, "Success") except Exception as e: return response.badRequest("", "Tidak dapat menampilkan")
def faceCheck(): user_id = request.form.get('user_id') file = request.files.get('file') faceEncoding = FaceEncodings(file) face_encodings = FaceDatas(user_id) distances = FaceDistance(face_encodings, faceEncoding) FaceAdd(user_id, faceEncoding, distances['current']) return success(distances)
def hapusBook(id): book = Buku.query.filter_by(nomor_buku=id).first() if book == None: return response.badRequest('', f'Buku dengan nomor #{id} tidak ada') try: db.session.delete(book) db.session.commit() return response.success('', f'Buku dengan nomor #{id} berhasil di Hapus') except Exception as e: return response.badRequest('', 'Tidak dapat menghapus')
def department_get_department_list(department_id, get_employee_info, sub_department_count, sub_employee_count, all_sub_department_count, all_sub_employee_count): ''' [ {"name": "department_id", "required": 1, "check": "int", "description": "父部门ID"}, {"name": "get_employee_info", "required": 0, "check": "bool", "description": "是否包含当前部门员工信息"}, {"name": "sub_department_count", "required": 0, "check": "bool", "description": "部门信息包含一级子部门数"}, {"name": "sub_employee_count", "required": 0, "check": "bool", "description": "部门信息包含一级子员工数"}, {"name": "all_sub_department_count", "required": 0, "check": "bool", "description": "部门信息包含所有子部门数"}, {"name": "all_sub_employee_count", "required": 0, "check": "bool", "description": "部门信息包含所有子员工数"} ] ''' if department_id == -1: department = Department.get_root_department() else: department = Department.query.filter( Department.enterprise_id == current_enterprise.object_id, Department.object_id == department_id).first() if not department: return custom(-1, "参数错误") departments = Department.query.filter( Department.enterprise_id == current_enterprise.object_id, Department.parent_id == department.object_id).all() department_info = [] for department in departments: res = department.to_json() if sub_department_count: res["sub_department_count"] = department.get_sub_department_query( ).count() if sub_employee_count: res["employee_count"] = department.get_current_employees_query( ).count() if all_sub_department_count: res["all_sub_department_count"] = department.get_all_sub_department_query( ).count() if all_sub_employee_count: res["all_employee_count"] = department.get_all_employees_query( ).count() department_info.append(res) employee_info = [] if get_employee_info: depmems = DepartmentMem.query.options( joinedload(DepartmentMem.employee).joinedload( Employee.account)).filter( DepartmentMem.department_id == department.object_id).all() for depmem in depmems: employee_info.append(depmem.to_json()) return success(data={ "department_info": department_info, "employee_info": employee_info })
def detailMahasiswabynpm(npm): try: dataMhs = db.session.query(Mahasiswa.npm, Mahasiswa.nama, Mahasiswa.no_hp, Mahasiswa.angkatan, Mahasiswa.alamat, Prodi.nama_prodi, Fakultas.nama_fakultas).select_from(Mahasiswa).join( Prodi).join(Fakultas).filter(Mahasiswa.npm == npm and Mahasiswa.prodi == Prodi.id_prodi and Prodi.id_fakultas == Fakultas.id_fakultas).first() if dataMhs is None: return response.badRequest('', 'Data tidak ditemukan') data = serializeDetailMahasiswa(dataMhs) return response.success(data, 'Success') except Exception as e: return response.badRequest('', 'Gagal menampilkan')
def faceUpdate(): user_id = request.form.get('user_id') file = request.files.get('file') if file: data = FaceEncodings(file) else: data = None UserUpdate(user_id, data) return success()
def deleteMahasiswa(npm): mhs = Mahasiswa.query.filter_by(npm=npm).first() if mhs is None: return response.badRequest('', f'Mahasiswa dengan NPM #{npm} tidak ada') try: db.session.delete(mhs) db.session.commit() return response.success('', 'Success') except Exception as e: return response.badRequest('', 'Gagal Menambahkan')
def detailMahasiwa(): try: dataMhs = db.session.query(Mahasiswa.npm, Mahasiswa.nama, Mahasiswa.no_hp, Mahasiswa.angkatan, Mahasiswa.alamat, Prodi.nama_prodi, Fakultas.nama_fakultas).select_from(Mahasiswa).join( Prodi).join(Fakultas).filter(Mahasiswa.prodi == Prodi.id_prodi and Prodi.id_fakultas == Fakultas.id_fakultas).all() if dataMhs is None: return response.badRequest('', 'Data tidak ada') data = [serializeDetailMahasiswa(data) for data in dataMhs] # data = formatarray(dataMhs) # data = serializeDetailMahasiswa(dataMhs) return response.success(data, 'Success') except Exception as e: print(e)
def buatAdmin(): try: name = request.form.get('name') email = request.form.get('email') password = request.form.get('password') level = 1 users = User(name=name, email=email, level=level) users.setPassword(password) db.session.add(users) db.session.commit() return response.success('', 'Sukses menambahkan data Admin') except Exception as e: print(e)
def detailBook(id): book = Buku.query.filter_by(nomor_buku=id).first() if book == None: return response.badRequest('', f'Buku dengan nomor #{id} tidak ada') data_buku = { 'nomor_buku': book.nomor_buku, 'pengarang': book.pengarang, 'tahun_terbit': book.tahun_terbit, 'penerbit': book.penerbit, 'created_at': book.created_at, 'update_at': book.update_at } return response.success(data_buku, f'Data Buku')
def detail(id): try: dosen = Dosen.query.filter_by(id=id).first() mahasiswa = Mahasiswa.query.filter((Mahasiswa.dosen_satu == id) | (Mahasiswa.dosen_dua == id)) if not dosen: return response.badrequest([], 'Tidak ada data dosen') datamahasiswa = formatMahasiswa(mahasiswa) data = singleDetailMahasiswa(dosen, datamahasiswa) return response.success(data, "success") except Exception as e: print(e)
def tampilDetail(): '''Fungsi ini digunakan untuk menampilkan data pada table User dengan menggunakan fungsi Join untuk mendapatkan nilai yang lebih Detail ''' users = db.session.query(User.id_user, User.npm, User.nama, User.email, User.password, User.level, Level.id_level, Level.keterangan).join(Level).filter( User.level == Level.id_level).all() # users = db.session.query( # User.id_user, User.npm, User.nama, User.email, User.password, # Level.keterangan, Prodi.nama_prodi, Fakultas.nama_fakultas).join( # Level).join(Mahasiswa).join(Prodi).join(Fakultas).filter( # User.level == Level.id_level and User.npm == Mahasiswa.npm # and Mahasiswa.prodi == Prodi.id_prodi # and Prodi.id_fakultas == Fakultas.id_fakultas).order_by( # User.id_user).all() data = formatArrrayDetail(users) return response.success(data, 'Succes')
def editMahasiswa(npm): mhs = Mahasiswa.query.filter_by(npm=npm).first() if mhs is None: return response.badRequest('', f'Mahasiswa dengan NPM #{npm} tidak ada') req_data = request.get_json() mhs.npm = req_data.get('npm') mhs.nama = req_data.get('nama') mhs.no_hp = req_data.get('no_hp') mhs.angakatan = req_data.get('angkatan') mhs.alamat = req_data.get('alamat') mhs.prodi = req_data.get('prodi') try: db.session.commit() return response.success('', 'Success') except Exception as e: return response.badRequest('', 'Gagal Update Mahasiswa')
def CreateUser(): '''Untuk Membuat User Admin dan Mahasiswa''' try: # req_data = request.get_json() npm = request.form.get('npm') nama = request.form.get('nama') email = request.form.get('email') password = request.form.get('password') level = request.form.get('level') users = User(npm=npm, nama=nama, email=email, level=level) users.setPassword(password) db.session.add(users) db.session.commit() return response.success('', "Berhasil Menambahkan User") except Exception as e: print(e)
def updateBook(id): book = Buku.query.filter_by(nomor_buku=id).first() if book == None: return response.badRequest('', f'Buku dengan nomor #{id} tidak ada') req_data = request.get_json() try: book.judul = req_data.get('judul') book.pengarang = req_data.get('pengarang') book.tahun_terbit = req_data.get('tahun_terbit') book.penerbit = req_data.get('penerbit') book.update_at = datetime.utcnow() db.session.commit() return response.success( '', f'Buku dengan nomor #{id} berhasil di berbaharui !') except Exception as e: return response.badRequest('', 'Gagal memperbaharui Buku')
def saveMahasiswa(): data_req = request.get_json() npm = data_req.get('npm') nama = data_req.get('nama') no_hp = data_req.get('no_hp') angkatan = data_req.get('angkatan') alamat = data_req.get('alamat') prodi = data_req.get('prodi') mahasiswa = Mahasiswa.query.filter_by(npm=npm).first() if mahasiswa == None: data = Mahasiswa(npm=npm, nama=nama, no_hp=no_hp, angkatan=angkatan, alamat=alamat, prodi=prodi) try: db.session.add(data) db.session.commit() return response.success('', 'Data Berhasil di tambahkan') except Exception as e: return response.badRequest('', 'Data Gagal di tambahkan') else: return response.badRequest('', f'Mahasiswa dengan npm #{npm} sudah ada')
def get(request, category): return success({'logs': get_logs(category)})
def put(request, category): lines = request.get_all('line') if len(lines): log(category, lines) return success()
def empty(): UserEmpty(request.args.get('user_id')) return success()
def delete(): UserDeleteFaces(request.args.get('user_id')) return success()
def create(): info = UserCreate(request.form.get('user_id')) return success({ 'user_id': info.id, })
def index(): return success({ 'time': datetime.now(), })
def department_get_department_tree(): departments = Department.get_department_tree(current_enterprise.object_id) return success(data=[dep.to_json() for dep in departments])