Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/main/java/site/easystartup/web/project/service/ProjectService.java
#	src/main/java/site/easystartup/web/service/UserService.java
This commit is contained in:
Viktoria committed 2022-08-29 14:53:25 +02:00
commit 3b5a6aab84
47 files changed
+361 -245

No files matched your search

@@ -1,40 +0,0 @@
package site.easystartup.easystartupcore.forum.controller;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import site.easystartup.easystartupcore.forum.filter.FilterService;
import site.easystartup.easystartupcore.forum.repo.TopicRepo;
@Controller
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ForumController {
private final TopicRepo topicRepo;
private final FilterService filterService;
@GetMapping("/forum")
public String forumMain(Model model) {
val topic = topicRepo.findAll();
model.addAttribute("topics", topic);
return "forum";
}
@GetMapping("/forum/my")
public String forumMy(Model model) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
val discussions = filterService.getDiscussionsByAuthor(user.getUsername());
model.addAttribute("discussions", discussions);
return "my-discussions";
}
@GetMapping("/forum/new")
public String forumNew() {
return "topic-new";
}
}
@@ -1,5 +0,0 @@
package site.easystartup.easystartupcore.forum.domain;
public enum DiscussionStatus {
OPEN, CLOSED;
}
@@ -1,65 +0,0 @@
package site.easystartup.easystartupcore.project.service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import site.easystartup.easystartupcore.project.domain.model.Project;
import site.easystartup.easystartupcore.project.repo.ProjectRepo;
import site.easystartup.easystartupcore.service.UserService;
import java.security.Principal;
import java.util.Arrays;
import java.util.Set;
@Service
@RequiredArgsConstructor
public class ProjectService {
private final ProjectRepo projectRepo;
private final UserService userService;
public Project createProject(Project project, Principal principal) {
project.setTechnology(technologyToString(project.getTechnology()));
project.setOwner(userService.getUserByPrincipal(principal));
return projectRepo.save(project);
}
//
// public Project updateProject(Project map, Long projectId, Principal principal) {
// }
//
// public void deleteProject(Long projectId, Principal principal) {
// }
//
// public Project getProjectById(Long projectId) {
// }
//
// public Set<Project> getAllProjectsForUser(Long userId) {
//
//
// }
//
// public Set<Project> getAllProjectsWithTechnology(String technology) {
// }
//
// public Set<Project> getAllProjectsForCurrentUser(Principal principal) {
// }
//
// public Set<Project> getAllProjectsWithPosition(String nameOfPosition) {
// }
//
// public Object applayOnProject(Long projectId, Principal principal) {
// }
//
// public Object confirmParticipant(Long projectId, Long participantId, Principal principal) {
// }
private String technologyToString(String technology) {
StringBuilder technologyResult = new StringBuilder();
Arrays.stream(technology.split(",")).forEach(tech -> technologyResult.append(tech.trim() + " "));
return technologyResult.toString();
}
}
@@ -1,20 +0,0 @@
package site.easystartup.easystartupcore.service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import site.easystartup.easystartupcore.domain.User;
import site.easystartup.easystartupcore.repo.UserRepo;
import java.security.Principal;
@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepo userRepo;
public User getUserByPrincipal(Principal principal) {
return userRepo.findByUsername(principal.getName());
}
}
@@ -1,15 +1,9 @@
package site.easystartup.easystartupcore;
package site.easystartup.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.Map;
@RestController
@SpringBootApplication
public class EasyStartupApplication {
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore;
package site.easystartup.web;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.auth.config;
package site.easystartup.web.auth.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.auth.config;
package site.easystartup.web.auth.config;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.auth.controller;
package site.easystartup.web.auth.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -7,9 +7,9 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import site.easystartup.easystartupcore.domain.Role;
import site.easystartup.easystartupcore.domain.User;
import site.easystartup.easystartupcore.repo.UserRepo;
import site.easystartup.web.domain.Role;
import site.easystartup.web.domain.User;
import site.easystartup.web.repo.UserRepo;
import java.util.Collections;
@@ -1,18 +1,16 @@
package site.easystartup.easystartupcore.config;
package site.easystartup.web.config;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
@ComponentScan(basePackages = {"site.easystartup.easystartupcore"})
@ComponentScan(basePackages = {"site.easystartup.web"})
public class AppConfig {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
@@ -1,7 +1,6 @@
package site.easystartup.easystartupcore.controller;
package site.easystartup.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.domain;
package site.easystartup.web.domain;
public enum Role {
USER, PREMIUM, MODER, ADMIN;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.domain;
package site.easystartup.web.domain;
import lombok.*;
import org.hibernate.Hibernate;
@@ -0,0 +1,82 @@
package site.easystartup.web.forum.controller;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import site.easystartup.web.forum.domain.Topic;
import site.easystartup.web.forum.filter.ForumFilterService;
import site.easystartup.web.forum.repo.TopicRepo;
import java.util.Date;
@Controller
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ForumController {
private final TopicRepo topicRepo;
private final ForumFilterService forumFilterService;
@GetMapping("/forum")
public String forumMain(Model model) {
val topic = topicRepo.findAll();
model.addAttribute("topics", topic);
return "/forum";
}
@GetMapping("/forum/my")
public String forumMy(Model model) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
val discussions = forumFilterService.getDiscussionsByAuthor(user.getUsername());
model.addAttribute("discussions", discussions);
return "/my-discussions";
}
@GetMapping("/forum/new")
public String forumNew() {
return "topic-new";
}
@PostMapping("/forum/new")
public String forumNewTopic(@RequestParam String title,
@RequestParam String description) {
description = description == null ? "" : description;
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Topic topic = new Topic();
topic.setTitle(title);
topic.setDescription(description);
topic.setAuthor(user.getUsername());
topic.setLast_update(new Date());
topic.setSize(0);
topicRepo.save(topic);
return "/forum";
}
@GetMapping("/forum/{topic_id}")
public String topicFirstPage(@PathVariable(value = "topic_id") long topic_id,
Model model) {
val pinned_discussions = forumFilterService.getPinnedDiscussionsByTopicId(topic_id);
model.addAttribute("pinned_discussions", pinned_discussions);
val discussions = forumFilterService.getSortedDiscussionsByTopicId(topic_id).subList(0, 15);
model.addAttribute("discussions", discussions);
return "topic-first";
}
@GetMapping("/forum/{topic_id}/page/{page_index}")
public String topicPage(@PathVariable(value = "topic_id") long topic_id,
@PathVariable(value = "topic_id") long page_index,
Model model) {
val pinned_discussions = forumFilterService.getPinnedDiscussionsByTopicId(topic_id);
model.addAttribute("pinned_discussions", pinned_discussions);
val discussions = forumFilterService.getSortedDiscussionsByTopicId(topic_id).subList(0, 15);
model.addAttribute("discussions", discussions);
return "topic-first";
}
}
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.forum.domain;
package site.easystartup.web.forum.domain;
import lombok.*;
import org.hibernate.Hibernate;
@@ -13,7 +13,7 @@ import java.util.Objects;
@ToString
@RequiredArgsConstructor
@Entity
public class Discussion {
public class Discussion implements Comparable<Discussion>{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@@ -21,6 +21,9 @@ public class Discussion {
private String author;
private Date date;
private Date last_update;
private boolean pinned;
private DiscussionStatus status;
private long topic;
@ElementCollection(targetClass = Long.class, fetch = FetchType.EAGER)
@CollectionTable(name = "discussion_messages", joinColumns = @JoinColumn(name = "discussion_id"))
@@ -38,4 +41,11 @@ public class Discussion {
public int hashCode() {
return getClass().hashCode();
}
@Override
public int compareTo(Discussion o) {
if (getLast_update() == null || o.getLast_update() == null)
return 0;
return getLast_update().compareTo(o.getLast_update());
}
}
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.forum.domain;
package site.easystartup.web.forum.domain;
import lombok.*;
import org.hibernate.Hibernate;
@@ -0,0 +1,5 @@
package site.easystartup.web.forum.domain;
public enum DiscussionStatus {
OPEN, CLOSED;
}
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.forum.domain;
package site.easystartup.web.forum.domain;
import lombok.*;
import org.hibernate.Hibernate;
@@ -1,19 +1,20 @@
package site.easystartup.easystartupcore.forum.filter;
package site.easystartup.web.forum.filter;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import site.easystartup.easystartupcore.forum.domain.Discussion;
import site.easystartup.easystartupcore.forum.domain.DiscussionMessage;
import site.easystartup.easystartupcore.forum.repo.DiscussionMessageRepo;
import site.easystartup.easystartupcore.forum.repo.DiscussionRepo;
import site.easystartup.web.forum.domain.Discussion;
import site.easystartup.web.forum.domain.DiscussionMessage;
import site.easystartup.web.forum.repo.DiscussionMessageRepo;
import site.easystartup.web.forum.repo.DiscussionRepo;
import java.util.Collections;
import java.util.List;
@Component
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class FilterService {
public class ForumFilterService {
private final DiscussionMessageRepo discussionMessageRepo;
private final DiscussionRepo discussionRepo;
@@ -33,4 +34,18 @@ public class FilterService {
.filter(d -> getMessagesByDiscussionId(d.getId()).stream()
.anyMatch(m -> m.getSender().equals(member))).toList();
}
public List<Discussion> getPinnedDiscussionsByTopicId(long topic_id) {
return Lists.newArrayList(discussionRepo.findAll()).stream()
.filter(Discussion::isPinned)
.filter(d -> d.getTopic() == topic_id).toList();
}
public List<Discussion> getSortedDiscussionsByTopicId(long topic_id) {
List<Discussion> result = Lists.newArrayList(discussionRepo.findAll()).stream()
.filter(d -> !d.isPinned())
.filter(d -> d.getTopic() == topic_id).toList();
Collections.sort(result, Discussion::compareTo);
return result;
}
}
@@ -1,7 +1,7 @@
package site.easystartup.easystartupcore.forum.repo;
package site.easystartup.web.forum.repo;
import org.springframework.data.repository.CrudRepository;
import site.easystartup.easystartupcore.forum.domain.DiscussionMessage;
import site.easystartup.web.forum.domain.DiscussionMessage;
public interface DiscussionMessageRepo extends CrudRepository<DiscussionMessage, Long> {
}
@@ -1,7 +1,7 @@
package site.easystartup.easystartupcore.forum.repo;
package site.easystartup.web.forum.repo;
import org.springframework.data.repository.CrudRepository;
import site.easystartup.easystartupcore.forum.domain.Discussion;
import site.easystartup.web.forum.domain.Discussion;
public interface DiscussionRepo extends CrudRepository<Discussion, Long> {
}
@@ -1,7 +1,7 @@
package site.easystartup.easystartupcore.forum.repo;
package site.easystartup.web.forum.repo;
import org.springframework.data.repository.CrudRepository;
import site.easystartup.easystartupcore.forum.domain.Topic;
import site.easystartup.web.forum.domain.Topic;
public interface TopicRepo extends CrudRepository<Topic, Long> {
}
@@ -1,17 +1,15 @@
package site.easystartup.easystartupcore.project.controller;
package site.easystartup.web.project.controller;
import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import site.easystartup.easystartupcore.project.domain.model.Project;
import site.easystartup.easystartupcore.project.domain.payload.response.ResponseMessage;
import site.easystartup.easystartupcore.project.domain.validation.ResponseErrorValidation;
import site.easystartup.easystartupcore.project.dto.ProjectDto;
import site.easystartup.easystartupcore.project.service.ProjectService;
import site.easystartup.web.project.domain.model.Project;
import site.easystartup.web.project.domain.validation.ResponseErrorValidation;
import site.easystartup.web.project.dto.ProjectDto;
import site.easystartup.web.project.service.ProjectService;
import java.security.Principal;
import java.util.Map;
@@ -1,7 +1,7 @@
package site.easystartup.easystartupcore.project.domain.model;
package site.easystartup.web.project.domain.model;
import lombok.Data;
import site.easystartup.easystartupcore.domain.User;
import site.easystartup.web.domain.User;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@@ -1,8 +1,8 @@
package site.easystartup.easystartupcore.project.domain.model;
package site.easystartup.web.project.domain.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import site.easystartup.easystartupcore.domain.User;
import site.easystartup.web.domain.User;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.project.domain.payload.response;
package site.easystartup.web.project.domain.payload.response;
import lombok.Data;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.project.domain.validation;
package site.easystartup.web.project.domain.validation;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.project.dto;
package site.easystartup.web.project.dto;
import lombok.Data;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.project.dto;
package site.easystartup.web.project.dto;
import lombok.Data;
@@ -1,7 +1,7 @@
package site.easystartup.easystartupcore.project.dto;
package site.easystartup.web.project.dto;
import lombok.Data;
import site.easystartup.easystartupcore.domain.Role;
import site.easystartup.web.domain.Role;
import java.io.Serializable;
import java.util.Set;
@@ -1,8 +1,8 @@
package site.easystartup.easystartupcore.project.repo;
package site.easystartup.web.project.repo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import site.easystartup.easystartupcore.project.domain.model.Project;
import site.easystartup.web.project.domain.model.Project;
@Repository
public interface ProjectRepo extends JpaRepository<Project, Long> {
@@ -0,0 +1,49 @@
package site.easystartup.web.project.service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import site.easystartup.web.project.domain.model.Project;
import site.easystartup.web.project.repo.ProjectRepo;
import java.security.Principal;
import java.util.Set;
@Service
@RequiredArgsConstructor
public class ProjectService {
private final ProjectRepo projectRepo;
public Project createProject(Project project, Principal principal) {
return null;
}
public Project updateProject(Project map, Long projectId, Principal principal) {
}
public void deleteProject(Long projectId, Principal principal) {
}
public Project getProjectById(Long projectId) {
}
public Set<Project> getAllProjectsForUser(Long userId) {
}
public Set<Project> getAllProjectsWithTechnology(String technology) {
}
public Set<Project> getAllProjectsForCurrentUser(Principal principal) {
}
public Set<Project> getAllProjectsWithPosition(String nameOfPosition) {
}
public Object applayOnProject(Long projectId, Principal principal) {
}
public Object confirmParticipant(Long projectId, Long participantId, Principal principal) {
}
}
@@ -1,7 +1,7 @@
package site.easystartup.easystartupcore.repo;
package site.easystartup.web.repo;
import org.springframework.data.jpa.repository.JpaRepository;
import site.easystartup.easystartupcore.domain.User;
import site.easystartup.web.domain.User;
public interface UserRepo extends JpaRepository<User, Long> {
User findByUsername(String username);
@@ -1,10 +1,10 @@
package site.easystartup.easystartupcore.storag.config;
package site.easystartup.web.storage.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import site.easystartup.easystartupcore.storag.service.FileLocalStorageService;
import site.easystartup.easystartupcore.storag.service.StorageService;
import site.easystartup.web.storage.service.FileLocalStorageService;
import site.easystartup.web.storage.service.StorageService;
@Configuration
public class FileConfig {
@@ -0,0 +1,70 @@
package site.easystartup.web.storage.controller;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
import site.easystartup.web.storage.service.StorageFileNotFoundException;
import site.easystartup.web.storage.service.StorageService;
import java.util.stream.Collectors;
@Controller
public class FileUploadController {
private final StorageService storageService;
@Autowired
public FileUploadController(StorageService storageService) {
this.storageService = storageService;
}
@GetMapping("/upload")
public String listUploadedFiles(Model model) {
if(storageService.loadAll() == null) {
model.addAttribute("message",
"Storage is emptiy");
return "upload";
}
model.addAttribute("files", storageService.loadAll().map(
path -> MvcUriComponentsBuilder.fromMethodName(FileUploadController.class,
"serveFile", path.getFileName().toString()).build().toUri().toString())
.collect(Collectors.toList()));
return "upload";
}
@SneakyThrows
@GetMapping("/files/{filename:.+}")
@ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
Resource file = storageService.load(filename);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"").body(file);
}
@PostMapping("/upload")
public String handleFileUpload(@RequestParam("file") MultipartFile file,
Model model) {
storageService.save(file);
model.addAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!");
return "upload";
}
@ExceptionHandler(StorageFileNotFoundException.class)
public ResponseEntity<?> handleStorageFileNotFound(StorageFileNotFoundException exc) {
return ResponseEntity.notFound().build();
}
}
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.storag.service;
package site.easystartup.web.storage.service;
import lombok.SneakyThrows;
import org.springframework.core.io.Resource;
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.storag.service;
package site.easystartup.web.storage.service;
public class StorageFileNotFoundException extends RuntimeException {
public StorageFileNotFoundException(String filename) {
@@ -1,4 +1,4 @@
package site.easystartup.easystartupcore.storag.service;
package site.easystartup.web.storage.service;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;