gordienski7799 4 tahun lalu
induk
melakukan
b033d2ada0
2 mengubah file dengan 156 tambahan dan 0 penghapusan
  1. 112 0
      hw15/555.js
  2. 44 0
      hw15/6666.html

+ 112 - 0
hw15/555.js

@@ -0,0 +1,112 @@
+let allUsers = [];
+let allFilms = [];
+let url = 'https://api-f22.herokuapp.com/';
+let userUrl = 'users/';
+let films = 'films/';
+let addFilm = 'addFilm/';
+
+
+class User {
+  constructor(name, filmId){
+    this.name = name;
+    this.films = tagFilm(this.id, filmId)
+  }
+};
+
+const createUser = function(name, filmId){
+  return new User(name, filmId)
+}; 
+
+const addNewUser = function(name, filmId){
+  axios
+  .post(url+userUrl, createUser(name, filmId))
+  .catch(error => console.log(error));
+};
+
+
+const updateUser = function(id, updatedInfo){
+  axios
+  .patch(url + userUrl, {
+    name: updatedInfo,
+    id: id
+  })
+};
+
+const showUserById = function(id){
+  return axios
+  .get(url+userUrl+id)
+};
+showUserById(2).then((response=>{
+  console.log(response.data);
+}));
+
+const deleteUser = function (id) {
+  axios.delete(url + userUrl + id)
+  .then(res => {
+          console.log('Deleted:', res.message)
+          return res
+        })
+        .catch(err => console.error(err))
+  
+};
+
+const updateServersData = function (){
+   addNewUser('Ruslan', 1);
+   deleteUser(2);
+   updateUser(2, 'Igor');
+}
+
+
+class Film {
+  constructor(title, author){
+    this.title = title;
+    this.author = author; 
+  }
+};
+
+const createFilm = function(title, author){
+  axios.post(url+films, new Film(title, author))
+};
+
+const  tagFilm = function (userId, filmId) {
+  axios.post(url+ userUrl + addFilm, {
+      userId: userId,
+      filmId: filmId
+  })
+}
+
+
+const getAllFilms = function (){
+  return axios.get(url+films).then((res=>{
+      allFilms.push(...res.data);
+    }))
+}
+
+
+const renderUsers =  users =>{
+  document.body.innerText = '';
+  for (let user of users){
+      document.body.innerHTML += `
+      <div class="card">
+      <h2>user: ${user.name}</h2>
+      <p>userId: ${user.id}</p>
+      <p>List of films: ${user.films}</p>
+      </div>`
+  }
+}
+
+async function getNewUsers(){
+  await updateServersData();
+   axios.get(url+userUrl)
+    .then(res => 
+      {
+      renderUsers(res.data)
+      allUsers.push(res.data)
+    })
+    
+};
+
+createFilm('Бумер', 'Кто-то');
+getAllFilms();
+console.log(allFilms);
+getNewUsers();

+ 44 - 0
hw15/6666.html

@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<meta name="viewport" content="width=device-width, initial-scale=1.0">
+	<title>Document</title>
+	<html lang="en">
+	<head class="head">
+		<meta charset="UTF-8">
+		<title>Title</title>
+		<style type="text/css">
+			.c3{
+				color: #6f507d;
+				font-size: 15px;
+				font-family: monospace;
+			}
+			.c2{
+				color: #219191;
+				font-size: 25px;
+			}
+			.c1{
+				color: #915021;
+				font-size: 35px;
+				font-family: cursive;
+			}
+			#btn1 {
+				margin-left: 30px;
+				transform: rotate(90deg);
+				background-color: ##F0E68C;
+				font-size: 20px;
+				color: #00FF00;
+				transition: 0.6s;
+			}
+			#btn1:hover{
+				background-color: #DC143C;
+				color: #6A5ACD;
+				padding-top: 11px;
+			}
+		</style>
+		<body>
+			<h1>slozhno</h1>
+			<script type="text/javascript" src="./script.js"></script>
+		</body>
+		</html>