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:
commit
3b5a6aab84
47 files changed
+361
-245
No files matched your search
+2
-1
@@ -7,7 +7,7 @@ plugins {
|
||||
|
||||
group = 'site.easy-startup'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '8'
|
||||
sourceCompatibility = "16"
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
@@ -43,3 +43,4 @@ dependencies {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
@@ -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
-7
@@ -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
-1
@@ -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
-1
@@ -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
-1
@@ -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;
|
||||
+4
-4
@@ -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;
|
||||
|
||||
+2
-4
@@ -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
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore.domain;
|
||||
package site.easystartup.web.domain;
|
||||
|
||||
public enum Role {
|
||||
USER, PREMIUM, MODER, ADMIN;
|
||||
+1
-1
@@ -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";
|
||||
}
|
||||
}
|
||||
+12
-2
@@ -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
-1
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore.forum.domain;
|
||||
package site.easystartup.web.forum.domain;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.Hibernate;
|
||||
+21
-6
@@ -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;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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> {
|
||||
}
|
||||
+2
-2
@@ -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> {
|
||||
}
|
||||
+2
-2
@@ -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> {
|
||||
}
|
||||
+5
-7
@@ -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;
|
||||
+2
-2
@@ -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;
|
||||
+2
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore.project.domain.payload.response;
|
||||
package site.easystartup.web.project.domain.payload.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
+1
-1
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore.project.dto;
|
||||
package site.easystartup.web.project.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore.project.dto;
|
||||
package site.easystartup.web.project.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
+2
-2
@@ -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) {
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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);
|
||||
+3
-3
@@ -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
-1
@@ -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
-1
@@ -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
-1
@@ -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;
|
||||
@@ -8,5 +8,4 @@ spring.sql.init.platform=postgres
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
|
||||
spring.datasource.username=postgres
|
||||
spring.datasource.password=root
|
||||
#spring.datasource.password=postgres
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<h1>Пожалуйста, войдите</h1>
|
||||
|
||||
<div>
|
||||
<input type="text" class="form-control" minlength="3" size="25" id="username" name="username" required placeholder="UserName">
|
||||
<input type="text" minlength="3" size="25" id="username" name="username" required placeholder="UserName">
|
||||
<label for="username">Логин</label>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
@@ -6,18 +6,6 @@
|
||||
<meta charset="utf-8">
|
||||
<title>Вход</title>
|
||||
|
||||
<style>
|
||||
div.error {
|
||||
color: #ff5967;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.logout {
|
||||
color: #2c84ec;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
</head>
|
||||
@@ -28,7 +16,7 @@
|
||||
<p>Мои обсуждения</p>
|
||||
<div th:each="el : ${discussions}">
|
||||
<h2 th:text="${el.title}"/>
|
||||
<p th:text="'Автор: ' + ${el.title}"/>
|
||||
<p th:text="'Автор: ' + ${el.author}"/>
|
||||
<p th:text="'Дата создания: ' + ${#dates.format(el.date, 'hh:mm dd MMM yyyy')}"/>
|
||||
<p th:text="'Последнее обновление: ' + ${#dates.format(el.last_update, 'hh:mm dd MMM yyyy')}"/>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
|
||||
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Вход</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<main>
|
||||
<h2>Закреплённые сообщения</h2>
|
||||
<div th:each="el : ${pinned_discussions}">
|
||||
<h2 th:text="${el.title}"/>
|
||||
<p th:text="'Автор: ' + ${el.author}"/>
|
||||
<p th:text="'Дата создания: ' + ${#dates.format(el.date, 'hh:mm dd MMM yyyy')}"/>
|
||||
<p th:text="'Последнее обновление: ' + ${#dates.format(el.last_update, 'hh:mm dd MMM yyyy')}"/>
|
||||
</div>
|
||||
<h2>Остальные сообщения</h2>
|
||||
<div th:each="el : ${discussions}">
|
||||
<h2 th:text="${el.title}"/>
|
||||
<p th:text="'Автор: ' + ${el.author}"/>
|
||||
<p th:text="'Дата создания: ' + ${#dates.format(el.date, 'hh:mm dd MMM yyyy')}"/>
|
||||
<p th:text="'Последнее обновление: ' + ${#dates.format(el.last_update, 'hh:mm dd MMM yyyy')}"/>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,20 +3,8 @@
|
||||
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Вход</title>
|
||||
<title>Новая тема</title>
|
||||
|
||||
<style>
|
||||
div.error {
|
||||
color: #ff5967;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.logout {
|
||||
color: #2c84ec;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
</head>
|
||||
@@ -29,28 +17,16 @@
|
||||
<h1>Пожалуйста, введите данные новой темы</h1>
|
||||
|
||||
<div>
|
||||
<input type="text" class="form-control" minlength="3" size="25" id="username" name="username" required placeholder="UserName">
|
||||
<label for="username">Логин</label>
|
||||
<input type="text" name="title" id="title" size="3" maxlength="15" required placeholder="Новая тема">
|
||||
<label for="title">Титул</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="password" name="password" minlength="3" id="password" required placeholder="Password123">
|
||||
<label for="password">Пароль</label>
|
||||
<input type="text" name="description" id="description" placeholder="Описание">
|
||||
<label for="description">Описание</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" name="remember-me"> Запомнить меня
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit">Создать тему</button>
|
||||
|
||||
<button type="submit">Войти</button>
|
||||
|
||||
<div th:if="${param.error}" class="error">
|
||||
Неправильный логин или пароль.
|
||||
</div>
|
||||
<div th:if="${param.logout}" class="logout">
|
||||
Вы вышли из аккаунта.
|
||||
</div>
|
||||
<input type="hidden" name="_csrf" th:value="${_csrf.token}">
|
||||
<p>© 2022</p>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<html xmlns:th="https://www.thymeleaf.org">
|
||||
<body>
|
||||
|
||||
<div th:if="${message}">
|
||||
<h2 th:text="${message}"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form method="POST" enctype="multipart/form-data" action="/upload">
|
||||
<table>
|
||||
<tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr>
|
||||
<tr><td></td><td><input type="submit" value="Upload" /></td></tr>
|
||||
</table>
|
||||
<input type="hidden" name="_csrf" th:value="${_csrf.token}">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
<li th:each="file : ${files}">
|
||||
<a th:href="${file}" th:text="${file}" />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore;
|
||||
package site.easystartup.web;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package site.easystartup.easystartupcore;
|
||||
package site.easystartup.web;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
@@ -10,8 +10,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import site.easystartup.easystartupcore.storag.service.StorageFileNotFoundException;
|
||||
import site.easystartup.easystartupcore.storag.service.StorageService;
|
||||
import site.easystartup.web.storage.service.StorageFileNotFoundException;
|
||||
import site.easystartup.web.storage.service.StorageService;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
Reference in new issue
Block a user