diff --git a/src/main/java/com/ays/user/controller/UserController.java b/src/main/java/com/ays/user/controller/UserController.java index b1a0a2cbf..526c65c48 100644 --- a/src/main/java/com/ays/user/controller/UserController.java +++ b/src/main/java/com/ays/user/controller/UserController.java @@ -8,10 +8,8 @@ import com.ays.user.model.dto.request.UserSaveRequest; import com.ays.user.model.dto.request.UserUpdateRequest; import com.ays.user.model.dto.response.UserResponse; -import com.ays.user.model.dto.response.UserSavedResponse; import com.ays.user.model.dto.response.UsersResponse; import com.ays.user.model.mapper.UserToUserResponseMapper; -import com.ays.user.model.mapper.UserToUserSavedResponseMapper; import com.ays.user.model.mapper.UserToUsersResponseMapper; import com.ays.user.service.UserSaveService; import com.ays.user.service.UserService; @@ -36,7 +34,6 @@ class UserController { private final UserService userService; private final UserSaveService userSaveService; - private final UserToUserSavedResponseMapper userToUserSavedResponseMapper = UserToUserSavedResponseMapper.initialize(); private final UserToUserResponseMapper userToUserResponseMapper = UserToUserResponseMapper.initialize(); private final UserToUsersResponseMapper userToUsersResponseMapper = UserToUsersResponseMapper.initialize(); @@ -83,10 +80,9 @@ public AysResponse getUserById(@PathVariable @UUID String id) { */ @PostMapping("/user") @PreAuthorize("hasAnyAuthority('ADMIN')") - public AysResponse saveUser(@RequestBody @Valid UserSaveRequest saveRequest) { - User user = userSaveService.saveUser(saveRequest); - UserSavedResponse userSavedResponse = userToUserSavedResponseMapper.map(user); - return AysResponse.successOf(userSavedResponse); + public AysResponse saveUser(@RequestBody @Valid UserSaveRequest saveRequest) { + userSaveService.saveUser(saveRequest); + return AysResponse.SUCCESS; } /** diff --git a/src/main/java/com/ays/user/model/dto/response/UserSavedResponse.java b/src/main/java/com/ays/user/model/dto/response/UserSavedResponse.java deleted file mode 100644 index 991b779c5..000000000 --- a/src/main/java/com/ays/user/model/dto/response/UserSavedResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.ays.user.model.dto.response; - -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -/** - * A DTO class representing the response data returned when a user is saved. - *

- * This class provides getters and setters for the username and password fields. - * It also includes a builder pattern implementation for constructing instances of this class with optional parameters. - *

- * The purpose of this class is to encapsulate the response data related to saving a user, allowing for easy - * transfer of the data between different layers of the application. - */ -@Getter -@Setter -@Builder -public class UserSavedResponse { - - /** - * This field is created by the application. - */ - private String username; - - /** - * This field is created by the application. - */ - private String password; - -} diff --git a/src/main/java/com/ays/user/model/mapper/UserToUserSavedResponseMapper.java b/src/main/java/com/ays/user/model/mapper/UserToUserSavedResponseMapper.java deleted file mode 100644 index 6b07b558d..000000000 --- a/src/main/java/com/ays/user/model/mapper/UserToUserSavedResponseMapper.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ays.user.model.mapper; - -import com.ays.common.model.mapper.BaseMapper; -import com.ays.user.model.User; -import com.ays.user.model.dto.response.UserSavedResponse; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -/** - * UserToUserResponseMapper is an interface that defines the mapping between an {@link User} and an {@link UserSavedResponse}. - * This interface uses the MapStruct annotation @Mapper to generate an implementation of this interface at compile-time. - *

The class provides a static method {@code initialize()} that returns an instance of the generated mapper implementation. - *

The interface extends the MapStruct interface {@link BaseMapper}, which defines basic mapping methods. - * The interface adds no additional mapping methods, but simply defines the types to be used in the mapping process. - */ -@Mapper -public interface UserToUserSavedResponseMapper extends BaseMapper { - - /** - * Initializes the mapper. - * - * @return the initialized mapper object. - */ - static UserToUserSavedResponseMapper initialize() { - return Mappers.getMapper(UserToUserSavedResponseMapper.class); - } - -} diff --git a/src/main/java/com/ays/user/service/UserSaveService.java b/src/main/java/com/ays/user/service/UserSaveService.java index 03f433863..a41be6860 100644 --- a/src/main/java/com/ays/user/service/UserSaveService.java +++ b/src/main/java/com/ays/user/service/UserSaveService.java @@ -12,8 +12,7 @@ public interface UserSaveService { * Saves a saveRequest to the database. * * @param saveRequest the UserSaveRequest entity - * @return User */ - User saveUser(UserSaveRequest saveRequest); + void saveUser(UserSaveRequest saveRequest); } diff --git a/src/main/java/com/ays/user/service/impl/UserSaveServiceImpl.java b/src/main/java/com/ays/user/service/impl/UserSaveServiceImpl.java index 27ff216a7..195480355 100644 --- a/src/main/java/com/ays/user/service/impl/UserSaveServiceImpl.java +++ b/src/main/java/com/ays/user/service/impl/UserSaveServiceImpl.java @@ -36,10 +36,9 @@ class UserSaveServiceImpl implements UserSaveService { * Saves a new user based on the provided save request. * * @param saveRequest the request object containing user data to be saved - * @return the saved user * @throws AysUserAlreadyExistsByPhoneNumberException if a user with the same phone number already exists */ - public User saveUser(final UserSaveRequest saveRequest) { + public void saveUser(final UserSaveRequest saveRequest) { final List usersFromDatabase = userRepository.findAll(); @@ -58,11 +57,6 @@ public User saveUser(final UserSaveRequest saveRequest) { ); userRepository.save(userEntity); - - return User.builder() - .username(username) - .password(password) - .build(); } /** diff --git a/src/test/java/com/ays/user/controller/UserControllerTest.java b/src/test/java/com/ays/user/controller/UserControllerTest.java index d92d5de02..1eeebff51 100644 --- a/src/test/java/com/ays/user/controller/UserControllerTest.java +++ b/src/test/java/com/ays/user/controller/UserControllerTest.java @@ -14,8 +14,6 @@ import com.ays.user.model.UserBuilder; import com.ays.user.model.dto.request.*; import com.ays.user.model.dto.response.UserResponse; -import com.ays.user.model.dto.response.UserSavedResponse; -import com.ays.user.model.dto.response.UserSavedResponseBuilder; import com.ays.user.model.dto.response.UsersResponse; import com.ays.user.model.entity.UserEntity; import com.ays.user.model.entity.UserEntityBuilder; @@ -35,7 +33,6 @@ import org.springframework.data.domain.PageImpl; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import java.util.List; @@ -62,20 +59,11 @@ void givenValidUserSaveRequest_whenUserSaved_thenReturnUserSavedResponse() throw .build(); // When - User mockUser = new UserBuilder() - .withUsername("123456") - .withPassword("987654") - .withStatus(UserStatus.ACTIVE).build(); - Mockito.when(userSaveService.saveUser(Mockito.any(UserSaveRequest.class))) - .thenReturn(mockUser); + Mockito.doNothing().when(userSaveService).saveUser(Mockito.any(UserSaveRequest.class)); // Then String endpoint = BASE_PATH.concat("/user"); - UserSavedResponse mockUserSavedResponse = new UserSavedResponseBuilder() - .withUsername(mockUser.getUsername()) - .withPassword(mockUser.getPassword()) - .build(); - AysResponse mockResponse = AysResponseBuilder.successOf(mockUserSavedResponse); + AysResponse mockResponse = AysResponseBuilder.SUCCESS; mockMvc.perform(AysMockMvcRequestBuilders .post(endpoint, mockAdminUserToken.getAccessToken(), mockUserSaveRequest)) .andDo(MockMvcResultHandlers.print()) @@ -87,11 +75,7 @@ void givenValidUserSaveRequest_whenUserSaved_thenReturnUserSavedResponse() throw .andExpect(AysMockResultMatchersBuilders.isSuccess() .value(mockResponse.getIsSuccess())) .andExpect(AysMockResultMatchersBuilders.response() - .isNotEmpty()) - .andExpect(MockMvcResultMatchers.jsonPath("$.response.username") - .value(mockResponse.getResponse().getUsername())) - .andExpect(MockMvcResultMatchers.jsonPath("$.response.password") - .value(mockResponse.getResponse().getPassword())); + .doesNotExist()); Mockito.verify(userSaveService, Mockito.times(1)) .saveUser(Mockito.any(UserSaveRequest.class)); diff --git a/src/test/java/com/ays/user/controller/UserSystemTest.java b/src/test/java/com/ays/user/controller/UserSystemTest.java index f37cae2d5..18485badd 100644 --- a/src/test/java/com/ays/user/controller/UserSystemTest.java +++ b/src/test/java/com/ays/user/controller/UserSystemTest.java @@ -13,8 +13,6 @@ import com.ays.user.model.UserBuilder; import com.ays.user.model.dto.request.*; import com.ays.user.model.dto.response.UserResponse; -import com.ays.user.model.dto.response.UserSavedResponse; -import com.ays.user.model.dto.response.UserSavedResponseBuilder; import com.ays.user.model.dto.response.UsersResponse; import com.ays.user.model.entity.UserEntity; import com.ays.user.model.entity.UserEntityBuilder; @@ -31,7 +29,6 @@ import org.springframework.data.domain.PageImpl; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import java.util.List; @@ -53,8 +50,7 @@ void givenValidUserSaveRequest_whenUserSaved_thenReturnUserSavedResponse() throw // Then String endpoint = BASE_PATH.concat("/user"); - UserSavedResponse userSavedResponse = new UserSavedResponseBuilder().build(); - AysResponse response = AysResponseBuilder.successOf(userSavedResponse); + AysResponse response = AysResponseBuilder.SUCCESS; mockMvc.perform(AysMockMvcRequestBuilders .post(endpoint, adminUserTokenOne.getAccessToken(), userSaveRequest)) .andDo(MockMvcResultHandlers.print()) @@ -66,11 +62,7 @@ void givenValidUserSaveRequest_whenUserSaved_thenReturnUserSavedResponse() throw .andExpect(AysMockResultMatchersBuilders.isSuccess() .value(response.getIsSuccess())) .andExpect(AysMockResultMatchersBuilders.response() - .isNotEmpty()) - .andExpect(MockMvcResultMatchers.jsonPath("$.response.username") - .isNotEmpty()) - .andExpect(MockMvcResultMatchers.jsonPath("$.response.password") - .isNotEmpty()); + .doesNotExist()); } @Test diff --git a/src/test/java/com/ays/user/model/dto/response/UserSavedResponseBuilder.java b/src/test/java/com/ays/user/model/dto/response/UserSavedResponseBuilder.java deleted file mode 100644 index e05228e84..000000000 --- a/src/test/java/com/ays/user/model/dto/response/UserSavedResponseBuilder.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ays.user.model.dto.response; - -import com.ays.common.model.TestDataBuilder; - -public class UserSavedResponseBuilder extends TestDataBuilder { - - public UserSavedResponseBuilder() { - super(UserSavedResponse.class); - } - - public UserSavedResponseBuilder withUsername(String username) { - data.setUsername(username); - return this; - } - - public UserSavedResponseBuilder withPassword(String password) { - data.setPassword(password); - return this; - } - -} diff --git a/src/test/java/com/ays/user/service/impl/UserSaveServiceImplTest.java b/src/test/java/com/ays/user/service/impl/UserSaveServiceImplTest.java index 083b27722..cc0ed1ee8 100644 --- a/src/test/java/com/ays/user/service/impl/UserSaveServiceImplTest.java +++ b/src/test/java/com/ays/user/service/impl/UserSaveServiceImplTest.java @@ -57,13 +57,8 @@ void givenValidUserSaveRequest_whenUserSaved_thenReturnUser() { .thenReturn(AysRandomUtil.generateUUID()); // Then - User user = userSaveService.saveUser(mockUserSaveRequest); - - Assertions.assertNotNull(user.getUsername()); - Assertions.assertEquals(6, user.getUsername().length()); - Assertions.assertNotNull(user.getPassword()); - Assertions.assertEquals(6, user.getPassword().length()); - + userSaveService.saveUser(mockUserSaveRequest); + Mockito.verify(userRepository, Mockito.times(1)).findAll(); Mockito.verify(identity, Mockito.times(1)).getInstitutionId(); Mockito.verify(passwordEncoder, Mockito.times(1)).encode(Mockito.anyString());