diff --git a/build.gradle b/build.gradle index a67c9cd..21b5f37 100644 --- a/build.gradle +++ b/build.gradle @@ -39,4 +39,6 @@ dependencies { compile(group: 'com.opencsv', name: 'opencsv', version: '4.0') testCompile('org.springframework.boot:spring-boot-starter-test') testCompile('org.springframework.security:spring-security-test') -} \ No newline at end of file + compile('com.fasterxml.jackson.dataformat:jackson-dataformat-xml') +} + diff --git a/database_files/Experience.csv b/database_files/Experience.csv new file mode 100644 index 0000000..282ef55 --- /dev/null +++ b/database_files/Experience.csv @@ -0,0 +1,101 @@ +ExperienceId,UserId,StartDate,EndDate,Company,Visible,Title +1,7,7/23/2018,12/7/2017,Wordify,0,0 +2,3,7/5/2018,7/20/2018,BlogXS,0,0 +3,7,5/15/2018,10/6/2017,Skibox,0,0 +4,8,7/3/2018,7/16/2018,Latz,0,0 +5,1,4/6/2018,4/10/2018,Jabbercube,0,0 +6,1,11/21/2017,8/11/2018,Camido,0,0 +7,9,5/30/2018,12/20/2017,Katz,0,0 +8,3,7/3/2018,3/18/2018,Vitz,0,0 +9,1,8/25/2018,8/10/2018,Twinte,0,0 +10,7,12/19/2017,7/15/2018,Realbridge,0,0 +11,5,12/20/2017,12/22/2017,Bubbletube,0,0 +12,5,12/15/2017,11/22/2017,Eabox,0,0 +13,8,2/1/2018,9/13/2018,Jayo,0,0 +14,8,2/23/2018,9/25/2018,Skalith,0,0 +15,8,6/27/2018,5/24/2018,Zoomzone,0,0 +16,1,10/3/2017,7/16/2018,Realmix,0,0 +17,2,6/28/2018,7/17/2018,Agivu,0,0 +18,8,8/27/2018,12/12/2017,Yombu,0,0 +19,1,10/9/2017,4/21/2018,Shufflebeat,0,0 +20,8,2/9/2018,1/15/2018,Quinu,0,0 +21,7,10/31/2017,10/28/2017,Yadel,0,0 +22,3,7/19/2018,9/1/2018,Miboo,0,0 +23,4,7/10/2018,4/23/2018,Dynabox,0,0 +24,3,9/15/2018,4/19/2018,Twimm,0,0 +25,1,12/25/2017,2/4/2018,Thoughtworks,0,0 +26,3,12/3/2017,1/25/2018,Latz,0,0 +27,1,9/17/2018,1/7/2018,Jaxbean,0,0 +28,2,5/13/2018,7/30/2018,Edgepulse,0,0 +29,7,10/12/2017,2/3/2018,Skinder,0,0 +30,1,1/7/2018,3/13/2018,Flipstorm,0,0 +31,9,10/28/2017,1/11/2018,Zoonoodle,0,0 +32,7,9/11/2018,11/17/2017,Twitterbridge,0,0 +33,7,1/27/2018,11/29/2017,Youopia,0,0 +34,1,11/9/2017,3/27/2018,Meemm,0,0 +35,5,4/10/2018,7/24/2018,Yodel,0,0 +36,1,5/27/2018,5/26/2018,Jetwire,0,0 +37,8,10/25/2017,2/10/2018,Bluezoom,0,0 +38,5,11/27/2017,11/4/2017,Zooveo,0,0 +39,5,1/17/2018,11/5/2017,Oyope,0,0 +40,6,8/23/2018,12/15/2017,Voolia,0,0 +41,9,10/20/2017,4/1/2018,Meetz,0,0 +42,3,10/31/2017,11/29/2017,Gabvine,0,0 +43,9,9/5/2018,6/25/2018,Aibox,0,0 +44,1,5/16/2018,8/25/2018,Yabox,0,0 +45,4,5/22/2018,4/15/2018,Realbridge,0,0 +46,1,12/20/2017,12/16/2017,Thoughtbeat,0,0 +47,7,2/18/2018,9/8/2018,Kwilith,0,0 +48,5,9/3/2018,10/2/2017,Geba,0,0 +49,1,12/27/2017,8/13/2018,Zoozzy,0,0 +50,5,11/16/2017,11/7/2017,Oozz,0,0 +51,2,11/14/2017,6/2/2018,Viva,0,0 +52,6,8/30/2018,7/19/2018,Miboo,0,0 +53,6,5/18/2018,1/9/2018,Kimia,0,0 +54,9,1/20/2018,7/27/2018,Jetpulse,0,0 +55,5,7/20/2018,5/14/2018,Agimba,0,0 +56,5,5/5/2018,4/24/2018,LiveZ,0,0 +57,8,1/24/2018,6/15/2018,Twitterlist,0,0 +58,5,12/31/2017,9/1/2018,Gigaclub,0,0 +59,7,8/18/2018,7/21/2018,Eabox,0,0 +60,4,7/26/2018,9/21/2018,Photobug,0,0 +61,6,8/25/2018,11/14/2017,Jaxbean,0,0 +62,6,6/1/2018,5/17/2018,Ntag,0,0 +63,9,3/30/2018,9/4/2018,Kazio,0,0 +64,9,10/14/2017,4/7/2018,Browsecat,0,0 +65,5,4/4/2018,2/25/2018,Snaptags,0,0 +66,3,9/30/2017,1/25/2018,Cogidoo,0,0 +67,4,10/3/2017,11/3/2017,Twitterlist,0,0 +68,4,12/16/2017,4/8/2018,Quaxo,0,0 +69,9,12/23/2017,12/16/2017,Voolith,0,0 +70,6,2/14/2018,8/28/2018,Yoveo,0,0 +71,4,9/10/2018,10/7/2017,Voolith,0,0 +72,2,8/10/2018,8/31/2018,Eamia,0,0 +73,4,5/30/2018,9/4/2018,Oyoyo,0,0 +74,4,9/14/2018,1/10/2018,Yakidoo,0,0 +75,8,2/25/2018,1/2/2018,Innojam,0,0 +76,1,5/21/2018,10/9/2017,Gabspot,0,0 +77,1,12/26/2017,6/15/2018,Twiyo,0,0 +78,4,5/30/2018,10/9/2017,Trupe,0,0 +79,1,8/10/2018,4/28/2018,Quinu,0,0 +80,7,10/4/2017,10/29/2017,Browseblab,0,0 +81,5,9/8/2018,7/31/2018,Pixoboo,0,0 +82,5,9/1/2018,11/26/2017,Meembee,0,0 +83,3,5/15/2018,2/12/2018,Dynabox,0,0 +84,1,7/3/2018,5/24/2018,Jatri,0,0 +85,9,10/17/2017,5/13/2018,Katz,0,0 +86,3,2/24/2018,1/18/2018,Flashpoint,0,0 +87,8,1/4/2018,1/15/2018,Eayo,0,0 +88,6,9/13/2018,7/5/2018,Dabjam,0,0 +89,8,5/16/2018,10/31/2017,Photobug,0,0 +90,5,11/27/2017,5/14/2018,Realcube,0,0 +91,5,6/7/2018,7/28/2018,Oyoloo,0,0 +92,8,10/29/2017,4/28/2018,Wordpedia,0,0 +93,3,2/26/2018,4/1/2018,Oyope,0,0 +94,7,7/28/2018,2/27/2018,Twitterlist,0,0 +95,1,8/20/2018,9/17/2018,Buzzshare,0,0 +96,7,3/7/2018,11/22/2017,Oyope,0,0 +97,1,3/20/2018,2/17/2018,Meezzy,0,0 +98,1,12/25/2017,8/8/2018,Fadeo,0,0 +99,1,6/9/2018,12/13/2017,Twitterworks,0,0 +100,9,3/29/2018,9/1/2018,Shuffledrive,0,0 diff --git a/src/main/java/com/linkedin/config/WebSecurityConfig.java b/src/main/java/com/linkedin/config/WebSecurityConfig.java index abf1b81..d2be57a 100644 --- a/src/main/java/com/linkedin/config/WebSecurityConfig.java +++ b/src/main/java/com/linkedin/config/WebSecurityConfig.java @@ -37,7 +37,7 @@ public void configure(WebSecurity web) throws Exception { "/swagger-ui.html", "/downloadFile/**", "/webjars/**"); - //"/**");//here we allow all routes without security + //here we allow all routes without security //TODO remove this because security doesnt work with this } diff --git a/src/main/java/com/linkedin/controller/AdminController.java b/src/main/java/com/linkedin/controller/AdminController.java new file mode 100644 index 0000000..c4b62c0 --- /dev/null +++ b/src/main/java/com/linkedin/controller/AdminController.java @@ -0,0 +1,39 @@ +package com.linkedin.controller; + +import com.linkedin.entities.model.AdminXmlDto; +import com.linkedin.entities.model.UserDto; +import com.linkedin.service.AdminService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = AdminController.tag) +@RestController +@RequestMapping("/api/admin/") +public class AdminController { + public static final String tag = "Admin Controller"; + +private final AdminService adminService; + + + @Autowired + public AdminController(AdminService adminService){ + this.adminService = adminService; + } + + + @ApiOperation(value = "Profile", notes = "Returns User's profile info", response = UserDto.class ) + @RequestMapping(value = "/get-xml/", method = RequestMethod.GET, produces=MediaType.APPLICATION_XML_VALUE, consumes = MediaType.ALL_VALUE ) + @ResponseBody + public List getXml()throws Exception { + return adminService.getXml(); + // return new UserDto(userService.getUser(login.getUserId())); + } +} diff --git a/src/main/java/com/linkedin/controller/CommentController.java b/src/main/java/com/linkedin/controller/CommentController.java index 65714d6..4ab91a4 100644 --- a/src/main/java/com/linkedin/controller/CommentController.java +++ b/src/main/java/com/linkedin/controller/CommentController.java @@ -35,6 +35,12 @@ public List getPostComments(){ return commentService.getAllComments(); } + @GetMapping("/post/user/{userId}") + @ApiOperation(value = "Comment", notes = "Returns all Comments a user made in all posts", response = Comment.class) + public List getPostUserComments(@PathVariable Long userId) throws Exception{ + return commentService.getPostUserComments(userId); + } + @GetMapping("/post/{postId}") @ApiOperation(value = "Comment", notes = "Returns all Comments of a Post", response = Comment.class) public List getPostComments(@PathVariable Long postId) throws Exception { diff --git a/src/main/java/com/linkedin/controller/ExperienceController.java b/src/main/java/com/linkedin/controller/ExperienceController.java index 6b61587..0df04a2 100644 --- a/src/main/java/com/linkedin/controller/ExperienceController.java +++ b/src/main/java/com/linkedin/controller/ExperienceController.java @@ -22,44 +22,50 @@ @RestController @RequestMapping("/api/profile/experience/") public class ExperienceController { - public static final String tag = "Experience Controller"; - private final ExperienceService experienceService; + public static final String tag = "Experience Controller"; + private final ExperienceService experienceService; - @Autowired - public ExperienceController(ExperienceService experienceService) { - this.experienceService = experienceService; - } + @Autowired + public ExperienceController(ExperienceService experienceService) { + this.experienceService = experienceService; + } - @ApiOperation(value = "Returns all Experiences of the user", response = ExperienceDto.class) - @GetMapping("/{userId}") - public List getExperiences(@PathVariable Long userId) { - return experienceService.getUsersExperiences(userId); - } + @ApiOperation(value = "Returns all Experiences of the user", response = ExperienceDto.class) + @GetMapping("/{userId}") + public List getExperiences(@PathVariable Long userId) { + return experienceService.getUsersExperiences(userId); + } - @ApiOperation(value = "Returns all Experiences of the user", response = ExperienceDto.class) - @GetMapping("/") - public List getExperiences() { - return experienceService.getExperiences(); - } + @ApiOperation(value = "Returns all Experiences of the user", response = ExperienceDto.class) + @GetMapping("/") + public List getExperiences() { + return experienceService.getExperiences(); + } - @ApiOperation(value = "Creates a new Experience", response = ExperienceDto.class) - @PostMapping("/") - public ExperienceDto createExperiences(@Valid @RequestBody ExperienceRequestDto experienceRequestDto) { - return experienceService.createExperience(experienceRequestDto); - } + @ApiOperation(value = "Returns all Experiences from database", response = ExperienceDto.class) + @GetMapping("/all-experience/") + public List getAllExperiences() { + return experienceService.getAllExperiences(); + } - @PutMapping("/{experienceId}") - @ApiOperation(value = "Experience", notes = "Updates an experience of the User", response = ExperienceDto.class) - public ExperienceDto updateExperience(@PathVariable Long experienceId, @Valid @RequestBody ExperienceRequestDto experienceRequestDto) throws Exception { + @ApiOperation(value = "Creates a new Experience", response = ExperienceDto.class) + @PostMapping("/") + public ExperienceDto createExperiences(@Valid @RequestBody ExperienceRequestDto experienceRequestDto) { + return experienceService.createExperience(experienceRequestDto); + } - return experienceService.updateExperience(experienceId, experienceRequestDto); + @PutMapping("/{experienceId}") + @ApiOperation(value = "Experience", notes = "Updates an experience of the User", response = ExperienceDto.class) + public ExperienceDto updateExperience(@PathVariable Long experienceId, @Valid @RequestBody ExperienceRequestDto experienceRequestDto) throws Exception { - } + return experienceService.updateExperience(experienceId, experienceRequestDto); - @ApiOperation(value = "Deletes a Users Experience", response = ExperienceDto.class) - @DeleteMapping("/{experienceId}") - public void deleteExperience(@PathVariable Long experienceId) throws Exception { - experienceService.removeExperience(experienceId); - } + } + + @ApiOperation(value = "Deletes a Users Experience", response = ExperienceDto.class) + @DeleteMapping("/{experienceId}") + public void deleteExperience(@PathVariable Long experienceId) throws Exception { + experienceService.removeExperience(experienceId); + } } \ No newline at end of file diff --git a/src/main/java/com/linkedin/controller/ProfileController.java b/src/main/java/com/linkedin/controller/ProfileController.java index 1e905ea..7ead0fa 100644 --- a/src/main/java/com/linkedin/controller/ProfileController.java +++ b/src/main/java/com/linkedin/controller/ProfileController.java @@ -2,7 +2,7 @@ import com.linkedin.converter.UserConverter; import com.linkedin.entities.database.Login; -import com.linkedin.entities.database.User; +import com.linkedin.entities.database.repo.UserRepository; import com.linkedin.entities.model.UploadFileResponse; import com.linkedin.entities.model.UserDto; import com.linkedin.entities.model.UserRequestDto; @@ -26,6 +26,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.util.List; +import java.util.stream.Collectors; + @Api(tags = ProfileController.tag) @RestController @@ -37,12 +40,14 @@ public class ProfileController { private final UserService userService; private final ProfileService profileService; private final UserConverter userConverter; + private final UserRepository userRepository; @Autowired - public ProfileController(UserService userService, ProfileService profileService, UserConverter userConverter) { + public ProfileController(UserService userService, ProfileService profileService, UserConverter userConverter, UserRepository userRepository) { this.userService = userService; this.profileService = profileService; this.userConverter = userConverter; + this.userRepository = userRepository; } @GetMapping("/") @@ -93,4 +98,5 @@ public void changeEmail(@RequestBody ChangeEmailRequestDto changeEmailRequestDto } + } diff --git a/src/main/java/com/linkedin/converter/ExperienceConverter.java b/src/main/java/com/linkedin/converter/ExperienceConverter.java index 7cdf7c1..84df706 100644 --- a/src/main/java/com/linkedin/converter/ExperienceConverter.java +++ b/src/main/java/com/linkedin/converter/ExperienceConverter.java @@ -15,6 +15,7 @@ public ExperienceDto toExperienceDto(Experience experience) { experienceDto.setEndDate(experience.getEndDate()); experienceDto.setExperienceId(experience.getExperienceId()); experienceDto.setVisible(experience.getVisible()); + experienceDto.setUserId(experience.getUserId()); return experienceDto; } } diff --git a/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java b/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java index 2528651..80c7f4a 100644 --- a/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java +++ b/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java @@ -33,7 +33,7 @@ */ @Component public class DatabaseCsvReader { - private final String[] FILE_ARRAY = new String[]{"database_files/Login.csv","database_files/Notification.csv", "database_files/Job.csv", "database_files/Connection.csv","database_files/User.csv" , "database_files/Post.csv" ,"database_files/Comment.csv" ,"database_files/Like.csv" ,"database_files/ConnectionRequest.csv", "database_files/Message.csv"}; + private final String[] FILE_ARRAY = new String[]{"database_files/Experience.csv","database_files/Login.csv","database_files/Notification.csv", "database_files/Job.csv", "database_files/Connection.csv","database_files/User.csv" , "database_files/Post.csv" ,"database_files/Comment.csv" ,"database_files/Like.csv" ,"database_files/ConnectionRequest.csv", "database_files/Message.csv"}; private final String ENTITIES_PACKAGE_NAME = "com.linkedin.entities.database"; private final Repositories repositories; diff --git a/src/main/java/com/linkedin/entities/database/repo/CommentRepository.java b/src/main/java/com/linkedin/entities/database/repo/CommentRepository.java index 737b243..0985056 100644 --- a/src/main/java/com/linkedin/entities/database/repo/CommentRepository.java +++ b/src/main/java/com/linkedin/entities/database/repo/CommentRepository.java @@ -9,4 +9,5 @@ @Repository public interface CommentRepository extends JpaRepository { List findAllByPostId(Long postId); + List findAllByCommenterId(Long userId); } diff --git a/src/main/java/com/linkedin/entities/database/repo/JobRepository.java b/src/main/java/com/linkedin/entities/database/repo/JobRepository.java index 1d84431..1b0bde1 100644 --- a/src/main/java/com/linkedin/entities/database/repo/JobRepository.java +++ b/src/main/java/com/linkedin/entities/database/repo/JobRepository.java @@ -4,6 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface JobRepository extends JpaRepository { + List findAllByAuthorId(Long userId); } diff --git a/src/main/java/com/linkedin/entities/model/AdminXmlDto.java b/src/main/java/com/linkedin/entities/model/AdminXmlDto.java new file mode 100644 index 0000000..b086972 --- /dev/null +++ b/src/main/java/com/linkedin/entities/model/AdminXmlDto.java @@ -0,0 +1,51 @@ +package com.linkedin.entities.model; + +import com.linkedin.entities.model.Comment.CommentDto; +import com.linkedin.entities.model.Post.PostDto; +import com.linkedin.entities.model.connection.ConnectionDto; +import com.linkedin.entities.model.experience.ExperienceDto; +import com.linkedin.entities.model.jobs.JobDto; +import com.linkedin.entities.model.likes.LikeDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.persistence.ElementCollection; +import java.util.ConcurrentModificationException; +import java.util.List; + +@Data +@ApiModel(description = "Admin xml response") + +public class AdminXmlDto { + @ApiModelProperty(value = "userId", example = "1", position = 1) + private Long userId; + + @ApiModelProperty(value = "userDto", example = "UserDto", position = 2) + private UserDto userDto; + + @ElementCollection + @ApiModelProperty(value = "list of PostDto", example = "[PostDto1, PostDto2]", position = 3) + public List posts; + + @ElementCollection + @ApiModelProperty(value = "list of PostDto", example = "[ExperienceDto1, ExperienceDto2]", position = 4) + public List experiences; + + @ElementCollection + @ApiModelProperty(value = "list of JobDto of jobs he created", example = "[JobDto1, JobDto2]", position = 5) + public List jobs; + + @ElementCollection + @ApiModelProperty(value = "list of CommentDto", example = "[CommentDto1, CommentDto2]", position = 6) + public List comments; + + + @ElementCollection + @ApiModelProperty(value = "list of LikeDto", example = "[LikeDto1, LikeDto2]", position = 7) + public List likes; + + @ElementCollection + @ApiModelProperty(value = "list of ConnectionDto", example = "[ConnectionDto1, ConnectionDto2]", position = 8) + public List connectionDtoList; +} diff --git a/src/main/java/com/linkedin/entities/model/experience/ExperienceDto.java b/src/main/java/com/linkedin/entities/model/experience/ExperienceDto.java index 82386db..fb7209c 100644 --- a/src/main/java/com/linkedin/entities/model/experience/ExperienceDto.java +++ b/src/main/java/com/linkedin/entities/model/experience/ExperienceDto.java @@ -12,27 +12,30 @@ @ApiModel(description = "user's Experience Dto") public class ExperienceDto { - @NotNull - @ApiModelProperty(value = "ExperienceId ", example = "1", position = 1) - private Long experienceId; + @NotNull + @ApiModelProperty(value = "ExperienceId ", example = "1", position = 1) + private Long experienceId; - @NotBlank - @ApiModelProperty(value = "Title ", example = "Software Engineer", position = 2) - private String title; + @ApiModelProperty(value = "userId ", example = "1", position = 2) + private Long userId; - @NotBlank - @ApiModelProperty(value = "Company Name", example = "Google", position = 3) - private String company; + @NotBlank + @ApiModelProperty(value = "Title ", example = "Software Engineer", position = 3) + private String title; - @NotNull - @ApiModelProperty(value = "Date started", example = "2010-01-01", position = 4) - private Date startDate; + @NotBlank + @ApiModelProperty(value = "Company Name", example = "Google", position = 4) + private String company; - @NotNull - @ApiModelProperty(value = "Date ended", example = "2018-01-01", position = 5) - private Date endDate; + @NotNull + @ApiModelProperty(value = "Date started", example = "2010-01-01", position = 5) + private Date startDate; - @NotNull - private Integer visible; + @NotNull + @ApiModelProperty(value = "Date ended", example = "2018-01-01", position = 6) + private Date endDate; + + @NotNull + private Integer visible; } diff --git a/src/main/java/com/linkedin/service/AdminService.java b/src/main/java/com/linkedin/service/AdminService.java new file mode 100644 index 0000000..221d660 --- /dev/null +++ b/src/main/java/com/linkedin/service/AdminService.java @@ -0,0 +1,69 @@ +package com.linkedin.service; + +import com.linkedin.converter.UserConverter; +import com.linkedin.entities.database.User; +import com.linkedin.entities.database.repo.JobRepository; +import com.linkedin.entities.database.repo.PostRepository; +import com.linkedin.entities.database.repo.UserRepository; +import com.linkedin.entities.model.AdminXmlDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service + +public class AdminService { + private final UserService userService; + private final UserConverter userConverter; + private final UserRepository userRepository; + private final PostRepository postRepository; + private final PostService postService; + private final ExperienceService experienceService; + private final CommentService commentService; + private final LikeService likeService; + private final ConnectionService connectionService; + private final JobService jobService; + private final JobRepository jobRepository; + + @Autowired + public AdminService(UserService userService, UserConverter userConverter, UserRepository userRepository, PostRepository postRepository, PostService postService, ExperienceService experienceService, CommentService commentService, LikeService likeService, ConnectionService connectionService, JobService jobService, JobRepository jobRepository){ + this.userService = userService; + this.userConverter = userConverter; + this.userRepository = userRepository; + this.postRepository = postRepository; + this.postService = postService; + this.experienceService = experienceService; + this.commentService = commentService; + this.likeService = likeService; + this.connectionService = connectionService; + this.jobService = jobService; + this.jobRepository = jobRepository; + } + + public List getXml() throws Exception { + List userList = userRepository.findAll(); + List adminXmlDtoList = new ArrayList<>(); + + for(int i =0;i < userList.size();++i){ + Long userId = userList.get(i).getId(); + AdminXmlDto adminXmlDto = new AdminXmlDto(); + + + adminXmlDto.setUserId(userId); + + adminXmlDto.setPosts(postService.getUsersPost(userId)); + adminXmlDto.setExperiences(experienceService.getUsersExperiences(userId)); + adminXmlDto.setUserDto( userConverter.toUserDto(userRepository.findById(userId).orElse(null) ) ); + adminXmlDto.setComments(commentService.getPostUserComments(userId)); + adminXmlDto.setLikes(likeService.getUserLikes(userId)); + adminXmlDto.setConnectionDtoList(connectionService.getUserConnections(userId)); + adminXmlDto.setJobs(jobService.getAllJobUserCreated(userId)); + adminXmlDtoList.add(adminXmlDto); + + } + return adminXmlDtoList; + + } +} diff --git a/src/main/java/com/linkedin/service/CommentService.java b/src/main/java/com/linkedin/service/CommentService.java index 7bfc496..9efd321 100644 --- a/src/main/java/com/linkedin/service/CommentService.java +++ b/src/main/java/com/linkedin/service/CommentService.java @@ -3,8 +3,10 @@ import com.linkedin.converter.CommentConverter; import com.linkedin.entities.database.Comment; import com.linkedin.entities.database.Post; +import com.linkedin.entities.database.User; import com.linkedin.entities.database.repo.CommentRepository; import com.linkedin.entities.database.repo.PostRepository; +import com.linkedin.entities.database.repo.UserRepository; import com.linkedin.entities.model.Comment.CommentDto; import com.linkedin.entities.model.Comment.CommentRequestDto; import com.linkedin.errors.NotAuthorizedException; @@ -24,13 +26,15 @@ public class CommentService { private final CommentConverter commentConverter; private final PostRepository postRepository; private final NotificationService notificationService; + private final UserRepository userRepository; @Autowired - public CommentService(CommentRepository commentRepository, CommentConverter commentConverter, PostRepository postRepository, NotificationService notificationService) { + public CommentService(CommentRepository commentRepository, CommentConverter commentConverter, PostRepository postRepository, NotificationService notificationService, UserRepository userRepository) { this.commentRepository = commentRepository; this.commentConverter = commentConverter; this.postRepository = postRepository; this.notificationService = notificationService; + this.userRepository = userRepository; } @@ -112,4 +116,12 @@ public CommentDto updateComment(Long commentId, CommentRequestDto commentRequest commentRepository.save(comment); return commentConverter.toCommentDto(comment); } + + public List getPostUserComments(Long userId) throws Exception{ + if(!userRepository.existsById(userId)){ + throw new ObjectNotFoundException(User.class, userId); + } + return commentRepository.findAllByCommenterId(userId).stream().map(commentConverter::toCommentDto).collect(Collectors.toList()); + + } } diff --git a/src/main/java/com/linkedin/service/ExperienceService.java b/src/main/java/com/linkedin/service/ExperienceService.java index aaccd23..6494d53 100644 --- a/src/main/java/com/linkedin/service/ExperienceService.java +++ b/src/main/java/com/linkedin/service/ExperienceService.java @@ -101,4 +101,8 @@ public ExperienceDto updateExperience(Long experienceId, ExperienceRequestDto ex return experienceConverter.toExperienceDto(experienceToUpdate); } + + public List getAllExperiences() { + return experienceRepository.findAll().stream().map(experienceConverter::toExperienceDto).collect(Collectors.toList()); + } } diff --git a/src/main/java/com/linkedin/service/JobService.java b/src/main/java/com/linkedin/service/JobService.java index edcf2a6..0b0f8a9 100644 --- a/src/main/java/com/linkedin/service/JobService.java +++ b/src/main/java/com/linkedin/service/JobService.java @@ -44,6 +44,10 @@ public JobService(JobRepository jobRepository, JobConverter jobConverter, UserSe this.userConverter = userConverter; } + public List getAllJobUserCreated(Long userId){ + return jobRepository.findAllByAuthorId(userId).stream().map(jobConverter::toJobDto).collect(Collectors.toList()); + } + public Job createJob(JobRequestDto dto) { Job job = new Job(); job.setTitle(dto.getTitle());