diff --git a/src/main/java/edu/university_connect/UniversityConnectApplication.java b/src/main/java/edu/university_connect/UniversityConnectApplication.java index ed714092..91d8ebdd 100644 --- a/src/main/java/edu/university_connect/UniversityConnectApplication.java +++ b/src/main/java/edu/university_connect/UniversityConnectApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing @SpringBootApplication public class UniversityConnectApplication { diff --git a/src/main/java/edu/university_connect/config/Laufe.java b/src/main/java/edu/university_connect/config/Laufe.java index dfdeb53f..4b8673a5 100644 --- a/src/main/java/edu/university_connect/config/Laufe.java +++ b/src/main/java/edu/university_connect/config/Laufe.java @@ -1,11 +1,12 @@ package edu.university_connect.config; -import edu.university_connect.model.entity.SystemAction; -import edu.university_connect.model.entity.SystemRole; -import edu.university_connect.model.entity.SystemUser; -import edu.university_connect.repository.SystemActionRepository; -import edu.university_connect.repository.SystemRoleRepository; -import edu.university_connect.repository.SystemUserRepository; +import edu.university_connect.domain.entity.Action; +import edu.university_connect.domain.entity.Resource; +import edu.university_connect.domain.entity.Role; +import edu.university_connect.domain.entity.User; +import edu.university_connect.repository.ActionRepository; +import edu.university_connect.repository.RoleRepository; +import edu.university_connect.repository.UserRepository; import org.springframework.boot.CommandLineRunner; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Component; @@ -18,51 +19,52 @@ //@Component public class Laufe implements CommandLineRunner { - SystemActionRepository systemActionRepository; - SystemRoleRepository systemRoleRepository; - SystemUserRepository systemUserRepository; + ActionRepository actionRepository; + RoleRepository roleRepository; + UserRepository userRepository; - public Laufe(SystemActionRepository systemActionRepository, SystemRoleRepository systemRoleRepository, SystemUserRepository systemUserRepository) { - this.systemActionRepository = systemActionRepository; - this.systemRoleRepository = systemRoleRepository; - this.systemUserRepository = systemUserRepository; + public Laufe(ActionRepository actionRepository, RoleRepository roleRepository, UserRepository userRepository) { + this.actionRepository = actionRepository; + this.roleRepository = roleRepository; + this.userRepository = userRepository; } @Override public void run(String... args) throws Exception { - SystemAction action1=new SystemAction("Create System User","create_user","Create System User"); - SystemAction action2=new SystemAction("Read System User","view_user","Read System User"); - SystemAction action3=new SystemAction("Update System User","modify_user","Update System User"); - SystemAction action4=new SystemAction("Delete System User","delete_user","Delete System User"); - SystemAction action5=new SystemAction("Read System User List","view_user_list","Read System User List"); + Action action1=new Action("Create User","create_user","Create User"); + Action action2=new Action("Read User","view_user","Read User"); + Action action3=new Action("Update User","modify_user","Update User"); + Action action4=new Action("Delete User","delete_user","Delete User"); + Action action5=new Action("Read User List","view_user_list","Read User List"); - SystemAction action11 = new SystemAction("Create System Role", "create_role", "Create new system roles"); - SystemAction action12 = new SystemAction("Read System Role", "view_role", "View existing system roles"); - SystemAction action13 = new SystemAction("Update System Role", "modify_role", "Modify system role details"); - SystemAction action14 = new SystemAction("Delete System Role", "delete_role", "Delete system roles"); - SystemAction action15=new SystemAction("Read System Action List","view_role_list","Read System role List"); + Action action11 = new Action("Create Role", "create_role", "Create new roles"); + Action action12 = new Action("Read Role", "view_role", "View existing roles"); + Action action13 = new Action("Update Role", "modify_role", "Modify role details"); + Action action14 = new Action("Delete Role", "delete_role", "Delete roles"); + Action action15=new Action("Read Action List","view_role_list","Read role List"); - SystemAction action6 = new SystemAction("Create System Action", "create_action", "Create new system actions"); - SystemAction action7 = new SystemAction("Read System Action", "view_action", "View existing system actions"); - SystemAction action8 = new SystemAction("Update System Action", "modify_action", "Modify system action details"); - SystemAction action9 = new SystemAction("Delete System Action", "delete_action", "Delete system actions"); - SystemAction action10=new SystemAction("Read System Action List","view_action_list","Read System action List"); + Action action6 = new Action("Create Action", "create_action", "Create new actions"); + Action action7 = new Action("Read Action", "view_action", "View existing actions"); + Action action8 = new Action("Update Action", "modify_action", "Modify action details"); + Action action9 = new Action("Delete Action", "delete_action", "Delete actions"); + Action action10=new Action("Read Action List","view_action_list","Read action List"); - systemActionRepository.saveAll(List.of(action1,action2,action3,action4,action5 ,action6,action7,action8,action9,action10 ,action11,action12,action13,action14,action15)); - Set systemActionSet=new HashSet(systemActionRepository.findAll()); - SystemRole role=new SystemRole("SuperUser","superuser","SuperUser",systemActionSet.stream().map(SystemAction::getCode).collect(Collectors.toSet())); - systemRoleRepository.save(role); - Optional roleOpt=systemRoleRepository.findByCodeIgnoreCase("superuser"); + actionRepository.saveAll(List.of(action1,action2,action3,action4,action5 ,action6,action7,action8,action9,action10 ,action11,action12,action13,action14,action15)); + Set actionSet =new HashSet(actionRepository.findAll()); + Role role=new Role("SuperUser","superuser","SuperUser", actionSet.stream().map(Action::getCode).collect(Collectors.toSet())); + roleRepository.save(role); + Optional roleOpt= roleRepository.findByCodeIgnoreCase("superuser"); if(roleOpt.isPresent()){ - Set roles=new HashSet<>(); + Set roles=new HashSet<>(); roles.add(roleOpt.get()); - // Create an encoder with strength 16 - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(16); + // Create an encoder with strength 10 + BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(10); String password = encoder.encode("kush"); - SystemUser user=new SystemUser("kush",password,"kushraj1204@gmail.com"); + User user=new User("kush",password,"kushraj1204@gmail.com"); + user.setEnabled(true); user.setRoles(roles); - systemUserRepository.save(user); + userRepository.save(user); } } } diff --git a/src/main/java/edu/university_connect/config/SecurityConfig.java b/src/main/java/edu/university_connect/config/SecurityConfig.java index 022aaf02..7b1d0262 100644 --- a/src/main/java/edu/university_connect/config/SecurityConfig.java +++ b/src/main/java/edu/university_connect/config/SecurityConfig.java @@ -41,7 +41,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, @Bean public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(16); + return new BCryptPasswordEncoder(); } diff --git a/src/main/java/edu/university_connect/config/jwt/JwtTokenProvider.java b/src/main/java/edu/university_connect/config/jwt/JwtTokenProvider.java index fcea8165..5f25a04a 100644 --- a/src/main/java/edu/university_connect/config/jwt/JwtTokenProvider.java +++ b/src/main/java/edu/university_connect/config/jwt/JwtTokenProvider.java @@ -1,7 +1,7 @@ package edu.university_connect.config.jwt; import edu.university_connect.model.SecurityUser; -import edu.university_connect.model.TokenType; +import edu.university_connect.model.enums.TokenType; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jws; import io.jsonwebtoken.JwtException; diff --git a/src/main/java/edu/university_connect/controller/ActionController.java b/src/main/java/edu/university_connect/controller/ActionController.java new file mode 100644 index 00000000..a58bfab4 --- /dev/null +++ b/src/main/java/edu/university_connect/controller/ActionController.java @@ -0,0 +1,93 @@ +package edu.university_connect.controller; + +import edu.university_connect.model.enums.AppStatusCode; +import edu.university_connect.model.contract.dto.ActionDto; +import edu.university_connect.model.contract.request.action.ActionCreateRequest; +import edu.university_connect.model.contract.request.action.ActionUpdateRequest; +import edu.university_connect.model.contract.response.ApiResponse; +import edu.university_connect.service.MessagingService; +import edu.university_connect.service.action.ActionService; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/action") +@CrossOrigin +@Slf4j +public class ActionController { + private final ActionService service; + + private final MessagingService messagingService; + + public ActionController(ActionService service, MessagingService messagingService) { + this.service = service; + this.messagingService = messagingService; + } + @GetMapping("/all") + public ResponseEntity>> getAll() { + List response= service.getAll(); + ApiResponse> apiResponse = new ApiResponse>(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"action"})); + return ResponseEntity.ok(apiResponse); + } + + @GetMapping("") + public ResponseEntity>> getPage(Pageable pageableReq) { + Pageable pageable = PageRequest.of(pageableReq.getPageNumber()>0? pageableReq.getPageNumber()-1 : 0, + pageableReq.getPageSize() , + pageableReq.getSort()); + Page response= service.getPage(pageable); + ApiResponse> apiResponse = new ApiResponse>(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"action"})); + return ResponseEntity.ok(apiResponse); + + } + @PostMapping("") + public ResponseEntity> create(@Valid @RequestBody ActionCreateRequest createRequest) { + ActionDto response= service.create(createRequest); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20002,new String[]{"action"})); + return ResponseEntity.ok(apiResponse); + + } + + @GetMapping("/{id}") + public ResponseEntity> get(@PathVariable Long id) { + ActionDto response= service.getById(id); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20003,new String[]{"action"})); + return ResponseEntity.ok(apiResponse); + + } + + @PutMapping("/{id}") + public ResponseEntity> update(@Valid @RequestBody ActionUpdateRequest updateRequest, + @PathVariable Long id) { + ActionDto response= service.update(id,updateRequest); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20004,new String[]{"action"})); + return ResponseEntity.ok(apiResponse); + } + + @DeleteMapping("/{id}") + public ResponseEntity> delete(@PathVariable Long id) { + boolean response= service.delete(id); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20005,new String[]{"action"})); + return ResponseEntity.ok(apiResponse); + } + +} diff --git a/src/main/java/edu/university_connect/controller/AuthController.java b/src/main/java/edu/university_connect/controller/AuthController.java index d8702cf3..77db1e42 100644 --- a/src/main/java/edu/university_connect/controller/AuthController.java +++ b/src/main/java/edu/university_connect/controller/AuthController.java @@ -1,12 +1,12 @@ package edu.university_connect.controller; -import edu.university_connect.model.AppStatusCode; +import edu.university_connect.model.enums.AppStatusCode; import edu.university_connect.model.contract.request.auth.AuthenticationRequest; import edu.university_connect.model.contract.request.auth.RefreshTokenRequest; -import edu.university_connect.model.contract.response.common.ApiResponse; -import edu.university_connect.model.contract.response.common.AuthenticationResponse; +import edu.university_connect.model.contract.response.ApiResponse; +import edu.university_connect.model.contract.response.AuthenticationResponse; import edu.university_connect.service.MessagingService; -import edu.university_connect.service.impl.AuthServiceImpl; +import edu.university_connect.service.auth.AuthServiceImpl; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/edu/university_connect/controller/RoleController.java b/src/main/java/edu/university_connect/controller/RoleController.java new file mode 100644 index 00000000..9e180ed0 --- /dev/null +++ b/src/main/java/edu/university_connect/controller/RoleController.java @@ -0,0 +1,92 @@ +package edu.university_connect.controller; + +import edu.university_connect.model.enums.AppStatusCode; +import edu.university_connect.model.contract.dto.RoleDto; +import edu.university_connect.model.contract.request.role.RoleCreateRequest; +import edu.university_connect.model.contract.request.role.RoleUpdateRequest; +import edu.university_connect.model.contract.response.ApiResponse; +import edu.university_connect.service.MessagingService; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/role") +@CrossOrigin +@Slf4j +public class RoleController { + private final MessagingService.RoleService service; + + private final MessagingService messagingService; + + public RoleController(MessagingService.RoleService service, MessagingService messagingService) { + this.service = service; + this.messagingService = messagingService; + } + @GetMapping("/all") + public ResponseEntity>> getAll() { + List response= service.getAll(); + ApiResponse> apiResponse = new ApiResponse>(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"role"})); + return ResponseEntity.ok(apiResponse); + } + + @GetMapping("") + public ResponseEntity>> getPage(Pageable pageableReq) { + Pageable pageable = PageRequest.of(pageableReq.getPageNumber()>0? pageableReq.getPageNumber()-1 : 0, + pageableReq.getPageSize() , + pageableReq.getSort()); + Page response= service.getPage(pageable); + ApiResponse> apiResponse = new ApiResponse>(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"role"})); + return ResponseEntity.ok(apiResponse); + + } + @PostMapping("") + public ResponseEntity> create(@Valid @RequestBody RoleCreateRequest createRequest) { + RoleDto response= service.create(createRequest); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20002,new String[]{"role"})); + return ResponseEntity.ok(apiResponse); + + } + + @GetMapping("/{id}") + public ResponseEntity> get(@PathVariable Long id) { + RoleDto response= service.getById(id); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20003,new String[]{"role"})); + return ResponseEntity.ok(apiResponse); + + } + + @PutMapping("/{id}") + public ResponseEntity> update(@Valid @RequestBody RoleUpdateRequest updateRequest, + @PathVariable Long id) { + RoleDto response= service.update(id,updateRequest); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20004,new String[]{"role"})); + return ResponseEntity.ok(apiResponse); + } + + @DeleteMapping("/{id}") + public ResponseEntity> delete(@PathVariable Long id) { + boolean response= service.delete(id); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20005,new String[]{"role"})); + return ResponseEntity.ok(apiResponse); + } + +} diff --git a/src/main/java/edu/university_connect/controller/SystemActionController.java b/src/main/java/edu/university_connect/controller/SystemActionController.java deleted file mode 100644 index 3a72b845..00000000 --- a/src/main/java/edu/university_connect/controller/SystemActionController.java +++ /dev/null @@ -1,93 +0,0 @@ -package edu.university_connect.controller; - -import edu.university_connect.model.AppStatusCode; -import edu.university_connect.model.contract.dto.SystemActionDto; -import edu.university_connect.model.contract.request.action.SystemActionCreateRequest; -import edu.university_connect.model.contract.request.action.SystemActionUpdateRequest; -import edu.university_connect.model.contract.response.common.ApiResponse; -import edu.university_connect.service.MessagingService; -import edu.university_connect.service.SystemActionService; -import jakarta.validation.Valid; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/system-action") -@CrossOrigin -@Slf4j -public class SystemActionController { - private final SystemActionService service; - - private final MessagingService messagingService; - - public SystemActionController(SystemActionService service, MessagingService messagingService) { - this.service = service; - this.messagingService = messagingService; - } - @GetMapping("/all") - public ResponseEntity>> getAll() { - List response= service.getAll(); - ApiResponse> apiResponse = new ApiResponse>(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"sys-action"})); - return ResponseEntity.ok(apiResponse); - } - - @GetMapping("") - public ResponseEntity>> getPage(Pageable pageableReq) { - Pageable pageable = PageRequest.of(pageableReq.getPageNumber()>0? pageableReq.getPageNumber()-1 : 0, - pageableReq.getPageSize() , - pageableReq.getSort()); - Page response= service.getPage(pageable); - ApiResponse> apiResponse = new ApiResponse>(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"sys-action"})); - return ResponseEntity.ok(apiResponse); - - } - @PostMapping("") - public ResponseEntity> create(@Valid @RequestBody SystemActionCreateRequest createRequest) { - SystemActionDto response= service.create(createRequest); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20002,new String[]{"sys-action"})); - return ResponseEntity.ok(apiResponse); - - } - - @GetMapping("/{id}") - public ResponseEntity> get(@PathVariable Long id) { - SystemActionDto response= service.getById(id); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20003,new String[]{"sys-action"})); - return ResponseEntity.ok(apiResponse); - - } - - @PutMapping("/{id}") - public ResponseEntity> update(@Valid @RequestBody SystemActionUpdateRequest updateRequest, - @PathVariable Long id) { - SystemActionDto response= service.update(id,updateRequest); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20004,new String[]{"sys-action"})); - return ResponseEntity.ok(apiResponse); - } - - @DeleteMapping("/{id}") - public ResponseEntity> delete(@PathVariable Long id) { - boolean response= service.delete(id); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20005,new String[]{"sys-action"})); - return ResponseEntity.ok(apiResponse); - } - -} diff --git a/src/main/java/edu/university_connect/controller/SystemRoleController.java b/src/main/java/edu/university_connect/controller/SystemRoleController.java deleted file mode 100644 index 32ffeb24..00000000 --- a/src/main/java/edu/university_connect/controller/SystemRoleController.java +++ /dev/null @@ -1,96 +0,0 @@ -package edu.university_connect.controller; - -import edu.university_connect.exception.ServiceException; -import edu.university_connect.model.AppStatusCode; -import edu.university_connect.model.contract.dto.SystemRoleDto; -import edu.university_connect.model.contract.request.role.SystemRoleCreateRequest; -import edu.university_connect.model.contract.request.role.SystemRoleUpdateRequest; -import edu.university_connect.model.contract.response.common.ApiResponse; -import edu.university_connect.model.entity.SystemAction; -import edu.university_connect.service.MessagingService; -import edu.university_connect.service.SystemRoleService; -import jakarta.validation.Valid; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Optional; - -@RestController -@RequestMapping("/api/v1/system-role") -@CrossOrigin -@Slf4j -public class SystemRoleController { - private final SystemRoleService service; - - private final MessagingService messagingService; - - public SystemRoleController(SystemRoleService service, MessagingService messagingService) { - this.service = service; - this.messagingService = messagingService; - } - @GetMapping("/all") - public ResponseEntity>> getAll() { - List response= service.getAll(); - ApiResponse> apiResponse = new ApiResponse>(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"sys-role"})); - return ResponseEntity.ok(apiResponse); - } - - @GetMapping("") - public ResponseEntity>> getPage(Pageable pageableReq) { - Pageable pageable = PageRequest.of(pageableReq.getPageNumber()>0? pageableReq.getPageNumber()-1 : 0, - pageableReq.getPageSize() , - pageableReq.getSort()); - Page response= service.getPage(pageable); - ApiResponse> apiResponse = new ApiResponse>(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"sys-role"})); - return ResponseEntity.ok(apiResponse); - - } - @PostMapping("") - public ResponseEntity> create(@Valid @RequestBody SystemRoleCreateRequest createRequest) { - SystemRoleDto response= service.create(createRequest); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20002,new String[]{"sys-role"})); - return ResponseEntity.ok(apiResponse); - - } - - @GetMapping("/{id}") - public ResponseEntity> get(@PathVariable Long id) { - SystemRoleDto response= service.getById(id); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20003,new String[]{"sys-role"})); - return ResponseEntity.ok(apiResponse); - - } - - @PutMapping("/{id}") - public ResponseEntity> update(@Valid @RequestBody SystemRoleUpdateRequest updateRequest, - @PathVariable Long id) { - SystemRoleDto response= service.update(id,updateRequest); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20004,new String[]{"sys-role"})); - return ResponseEntity.ok(apiResponse); - } - - @DeleteMapping("/{id}") - public ResponseEntity> delete(@PathVariable Long id) { - boolean response= service.delete(id); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20005,new String[]{"sys-role"})); - return ResponseEntity.ok(apiResponse); - } - -} diff --git a/src/main/java/edu/university_connect/controller/SystemUserController.java b/src/main/java/edu/university_connect/controller/SystemUserController.java deleted file mode 100644 index a78366fd..00000000 --- a/src/main/java/edu/university_connect/controller/SystemUserController.java +++ /dev/null @@ -1,93 +0,0 @@ -package edu.university_connect.controller; - -import edu.university_connect.model.AppStatusCode; -import edu.university_connect.model.contract.dto.SystemUserDto; -import edu.university_connect.model.contract.request.user.SystemUserCreateRequest; -import edu.university_connect.model.contract.request.user.SystemUserUpdateRequest; -import edu.university_connect.model.contract.response.common.ApiResponse; -import edu.university_connect.service.MessagingService; -import edu.university_connect.service.SystemUserService; -import jakarta.validation.Valid; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/system-user") -@CrossOrigin -@Slf4j -public class SystemUserController { - private final SystemUserService service; - - private final MessagingService messagingService; - - public SystemUserController(SystemUserService service, MessagingService messagingService) { - this.service = service; - this.messagingService = messagingService; - } - @GetMapping("/all") - public ResponseEntity>> getAll() { - List response= service.getAll(); - ApiResponse> apiResponse = new ApiResponse>(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"sys-user"})); - return ResponseEntity.ok(apiResponse); - } - - @GetMapping("") - public ResponseEntity>> getPage(Pageable pageableReq) { - Pageable pageable = PageRequest.of(pageableReq.getPageNumber()>0? pageableReq.getPageNumber()-1 : 0, - pageableReq.getPageSize() , - pageableReq.getSort()); - Page response= service.getPage(pageable); - ApiResponse> apiResponse = new ApiResponse>(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"sys-user"})); - return ResponseEntity.ok(apiResponse); - - } - @PostMapping("") - public ResponseEntity> create(@Valid @RequestBody SystemUserCreateRequest createRequest) { - SystemUserDto response= service.create(createRequest); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20002,new String[]{"sys-user"})); - return ResponseEntity.ok(apiResponse); - - } - - @GetMapping("/{id}") - public ResponseEntity> get(@PathVariable Long id) { - SystemUserDto response= service.getById(id); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20003,new String[]{"sys-user"})); - return ResponseEntity.ok(apiResponse); - - } - - @PutMapping("/{id}") - public ResponseEntity> update(@Valid @RequestBody SystemUserUpdateRequest updateRequest, - @PathVariable Long id) { - SystemUserDto response= service.update(id,updateRequest); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20004,new String[]{"sys-user"})); - return ResponseEntity.ok(apiResponse); - } - - @DeleteMapping("/{id}") - public ResponseEntity> delete(@PathVariable Long id) { - boolean response= service.delete(id); - ApiResponse apiResponse = new ApiResponse(); - apiResponse.setResponseData(response); - apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20005,new String[]{"sys-user"})); - return ResponseEntity.ok(apiResponse); - } - -} diff --git a/src/main/java/edu/university_connect/controller/UserController.java b/src/main/java/edu/university_connect/controller/UserController.java new file mode 100644 index 00000000..cc825a19 --- /dev/null +++ b/src/main/java/edu/university_connect/controller/UserController.java @@ -0,0 +1,93 @@ +package edu.university_connect.controller; + +import edu.university_connect.model.enums.AppStatusCode; +import edu.university_connect.model.contract.dto.UserDto; +import edu.university_connect.model.contract.request.user.UserCreateRequest; +import edu.university_connect.model.contract.request.user.UserUpdateRequest; +import edu.university_connect.model.contract.response.ApiResponse; +import edu.university_connect.service.MessagingService; +import edu.university_connect.service.user.UserService; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/user") +@CrossOrigin +@Slf4j +public class UserController { + private final UserService service; + + private final MessagingService messagingService; + + public UserController(UserService service, MessagingService messagingService) { + this.service = service; + this.messagingService = messagingService; + } + @GetMapping("/all") + public ResponseEntity>> getAll() { + List response= service.getAll(); + ApiResponse> apiResponse = new ApiResponse>(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"user"})); + return ResponseEntity.ok(apiResponse); + } + + @GetMapping("") + public ResponseEntity>> getPage(Pageable pageableReq) { + Pageable pageable = PageRequest.of(pageableReq.getPageNumber()>0? pageableReq.getPageNumber()-1 : 0, + pageableReq.getPageSize() , + pageableReq.getSort()); + Page response= service.getPage(pageable); + ApiResponse> apiResponse = new ApiResponse>(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20001,new String[]{"user"})); + return ResponseEntity.ok(apiResponse); + + } + @PostMapping("") + public ResponseEntity> create(@Valid @RequestBody UserCreateRequest createRequest) { + UserDto response= service.create(createRequest); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20002,new String[]{"user"})); + return ResponseEntity.ok(apiResponse); + + } + + @GetMapping("/{id}") + public ResponseEntity> get(@PathVariable Long id) { + UserDto response= service.getById(id); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20003,new String[]{"user"})); + return ResponseEntity.ok(apiResponse); + + } + + @PutMapping("/{id}") + public ResponseEntity> update(@Valid @RequestBody UserUpdateRequest updateRequest, + @PathVariable Long id) { + UserDto response= service.update(id,updateRequest); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20004,new String[]{"user"})); + return ResponseEntity.ok(apiResponse); + } + + @DeleteMapping("/{id}") + public ResponseEntity> delete(@PathVariable Long id) { + boolean response= service.delete(id); + ApiResponse apiResponse = new ApiResponse(); + apiResponse.setResponseData(response); + apiResponse.setMessage(messagingService.getResponseMessage(AppStatusCode.S20005,new String[]{"user"})); + return ResponseEntity.ok(apiResponse); + } + +} diff --git a/src/main/java/edu/university_connect/domain/AcademicAchievement.java b/src/main/java/edu/university_connect/domain/AcademicAchievement.java new file mode 100644 index 00000000..79af4a20 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/AcademicAchievement.java @@ -0,0 +1,8 @@ +package edu.university_connect.domain; + +import lombok.Data; + +@Data +public class AcademicAchievement { + private String achievement; +} diff --git a/src/main/java/edu/university_connect/domain/ExtraCurricularActivity.java b/src/main/java/edu/university_connect/domain/ExtraCurricularActivity.java new file mode 100644 index 00000000..1e4dc095 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/ExtraCurricularActivity.java @@ -0,0 +1,8 @@ +package edu.university_connect.domain; + +import lombok.Data; + +@Data +public class ExtraCurricularActivity { + private String activity; +} diff --git a/src/main/java/edu/university_connect/domain/Interest.java b/src/main/java/edu/university_connect/domain/Interest.java new file mode 100644 index 00000000..0ff3f5e6 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/Interest.java @@ -0,0 +1,8 @@ +package edu.university_connect.domain; + +import lombok.Data; + +@Data +public class Interest { + private String interest; +} diff --git a/src/main/java/edu/university_connect/model/entity/SystemAction.java b/src/main/java/edu/university_connect/domain/entity/Action.java similarity index 64% rename from src/main/java/edu/university_connect/model/entity/SystemAction.java rename to src/main/java/edu/university_connect/domain/entity/Action.java index 9d932372..8f85e5a6 100644 --- a/src/main/java/edu/university_connect/model/entity/SystemAction.java +++ b/src/main/java/edu/university_connect/domain/entity/Action.java @@ -1,6 +1,6 @@ -package edu.university_connect.model.entity; +package edu.university_connect.domain.entity; -import edu.university_connect.model.entity.meta.AbstractPersistableEntity; +import edu.university_connect.domain.meta.MetaData; import jakarta.persistence.*; import lombok.Data; import lombok.NoArgsConstructor; @@ -8,8 +8,8 @@ @Data @Entity @NoArgsConstructor -@Table(name = "system_action") -public class SystemAction extends AbstractPersistableEntity{ +@Table(name = "action") +public class Action extends MetaData { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -23,9 +23,10 @@ public class SystemAction extends AbstractPersistableEntity{ @Column(name = "description") private String description; - public SystemAction(String name, String code, String description) { + public Action(String name, String code, String description) { this.name = name; this.code = code; this.description = description; } + } diff --git a/src/main/java/edu/university_connect/domain/entity/Event.java b/src/main/java/edu/university_connect/domain/entity/Event.java new file mode 100644 index 00000000..9e48c0af --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/Event.java @@ -0,0 +1,29 @@ +package edu.university_connect.domain.entity; + +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +import java.time.LocalDate; +import java.util.List; +@Data +@Entity +public class Event extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + private String description; + + @Column(nullable = false) + private String location; + + @Column(nullable = false) + private LocalDate date; + + @ManyToMany + private List attendees; +} diff --git a/src/main/java/edu/university_connect/domain/entity/ModerationReport.java b/src/main/java/edu/university_connect/domain/entity/ModerationReport.java new file mode 100644 index 00000000..3c59cd8a --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/ModerationReport.java @@ -0,0 +1,30 @@ +package edu.university_connect.domain.entity; + +import edu.university_connect.domain.entity.discussionthread.Post; +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +@Data +@Entity +public class ModerationReport extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String reason; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "reporter_id") + private User reporter; + + @ManyToOne(fetch = FetchType.LAZY) + private Post post; + + private boolean actionTaken; + + private String actionComment; + + +} diff --git a/src/main/java/edu/university_connect/domain/entity/Profile.java b/src/main/java/edu/university_connect/domain/entity/Profile.java new file mode 100644 index 00000000..37468394 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/Profile.java @@ -0,0 +1,36 @@ +package edu.university_connect.domain.entity; + +import edu.university_connect.domain.AcademicAchievement; +import edu.university_connect.domain.ExtraCurricularActivity; +import edu.university_connect.domain.Interest; +import edu.university_connect.domain.meta.MetaData; +import io.hypersistence.utils.hibernate.type.json.JsonType; +import jakarta.persistence.*; +import lombok.Data; +import org.hibernate.annotations.Type; + +import java.util.Set; + +@Data +@Entity +public class Profile extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Type(JsonType.class) + @Column(name = "achievements", columnDefinition = "json") + private Set achievements; + + @Type(JsonType.class) + @Column(name = "interests", columnDefinition = "json") + private Set interests; + + @Type(JsonType.class) + @Column(name = "extraCurricularActivities", columnDefinition = "json") + private Set extraCurricularActivities; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User user; +} diff --git a/src/main/java/edu/university_connect/domain/entity/Resource.java b/src/main/java/edu/university_connect/domain/entity/Resource.java new file mode 100644 index 00000000..7aa2ac93 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/Resource.java @@ -0,0 +1,29 @@ +package edu.university_connect.domain.entity; + +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Set; + +@Data +@Entity +public class Resource extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String title; + + private String description; + + @Column(nullable = false) + private String url; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User user; +} diff --git a/src/main/java/edu/university_connect/model/entity/SystemRole.java b/src/main/java/edu/university_connect/domain/entity/Role.java similarity index 72% rename from src/main/java/edu/university_connect/model/entity/SystemRole.java rename to src/main/java/edu/university_connect/domain/entity/Role.java index 3f8d4d0c..74c5e7b7 100644 --- a/src/main/java/edu/university_connect/model/entity/SystemRole.java +++ b/src/main/java/edu/university_connect/domain/entity/Role.java @@ -1,6 +1,6 @@ -package edu.university_connect.model.entity; +package edu.university_connect.domain.entity; -import edu.university_connect.model.entity.meta.AbstractPersistableEntity; +import edu.university_connect.domain.meta.MetaData; import io.hypersistence.utils.hibernate.type.json.JsonType; import jakarta.persistence.*; import lombok.Data; @@ -12,8 +12,8 @@ @Data @NoArgsConstructor @Entity -@Table(name = "system_role") -public class SystemRole extends AbstractPersistableEntity { +@Table(name = "role") +public class Role extends MetaData { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -32,7 +32,7 @@ public class SystemRole extends AbstractPersistableEntity { @Column(name = "actions", columnDefinition = "json") private Set actions; - public SystemRole(String name, String code, String description, Set actions) { + public Role(String name, String code, String description, Set actions) { this.name = name; this.code = code; this.description = description; diff --git a/src/main/java/edu/university_connect/domain/entity/Student.java b/src/main/java/edu/university_connect/domain/entity/Student.java new file mode 100644 index 00000000..5bbcdb38 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/Student.java @@ -0,0 +1,27 @@ +package edu.university_connect.domain.entity; + +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +@Data +@Entity +public class Student extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column(nullable = false) + private String firstName; + @Column(nullable = false) + private String lastName; + @Column(nullable = false) + private String email; + @Column(nullable = false) + private String year; + @Column(nullable = false) + private String major; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; +} diff --git a/src/main/java/edu/university_connect/domain/entity/User.java b/src/main/java/edu/university_connect/domain/entity/User.java new file mode 100644 index 00000000..34126d72 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/User.java @@ -0,0 +1,68 @@ +package edu.university_connect.domain.entity; + +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Set; + +@Data +@NoArgsConstructor +@Entity +@Table(name = "user") +public class User extends MetaData { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "username", unique = true, nullable = false) + private String username; + + @Column(name = "password") + private String password; + + @Column(name = "email", unique = true, nullable = false) + private String email; + + @Column(name = "enabled", nullable = false) + private boolean enabled; + + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable(name = "user_role") + private Set roles; + + @OneToOne(mappedBy = "user",fetch = FetchType.LAZY) + private Profile profile; + +// @OneToMany(mappedBy = "user") +// private List posts; + +// @OneToMany(mappedBy = "user") +// private List replies; + +// @OneToMany(mappedBy="user") +// private List resources; + +// @OneToMany(mappedBy = "creator") +// private List createdSurveys; + + @ManyToMany + @JoinTable( + name = "user_block", + joinColumns = @JoinColumn(name = "user_id"), + inverseJoinColumns = @JoinColumn(name = "blocked_user_id") + ) + private List blockedUsers; + + + + public User(String username, String password, String email) { + super(); + this.username = username; + this.password = password; + this.email = email; + } +} diff --git a/src/main/java/edu/university_connect/domain/entity/discussionthread/Category.java b/src/main/java/edu/university_connect/domain/entity/discussionthread/Category.java new file mode 100644 index 00000000..2ee6a922 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/discussionthread/Category.java @@ -0,0 +1,22 @@ +package edu.university_connect.domain.entity.discussionthread; + +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +import java.util.List; +@Data +@Entity +public class Category extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(unique = true,nullable = false) + private String title; + + @OneToMany + @JoinColumn(name="category_id") + private List posts; + +} diff --git a/src/main/java/edu/university_connect/domain/entity/discussionthread/Post.java b/src/main/java/edu/university_connect/domain/entity/discussionthread/Post.java new file mode 100644 index 00000000..97275976 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/discussionthread/Post.java @@ -0,0 +1,35 @@ +package edu.university_connect.domain.entity.discussionthread; + +import edu.university_connect.domain.entity.ModerationReport; +import edu.university_connect.domain.entity.User; +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +import java.util.List; +@Data +@Entity +public class Post extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Lob + @Column(length = 5000,nullable = false) + private String content; + + @ManyToOne(fetch=FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; + + @OneToMany + @JoinColumn(name="post_id") + private List replies; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User user; + + @OneToMany(mappedBy = "post") + private List moderationReports; + +} diff --git a/src/main/java/edu/university_connect/domain/entity/discussionthread/Reply.java b/src/main/java/edu/university_connect/domain/entity/discussionthread/Reply.java new file mode 100644 index 00000000..c6c2cc10 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/discussionthread/Reply.java @@ -0,0 +1,25 @@ +package edu.university_connect.domain.entity.discussionthread; + +import edu.university_connect.domain.entity.User; +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +@Data +@Entity +public class Reply extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Lob + @Column(length = 5000,nullable = false) + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="post_id") + private Post post; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User user; +} diff --git a/src/main/java/edu/university_connect/domain/entity/survey/Questionnaire.java b/src/main/java/edu/university_connect/domain/entity/survey/Questionnaire.java new file mode 100644 index 00000000..7c962909 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/survey/Questionnaire.java @@ -0,0 +1,20 @@ +package edu.university_connect.domain.entity.survey; + +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +import java.util.List; + +@Data +@Entity +public class Questionnaire extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + @Column(nullable = false) + private String question; + + @OneToMany(mappedBy = "surveyQuestionnaire") + private List surveyResponse; +} diff --git a/src/main/java/edu/university_connect/domain/entity/survey/Response.java b/src/main/java/edu/university_connect/domain/entity/survey/Response.java new file mode 100644 index 00000000..96d6eb5b --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/survey/Response.java @@ -0,0 +1,20 @@ +package edu.university_connect.domain.entity.survey; + +import edu.university_connect.model.contract.dto.UserDto; +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +@Data +@Entity +public class Response extends MetaData { + @Id + private int id; + + @Column(nullable = false) + private String response; + + @ManyToOne(fetch = FetchType.LAZY) + private Questionnaire surveyQuestionnaire; + +} diff --git a/src/main/java/edu/university_connect/domain/entity/survey/Survey.java b/src/main/java/edu/university_connect/domain/entity/survey/Survey.java new file mode 100644 index 00000000..78a97d27 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/entity/survey/Survey.java @@ -0,0 +1,28 @@ +package edu.university_connect.domain.entity.survey; + +import edu.university_connect.domain.entity.User; +import edu.university_connect.model.contract.dto.UserDto; +import edu.university_connect.domain.entity.Resource; +import edu.university_connect.domain.meta.MetaData; +import jakarta.persistence.*; +import lombok.Data; + +import java.util.List; + +@Data +@Entity +public class Survey extends MetaData { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column(nullable = false) + private String title; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User creator; + + @OneToMany + @JoinColumn(name="survey_id") + private List surveyQuestionnaire; +} diff --git a/src/main/java/edu/university_connect/domain/meta/MetaData.java b/src/main/java/edu/university_connect/domain/meta/MetaData.java new file mode 100644 index 00000000..6569bea1 --- /dev/null +++ b/src/main/java/edu/university_connect/domain/meta/MetaData.java @@ -0,0 +1,32 @@ +package edu.university_connect.domain.meta; + +import jakarta.persistence.*; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.io.Serializable; +import java.time.LocalDateTime; + +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class MetaData implements Serializable { + + @CreatedDate + @Column(name = "created_at", updatable = false) + LocalDateTime createdAt; + + @CreatedBy + @Column(name = "created_by", updatable = false) + String createdBy; + + @LastModifiedDate + @Column(name = "last_modified_at", insertable = false) + LocalDateTime lastModifiedAt; + + @LastModifiedBy + @Column(name = "last_modified_by", insertable = false) + String lastModifiedBy; +} diff --git a/src/main/java/edu/university_connect/model/entity/meta/SystemUsername.java b/src/main/java/edu/university_connect/domain/meta/Username.java similarity index 70% rename from src/main/java/edu/university_connect/model/entity/meta/SystemUsername.java rename to src/main/java/edu/university_connect/domain/meta/Username.java index 62eb09ce..545b262b 100644 --- a/src/main/java/edu/university_connect/model/entity/meta/SystemUsername.java +++ b/src/main/java/edu/university_connect/domain/meta/Username.java @@ -1,4 +1,4 @@ -package edu.university_connect.model.entity.meta; +package edu.university_connect.domain.meta; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; @@ -11,7 +11,6 @@ @Embeddable @AllArgsConstructor @NoArgsConstructor -public class SystemUsername implements Serializable { - +public class Username implements Serializable { private String username; } \ No newline at end of file diff --git a/src/main/java/edu/university_connect/exception/ServiceException.java b/src/main/java/edu/university_connect/exception/ServiceException.java index 7b4e7e87..22852789 100644 --- a/src/main/java/edu/university_connect/exception/ServiceException.java +++ b/src/main/java/edu/university_connect/exception/ServiceException.java @@ -1,6 +1,6 @@ package edu.university_connect.exception; -import edu.university_connect.model.AppStatusCode; +import edu.university_connect.model.enums.AppStatusCode; import lombok.Getter; @Getter diff --git a/src/main/java/edu/university_connect/exception/DefaultExceptionHandler.java b/src/main/java/edu/university_connect/exception/handler/DefaultExceptionHandler.java similarity index 95% rename from src/main/java/edu/university_connect/exception/DefaultExceptionHandler.java rename to src/main/java/edu/university_connect/exception/handler/DefaultExceptionHandler.java index 2ca72143..fed28f51 100644 --- a/src/main/java/edu/university_connect/exception/DefaultExceptionHandler.java +++ b/src/main/java/edu/university_connect/exception/handler/DefaultExceptionHandler.java @@ -1,9 +1,10 @@ -package edu.university_connect.exception; +package edu.university_connect.exception.handler; -import edu.university_connect.model.contract.response.common.ApiResponse; -import edu.university_connect.model.contract.response.common.ErrorField; -import edu.university_connect.model.contract.response.common.MessageErrorNode; +import edu.university_connect.exception.ServiceException; +import edu.university_connect.model.contract.response.ApiResponse; +import edu.university_connect.model.contract.response.ErrorField; +import edu.university_connect.model.contract.response.Error; import edu.university_connect.service.MessagingService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -170,7 +171,7 @@ private ResponseEntity createResponseEntity(HttpStatus httpStatus, errorResponse.status(false); errorResponse.code(String.valueOf(HttpStatus.BAD_REQUEST.value())); } else { - errorResponse.errors(MessageErrorNode.builder().fields(errorFields).build()); + errorResponse.errors(Error.builder().fields(errorFields).build()); } return handleExceptionInternal(ex, errorResponse.build(), new HttpHeaders(), httpStatus, request); diff --git a/src/main/java/edu/university_connect/mapper/ActionDtoMapper.java b/src/main/java/edu/university_connect/mapper/ActionDtoMapper.java new file mode 100644 index 00000000..f56bfbeb --- /dev/null +++ b/src/main/java/edu/university_connect/mapper/ActionDtoMapper.java @@ -0,0 +1,22 @@ +package edu.university_connect.mapper; + +import edu.university_connect.model.contract.request.action.ActionCreateRequest; +import edu.university_connect.model.contract.request.action.ActionUpdateRequest; +import edu.university_connect.model.contract.dto.ActionDto; +import edu.university_connect.domain.entity.Action; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface ActionDtoMapper { + ActionDtoMapper MAPPER = + Mappers.getMapper(ActionDtoMapper.class); + + Action dtoToEntity(ActionCreateRequest request); + Action dtoToEntity(ActionUpdateRequest request); + @Mapping(target = "createdBy", ignore = true) + @Mapping(target = "lastModifiedBy", ignore = true) + ActionDto entityToDto(Action action); +} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/mapper/RoleDtoMapper.java b/src/main/java/edu/university_connect/mapper/RoleDtoMapper.java new file mode 100644 index 00000000..158d9101 --- /dev/null +++ b/src/main/java/edu/university_connect/mapper/RoleDtoMapper.java @@ -0,0 +1,24 @@ +package edu.university_connect.mapper; + +import edu.university_connect.model.contract.request.role.RoleCreateRequest; +import edu.university_connect.model.contract.request.role.RoleUpdateRequest; +import edu.university_connect.model.contract.dto.RoleDto; +import edu.university_connect.domain.entity.Role; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface RoleDtoMapper { + RoleDtoMapper MAPPER = + Mappers.getMapper(RoleDtoMapper.class); + + Role dtoToEntity(RoleCreateRequest request); + Role dtoToEntity(RoleUpdateRequest request); + @Mapping(target = "createdBy", ignore = true) + @Mapping(target = "lastModifiedBy", ignore = true) + RoleDto entityToDto(Role role); + + +} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/mapper/SystemActionDtoMapper.java b/src/main/java/edu/university_connect/mapper/SystemActionDtoMapper.java deleted file mode 100644 index 3fb93ff1..00000000 --- a/src/main/java/edu/university_connect/mapper/SystemActionDtoMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package edu.university_connect.mapper; - -import edu.university_connect.model.contract.request.action.SystemActionCreateRequest; -import edu.university_connect.model.contract.request.action.SystemActionUpdateRequest; -import edu.university_connect.model.contract.dto.SystemActionDto; -import edu.university_connect.model.entity.SystemAction; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; - -@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface SystemActionDtoMapper { - SystemActionDtoMapper MAPPER = - Mappers.getMapper(SystemActionDtoMapper.class); - - SystemAction dtoToEntity(SystemActionCreateRequest request); - SystemAction dtoToEntity(SystemActionUpdateRequest request); - @Mapping(target = "createdBy", ignore = true) - @Mapping(target = "lastModifiedBy", ignore = true) - SystemActionDto entityToDto(SystemAction action); - - -} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/mapper/SystemRoleDtoMapper.java b/src/main/java/edu/university_connect/mapper/SystemRoleDtoMapper.java deleted file mode 100644 index 0f099018..00000000 --- a/src/main/java/edu/university_connect/mapper/SystemRoleDtoMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package edu.university_connect.mapper; - -import edu.university_connect.model.contract.request.role.SystemRoleCreateRequest; -import edu.university_connect.model.contract.request.role.SystemRoleUpdateRequest; -import edu.university_connect.model.contract.dto.SystemRoleDto; -import edu.university_connect.model.entity.SystemRole; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; - -@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface SystemRoleDtoMapper { - SystemRoleDtoMapper MAPPER = - Mappers.getMapper(SystemRoleDtoMapper.class); - - SystemRole dtoToEntity(SystemRoleCreateRequest request); - SystemRole dtoToEntity(SystemRoleUpdateRequest request); - @Mapping(target = "createdBy", ignore = true) - @Mapping(target = "lastModifiedBy", ignore = true) - SystemRoleDto entityToDto(SystemRole role); - - -} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/mapper/SystemUserDtoMapper.java b/src/main/java/edu/university_connect/mapper/SystemUserDtoMapper.java deleted file mode 100644 index f7ba5702..00000000 --- a/src/main/java/edu/university_connect/mapper/SystemUserDtoMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package edu.university_connect.mapper; - -import edu.university_connect.model.contract.request.user.SystemUserCreateRequest; -import edu.university_connect.model.contract.request.user.SystemUserUpdateRequest; -import edu.university_connect.model.contract.dto.SystemUserDto; -import edu.university_connect.model.entity.SystemUser; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; - -@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface SystemUserDtoMapper { - SystemUserDtoMapper MAPPER = - Mappers.getMapper(SystemUserDtoMapper.class); - - SystemUser dtoToEntity(SystemUserCreateRequest request); - SystemUser dtoToEntity(SystemUserUpdateRequest request); - @Mapping(target = "createdBy", ignore = true) - @Mapping(target = "lastModifiedBy", ignore = true) - SystemUserDto entityToDto(SystemUser user); - - -} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/mapper/UserDtoMapper.java b/src/main/java/edu/university_connect/mapper/UserDtoMapper.java new file mode 100644 index 00000000..b156103c --- /dev/null +++ b/src/main/java/edu/university_connect/mapper/UserDtoMapper.java @@ -0,0 +1,25 @@ +package edu.university_connect.mapper; + +import edu.university_connect.domain.entity.User; +import edu.university_connect.model.contract.request.user.UserCreateRequest; +import edu.university_connect.model.contract.request.user.UserUpdateRequest; +import edu.university_connect.model.contract.dto.UserDto; +import edu.university_connect.domain.entity.Resource; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface UserDtoMapper { + UserDtoMapper MAPPER = + Mappers.getMapper(UserDtoMapper.class); + + User dtoToEntity(UserCreateRequest request); + User dtoToEntity(UserUpdateRequest request); + @Mapping(target = "createdBy", ignore = true) + @Mapping(target = "lastModifiedBy", ignore = true) + UserDto entityToDto(User user); + + +} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/model/SecurityUser.java b/src/main/java/edu/university_connect/model/SecurityUser.java index 0be32cc2..f199234a 100644 --- a/src/main/java/edu/university_connect/model/SecurityUser.java +++ b/src/main/java/edu/university_connect/model/SecurityUser.java @@ -1,7 +1,8 @@ package edu.university_connect.model; -import edu.university_connect.model.entity.SystemRole; -import edu.university_connect.model.entity.SystemUser; +import edu.university_connect.domain.entity.Resource; +import edu.university_connect.domain.entity.Role; +import edu.university_connect.domain.entity.User; import lombok.Data; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -24,21 +25,21 @@ public class SecurityUser implements UserDetails { private boolean credentialsNonExpired; private boolean enabled; - public SecurityUser(SystemUser systemUser){ - Set roles=systemUser.getRoles(); + public SecurityUser(User user){ + Set roles= user.getRoles(); Set actions=roles.stream() .flatMap(role -> role.getActions().stream()) .collect(Collectors.toSet()); Collection directAuthorities=actions.stream() .map(SimpleGrantedAuthority::new).toList(); Collection authorities = new ArrayList<>(directAuthorities); - this.id = systemUser.getId(); - this.username = systemUser.getUsername(); - this.password = systemUser.getPassword(); + this.id = user.getId(); + this.username = user.getUsername(); + this.password = user.getPassword(); this.accountNonExpired = true; this.accountNonLocked = true; this.credentialsNonExpired = true; - this.enabled = systemUser.isEnabled(); + this.enabled = user.isEnabled(); this.authorities = authorities; } diff --git a/src/main/java/edu/university_connect/model/contract/dto/SystemActionDto.java b/src/main/java/edu/university_connect/model/contract/dto/ActionDto.java similarity index 92% rename from src/main/java/edu/university_connect/model/contract/dto/SystemActionDto.java rename to src/main/java/edu/university_connect/model/contract/dto/ActionDto.java index 6bec116c..df3b3232 100644 --- a/src/main/java/edu/university_connect/model/contract/dto/SystemActionDto.java +++ b/src/main/java/edu/university_connect/model/contract/dto/ActionDto.java @@ -5,7 +5,7 @@ import java.time.LocalDateTime; @Data -public class SystemActionDto { +public class ActionDto { private Long id; private String name; diff --git a/src/main/java/edu/university_connect/model/contract/dto/SystemRoleDto.java b/src/main/java/edu/university_connect/model/contract/dto/RoleDto.java similarity index 93% rename from src/main/java/edu/university_connect/model/contract/dto/SystemRoleDto.java rename to src/main/java/edu/university_connect/model/contract/dto/RoleDto.java index bf2ffe4b..881a3c90 100644 --- a/src/main/java/edu/university_connect/model/contract/dto/SystemRoleDto.java +++ b/src/main/java/edu/university_connect/model/contract/dto/RoleDto.java @@ -6,7 +6,7 @@ import java.util.Set; @Data -public class SystemRoleDto { +public class RoleDto { private Long id; private String name; diff --git a/src/main/java/edu/university_connect/model/contract/dto/SystemUserDto.java b/src/main/java/edu/university_connect/model/contract/dto/UserDto.java similarity index 91% rename from src/main/java/edu/university_connect/model/contract/dto/SystemUserDto.java rename to src/main/java/edu/university_connect/model/contract/dto/UserDto.java index a7c3e957..49013e30 100644 --- a/src/main/java/edu/university_connect/model/contract/dto/SystemUserDto.java +++ b/src/main/java/edu/university_connect/model/contract/dto/UserDto.java @@ -5,7 +5,7 @@ import java.time.LocalDateTime; @Data -public class SystemUserDto { +public class UserDto { private Long id; private String username; @@ -21,5 +21,4 @@ public class SystemUserDto { LocalDateTime lastModifiedAt; String lastModifiedBy; - } diff --git a/src/main/java/edu/university_connect/model/contract/request/action/SystemActionCreateRequest.java b/src/main/java/edu/university_connect/model/contract/request/action/ActionCreateRequest.java similarity index 88% rename from src/main/java/edu/university_connect/model/contract/request/action/SystemActionCreateRequest.java rename to src/main/java/edu/university_connect/model/contract/request/action/ActionCreateRequest.java index 68bf5a61..2c4d148b 100644 --- a/src/main/java/edu/university_connect/model/contract/request/action/SystemActionCreateRequest.java +++ b/src/main/java/edu/university_connect/model/contract/request/action/ActionCreateRequest.java @@ -5,7 +5,7 @@ import lombok.Data; @Data -public class SystemActionCreateRequest { +public class ActionCreateRequest { @NotBlank @NotEmpty diff --git a/src/main/java/edu/university_connect/model/contract/request/action/SystemActionUpdateRequest.java b/src/main/java/edu/university_connect/model/contract/request/action/ActionUpdateRequest.java similarity index 81% rename from src/main/java/edu/university_connect/model/contract/request/action/SystemActionUpdateRequest.java rename to src/main/java/edu/university_connect/model/contract/request/action/ActionUpdateRequest.java index c4f173ab..0928b533 100644 --- a/src/main/java/edu/university_connect/model/contract/request/action/SystemActionUpdateRequest.java +++ b/src/main/java/edu/university_connect/model/contract/request/action/ActionUpdateRequest.java @@ -3,7 +3,7 @@ import lombok.Data; @Data -public class SystemActionUpdateRequest { +public class ActionUpdateRequest { private String name; diff --git a/src/main/java/edu/university_connect/model/contract/request/role/SystemRoleCreateRequest.java b/src/main/java/edu/university_connect/model/contract/request/role/RoleCreateRequest.java similarity index 85% rename from src/main/java/edu/university_connect/model/contract/request/role/SystemRoleCreateRequest.java rename to src/main/java/edu/university_connect/model/contract/request/role/RoleCreateRequest.java index 54321632..8337bb0a 100644 --- a/src/main/java/edu/university_connect/model/contract/request/role/SystemRoleCreateRequest.java +++ b/src/main/java/edu/university_connect/model/contract/request/role/RoleCreateRequest.java @@ -5,7 +5,7 @@ import java.util.Set; @Data -public class SystemRoleCreateRequest { +public class RoleCreateRequest { private String name; diff --git a/src/main/java/edu/university_connect/model/contract/request/role/SystemRoleUpdateRequest.java b/src/main/java/edu/university_connect/model/contract/request/role/RoleUpdateRequest.java similarity index 85% rename from src/main/java/edu/university_connect/model/contract/request/role/SystemRoleUpdateRequest.java rename to src/main/java/edu/university_connect/model/contract/request/role/RoleUpdateRequest.java index 2754f8f5..ae3883ad 100644 --- a/src/main/java/edu/university_connect/model/contract/request/role/SystemRoleUpdateRequest.java +++ b/src/main/java/edu/university_connect/model/contract/request/role/RoleUpdateRequest.java @@ -5,7 +5,7 @@ import java.util.Set; @Data -public class SystemRoleUpdateRequest { +public class RoleUpdateRequest { private String name; diff --git a/src/main/java/edu/university_connect/model/contract/request/user/SystemUserCreateRequest.java b/src/main/java/edu/university_connect/model/contract/request/user/UserCreateRequest.java similarity index 84% rename from src/main/java/edu/university_connect/model/contract/request/user/SystemUserCreateRequest.java rename to src/main/java/edu/university_connect/model/contract/request/user/UserCreateRequest.java index cc2536fd..fb4231ad 100644 --- a/src/main/java/edu/university_connect/model/contract/request/user/SystemUserCreateRequest.java +++ b/src/main/java/edu/university_connect/model/contract/request/user/UserCreateRequest.java @@ -3,7 +3,7 @@ import lombok.Data; @Data -public class SystemUserCreateRequest { +public class UserCreateRequest { private String username; diff --git a/src/main/java/edu/university_connect/model/contract/request/user/SystemUserUpdateRequest.java b/src/main/java/edu/university_connect/model/contract/request/user/UserUpdateRequest.java similarity index 81% rename from src/main/java/edu/university_connect/model/contract/request/user/SystemUserUpdateRequest.java rename to src/main/java/edu/university_connect/model/contract/request/user/UserUpdateRequest.java index e3f4a2cb..e69a216f 100644 --- a/src/main/java/edu/university_connect/model/contract/request/user/SystemUserUpdateRequest.java +++ b/src/main/java/edu/university_connect/model/contract/request/user/UserUpdateRequest.java @@ -3,7 +3,7 @@ import lombok.Data; @Data -public class SystemUserUpdateRequest { +public class UserUpdateRequest { private String username; diff --git a/src/main/java/edu/university_connect/model/contract/response/common/ApiResponse.java b/src/main/java/edu/university_connect/model/contract/response/ApiResponse.java similarity index 86% rename from src/main/java/edu/university_connect/model/contract/response/common/ApiResponse.java rename to src/main/java/edu/university_connect/model/contract/response/ApiResponse.java index bec72f4a..e2860379 100644 --- a/src/main/java/edu/university_connect/model/contract/response/common/ApiResponse.java +++ b/src/main/java/edu/university_connect/model/contract/response/ApiResponse.java @@ -1,7 +1,7 @@ -package edu.university_connect.model.contract.response.common; +package edu.university_connect.model.contract.response; -import edu.university_connect.model.AppStatusCode; +import edu.university_connect.model.enums.AppStatusCode; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Builder; @@ -21,7 +21,7 @@ public class ApiResponse implements Serializable { private boolean status; private T data; - private MessageErrorNode errors; + private Error errors; public ApiResponse(boolean status, T data) { this.status = status; diff --git a/src/main/java/edu/university_connect/model/contract/response/common/AuthenticationResponse.java b/src/main/java/edu/university_connect/model/contract/response/AuthenticationResponse.java similarity index 81% rename from src/main/java/edu/university_connect/model/contract/response/common/AuthenticationResponse.java rename to src/main/java/edu/university_connect/model/contract/response/AuthenticationResponse.java index 37a1f4f6..7329c98c 100644 --- a/src/main/java/edu/university_connect/model/contract/response/common/AuthenticationResponse.java +++ b/src/main/java/edu/university_connect/model/contract/response/AuthenticationResponse.java @@ -1,4 +1,4 @@ -package edu.university_connect.model.contract.response.common; +package edu.university_connect.model.contract.response; import lombok.AllArgsConstructor; import lombok.Getter; @@ -11,5 +11,4 @@ public class AuthenticationResponse { private String refreshToken; private int accessTokenExpiry; private int refreshTokenExpiry; - } diff --git a/src/main/java/edu/university_connect/model/contract/response/common/MessageErrorNode.java b/src/main/java/edu/university_connect/model/contract/response/Error.java similarity index 74% rename from src/main/java/edu/university_connect/model/contract/response/common/MessageErrorNode.java rename to src/main/java/edu/university_connect/model/contract/response/Error.java index 5a2185e1..58924cb5 100644 --- a/src/main/java/edu/university_connect/model/contract/response/common/MessageErrorNode.java +++ b/src/main/java/edu/university_connect/model/contract/response/Error.java @@ -1,4 +1,4 @@ -package edu.university_connect.model.contract.response.common; +package edu.university_connect.model.contract.response; import com.fasterxml.jackson.annotation.JsonInclude; @@ -12,7 +12,7 @@ @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) -public class MessageErrorNode { +public class Error { private List fields; diff --git a/src/main/java/edu/university_connect/model/contract/response/common/ErrorField.java b/src/main/java/edu/university_connect/model/contract/response/ErrorField.java similarity index 85% rename from src/main/java/edu/university_connect/model/contract/response/common/ErrorField.java rename to src/main/java/edu/university_connect/model/contract/response/ErrorField.java index ddbf8712..b76c2a88 100644 --- a/src/main/java/edu/university_connect/model/contract/response/common/ErrorField.java +++ b/src/main/java/edu/university_connect/model/contract/response/ErrorField.java @@ -1,4 +1,4 @@ -package edu.university_connect.model.contract.response.common; +package edu.university_connect.model.contract.response; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; diff --git a/src/main/java/edu/university_connect/model/entity/SystemUser.java b/src/main/java/edu/university_connect/model/entity/SystemUser.java deleted file mode 100644 index e26f6a0f..00000000 --- a/src/main/java/edu/university_connect/model/entity/SystemUser.java +++ /dev/null @@ -1,48 +0,0 @@ -package edu.university_connect.model.entity; - -import edu.university_connect.model.entity.meta.AbstractPersistableEntity; -import jakarta.persistence.*; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Set; - -@Data -@NoArgsConstructor -@Entity -@Table(name = "system_user") -public class SystemUser extends AbstractPersistableEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "username", unique = true, nullable = false) - private String username; - - @Column(name = "password") - private String password; - - @Column(name = "email", unique = true, nullable = false) - private String email; - - @Column(name = "account_non_expired") - private boolean accountNonExpired; - - @Column(name = "credential_non_expired") - private boolean credentialNonExpired; - - @Column(name = "account_non_locked") - private boolean accountNonLocked; - - @ManyToMany(fetch = FetchType.LAZY) - @JoinTable(name = "system_user_system_role") - private Set roles; - - public SystemUser(String username, String password, String email) { - super(); - this.username = username; - this.password = password; - this.email = email; - } -} diff --git a/src/main/java/edu/university_connect/model/entity/meta/AbstractPersistableEntity.java b/src/main/java/edu/university_connect/model/entity/meta/AbstractPersistableEntity.java deleted file mode 100644 index 3bc0eb9a..00000000 --- a/src/main/java/edu/university_connect/model/entity/meta/AbstractPersistableEntity.java +++ /dev/null @@ -1,47 +0,0 @@ -package edu.university_connect.model.entity.meta; - -import jakarta.persistence.*; -import lombok.Data; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; - -import java.io.Serializable; -import java.time.LocalDateTime; - -@MappedSuperclass -@Data -public abstract class AbstractPersistableEntity implements Serializable { - - @CreatedDate - @Column(name = "created_at", updatable=false) - LocalDateTime createdAt; - - @CreatedBy - @AttributeOverride(name = "username", column = @Column(name = "created_by", updatable=false)) - @Embedded - SystemUsername createdBy; - - @LastModifiedDate - @Column(name = "last_modified_at",insertable=false) - LocalDateTime lastModifiedAt; - - @LastModifiedBy - @AttributeOverride(name = "username", column = @Column(name = "last_modified_by",insertable=false)) - @Embedded - SystemUsername lastModifiedBy; - - @Column(name = "enabled", nullable = false) - private boolean enabled; - - @Column(name = "deleted") - private boolean deleted; - - @Version - private Long version; - - public AbstractPersistableEntity() { - this.enabled=true; - } -} diff --git a/src/main/java/edu/university_connect/model/AppStatusCode.java b/src/main/java/edu/university_connect/model/enums/AppStatusCode.java similarity index 98% rename from src/main/java/edu/university_connect/model/AppStatusCode.java rename to src/main/java/edu/university_connect/model/enums/AppStatusCode.java index a9050758..bda6414c 100644 --- a/src/main/java/edu/university_connect/model/AppStatusCode.java +++ b/src/main/java/edu/university_connect/model/enums/AppStatusCode.java @@ -1,4 +1,4 @@ -package edu.university_connect.model; +package edu.university_connect.model.enums; import org.springframework.http.HttpStatus; diff --git a/src/main/java/edu/university_connect/model/TokenType.java b/src/main/java/edu/university_connect/model/enums/TokenType.java similarity index 51% rename from src/main/java/edu/university_connect/model/TokenType.java rename to src/main/java/edu/university_connect/model/enums/TokenType.java index d03b3235..1735094d 100644 --- a/src/main/java/edu/university_connect/model/TokenType.java +++ b/src/main/java/edu/university_connect/model/enums/TokenType.java @@ -1,4 +1,4 @@ -package edu.university_connect.model; +package edu.university_connect.model.enums; public enum TokenType { ACCESS, REFRESH diff --git a/src/main/java/edu/university_connect/repository/ActionRepository.java b/src/main/java/edu/university_connect/repository/ActionRepository.java new file mode 100644 index 00000000..e5b1547c --- /dev/null +++ b/src/main/java/edu/university_connect/repository/ActionRepository.java @@ -0,0 +1,10 @@ +package edu.university_connect.repository; + +import edu.university_connect.domain.entity.Action; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface ActionRepository extends JpaRepository { + Optional findByCodeIgnoreCase(String code); +} diff --git a/src/main/java/edu/university_connect/repository/RoleRepository.java b/src/main/java/edu/university_connect/repository/RoleRepository.java new file mode 100644 index 00000000..cc632207 --- /dev/null +++ b/src/main/java/edu/university_connect/repository/RoleRepository.java @@ -0,0 +1,10 @@ +package edu.university_connect.repository; + +import edu.university_connect.domain.entity.Role; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface RoleRepository extends JpaRepository { + Optional findByCodeIgnoreCase(String roleCode); +} diff --git a/src/main/java/edu/university_connect/repository/SystemActionRepository.java b/src/main/java/edu/university_connect/repository/SystemActionRepository.java deleted file mode 100644 index 1c412af6..00000000 --- a/src/main/java/edu/university_connect/repository/SystemActionRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package edu.university_connect.repository; - -import edu.university_connect.model.entity.SystemAction; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface SystemActionRepository extends JpaRepository { - Optional findByCodeIgnoreCase(String code); -} diff --git a/src/main/java/edu/university_connect/repository/SystemRoleRepository.java b/src/main/java/edu/university_connect/repository/SystemRoleRepository.java deleted file mode 100644 index 4f8454f3..00000000 --- a/src/main/java/edu/university_connect/repository/SystemRoleRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package edu.university_connect.repository; - -import edu.university_connect.model.entity.SystemRole; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface SystemRoleRepository extends JpaRepository { - Optional findByCodeIgnoreCase(String roleCode); -} diff --git a/src/main/java/edu/university_connect/repository/SystemUserRepository.java b/src/main/java/edu/university_connect/repository/SystemUserRepository.java deleted file mode 100644 index 82ecf60a..00000000 --- a/src/main/java/edu/university_connect/repository/SystemUserRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package edu.university_connect.repository; - -import edu.university_connect.model.entity.SystemUser; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface SystemUserRepository extends JpaRepository { - Optional findByUsername(String username); - -} diff --git a/src/main/java/edu/university_connect/repository/UserRepository.java b/src/main/java/edu/university_connect/repository/UserRepository.java new file mode 100644 index 00000000..6e09a47b --- /dev/null +++ b/src/main/java/edu/university_connect/repository/UserRepository.java @@ -0,0 +1,12 @@ +package edu.university_connect.repository; + +import edu.university_connect.domain.entity.Resource; +import edu.university_connect.domain.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface UserRepository extends JpaRepository { + Optional findByUsername(String username); + +} diff --git a/src/main/java/edu/university_connect/service/AuthService.java b/src/main/java/edu/university_connect/service/AuthService.java deleted file mode 100644 index e98bd0a8..00000000 --- a/src/main/java/edu/university_connect/service/AuthService.java +++ /dev/null @@ -1,4 +0,0 @@ -package edu.university_connect.service; - -public interface AuthService { -} diff --git a/src/main/java/edu/university_connect/service/MessagingService.java b/src/main/java/edu/university_connect/service/MessagingService.java index a8b8b663..c06b4f23 100644 --- a/src/main/java/edu/university_connect/service/MessagingService.java +++ b/src/main/java/edu/university_connect/service/MessagingService.java @@ -1,13 +1,19 @@ package edu.university_connect.service; -import edu.university_connect.model.AppStatusCode; +import edu.university_connect.model.contract.dto.RoleDto; +import edu.university_connect.model.contract.request.role.RoleCreateRequest; +import edu.university_connect.model.contract.request.role.RoleUpdateRequest; +import edu.university_connect.model.enums.AppStatusCode; import edu.university_connect.exception.ServiceException; import lombok.RequiredArgsConstructor; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.util.Arrays; +import java.util.List; @Service @RequiredArgsConstructor @@ -48,4 +54,18 @@ public String getResponseMessage(AppStatusCode appStatusCode) { return getResponseMessage(appStatusCode.getDescription()); } + + public static interface RoleService { + Page getPage(Pageable pageable); + List getAll(); + RoleDto getById(Long id); + + RoleDto create(RoleCreateRequest createRequest); + + RoleDto update(Long id, RoleUpdateRequest updateRequest); + + boolean delete(Long id); + + + } } diff --git a/src/main/java/edu/university_connect/service/SystemActionService.java b/src/main/java/edu/university_connect/service/SystemActionService.java deleted file mode 100644 index 468fe912..00000000 --- a/src/main/java/edu/university_connect/service/SystemActionService.java +++ /dev/null @@ -1,24 +0,0 @@ -package edu.university_connect.service; - -import edu.university_connect.model.contract.request.action.SystemActionCreateRequest; -import edu.university_connect.model.contract.request.action.SystemActionUpdateRequest; -import edu.university_connect.model.contract.dto.SystemActionDto; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -public interface SystemActionService { - Page getPage(Pageable pageable); - List getAll(); - SystemActionDto getById(Long id); - - SystemActionDto create(SystemActionCreateRequest createRequest); - - SystemActionDto update(Long id, SystemActionUpdateRequest updateRequest); - - boolean delete(Long id); - - - SystemActionDto getByCode(String code); -} diff --git a/src/main/java/edu/university_connect/service/SystemRoleService.java b/src/main/java/edu/university_connect/service/SystemRoleService.java deleted file mode 100644 index 5c966dca..00000000 --- a/src/main/java/edu/university_connect/service/SystemRoleService.java +++ /dev/null @@ -1,23 +0,0 @@ -package edu.university_connect.service; - -import edu.university_connect.model.contract.request.role.SystemRoleCreateRequest; -import edu.university_connect.model.contract.request.role.SystemRoleUpdateRequest; -import edu.university_connect.model.contract.dto.SystemRoleDto; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -public interface SystemRoleService { - Page getPage(Pageable pageable); - List getAll(); - SystemRoleDto getById(Long id); - - SystemRoleDto create(SystemRoleCreateRequest createRequest); - - SystemRoleDto update(Long id, SystemRoleUpdateRequest updateRequest); - - boolean delete(Long id); - - -} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/service/SystemUserService.java b/src/main/java/edu/university_connect/service/SystemUserService.java deleted file mode 100644 index 39e3d684..00000000 --- a/src/main/java/edu/university_connect/service/SystemUserService.java +++ /dev/null @@ -1,23 +0,0 @@ -package edu.university_connect.service; - -import edu.university_connect.model.contract.request.user.SystemUserCreateRequest; -import edu.university_connect.model.contract.request.user.SystemUserUpdateRequest; -import edu.university_connect.model.contract.dto.SystemUserDto; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -public interface SystemUserService { - Page getPage(Pageable pageable); - List getAll(); - SystemUserDto getById(Long id); - - SystemUserDto create(SystemUserCreateRequest createRequest); - - SystemUserDto update(Long id, SystemUserUpdateRequest updateRequest); - - boolean delete(Long id); - - -} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/service/action/ActionService.java b/src/main/java/edu/university_connect/service/action/ActionService.java new file mode 100644 index 00000000..9ca331f8 --- /dev/null +++ b/src/main/java/edu/university_connect/service/action/ActionService.java @@ -0,0 +1,24 @@ +package edu.university_connect.service.action; + +import edu.university_connect.model.contract.request.action.ActionCreateRequest; +import edu.university_connect.model.contract.request.action.ActionUpdateRequest; +import edu.university_connect.model.contract.dto.ActionDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface ActionService { + Page getPage(Pageable pageable); + List getAll(); + ActionDto getById(Long id); + + ActionDto create(ActionCreateRequest createRequest); + + ActionDto update(Long id, ActionUpdateRequest updateRequest); + + boolean delete(Long id); + + + ActionDto getByCode(String code); +} diff --git a/src/main/java/edu/university_connect/service/action/ActionServiceImpl.java b/src/main/java/edu/university_connect/service/action/ActionServiceImpl.java new file mode 100644 index 00000000..84c01e06 --- /dev/null +++ b/src/main/java/edu/university_connect/service/action/ActionServiceImpl.java @@ -0,0 +1,106 @@ +package edu.university_connect.service.action; + +import edu.university_connect.exception.ServiceException; +import edu.university_connect.mapper.ActionDtoMapper; +import edu.university_connect.model.enums.AppStatusCode; +import edu.university_connect.model.contract.dto.ActionDto; +import edu.university_connect.model.contract.request.action.ActionCreateRequest; +import edu.university_connect.model.contract.request.action.ActionUpdateRequest; +import edu.university_connect.domain.entity.Action; +import edu.university_connect.repository.ActionRepository; +import edu.university_connect.service.action.ActionService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +@RequiredArgsConstructor +@Service +@Transactional +public class ActionServiceImpl implements ActionService { + + private final ActionRepository repository; + + @Override + public Page getPage(Pageable pageable) { + Page actionPage = repository.findAll(pageable); + return actionPage.map(ActionDtoMapper.MAPPER::entityToDto); + } + + @Override + public List getAll() { + return repository.findAll() + .stream() + .map(ActionDtoMapper.MAPPER::entityToDto) + .toList(); + } + + @Override + public ActionDto getById(Long id) { + Optional actionOpt= getActionById(id); + if(actionOpt.isPresent()){ + return ActionDtoMapper.MAPPER.entityToDto(actionOpt.get()); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "action","id = "+id.toString()); + } + } + + @Override + public ActionDto create(ActionCreateRequest createRequest) { + Optional actionWithCode=repository.findByCodeIgnoreCase(createRequest.getCode()); + if(actionWithCode.isPresent()){ + throw ServiceException.of(AppStatusCode.E40006,"action","code="+createRequest.getCode()); + } + Action action= ActionDtoMapper.MAPPER.dtoToEntity(createRequest); + Action savedAction=repository.save(action); + return ActionDtoMapper.MAPPER.entityToDto(savedAction); + } + + @Override + public ActionDto update(Long id, ActionUpdateRequest updateRequest) { + Optional actionOpt= getActionById(id); + if(actionOpt.isPresent()){ + Action action=actionOpt.get(); + action.setName(updateRequest.getName()); + action.setCode(updateRequest.getCode()); + action.setDescription(updateRequest.getDescription()); + Action savedAction=repository.save(action); + return ActionDtoMapper.MAPPER.entityToDto(savedAction); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "role"); + } + } + + @Override + public boolean delete(Long id) { + if(Objects.nonNull(getById(id))){ + repository.deleteById(id); + } + return true; + } + + @Override + public ActionDto getByCode(String code) { + Optional actionOpt= getActionByCode(code); + if(actionOpt.isPresent()){ + return ActionDtoMapper.MAPPER.entityToDto(actionOpt.get()); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "action","code = "+code); + } + } + private Optional getActionByCode(String code){ + return repository.findByCodeIgnoreCase(code); + } + + private Optional getActionById(Long id){ + return repository.findById(id); + } +} diff --git a/src/main/java/edu/university_connect/service/auth/AuthService.java b/src/main/java/edu/university_connect/service/auth/AuthService.java new file mode 100644 index 00000000..451f4c2d --- /dev/null +++ b/src/main/java/edu/university_connect/service/auth/AuthService.java @@ -0,0 +1,4 @@ +package edu.university_connect.service.auth; + +public interface AuthService { +} diff --git a/src/main/java/edu/university_connect/service/impl/AuthServiceImpl.java b/src/main/java/edu/university_connect/service/auth/AuthServiceImpl.java similarity index 91% rename from src/main/java/edu/university_connect/service/impl/AuthServiceImpl.java rename to src/main/java/edu/university_connect/service/auth/AuthServiceImpl.java index de535ef6..12a9134c 100644 --- a/src/main/java/edu/university_connect/service/impl/AuthServiceImpl.java +++ b/src/main/java/edu/university_connect/service/auth/AuthServiceImpl.java @@ -1,13 +1,12 @@ -package edu.university_connect.service.impl; +package edu.university_connect.service.auth; import edu.university_connect.config.jwt.JwtTokenProvider; import edu.university_connect.exception.ServiceException; -import edu.university_connect.model.AppStatusCode; +import edu.university_connect.model.enums.AppStatusCode; import edu.university_connect.model.SecurityUser; -import edu.university_connect.model.TokenType; +import edu.university_connect.model.enums.TokenType; import edu.university_connect.model.contract.request.auth.RefreshTokenRequest; -import edu.university_connect.model.contract.response.common.AuthenticationResponse; -import edu.university_connect.service.AuthService; +import edu.university_connect.model.contract.response.AuthenticationResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/edu/university_connect/service/impl/SystemActionServiceImpl.java b/src/main/java/edu/university_connect/service/impl/SystemActionServiceImpl.java deleted file mode 100644 index 1c41b912..00000000 --- a/src/main/java/edu/university_connect/service/impl/SystemActionServiceImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -package edu.university_connect.service.impl; - -import edu.university_connect.exception.ServiceException; -import edu.university_connect.mapper.SystemActionDtoMapper; -import edu.university_connect.model.AppStatusCode; -import edu.university_connect.model.contract.dto.SystemActionDto; -import edu.university_connect.model.contract.request.action.SystemActionCreateRequest; -import edu.university_connect.model.contract.request.action.SystemActionUpdateRequest; -import edu.university_connect.model.entity.SystemAction; -import edu.university_connect.repository.SystemActionRepository; -import edu.university_connect.service.SystemActionService; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@RequiredArgsConstructor -@Service -@Transactional -public class SystemActionServiceImpl implements SystemActionService { - - private final SystemActionRepository repository; - - @Override - public Page getPage(Pageable pageable) { - Page actionPage = repository.findAll(pageable); - return actionPage.map(SystemActionDtoMapper.MAPPER::entityToDto); - } - - @Override - public List getAll() { - return repository.findAll() - .stream() - .map(SystemActionDtoMapper.MAPPER::entityToDto) - .toList(); - } - - @Override - public SystemActionDto getById(Long id) { - Optional sysActionOpt=getSystemActionById(id); - if(sysActionOpt.isPresent()){ - return SystemActionDtoMapper.MAPPER.entityToDto(sysActionOpt.get()); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "sys-action","id = "+id.toString()); - } - } - - @Override - public SystemActionDto create(SystemActionCreateRequest createRequest) { - Optional actionWithCode=repository.findByCodeIgnoreCase(createRequest.getCode()); - if(actionWithCode.isPresent()){ - throw ServiceException.of(AppStatusCode.E40006,"sys-action","code="+createRequest.getCode()); - } - SystemAction action=SystemActionDtoMapper.MAPPER.dtoToEntity(createRequest); - SystemAction savedAction=repository.save(action); - return SystemActionDtoMapper.MAPPER.entityToDto(savedAction); - } - - @Override - public SystemActionDto update(Long id, SystemActionUpdateRequest updateRequest) { - Optional sysActionOpt=getSystemActionById(id); - if(sysActionOpt.isPresent()){ - SystemAction action=sysActionOpt.get(); - action.setName(updateRequest.getName()); - action.setCode(updateRequest.getCode()); - action.setDescription(updateRequest.getDescription()); - SystemAction savedAction=repository.save(action); - return SystemActionDtoMapper.MAPPER.entityToDto(savedAction); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "role"); - } - } - - @Override - public boolean delete(Long id) { - if(Objects.nonNull(getById(id))){ - repository.deleteById(id); - } - return true; - } - - @Override - public SystemActionDto getByCode(String code) { - Optional sysActionOpt=getSystemActionByCode(code); - if(sysActionOpt.isPresent()){ - return SystemActionDtoMapper.MAPPER.entityToDto(sysActionOpt.get()); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "sys-action","code = "+code); - } - } - private Optional getSystemActionByCode(String code){ - return repository.findByCodeIgnoreCase(code); - } - - private Optional getSystemActionById(Long id){ - return repository.findById(id); - } -} diff --git a/src/main/java/edu/university_connect/service/impl/SystemRoleServiceImpl.java b/src/main/java/edu/university_connect/service/impl/SystemRoleServiceImpl.java deleted file mode 100644 index 3019b28e..00000000 --- a/src/main/java/edu/university_connect/service/impl/SystemRoleServiceImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -package edu.university_connect.service.impl; - -import edu.university_connect.exception.ServiceException; -import edu.university_connect.mapper.SystemRoleDtoMapper; -import edu.university_connect.model.AppStatusCode; -import edu.university_connect.model.contract.dto.SystemRoleDto; -import edu.university_connect.model.contract.request.role.SystemRoleCreateRequest; -import edu.university_connect.model.contract.request.role.SystemRoleUpdateRequest; -import edu.university_connect.model.entity.SystemAction; -import edu.university_connect.model.entity.SystemRole; -import edu.university_connect.repository.SystemRoleRepository; -import edu.university_connect.service.SystemRoleService; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@RequiredArgsConstructor -@Service -@Transactional -public class SystemRoleServiceImpl implements SystemRoleService { - - private final SystemRoleRepository repository; - - @Override - public Page getPage(Pageable pageable) { - Page page = repository.findAll(pageable); - return page.map(SystemRoleDtoMapper.MAPPER::entityToDto); - } - - @Override - public List getAll() { - return repository.findAll() - .stream() - .map(SystemRoleDtoMapper.MAPPER::entityToDto) - .toList(); - } - - @Override - public SystemRoleDto getById(Long id) { - Optional sysRoleOpt= getSystemRoleById(id); - if(sysRoleOpt.isPresent()){ - return SystemRoleDtoMapper.MAPPER.entityToDto(sysRoleOpt.get()); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "role",id.toString()); - } - } - - @Override - public SystemRoleDto create(SystemRoleCreateRequest createRequest) { - Optional roleWithCode=repository.findByCodeIgnoreCase(createRequest.getCode()); - if(roleWithCode.isPresent()){ - throw ServiceException.of(AppStatusCode.E40006,"sys-role","code="+createRequest.getCode()); - } - //check valid action codes - SystemRole role=SystemRoleDtoMapper.MAPPER.dtoToEntity(createRequest); - SystemRole savedRole=repository.save(role); - return SystemRoleDtoMapper.MAPPER.entityToDto(savedRole); - } - - @Override - public SystemRoleDto update(Long id, SystemRoleUpdateRequest updateRequest) { - Optional sysRoleOpt= getSystemRoleById(id); - if(sysRoleOpt.isPresent()){ - //check valid action codes - SystemRole role=sysRoleOpt.get(); - role.setName(updateRequest.getName()); - role.setCode(updateRequest.getCode()); - role.setDescription(updateRequest.getDescription()); - role.setActions(updateRequest.getActions()); - SystemRole savedRole=repository.save(role); - return SystemRoleDtoMapper.MAPPER.entityToDto(savedRole); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "role"); - } - } - - @Override - public boolean delete(Long id) { - if(Objects.nonNull(getById(id))){ - repository.deleteById(id); - } - return true; - } - - private Optional getSystemRoleById(Long id){ - return repository.findById(id); - } -} diff --git a/src/main/java/edu/university_connect/service/impl/SystemUserServiceImpl.java b/src/main/java/edu/university_connect/service/impl/SystemUserServiceImpl.java deleted file mode 100644 index 401b5e09..00000000 --- a/src/main/java/edu/university_connect/service/impl/SystemUserServiceImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -package edu.university_connect.service.impl; - -import edu.university_connect.exception.ServiceException; -import edu.university_connect.mapper.SystemUserDtoMapper; -import edu.university_connect.model.AppStatusCode; -import edu.university_connect.model.contract.dto.SystemUserDto; -import edu.university_connect.model.contract.request.user.SystemUserCreateRequest; -import edu.university_connect.model.contract.request.user.SystemUserUpdateRequest; -import edu.university_connect.model.entity.SystemUser; -import edu.university_connect.repository.SystemUserRepository; -import edu.university_connect.service.SystemUserService; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; - -@Service -@RequiredArgsConstructor -@Transactional -public class SystemUserServiceImpl implements SystemUserService { - - private final SystemUserRepository repository; - - - @Override - public Page getPage(Pageable pageable) { - Page page = repository.findAll(pageable); - return page.map(SystemUserDtoMapper.MAPPER::entityToDto); - } - - @Override - public List getAll() { - return repository.findAll() - .stream() - .map(SystemUserDtoMapper.MAPPER::entityToDto) - .toList(); - } - - @Override - public SystemUserDto getById(Long id) { - Optional sysUserOpt= getSystemUserById(id); - if(sysUserOpt.isPresent()){ - return SystemUserDtoMapper.MAPPER.entityToDto(sysUserOpt.get()); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "user"); - } - } - - @Override - public SystemUserDto create(SystemUserCreateRequest createRequest) { - - SystemUser user=SystemUserDtoMapper.MAPPER.dtoToEntity(createRequest); - SystemUser savedUser=repository.save(user); - return SystemUserDtoMapper.MAPPER.entityToDto(savedUser); - } - - @Override - public SystemUserDto update(Long id, SystemUserUpdateRequest updateRequest) { - Optional sysUserOpt= getSystemUserById(id); - if(sysUserOpt.isPresent()){ - SystemUser user=sysUserOpt.get(); - user.setUsername(updateRequest.getUsername()); - user.setEmail(updateRequest.getEmail()); - user.setEnabled(updateRequest.isEnabled()); - SystemUser savedUser=repository.save(user); - return SystemUserDtoMapper.MAPPER.entityToDto(savedUser); - } - else { - throw ServiceException.of(AppStatusCode.E40000, "user"); - } - } - - @Override - public boolean delete(Long id) { - if(Objects.nonNull(getById(id))){ - repository.deleteById(id); - } - return true; - } - - private Optional getSystemUserById(Long id){ - return repository.findById(id); - } -} diff --git a/src/main/java/edu/university_connect/service/role/RoleService.java b/src/main/java/edu/university_connect/service/role/RoleService.java new file mode 100644 index 00000000..60e6ba8d --- /dev/null +++ b/src/main/java/edu/university_connect/service/role/RoleService.java @@ -0,0 +1,23 @@ +package edu.university_connect.service.role; + +import edu.university_connect.model.contract.request.role.RoleCreateRequest; +import edu.university_connect.model.contract.request.role.RoleUpdateRequest; +import edu.university_connect.model.contract.dto.RoleDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface RoleService { + Page getPage(Pageable pageable); + List getAll(); + RoleDto getById(Long id); + + RoleDto create(RoleCreateRequest createRequest); + + RoleDto update(Long id, RoleUpdateRequest updateRequest); + + boolean delete(Long id); + + +} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/service/role/RoleServiceImpl.java b/src/main/java/edu/university_connect/service/role/RoleServiceImpl.java new file mode 100644 index 00000000..4a6daa79 --- /dev/null +++ b/src/main/java/edu/university_connect/service/role/RoleServiceImpl.java @@ -0,0 +1,95 @@ +package edu.university_connect.service.role; + +import edu.university_connect.exception.ServiceException; +import edu.university_connect.mapper.RoleDtoMapper; +import edu.university_connect.model.enums.AppStatusCode; +import edu.university_connect.model.contract.dto.RoleDto; +import edu.university_connect.model.contract.request.role.RoleCreateRequest; +import edu.university_connect.model.contract.request.role.RoleUpdateRequest; +import edu.university_connect.domain.entity.Role; +import edu.university_connect.repository.RoleRepository; +import edu.university_connect.service.MessagingService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +@RequiredArgsConstructor +@Service +@Transactional +public class RoleServiceImpl implements MessagingService.RoleService { + + private final RoleRepository repository; + + @Override + public Page getPage(Pageable pageable) { + Page page = repository.findAll(pageable); + return page.map(RoleDtoMapper.MAPPER::entityToDto); + } + + @Override + public List getAll() { + return repository.findAll() + .stream() + .map(RoleDtoMapper.MAPPER::entityToDto) + .toList(); + } + + @Override + public RoleDto getById(Long id) { + Optional roleOpt= getRoleById(id); + if(roleOpt.isPresent()){ + return RoleDtoMapper.MAPPER.entityToDto(roleOpt.get()); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "role",id.toString()); + } + } + + @Override + public RoleDto create(RoleCreateRequest createRequest) { + Optional roleWithCode=repository.findByCodeIgnoreCase(createRequest.getCode()); + if(roleWithCode.isPresent()){ + throw ServiceException.of(AppStatusCode.E40006,"role","code="+createRequest.getCode()); + } + //check valid action codes + Role role= RoleDtoMapper.MAPPER.dtoToEntity(createRequest); + Role savedRole=repository.save(role); + return RoleDtoMapper.MAPPER.entityToDto(savedRole); + } + + @Override + public RoleDto update(Long id, RoleUpdateRequest updateRequest) { + Optional roleOpt= getRoleById(id); + if(roleOpt.isPresent()){ + //check valid action codes + Role role=roleOpt.get(); + role.setName(updateRequest.getName()); + role.setCode(updateRequest.getCode()); + role.setDescription(updateRequest.getDescription()); + role.setActions(updateRequest.getActions()); + Role savedRole=repository.save(role); + return RoleDtoMapper.MAPPER.entityToDto(savedRole); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "role"); + } + } + + @Override + public boolean delete(Long id) { + if(Objects.nonNull(getById(id))){ + repository.deleteById(id); + } + return true; + } + + private Optional getRoleById(Long id){ + return repository.findById(id); + } +} diff --git a/src/main/java/edu/university_connect/service/impl/UserDetailsServiceImpl.java b/src/main/java/edu/university_connect/service/user/UserDetailsServiceImpl.java similarity index 64% rename from src/main/java/edu/university_connect/service/impl/UserDetailsServiceImpl.java rename to src/main/java/edu/university_connect/service/user/UserDetailsServiceImpl.java index a36e1c4c..34fff206 100644 --- a/src/main/java/edu/university_connect/service/impl/UserDetailsServiceImpl.java +++ b/src/main/java/edu/university_connect/service/user/UserDetailsServiceImpl.java @@ -1,8 +1,9 @@ -package edu.university_connect.service.impl; +package edu.university_connect.service.user; +import edu.university_connect.domain.entity.User; import edu.university_connect.model.SecurityUser; -import edu.university_connect.model.entity.SystemUser; -import edu.university_connect.repository.SystemUserRepository; +import edu.university_connect.domain.entity.Resource; +import edu.university_connect.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -17,14 +18,14 @@ @Transactional public class UserDetailsServiceImpl implements UserDetailsService{ - private final SystemUserRepository repository; + private final UserRepository repository; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - Optional systemUserOpt= repository.findByUsername(username); - if(systemUserOpt.isPresent()){ - SystemUser user=systemUserOpt.get(); + Optional userOpt= repository.findByUsername(username); + if(userOpt.isPresent()){ + User user=userOpt.get(); user.setRoles(user.getRoles()); - return new SecurityUser(systemUserOpt.get()); + return new SecurityUser(userOpt.get()); } else throw new UsernameNotFoundException(username); } diff --git a/src/main/java/edu/university_connect/service/user/UserService.java b/src/main/java/edu/university_connect/service/user/UserService.java new file mode 100644 index 00000000..93d77d7a --- /dev/null +++ b/src/main/java/edu/university_connect/service/user/UserService.java @@ -0,0 +1,23 @@ +package edu.university_connect.service.user; + +import edu.university_connect.model.contract.request.user.UserCreateRequest; +import edu.university_connect.model.contract.request.user.UserUpdateRequest; +import edu.university_connect.model.contract.dto.UserDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface UserService { + Page getPage(Pageable pageable); + List getAll(); + UserDto getById(Long id); + + UserDto create(UserCreateRequest createRequest); + + UserDto update(Long id, UserUpdateRequest updateRequest); + + boolean delete(Long id); + + +} \ No newline at end of file diff --git a/src/main/java/edu/university_connect/service/user/UserServiceImpl.java b/src/main/java/edu/university_connect/service/user/UserServiceImpl.java new file mode 100644 index 00000000..05110cc8 --- /dev/null +++ b/src/main/java/edu/university_connect/service/user/UserServiceImpl.java @@ -0,0 +1,92 @@ +package edu.university_connect.service.user; + +import edu.university_connect.domain.entity.User; +import edu.university_connect.exception.ServiceException; +import edu.university_connect.mapper.UserDtoMapper; +import edu.university_connect.model.enums.AppStatusCode; +import edu.university_connect.model.contract.dto.UserDto; +import edu.university_connect.model.contract.request.user.UserCreateRequest; +import edu.university_connect.model.contract.request.user.UserUpdateRequest; +import edu.university_connect.domain.entity.Resource; +import edu.university_connect.repository.UserRepository; +import edu.university_connect.service.user.UserService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +@Service +@RequiredArgsConstructor +@Transactional +public class UserServiceImpl implements UserService { + + private final UserRepository repository; + private final PasswordEncoder passwordEncoder; + + + @Override + public Page getPage(Pageable pageable) { + Page page = repository.findAll(pageable); + return page.map(UserDtoMapper.MAPPER::entityToDto); + } + + @Override + public List getAll() { + return repository.findAll() + .stream() + .map(UserDtoMapper.MAPPER::entityToDto) + .toList(); + } + + @Override + public UserDto getById(Long id) { + Optional userOpt= getUserById(id); + if(userOpt.isPresent()){ + return UserDtoMapper.MAPPER.entityToDto(userOpt.get()); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "user"); + } + } + + @Override + public UserDto create(UserCreateRequest createRequest) { + + User user= UserDtoMapper.MAPPER.dtoToEntity(createRequest); + user.setPassword(passwordEncoder.encode(user.getPassword())); + User savedUser=repository.save(user); + return UserDtoMapper.MAPPER.entityToDto(savedUser); + } + + @Override + public UserDto update(Long id, UserUpdateRequest updateRequest) { + Optional userOpt= getUserById(id); + if(userOpt.isPresent()){ + User user=userOpt.get(); + user.setUsername(updateRequest.getUsername()); + user.setEmail(updateRequest.getEmail()); + user.setEnabled(updateRequest.isEnabled()); + User savedUser=repository.save(user); + return UserDtoMapper.MAPPER.entityToDto(savedUser); + } + else { + throw ServiceException.of(AppStatusCode.E40000, "user"); + } + } + + @Override + public boolean delete(Long id) { + if(Objects.nonNull(getById(id))){ + repository.deleteById(id); + } + return true; + } + + private Optional getUserById(Long id){ + return repository.findById(id); + } +} diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index c5631b5e..973b32a9 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,45 +1,45 @@ -INSERT INTO system_action +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('063cac59-0301-480f-a8ed-dcf7eeafa7ce'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00000', 'Create System Action', 'Create System Action'); -INSERT INTO system_action +VALUES('063cac59-0301-480f-a8ed-dcf7eeafa7ce'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00000', 'Create Action', 'Create Action'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('8fd43131-4ed5-4f2f-a485-b706be655557'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00001', 'Read System Action', 'Read System Action'); -INSERT INTO system_action +VALUES('8fd43131-4ed5-4f2f-a485-b706be655557'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00001', 'Read Action', 'Read Action'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('47a2022c-fed0-45a0-afc4-66674a7e0ce4'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00003', 'Update System Action', 'Update System Action'); -INSERT INTO system_action +VALUES('47a2022c-fed0-45a0-afc4-66674a7e0ce4'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00003', 'Update Action', 'Update Action'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('2c2ef853-7d2a-4e73-80ae-df0062fe195a'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00004', 'Delete System Action', 'Delete System Action'); -INSERT INTO system_action +VALUES('2c2ef853-7d2a-4e73-80ae-df0062fe195a'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00004', 'Delete Action', 'Delete Action'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('c2d24bc5-1fe5-4f13-add5-a768d5bf4258'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00002', 'Read System Action List', 'Read System Action List'); -INSERT INTO system_action +VALUES('c2d24bc5-1fe5-4f13-add5-a768d5bf4258'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SAC00002', 'Read Action List', 'Read Action List'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('68c5ea35-6a18-4049-8a0a-c0d8e17f3981'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00000', 'Create System Role', 'Create System Role'); -INSERT INTO system_action +VALUES('68c5ea35-6a18-4049-8a0a-c0d8e17f3981'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00000', 'Create Role', 'Create Role'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('991a8840-1039-415a-8e80-878c96aa6d19'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00001', 'Read System Role', 'Read System Role'); -INSERT INTO system_action +VALUES('991a8840-1039-415a-8e80-878c96aa6d19'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00001', 'Read Role', 'Read Role'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('67895124-07fb-44a3-8ab7-7703a4316fa2'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00003', 'Update System Role', 'Update System Role'); -INSERT INTO system_action +VALUES('67895124-07fb-44a3-8ab7-7703a4316fa2'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00003', 'Update Role', 'Update Role'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('4239435a-4fc8-4b35-b565-3c64403e9a7a'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00004', 'Delete System Role', 'Delete System Role'); -INSERT INTO system_action +VALUES('4239435a-4fc8-4b35-b565-3c64403e9a7a'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00004', 'Delete Role', 'Delete Role'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('b647869e-5f06-4d78-8946-97dcb03097f4'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00002', 'Read System Role List', 'Read System Role List'); -INSERT INTO system_action +VALUES('b647869e-5f06-4d78-8946-97dcb03097f4'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SRO00002', 'Read Role List', 'Read Role List'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('f35b2b64-76e5-4821-ab1d-47eb7742ee45'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00000', 'Create System User', 'Create System User'); -INSERT INTO system_action +VALUES('f35b2b64-76e5-4821-ab1d-47eb7742ee45'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00000', 'Create User', 'Create User'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('86ed352c-c77d-4899-a290-04af4ef01ce5'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00001', 'Read System User', 'Read System User'); -INSERT INTO system_action +VALUES('86ed352c-c77d-4899-a290-04af4ef01ce5'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00001', 'Read User', 'Read User'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('e64b4e6c-3230-4327-9dba-2a7e5456ad0d'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00003', 'Update System User', 'Update System User'); -INSERT INTO system_action +VALUES('e64b4e6c-3230-4327-9dba-2a7e5456ad0d'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00003', 'Update User', 'Update User'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('136d2079-2b54-4e31-89f5-db09898c1be2'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00004', 'Delete System User', 'Delete System User'); -INSERT INTO system_action +VALUES('136d2079-2b54-4e31-89f5-db09898c1be2'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00004', 'Delete User', 'Delete User'); +INSERT INTO action (id, created_at, created_by, deleted, enabled, last_modified_at, last_modified_by, "version", code, description, "name") -VALUES('5b2b13b4-d58b-483d-b5a0-39d9285c123d'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00002', 'Read System User List', 'Read System User List'); \ No newline at end of file +VALUES('5b2b13b4-d58b-483d-b5a0-39d9285c123d'::uuid, NULL, NULL, false, false, NULL, NULL, 0, 'SUS00002', 'Read User List', 'Read User List'); \ No newline at end of file diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index d3dfd519..ac17e798 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -12,7 +12,7 @@ not.found={0} with {1} not found bad.values.supplied=Bad values supplied. already.exist={0} with {1} already exists. -sys-user = System User -sys-role = System Role -sys-action = System Action +user = User +role = Role +action = Action