Tag rename, project refactor, user fix
This commit is contained in:
1 parent
7d661c52f8
commit
a7a003734a
20 files changed
+231
-159
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'site.easy-startup'
|
||||
version = '0.0.11-a'
|
||||
version = '0.0.12'
|
||||
sourceCompatibility = "17"
|
||||
|
||||
configurations {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class UserController {
|
||||
@PutMapping("/user/edit/{username}")
|
||||
public ResponseEntity<Object> userEdit(@PathVariable String username,@Valid @RequestBody UserRequest userRequest,
|
||||
BindingResult bindingResult, Principal principal) {
|
||||
if(!principal.getName().equals(username) && !userService.getUserByPrincipal(principal).isAdmin())
|
||||
if(!userService.getCurrent().getUsername().equals(username) && !userService.getUserByPrincipal(principal).isAdmin())
|
||||
throw new NoPermissionException(String.format("User %s can not edit profile of user %s", principal.getName(),
|
||||
username));
|
||||
|
||||
|
||||
@@ -22,38 +22,38 @@ public class User implements UserDetails {
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean active;
|
||||
private String full_name;
|
||||
private String fullName;
|
||||
private String status;
|
||||
private String iconPath;
|
||||
private String email;
|
||||
private String about;
|
||||
private String country;
|
||||
private String city;
|
||||
|
||||
private String birthday;
|
||||
|
||||
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "user_technologies", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@CollectionTable(name = "technologies", joinColumns = @JoinColumn(name = "user_id"))
|
||||
private Set<String> technologies;
|
||||
|
||||
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "user_profession", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@CollectionTable(name = "profession", joinColumns = @JoinColumn(name = "user_id"))
|
||||
private Set<String> professions;
|
||||
|
||||
@ElementCollection(targetClass = Long.class, fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "user_projects", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@CollectionTable(name = "projects", joinColumns = @JoinColumn(name = "user_id"))
|
||||
private Set<Long> projects;
|
||||
|
||||
@ManyToMany(mappedBy = "requests")
|
||||
private List<Participant> requests;
|
||||
|
||||
@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@CollectionTable(name = "role", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Set<Role> roles;
|
||||
|
||||
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "user_lang", joinColumns = @JoinColumn(name = "user_id"))
|
||||
private Set<String> langs;
|
||||
@CollectionTable(name = "languages", joinColumns = @JoinColumn(name = "user_id"))
|
||||
private Set<String> languages;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "user_contact",
|
||||
|
||||
@@ -18,7 +18,7 @@ public class UserDto implements Serializable {
|
||||
private String status;
|
||||
private String iconPath;
|
||||
private String email;
|
||||
private Set<String> tags;
|
||||
private Set<String> technologies;
|
||||
private Set<String> professions;
|
||||
private Set<Long> projects;
|
||||
private List<Participant> requests;
|
||||
@@ -26,6 +26,7 @@ public class UserDto implements Serializable {
|
||||
private String about;
|
||||
private String country;
|
||||
private String city;
|
||||
private Set<String> langs;
|
||||
private String birthday;
|
||||
private Set<String> languages;
|
||||
private Map<String, String> contacts;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/project")
|
||||
@RequestMapping("/projects")
|
||||
@Tag(name = "Проекты", description = "контроллер для работы с проектами")
|
||||
public class ProjectController {
|
||||
private final ProjectService projectService;
|
||||
@@ -34,7 +34,20 @@ public class ProjectController {
|
||||
|
||||
private final ParticipantService participantService;
|
||||
|
||||
// new
|
||||
|
||||
|
||||
//@
|
||||
@GetMapping
|
||||
@Operation(summary = "Получение всех проектов для пользователя")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjects() {
|
||||
List<ProjectDto> projects = projectService.getAllProjects()
|
||||
.stream().map(project -> modelMapper.map(project, ProjectDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "Создание проекта")
|
||||
public ResponseEntity<Object> createProject(@Valid @RequestBody ProjectRequest projectRequest,
|
||||
@@ -48,6 +61,12 @@ public class ProjectController {
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{projectId}")
|
||||
@Operation(summary = "получение проекта по id")
|
||||
public ResponseEntity<ProjectDto> getProject(@PathVariable("projectId") Long projectId) {
|
||||
return ResponseEntity.ok().body(modelMapper.map(projectService.getProjectById(projectId), ProjectDto.class));
|
||||
}
|
||||
|
||||
@PutMapping("/{projectId}")
|
||||
@Operation(summary = "Изменение проекта")
|
||||
public ResponseEntity<Object> editProject(@Valid @RequestBody ProjectRequest projectRequest,
|
||||
@@ -61,6 +80,78 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(projectUpdated, ProjectDto.class));
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@DeleteMapping("/{projectId}")
|
||||
@Operation(summary = "Удаление проекта")
|
||||
public ResponseEntity<Object> deleteProject(@PathVariable("projectId") Long projectId,
|
||||
Principal principal) {
|
||||
projectService.deleteProject(projectId, principal);
|
||||
return ResponseEntity.ok(new MessageResponse("Project was deleted!"));
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@GetMapping("/user/{userId}")
|
||||
@Operation(summary = "Получение всех проектов для пользователя")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsForUser(@PathVariable("userId") Long userId) {
|
||||
List<ProjectDto> projects = projectService.getAllProjectsForUser(userId)
|
||||
.stream().map(project -> modelMapper.map(project, ProjectDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/requests")
|
||||
@Operation(summary = "получение всех проектов для текущего пользователя")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsForCurrentUser(Principal principal) {
|
||||
List<ProjectDto> projects = projectService.getAllProjectsForCurrentUser(principal)
|
||||
.stream().map(project -> modelMapper.map(project, ProjectDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@GetMapping("/{projectId}/requests")
|
||||
@Operation(summary = "получение всех поданных заявок на проект")
|
||||
public ResponseEntity<List<ParticipantDto>> getAllRequestsForProject(@PathVariable Long projectId) {
|
||||
List<ParticipantDto> requests = projectService.getAllRequestsForProject(projectId)
|
||||
.stream().map(project -> modelMapper.map(project, ParticipantDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(requests);
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@PostMapping("/requests")
|
||||
@Operation(summary = "утвердить участника на проект")
|
||||
public ResponseEntity<ProjectDto> confirmParticipant(
|
||||
@RequestBody ParticipantRequest participantRequest,
|
||||
Principal principal) {
|
||||
Project project;
|
||||
if(participantRequest.isApproved())
|
||||
project = projectService.confirmParticipant(participantRequest.getProjectId(),
|
||||
participantRequest.getNameOfPosition(),
|
||||
participantRequest.getParticipantId(),
|
||||
principal);
|
||||
else {
|
||||
project = projectService.rejectParticipant(participantRequest.getProjectId(),
|
||||
participantRequest.getNameOfPosition(),
|
||||
participantRequest.getParticipantId(),
|
||||
principal);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok().body(modelMapper.map(project, ProjectDto.class));
|
||||
}
|
||||
|
||||
|
||||
// old
|
||||
|
||||
//@
|
||||
|
||||
|
||||
//@
|
||||
|
||||
|
||||
//@
|
||||
@PutMapping("/{projectId}/{partId}/part")
|
||||
@Operation(summary = "Изменение позиции в проекте: Дизайнер/Ui designer")
|
||||
@@ -77,30 +168,15 @@ public class ProjectController {
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@DeleteMapping("/{projectId}")
|
||||
@Operation(summary = "Удаление проекта")
|
||||
public ResponseEntity<Object> deleteProject(@PathVariable("projectId") Long projectId,
|
||||
Principal principal) {
|
||||
projectService.deleteProject(projectId, principal);
|
||||
return ResponseEntity.ok(new MessageResponse("Project was deleted!"));
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{projectId}")
|
||||
@Operation(summary = "получение проекта по id")
|
||||
public ResponseEntity<ProjectDto> getProject(@PathVariable("projectId") Long projectId) {
|
||||
return ResponseEntity.ok().body(modelMapper.map(projectService.getProjectById(projectId), ProjectDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{userId}/all")
|
||||
@Operation(summary = "Получение всех проектов для пользователя")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsForUser(@PathVariable("userId") Long userId) {
|
||||
List<ProjectDto> projects = projectService.getAllProjectsForUser(userId)
|
||||
.stream().map(project -> modelMapper.map(project, ProjectDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//@
|
||||
@GetMapping("/{technology}/tech")
|
||||
@@ -111,13 +187,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
@GetMapping("/my")
|
||||
@Operation(summary = "получение всех проектов для текущего пользователя")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsForCurrentUser(Principal principal) {
|
||||
List<ProjectDto> projects = projectService.getAllProjectsForCurrentUser(principal)
|
||||
.stream().map(project -> modelMapper.map(project, ProjectDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@GetMapping("/{nameOfPosition}/positions")
|
||||
@@ -137,14 +207,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/requests")
|
||||
@Operation(summary = "получение всех поданных заявок на проект")
|
||||
public ResponseEntity<List<ParticipantDto>> getAllRequestsForProject(@RequestBody Long projectId) {
|
||||
List<ParticipantDto> requests = projectService.getAllRequestsForProject(projectId)
|
||||
.stream().map(project -> modelMapper.map(project, ParticipantDto.class)).collect(Collectors.toList());
|
||||
return ResponseEntity.ok().body(requests);
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@PostMapping("/apply")
|
||||
@@ -156,16 +219,5 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(project, ProjectDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/participant")
|
||||
@Operation(summary = "утвердить участница на проект")
|
||||
public ResponseEntity<ProjectDto> confirmParticipant(@RequestBody ParticipantRequest participantRequest,
|
||||
Principal principal) {
|
||||
Project project = projectService.confirmParticipant(participantRequest.getProjectId(),
|
||||
participantRequest.getNameOfPosition(),
|
||||
participantRequest.getParticipantId(),
|
||||
principal);
|
||||
|
||||
return ResponseEntity.ok().body(modelMapper.map(project, ProjectDto.class));
|
||||
}
|
||||
}
|
||||
@@ -16,24 +16,24 @@ import java.util.Objects;
|
||||
public class Participant {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "participant_id")
|
||||
@Column(name = "participantId")
|
||||
private Long participantId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "project_id", updatable = false)
|
||||
@JoinColumn(name = "projectId", updatable = false)
|
||||
private Project project;
|
||||
|
||||
@Column(name = "name_of_position")
|
||||
@Column(name = "nameOfPosition")
|
||||
@NotNull
|
||||
private String nameOfPosition;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id")
|
||||
@JoinColumn(name = "userId")
|
||||
private User user;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "user_request",
|
||||
joinColumns = @JoinColumn(name = "participant_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
@JoinTable(name = "userRequest",
|
||||
joinColumns = @JoinColumn(name = "participantId"),
|
||||
inverseJoinColumns = @JoinColumn(name = "userId"))
|
||||
@ToString.Exclude
|
||||
private List<User> requests;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package site.easystartup.web.project.domain.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.*;
|
||||
import org.hibernate.Hibernate;
|
||||
import site.easystartup.web.domain.model.User;
|
||||
|
||||
import javax.persistence.*;
|
||||
@@ -10,8 +9,6 @@ import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@@ -20,10 +17,10 @@ import java.util.Set;
|
||||
public class Project {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "project_id")
|
||||
@Column(name = "projectId")
|
||||
private Long projectId;
|
||||
|
||||
@Column(name = "cover_link")
|
||||
@Column(name = "coverLink")
|
||||
private String coverLink;
|
||||
|
||||
@Column(name = "title")
|
||||
@@ -36,25 +33,25 @@ public class Project {
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@Column(name = "commercial_status") // 1 - commercial, 0 - non-commercial
|
||||
@Column(name = "commercialStatus") // 1 - commercial, 0 - non-commercial
|
||||
private int commercialStatus;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "project_tag",
|
||||
joinColumns = @JoinColumn(name = "project_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "tag_id")
|
||||
@JoinTable(name = "projectTag",
|
||||
joinColumns = @JoinColumn(name = "projectId"),
|
||||
inverseJoinColumns = @JoinColumn(name = "technologyId")
|
||||
)
|
||||
private List<Tag> technology;
|
||||
private List<Technology> technology;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "owner_id", updatable = false)
|
||||
@JoinColumn(name = "ownerId", updatable = false)
|
||||
private User owner;
|
||||
|
||||
@OneToMany(mappedBy = "project", cascade = {CascadeType.ALL})
|
||||
// @ToString.Exclude
|
||||
private List<Participant> participants;
|
||||
|
||||
@Column(name = "created_date", updatable = false)
|
||||
@Column(name = "createdDate", updatable = false)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdDate;
|
||||
|
||||
|
||||
+7
-7
@@ -13,14 +13,14 @@ import java.util.Set;
|
||||
@RequiredArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "tag")
|
||||
public class Tag {
|
||||
public class Technology {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "tag_id")
|
||||
private Long tagId;
|
||||
@Column(name = "technologyId")
|
||||
private Long technologyId;
|
||||
|
||||
@Column(name = "tage_name")
|
||||
private String tagName;
|
||||
@Column(name = "technologyName")
|
||||
private String technologyName;
|
||||
|
||||
@ManyToMany(mappedBy = "technology")
|
||||
private Set<Project> projects;
|
||||
@@ -29,8 +29,8 @@ public class Tag {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
Tag tag = (Tag) o;
|
||||
return tagId != null && Objects.equals(tagId, tag.tagId);
|
||||
Technology technology = (Technology) o;
|
||||
return technologyId != null && Objects.equals(technologyId, technology.technologyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -9,4 +9,5 @@ public class ParticipantRequest {
|
||||
private Long projectId;
|
||||
private Long participantId;
|
||||
private String nameOfPosition;
|
||||
private boolean approved;
|
||||
}
|
||||
@@ -2,9 +2,7 @@ package site.easystartup.web.project.domain.requst;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import site.easystartup.web.project.domain.model.Tag;
|
||||
import site.easystartup.web.project.domain.model.Technology;
|
||||
import site.easystartup.web.project.dto.ParticipantDto;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -25,6 +23,6 @@ public class ProjectRequest {
|
||||
private String description;
|
||||
private int commercialStatus;
|
||||
@NotNull
|
||||
private List<Tag> technology;
|
||||
private List<Technology> technology;
|
||||
private List<ParticipantDto> participants;
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package site.easystartup.web.project.repo;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import site.easystartup.web.domain.model.User;
|
||||
import site.easystartup.web.project.domain.model.Project;
|
||||
import site.easystartup.web.project.domain.model.Tag;
|
||||
import site.easystartup.web.project.domain.model.Technology;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,7 +12,7 @@ import java.util.List;
|
||||
public interface ProjectRepo extends JpaRepository<Project, Long> {
|
||||
|
||||
List<Project> findAllByOwnerOrderByCreatedDate(User owner);
|
||||
List<Project> findAllByTechnology(Tag tag);
|
||||
List<Project> findAllByTechnology(Technology technology);
|
||||
|
||||
List<Project> findAllByCommercialStatusOrderByCreatedDateAsc(int commercialStatus);
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package site.easystartup.web.project.repo;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import site.easystartup.web.project.domain.model.Tag;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface TagRepo extends JpaRepository<Tag, Long> {
|
||||
|
||||
Optional<Tag> findTagByTagNameIgnoreCase(String tagName);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package site.easystartup.web.project.repo;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import site.easystartup.web.project.domain.model.Technology;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface TechnologyRepo extends JpaRepository<Technology, Long> {
|
||||
|
||||
Optional<Technology> findTechnologyByTechnologyName(String technologyName);
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import site.easystartup.web.storage.service.StorageService;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -25,7 +24,7 @@ public class ProjectService {
|
||||
private final ModelMapper modelMapper;
|
||||
private final StorageService storageService;
|
||||
private final ParticipantRepo participantRepo;
|
||||
private final TagService tagService;
|
||||
private final TechnologyService technologyService;
|
||||
|
||||
|
||||
|
||||
@@ -79,8 +78,12 @@ public class ProjectService {
|
||||
return projectRepo.findAllByOwnerOrderByCreatedDate(user);
|
||||
}
|
||||
|
||||
public List<Project> getAllProjects() {
|
||||
return projectRepo.findAll();
|
||||
}
|
||||
|
||||
public List<Project> getAllProjectsWithTechnology(String technology) {
|
||||
return projectRepo.findAllByTechnology(tagService.getTechnologyByName(technology.trim()));
|
||||
return projectRepo.findAllByTechnology(technologyService.getTechnologyByName(technology.trim()));
|
||||
}
|
||||
|
||||
public List<Project> getAllProjectsForCurrentUser(Principal principal) {
|
||||
@@ -127,12 +130,28 @@ public class ProjectService {
|
||||
return projectRepo.save(project);
|
||||
}
|
||||
|
||||
public Project rejectParticipant(Long projectId, String nameOfPosition, Long participantId, Principal principal) {
|
||||
Project project = getProjectById(projectId);
|
||||
|
||||
if (!projectIsBelongUser(project, principal))
|
||||
throw new RuntimeException("This project cannot be changed");
|
||||
|
||||
User user = userService.getUserById(participantId);
|
||||
project.getParticipants().forEach(participant -> {
|
||||
if (participant.getNameOfPosition().equals(nameOfPosition)) {
|
||||
participant.getRequests().remove(user);
|
||||
}
|
||||
});
|
||||
projectRepo.save(project);
|
||||
return projectRepo.save(project);
|
||||
}
|
||||
|
||||
private Project projectRequestToProject(ProjectRequest projectRequest, Principal principal) {
|
||||
Project project = new Project();
|
||||
|
||||
project.setTitle(projectRequest.getTitle());
|
||||
project.setDescription(projectRequest.getDescription());
|
||||
project.setTechnology(tagService.convertTechnology(projectRequest.getTechnology()));
|
||||
project.setTechnology(technologyService.convertTechnology(projectRequest.getTechnology()));
|
||||
project.setCommercialStatus(project.getCommercialStatus());
|
||||
// project.setCoverLink(projectRequest.getCover().getName());
|
||||
project.setOwner(userService.getUserByPrincipal(principal));
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package site.easystartup.web.project.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import site.easystartup.web.project.domain.model.Tag;
|
||||
import site.easystartup.web.project.repo.TagRepo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TagService {
|
||||
private final TagRepo tagRepo;
|
||||
|
||||
public List<Tag> getAllTags() {
|
||||
return tagRepo.findAll();
|
||||
}
|
||||
public List<Tag> convertTechnology(List<Tag> technology) {
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
technology.forEach(tag -> {
|
||||
Optional<Tag> foundTag = tagRepo.findTagByTagNameIgnoreCase(tag.getTagName());
|
||||
if (foundTag.isPresent()) {
|
||||
tags.add(foundTag.get());
|
||||
}
|
||||
else {
|
||||
tagRepo.save(tag);
|
||||
tags.add(tagRepo.findTagByTagNameIgnoreCase(tag.getTagName()).get());
|
||||
}
|
||||
});
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Tag getTechnologyByName(String tag) {
|
||||
return tagRepo.findTagByTagNameIgnoreCase(tag).orElseThrow(() -> new RuntimeException("Technolohy not found"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package site.easystartup.web.project.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import site.easystartup.web.project.domain.model.Technology;
|
||||
import site.easystartup.web.project.repo.TechnologyRepo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TechnologyService {
|
||||
private final TechnologyRepo technologyRepo;
|
||||
|
||||
public List<Technology> getAllTags() {
|
||||
return technologyRepo.findAll();
|
||||
}
|
||||
public List<Technology> convertTechnology(List<Technology> technology) {
|
||||
List<Technology> technologies = new ArrayList<>();
|
||||
technology.forEach(tag -> {
|
||||
Optional<Technology> foundTag = technologyRepo.findTechnologyByTechnologyName(tag.getTechnologyName());
|
||||
if (foundTag.isPresent()) {
|
||||
technologies.add(foundTag.get());
|
||||
}
|
||||
else {
|
||||
technologyRepo.save(tag);
|
||||
technologies.add(technologyRepo.findTechnologyByTechnologyName(tag.getTechnologyName()).get());
|
||||
}
|
||||
});
|
||||
return technologies;
|
||||
}
|
||||
|
||||
public Technology getTechnologyByName(String tag) {
|
||||
return technologyRepo.findTechnologyByTechnologyName(tag).orElseThrow(() -> new RuntimeException("Technolohy not found"));
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,7 @@ public class UserRequest {
|
||||
@NotNull
|
||||
private boolean active;
|
||||
|
||||
@NotNull
|
||||
private String full_name;
|
||||
private String fullName;
|
||||
|
||||
@Size(max = 60, message = "Status should be no more 60 signs")
|
||||
private String status;
|
||||
@@ -31,7 +30,7 @@ public class UserRequest {
|
||||
@NotBlank(message = "Email is required")
|
||||
private String email;
|
||||
|
||||
private Set<String> tags;
|
||||
private Set<String> technologies;
|
||||
private Set<String> professions;
|
||||
private Set<Long> projects;
|
||||
private List<Participant> requests;
|
||||
@@ -42,6 +41,7 @@ public class UserRequest {
|
||||
private String country;
|
||||
@Size(max = 100, message = "Status should be no more 100 signs")
|
||||
private String city;
|
||||
private Set<String> langs;
|
||||
private String birthday;
|
||||
private Set<String> languages;
|
||||
private Map<String, String> contacts;
|
||||
}
|
||||
@@ -41,20 +41,20 @@ public class UserService {
|
||||
public User editUser(String username, UserRequest userRequest) {
|
||||
User user = userRepo.findByUsername(username);
|
||||
user.setActive(userRequest.isActive());
|
||||
user.setFull_name(userRequest.getFull_name());
|
||||
user.setFullName(userRequest.getFullName());
|
||||
user.setStatus(userRequest.getStatus());
|
||||
|
||||
if(userRequest.getIcon() != null) storageService.saveImage(userRequest.getIcon(), username + "-icon");
|
||||
user.setIconPath(user.getIconPath() == null ? "" : username + "-icon.jpg");
|
||||
user.setEmail(userRequest.getEmail() == null ? "" : userRequest.getEmail());
|
||||
user.setTechnologies(userRequest.getTags() == null ? Collections.emptySet() : userRequest.getTags());
|
||||
user.setTechnologies(userRequest.getTechnologies() == null ? Collections.emptySet() : userRequest.getTechnologies());
|
||||
user.setProfessions(userRequest.getProfessions() == null ? Collections.emptySet() : userRequest.getProfessions());
|
||||
user.setProjects(userRequest.getProjects() == null ? Collections.emptySet() : userRequest.getProjects());
|
||||
user.setRequests(userRequest.getRequests() == null ? Collections.emptyList() : userRequest.getRequests());
|
||||
user.setAbout(userRequest.getAbout() == null ? "" : userRequest.getAbout());
|
||||
user.setCountry(userRequest.getCountry() == null ? "" : userRequest.getCountry());
|
||||
user.setCity(userRequest.getCity() == null ? "" : userRequest.getCity());
|
||||
user.setLangs(userRequest.getLangs() == null ? Collections.emptySet() : userRequest.getLangs());
|
||||
user.setLanguages(userRequest.getLanguages() == null ? Collections.emptySet() : userRequest.getLanguages());
|
||||
user.setContacts(userRequest.getContacts() == null ? Collections.emptyMap() : userRequest.getContacts());
|
||||
return userRepo.save(user);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
||||
|
||||
<head>
|
||||
<title>API</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>k</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>API</h1>
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user