diff --git a/server/src/main/java/com/mixel/docusphere/controller/UserController.java b/server/src/main/java/com/mixel/docusphere/controller/UserController.java index 9ab56ae..20e3bfb 100644 --- a/server/src/main/java/com/mixel/docusphere/controller/UserController.java +++ b/server/src/main/java/com/mixel/docusphere/controller/UserController.java @@ -1,7 +1,7 @@ package com.mixel.docusphere.controller; -import com.mixel.docusphere.dto.UserDTO; -import com.mixel.docusphere.entity.User; +import com.mixel.docusphere.dto.request.UserRequestDTO; +import com.mixel.docusphere.dto.response.UserRespondDTO; import com.mixel.docusphere.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -23,24 +23,24 @@ public class UserController { } @GetMapping - public List getAllUsers() { + public List getAllUsers() { return userService.findAll(); } @GetMapping("/{id}") - public ResponseEntity getUserById(@PathVariable UUID id) { - Optional user = userService.findById(id); + public ResponseEntity getUserById(@PathVariable UUID id) { + Optional user = userService.findById(id); return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } @PostMapping - public UserDTO createUser(@RequestBody UserDTO userDTO) { - return userService.save(userDTO); + public UserRespondDTO createUser(@RequestBody UserRequestDTO userRequestDTO) { + return userService.save(userRequestDTO); } @PutMapping("/{id}") - public ResponseEntity updateUser(@PathVariable UUID id, @RequestBody UserDTO userDTO) { - Optional updatedUser = userService.update(id, userDTO); + public ResponseEntity updateUser(@PathVariable UUID id, @RequestBody UserRequestDTO userRequestDTO) { + Optional updatedUser = userService.update(id, userRequestDTO); return updatedUser.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } diff --git a/server/src/main/java/com/mixel/docusphere/dto/DocumentDTO.java b/server/src/main/java/com/mixel/docusphere/dto/request/DocumentRequestDTO.java similarity index 65% rename from server/src/main/java/com/mixel/docusphere/dto/DocumentDTO.java rename to server/src/main/java/com/mixel/docusphere/dto/request/DocumentRequestDTO.java index 21eb4ef..59bc0d2 100644 --- a/server/src/main/java/com/mixel/docusphere/dto/DocumentDTO.java +++ b/server/src/main/java/com/mixel/docusphere/dto/request/DocumentRequestDTO.java @@ -1,10 +1,12 @@ -package com.mixel.docusphere.dto; +package com.mixel.docusphere.dto.request; -public class DocumentDTO { +import org.springframework.web.multipart.MultipartFile; + +public class DocumentRequestDTO { private String name; private String description; - private String s3Path; private String userId; + private MultipartFile file; // Getters and Setters public String getName() { @@ -23,14 +25,6 @@ public class DocumentDTO { this.description = description; } - public String getS3Path() { - return s3Path; - } - - public void setS3Path(String s3Path) { - this.s3Path = s3Path; - } - public String getUserId() { return userId; } @@ -38,4 +32,12 @@ public class DocumentDTO { public void setUserId(String userId) { this.userId = userId; } + + public MultipartFile getFile() { + return file; + } + + public void setFile(MultipartFile file) { + this.file = file; + } } diff --git a/server/src/main/java/com/mixel/docusphere/dto/UserDTO.java b/server/src/main/java/com/mixel/docusphere/dto/request/UserRequestDTO.java similarity index 94% rename from server/src/main/java/com/mixel/docusphere/dto/UserDTO.java rename to server/src/main/java/com/mixel/docusphere/dto/request/UserRequestDTO.java index ec85724..01070f0 100644 --- a/server/src/main/java/com/mixel/docusphere/dto/UserDTO.java +++ b/server/src/main/java/com/mixel/docusphere/dto/request/UserRequestDTO.java @@ -1,8 +1,8 @@ -package com.mixel.docusphere.dto; +package com.mixel.docusphere.dto.request; import java.time.LocalDateTime; -public class UserDTO { +public class UserRequestDTO { private String username; private String name; private String email; diff --git a/server/src/main/java/com/mixel/docusphere/dto/response/UserRespondDTO.java b/server/src/main/java/com/mixel/docusphere/dto/response/UserRespondDTO.java new file mode 100644 index 0000000..d6de897 --- /dev/null +++ b/server/src/main/java/com/mixel/docusphere/dto/response/UserRespondDTO.java @@ -0,0 +1,62 @@ +package com.mixel.docusphere.dto.response; + +import java.time.LocalDateTime; +import java.util.UUID; + +public class UserRespondDTO { + private UUID userId; + private String username; + private String name; + private String email; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + // Getters and Setters + public UUID getUserId() { + return userId; + } + + public void setUserId(UUID userId) { + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } +} diff --git a/server/src/main/java/com/mixel/docusphere/mapper/UserMapper.java b/server/src/main/java/com/mixel/docusphere/mapper/UserMapper.java index d52abb5..9bfd4a4 100644 --- a/server/src/main/java/com/mixel/docusphere/mapper/UserMapper.java +++ b/server/src/main/java/com/mixel/docusphere/mapper/UserMapper.java @@ -1,25 +1,38 @@ package com.mixel.docusphere.mapper; -import com.mixel.docusphere.dto.UserDTO; +import com.mixel.docusphere.dto.request.UserRequestDTO; +import com.mixel.docusphere.dto.response.UserRespondDTO; import com.mixel.docusphere.entity.User; public class UserMapper { - public static UserDTO toDTO(User user) { - UserDTO userDTO = new UserDTO(); - userDTO.setUsername(user.getUsername()); - userDTO.setName(user.getName()); - userDTO.setEmail(user.getEmail()); - userDTO.setCreatedAt(user.getCreatedAt()); - userDTO.setUpdatedAt(user.getUpdatedAt()); + public static UserRequestDTO toRequestDTO(User user) { + UserRequestDTO userRequestDTO = new UserRequestDTO(); + userRequestDTO.setUsername(user.getUsername()); + userRequestDTO.setName(user.getName()); + userRequestDTO.setEmail(user.getEmail()); + userRequestDTO.setCreatedAt(user.getCreatedAt()); + userRequestDTO.setUpdatedAt(user.getUpdatedAt()); - return userDTO; + return userRequestDTO; } - public static User toEntity(UserDTO userDTO) { + public static UserRespondDTO toRespondDTO(User user) { + UserRespondDTO userRespondDTO = new UserRespondDTO(); + userRespondDTO.setUserId(user.getUserId()); + userRespondDTO.setUsername(user.getUsername()); + userRespondDTO.setName(user.getName()); + userRespondDTO.setEmail(user.getEmail()); + userRespondDTO.setCreatedAt(user.getCreatedAt()); + userRespondDTO.setUpdatedAt(user.getUpdatedAt()); + + return userRespondDTO; + } + + public static User toEntity(UserRequestDTO userRequestDTO) { User user = new User(); - user.setUsername(userDTO.getUsername()); - user.setName(userDTO.getName()); - user.setEmail(userDTO.getEmail()); + user.setUsername(userRequestDTO.getUsername()); + user.setName(userRequestDTO.getName()); + user.setEmail(userRequestDTO.getEmail()); return user; } diff --git a/server/src/main/java/com/mixel/docusphere/service/UserService.java b/server/src/main/java/com/mixel/docusphere/service/UserService.java index ba467d6..1241d80 100644 --- a/server/src/main/java/com/mixel/docusphere/service/UserService.java +++ b/server/src/main/java/com/mixel/docusphere/service/UserService.java @@ -1,6 +1,7 @@ package com.mixel.docusphere.service; -import com.mixel.docusphere.dto.UserDTO; +import com.mixel.docusphere.dto.request.UserRequestDTO; +import com.mixel.docusphere.dto.response.UserRespondDTO; import com.mixel.docusphere.entity.User; import com.mixel.docusphere.mapper.UserMapper; import com.mixel.docusphere.repository.UserRepository; @@ -25,40 +26,40 @@ public class UserService { this.userRepository = userRepository; } - public List findAll() { + public List findAll() { return userRepository.findAll().stream() - .map(UserMapper::toDTO) + .map(UserMapper::toRespondDTO) .collect(Collectors.toList()); } - public Optional findById(UUID id) { + public Optional findById(UUID id) { return userRepository.findById(id) - .map(UserMapper::toDTO); + .map(UserMapper::toRespondDTO); } - public UserDTO save(UserDTO userDTO) { - User user = UserMapper.toEntity(userDTO); - isPasswordAlreadySet(userDTO, user); - return UserMapper.toDTO(userRepository.save(user)); + public UserRespondDTO save(UserRequestDTO userRequestDTO) { + User user = UserMapper.toEntity(userRequestDTO); + isPasswordAlreadySet(userRequestDTO, user); + return UserMapper.toRespondDTO(userRepository.save(user)); } - public Optional update(UUID id, UserDTO userDTO){ + public Optional update(UUID id, UserRequestDTO userRequestDTO){ Optional userOptional = userRepository.findById(id); if (userOptional.isPresent()) { User user = userOptional.get(); - user.setUsername(userDTO.getUsername()); - user.setName(userDTO.getName()); - user.setEmail(userDTO.getEmail()); + user.setUsername(userRequestDTO.getUsername()); + user.setName(userRequestDTO.getName()); + user.setEmail(userRequestDTO.getEmail()); - isPasswordAlreadySet(userDTO, user); - return Optional.of(UserMapper.toDTO(userRepository.save(user))); + isPasswordAlreadySet(userRequestDTO, user); + return Optional.of(UserMapper.toRespondDTO(userRepository.save(user))); } return Optional.empty(); } - private void isPasswordAlreadySet(UserDTO userDTO, User user) { - if (userDTO.getPassword() != null && !userDTO.getPassword().isEmpty()) { - user.setPasswordHash(passwordEncoder.encode(userDTO.getPassword())); + private void isPasswordAlreadySet(UserRequestDTO userRequestDTO, User user) { + if (userRequestDTO.getPassword() != null && !userRequestDTO.getPassword().isEmpty()) { + user.setPasswordHash(passwordEncoder.encode(userRequestDTO.getPassword())); } }