From 6d158906ba52c5f5f59bdd88d26667c5d5d994b7 Mon Sep 17 00:00:00 2001 From: Evie Ma Date: Thu, 19 Oct 2017 00:43:04 +1100 Subject: [PATCH 1/5] add GET, PUT and DELETE user by id --- .../classes/spaceshuttle/Application.class | Bin 0 -> 2223 bytes .../controller/UserController.class | Bin 0 -> 3066 bytes .../classes/spaceshuttle/model/User.class | Bin 0 -> 972 bytes .../repository/UserRepository.class | Bin 0 -> 465 bytes .../resources/application.properties | 6 ++++ .../controller/UserController.java | 29 ++++++++++++++++++ 6 files changed, 35 insertions(+) create mode 100644 out/production/classes/spaceshuttle/Application.class create mode 100644 out/production/classes/spaceshuttle/controller/UserController.class create mode 100644 out/production/classes/spaceshuttle/model/User.class create mode 100644 out/production/classes/spaceshuttle/repository/UserRepository.class create mode 100644 out/production/resources/application.properties diff --git a/out/production/classes/spaceshuttle/Application.class b/out/production/classes/spaceshuttle/Application.class new file mode 100644 index 0000000000000000000000000000000000000000..81f40d546b05f1ce5a9b023e9aa1f36c1e0e7575 GIT binary patch literal 2223 zcmb7FT~`}b6x}x@83?IRXrQ2CtkfnH7+Nc>O>Kp=*lM7)LF&g^u5}YGVM;QSHFJaT z?l1AhSM@=$5B&iye~3T9C+og5&02XP%YGWY;DEtCY(w;b2ew*~qN#SMXE+1peCLlwtWYn@h2 z`RlUQq-3Px)n#)-`i?mt3X^)<2?Qo9L0i^Uu-(zRsqCe8yXn-Wc088>k}c`D0%L`* zD^KOFw42gx*j4R2Zle@NlzxLgMtfWfoUMDUmUK4_oW~v4RldMCg^K4l?4WI2Z27XK zzV-YayY9JK?df>*awIAhdm7X{Put~x`zPYQy5195=xKCH6oCms)J{unIDtcwmR#4< zAq~uL?o@a3rK-KGq@iuHDO>t6SEir`yN3M!8l$a|LQ~)qM=2s`R$E84RVdG>lO$%SL6~ zLOF}OxMxbO^ray0xItUhbzX0)yvaMrw|#Hd*;JeP+I~L5lQ&*DIV)LwjQb=ZiwF3` z!lzkOu*#@i5+Bx{(wo5it92_!q3h!%xdJo2+=RSE$YLz9h5Zg^u3m`MG=fv=)d)RH za@6S@qOc-n>|-$~Hse;xU=0s5NZ`@2M;cz_r5rYglo!MC;Ic{`o9 zK=y%oy2?!%1P0|F@w5*8MNN92Z(UOb(~)5*R=&gRW0GTr>-%jLSO5Q)QOMJ6izmaD zWwTjzv?^KnQsCkVetP92Fm<{f-ex0Z_>%=BK|+z`_Y6-qSHU$k^DD$p+$8WCzv)nz z#Sr&Kl?oWfS*`;Z!6+rhc#+!Xu74ykbAY}lU3=5FptVJ-u8)44LymGb2ga#ke3W=H zy4K}qgoYovjYBvWnvX>)hY+ZY^O&IFB()9H*MZ@TX{bY|2V5=Q-S`=)k@PRHW`0Az z!0PM)24>gho-Zc*7E`%YF8Mvi=W?m5H`7#{FpA%$#1Ak2G>Ply literal 0 HcmV?d00001 diff --git a/out/production/classes/spaceshuttle/controller/UserController.class b/out/production/classes/spaceshuttle/controller/UserController.class new file mode 100644 index 0000000000000000000000000000000000000000..a1a0dd4fb6cb8072cd54ba3ac80f12917561a7b4 GIT binary patch literal 3066 zcmb7GYg5}s6ut5rV;pJ{5{Ev3Py!~7n$~$VP!dcMLgRpo18JJRWP1UnLUJV;N;~}r z{V~lh#=|uw`Rs;DdLy(%yT{z31*-|NGyce-lxGs!1BAl>|K;pfj{O zNT1WAIF*tVr4=3?^RULR*ArCc`HKW?@LWmIlQ?b0X-lDW(-HQDXjqQ!TK1trGbN{? z)r7O#bX`NJcI%V6*|Bq8q3lM}boD*4r8|1n5KE?Mxtgn6rlZiUl4b9xPQ%vCoo!p& z69<<4gIX1u>8RUUjj>d%WuPuKUF$%%MICNq3%aShiwcEjX2CGBY}JKAXG*#$)|z`& zVL#D;rckD2)ih&EvvpqkFC*@*4*0GpYL@BRmSG56MzP#l0xr5M48v0B?96QGg|@G$ zhGy=l6_=UgbMHV7L{+WoW<40ghWN259QU!-Xn3a4ea&csXiW7X26u$JWEh-Ca2)Lb zTy=%baR73lqVJfR+q7YOt>>n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/classes/spaceshuttle/repository/UserRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..3bb85e03454736f8a11e2de5f4faab2fad9a4362 GIT binary patch literal 465 zcmb7>!Ab)$5Qb-J?b@nE@D)V#VnDpDC@6Re2rfQA+)dZibhAzprLX3}2k@c9i3@gn z5cDvRf0&u?pUKDP+dBZ9!8C*I40bZuMVQV^Q(Z0Zy{1MjG{V7=oU0cltZHge1TsyX zA9tx3j1|)OkRyx>Q#UF^;+D%lw46)ds#5#M7=qPe;VNxKqUIMo?YYOieVFSqndn*A%O}ANf0@H(okkC^096i&W|xV|j)BWMwt!B%J`^ vaLsd%yIzg3w>nv8AK~=>{znK11C9;;CLAIRVUyK})c`V%?zIKu@66;2SiqAh literal 0 HcmV?d00001 diff --git a/out/production/resources/application.properties b/out/production/resources/application.properties new file mode 100644 index 0000000..a96e416 --- /dev/null +++ b/out/production/resources/application.properties @@ -0,0 +1,6 @@ +#spring.jpa.hibernate.ddl-auto=create +spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:mysql://localhost:3306/spaceshuttle +spring.datasource.username=spaceshuttle +spring.datasource.password=spaceshuttle +thisisgood=true \ No newline at end of file diff --git a/src/main/java/spaceshuttle/controller/UserController.java b/src/main/java/spaceshuttle/controller/UserController.java index 7cab56e..75d4f10 100644 --- a/src/main/java/spaceshuttle/controller/UserController.java +++ b/src/main/java/spaceshuttle/controller/UserController.java @@ -46,4 +46,33 @@ User addUser(@RequestBody User newUser) { // @RequestParam means it is a parameter from the GET or POST request return userRepository.save(newUser); } + + // Homework 1: GET user by id + @GetMapping(value = "/{id}") + public @ResponseBody + User getUserById(@PathVariable Long id) { + return userRepository.findOne(id); + } + + // Homework 2: PUT user by id + @PutMapping(value = "/{id}") + public @ResponseBody + String updateUserById(@PathVariable Long id, + @RequestParam String username, + @RequestParam String password) { + User user = userRepository.findOne(id); + user.setUsername(username); + user.setPassword(password); + userRepository.save(user); + return "Updated"; + } + + // Homework 3: DELETE user by id + @DeleteMapping(value = "/{id}") + public @ResponseBody + String deleteUserById(@PathVariable Long id) { + userRepository.delete(id); + return "Deleted"; + } + } \ No newline at end of file From fa824a320c92b7b30a1efb62d44c434318c22009 Mon Sep 17 00:00:00 2001 From: Evie Ma Date: Thu, 19 Oct 2017 11:08:41 +1100 Subject: [PATCH 2/5] delete dir out/production --- .../classes/spaceshuttle/Application.class | Bin 2223 -> 0 bytes .../spaceshuttle/controller/UserController.class | Bin 3066 -> 0 bytes .../classes/spaceshuttle/model/User.class | Bin 972 -> 0 bytes .../spaceshuttle/repository/UserRepository.class | Bin 465 -> 0 bytes out/production/resources/application.properties | 6 ------ 5 files changed, 6 deletions(-) delete mode 100644 out/production/classes/spaceshuttle/Application.class delete mode 100644 out/production/classes/spaceshuttle/controller/UserController.class delete mode 100644 out/production/classes/spaceshuttle/model/User.class delete mode 100644 out/production/classes/spaceshuttle/repository/UserRepository.class delete mode 100644 out/production/resources/application.properties diff --git a/out/production/classes/spaceshuttle/Application.class b/out/production/classes/spaceshuttle/Application.class deleted file mode 100644 index 81f40d546b05f1ce5a9b023e9aa1f36c1e0e7575..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2223 zcmb7FT~`}b6x}x@83?IRXrQ2CtkfnH7+Nc>O>Kp=*lM7)LF&g^u5}YGVM;QSHFJaT z?l1AhSM@=$5B&iye~3T9C+og5&02XP%YGWY;DEtCY(w;b2ew*~qN#SMXE+1peCLlwtWYn@h2 z`RlUQq-3Px)n#)-`i?mt3X^)<2?Qo9L0i^Uu-(zRsqCe8yXn-Wc088>k}c`D0%L`* zD^KOFw42gx*j4R2Zle@NlzxLgMtfWfoUMDUmUK4_oW~v4RldMCg^K4l?4WI2Z27XK zzV-YayY9JK?df>*awIAhdm7X{Put~x`zPYQy5195=xKCH6oCms)J{unIDtcwmR#4< zAq~uL?o@a3rK-KGq@iuHDO>t6SEir`yN3M!8l$a|LQ~)qM=2s`R$E84RVdG>lO$%SL6~ zLOF}OxMxbO^ray0xItUhbzX0)yvaMrw|#Hd*;JeP+I~L5lQ&*DIV)LwjQb=ZiwF3` z!lzkOu*#@i5+Bx{(wo5it92_!q3h!%xdJo2+=RSE$YLz9h5Zg^u3m`MG=fv=)d)RH za@6S@qOc-n>|-$~Hse;xU=0s5NZ`@2M;cz_r5rYglo!MC;Ic{`o9 zK=y%oy2?!%1P0|F@w5*8MNN92Z(UOb(~)5*R=&gRW0GTr>-%jLSO5Q)QOMJ6izmaD zWwTjzv?^KnQsCkVetP92Fm<{f-ex0Z_>%=BK|+z`_Y6-qSHU$k^DD$p+$8WCzv)nz z#Sr&Kl?oWfS*`;Z!6+rhc#+!Xu74ykbAY}lU3=5FptVJ-u8)44LymGb2ga#ke3W=H zy4K}qgoYovjYBvWnvX>)hY+ZY^O&IFB()9H*MZ@TX{bY|2V5=Q-S`=)k@PRHW`0Az z!0PM)24>gho-Zc*7E`%YF8Mvi=W?m5H`7#{FpA%$#1Ak2G>Ply diff --git a/out/production/classes/spaceshuttle/controller/UserController.class b/out/production/classes/spaceshuttle/controller/UserController.class deleted file mode 100644 index a1a0dd4fb6cb8072cd54ba3ac80f12917561a7b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3066 zcmb7GYg5}s6ut5rV;pJ{5{Ev3Py!~7n$~$VP!dcMLgRpo18JJRWP1UnLUJV;N;~}r z{V~lh#=|uw`Rs;DdLy(%yT{z31*-|NGyce-lxGs!1BAl>|K;pfj{O zNT1WAIF*tVr4=3?^RULR*ArCc`HKW?@LWmIlQ?b0X-lDW(-HQDXjqQ!TK1trGbN{? z)r7O#bX`NJcI%V6*|Bq8q3lM}boD*4r8|1n5KE?Mxtgn6rlZiUl4b9xPQ%vCoo!p& z69<<4gIX1u>8RUUjj>d%WuPuKUF$%%MICNq3%aShiwcEjX2CGBY}JKAXG*#$)|z`& zVL#D;rckD2)ih&EvvpqkFC*@*4*0GpYL@BRmSG56MzP#l0xr5M48v0B?96QGg|@G$ zhGy=l6_=Ugb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bI(qBpUJl?z626%G!fZvdCxy1kg diff --git a/out/production/classes/spaceshuttle/repository/UserRepository.class b/out/production/classes/spaceshuttle/repository/UserRepository.class deleted file mode 100644 index 3bb85e03454736f8a11e2de5f4faab2fad9a4362..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 465 zcmb7>!Ab)$5Qb-J?b@nE@D)V#VnDpDC@6Re2rfQA+)dZibhAzprLX3}2k@c9i3@gn z5cDvRf0&u?pUKDP+dBZ9!8C*I40bZuMVQV^Q(Z0Zy{1MjG{V7=oU0cltZHge1TsyX zA9tx3j1|)OkRyx>Q#UF^;+D%lw46)ds#5#M7=qPe;VNxKqUIMo?YYOieVFSqndn*A%O}ANf0@H(okkC^096i&W|xV|j)BWMwt!B%J`^ vaLsd%yIzg3w>nv8AK~=>{znK11C9;;CLAIRVUyK})c`V%?zIKu@66;2SiqAh diff --git a/out/production/resources/application.properties b/out/production/resources/application.properties deleted file mode 100644 index a96e416..0000000 --- a/out/production/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -#spring.jpa.hibernate.ddl-auto=create -spring.jpa.hibernate.ddl-auto=update -spring.datasource.url=jdbc:mysql://localhost:3306/spaceshuttle -spring.datasource.username=spaceshuttle -spring.datasource.password=spaceshuttle -thisisgood=true \ No newline at end of file From 649cb665864b4c952d6b857b556983c42076ba07 Mon Sep 17 00:00:00 2001 From: Evie Ma Date: Thu, 19 Oct 2017 11:25:24 +1100 Subject: [PATCH 3/5] update .gitignore to add out/ --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bdcbe24..79da8e2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ .idea/ *.iml *.iws +out/ # Mac .DS_Store @@ -17,4 +18,4 @@ target/ #gradle .gradle -build/ \ No newline at end of file +build/ From c593a10b3604e7654479c648e6828fc37989dd57 Mon Sep 17 00:00:00 2001 From: Evie Ma Date: Thu, 19 Oct 2017 15:21:54 +1100 Subject: [PATCH 4/5] add getter & setter for user id --- src/main/java/spaceshuttle/model/User.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/spaceshuttle/model/User.java b/src/main/java/spaceshuttle/model/User.java index b9a59e3..1584a63 100644 --- a/src/main/java/spaceshuttle/model/User.java +++ b/src/main/java/spaceshuttle/model/User.java @@ -7,12 +7,21 @@ @Entity public class User { + @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String username; private String password; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public String getUsername() { return username; } From 2c7288fc918ad18f2ce2678066341e5a56d32273 Mon Sep 17 00:00:00 2001 From: Evie Ma Date: Fri, 20 Oct 2017 12:55:04 +1100 Subject: [PATCH 5/5] change return type String to void for updateUserById & deleteUserById --- src/main/java/spaceshuttle/controller/UserController.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/spaceshuttle/controller/UserController.java b/src/main/java/spaceshuttle/controller/UserController.java index 75d4f10..4bec930 100644 --- a/src/main/java/spaceshuttle/controller/UserController.java +++ b/src/main/java/spaceshuttle/controller/UserController.java @@ -57,22 +57,20 @@ User getUserById(@PathVariable Long id) { // Homework 2: PUT user by id @PutMapping(value = "/{id}") public @ResponseBody - String updateUserById(@PathVariable Long id, + void updateUserById(@PathVariable Long id, @RequestParam String username, @RequestParam String password) { User user = userRepository.findOne(id); user.setUsername(username); user.setPassword(password); userRepository.save(user); - return "Updated"; } // Homework 3: DELETE user by id @DeleteMapping(value = "/{id}") public @ResponseBody - String deleteUserById(@PathVariable Long id) { + void deleteUserById(@PathVariable Long id) { userRepository.delete(id); - return "Deleted"; } } \ No newline at end of file