Skip to content

Commit f77c4d3

Browse files
committed
Initial Commit
1 parent 08535ba commit f77c4d3

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

src/main/java/com/webservice/mobile/app/service/UserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public interface UserService extends UserDetailsService {
77
UserDTO createUser(UserDTO userDTO);
88
UserDTO getUser(String email);
99
UserDTO getUserByUserId(String userId);
10-
1110
UserDTO updateUser(String userId, UserDTO user);
11+
void deleteUser(String userId);
1212
}

src/main/java/com/webservice/mobile/app/service/impl/UserServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ public UserDTO updateUser(String userId, UserDTO user) {
9292
return returnValue;
9393
}
9494

95+
@Override
96+
public void deleteUser(String userId) {
97+
98+
UserEntity userEntity = userRepository.findByUserId(userId);
99+
if (userEntity == null) throw new
100+
UserServiceException((ErrorMessages.NO_RECORD_FOUND.getErrorMessage()));
101+
userRepository.delete(userEntity);
102+
103+
}
104+
95105
@Override
96106
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
97107
UserEntity userEntity= userRepository.findUserByEmail(email);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.webservice.mobile.app.ui.controller;
2+
3+
public enum RequestOperationName {
4+
DELETE
5+
}

src/main/java/com/webservice/mobile/app/ui/controller/UserController.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.webservice.mobile.app.shared.dto.UserDTO;
66
import com.webservice.mobile.app.ui.model.request.UserDetailsRequestModel;
77
import com.webservice.mobile.app.ui.model.response.ErrorMessages;
8+
import com.webservice.mobile.app.ui.model.response.OperationStatusModel;
9+
import com.webservice.mobile.app.ui.model.response.RequestOperationStatus;
810
import com.webservice.mobile.app.ui.model.response.UserRest;
911
import org.springframework.beans.BeanUtils;
1012
import org.springframework.beans.factory.annotation.Autowired;
@@ -64,17 +66,23 @@ public UserRest updateUser(@PathVariable String id, @RequestBody UserDetailsRequ
6466

6567
UserDTO userDTO = new UserDTO();
6668
BeanUtils.copyProperties(userDetails,userDTO);
67-
6869
UserDTO updateUser = userService.updateUser(id,userDTO);
6970
BeanUtils.copyProperties(updateUser,returnValue);
7071

71-
7272
return returnValue;
7373
}
7474

75-
@DeleteMapping
76-
public String deleteUser(){
77-
return "delete user was called";
75+
@DeleteMapping(path = "/{id}",produces = {MediaType.APPLICATION_XML_VALUE,
76+
MediaType.APPLICATION_JSON_VALUE})
77+
public OperationStatusModel deleteUser(@PathVariable String id){
78+
OperationStatusModel returnValue = new OperationStatusModel();
79+
returnValue.setOperationName(RequestOperationName.DELETE.name());
80+
81+
userService.deleteUser(id);
82+
83+
returnValue.setOperationResult(RequestOperationStatus.SUCCESS.name());
84+
85+
return returnValue;
7886
}
7987

8088

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.webservice.mobile.app.ui.model.response;
2+
3+
public class OperationStatusModel {
4+
private String operationResult;
5+
private String operationName;
6+
7+
8+
public String getOperationResult() {
9+
return operationResult;
10+
}
11+
12+
public void setOperationResult(String operationResult) {
13+
this.operationResult = operationResult;
14+
}
15+
16+
public String getOperationName() {
17+
return operationName;
18+
}
19+
20+
public void setOperationName(String operationName) {
21+
this.operationName = operationName;
22+
}
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.webservice.mobile.app.ui.model.response;
2+
3+
public enum RequestOperationStatus {
4+
5+
ERROR, SUCCESS
6+
}
7+

0 commit comments

Comments
 (0)