Skip to content
Merged

S4.1 #127

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b9991ed
* Edit db structure
LordRenDS Apr 21, 2023
7226375
* finished login and registration for sponsor
LordRenDS Apr 22, 2023
8cab03e
S3.2US2&4 (#103)
Maslyna Apr 23, 2023
f408263
S3.2 us3 (#105)
Denis973 Apr 25, 2023
a1cd2d4
Updated liquibase:
Maslyna Apr 25, 2023
1ddf4d1
BUGFIX: `GET(/api/v3/proofs/1/kudos)`` has problems after deleting a …
Maslyna Apr 25, 2023
1b4588d
Little update
Maslyna Apr 25, 2023
d4da2b9
Removed exception handler for Exception.class
Maslyna Apr 26, 2023
1bea5c8
Code refactor:
Maslyna Apr 26, 2023
631829b
bug fix
Denis973 Apr 26, 2023
8097335
aws update
Maslyna Apr 28, 2023
8410148
Created PhotoService
Maslyna Apr 29, 2023
1e9560e
minore update
Maslyna Apr 29, 2023
44b3666
refactored and optimized code
LordRenDS Apr 29, 2023
8605ed4
fix .findByLogin(authentication.getName()) - getTalentProofs
Denis973 Apr 29, 2023
0382ddc
fix !userInfo.getTalent().getId().equals(talentId)
Denis973 Apr 29, 2023
ae08a0c
Doc update
Maslyna May 1, 2023
a607b07
Merge remote-tracking branch 'origin/S3.2-refactor' into S3.2-refactor
Maslyna May 1, 2023
1a1f027
New test endpoint for images
Maslyna May 2, 2023
c840232
DB EDIT: SIZE UP
Maslyna May 3, 2023
98aa8a2
S3.2 refactor (#107)
Maslyna May 3, 2023
fdc5c11
AWS update: PresignedURL
Maslyna May 4, 2023
63b7c04
AWS update: Scheduler for presigned url
Maslyna May 4, 2023
372ba13
Merge branch 'S3.2-refactor' into S3.2
Maslyna May 4, 2023
64cdb36
* Create table:
LordRenDS May 4, 2023
0933751
* edit data.sql
LordRenDS May 4, 2023
b537a5e
* add entity for Skills
LordRenDS May 5, 2023
30156ca
S4.1T1-3 (#118)
LordRenDS May 6, 2023
d24784e
S4.1 tasks 4 5 (#119)
Denis973 May 7, 2023
a6268c6
S4.1S2T1 (#121)
Maslyna May 9, 2023
6593e5a
Merge branch 'dev' into S4.1
Maslyna May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@Transactional
@AllArgsConstructor
public class UpdateScheduler {

FileService fileService;
TalentRepository talentRepository;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/provedcode/aws/service/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private String getFullPath(String fileType, String userLogin) {

private String getFileType(MultipartFile file) {
String fileName = file.getOriginalFilename();
return fileName.substring(fileName.lastIndexOf('.') + 1);
return fileName != null ? fileName.substring(fileName.lastIndexOf('.') + 1) : null;
}

private File convertMultiPartToFile(MultipartFile file)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/provedcode/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers(antMatcher("/api/*/talents/**")).permitAll()
.requestMatchers(antMatcher("/api/*/sponsors/**")).permitAll()
.requestMatchers(antMatcher("/api/*/login")).permitAll()
.requestMatchers(antMatcher("/api/*/skills")).permitAll()
.requestMatchers(antMatcher("/error")).permitAll()
.requestMatchers(antMatcher("/v3/api-docs/**")).permitAll() // for openAPI
.requestMatchers(antMatcher("/swagger-ui/**")).permitAll() // for openAPI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.provedcode.talent.controller;

import com.provedcode.talent.model.dto.SkillDTO;
import com.provedcode.talent.service.SkillsService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Validated
@AllArgsConstructor

@RestController
@RequestMapping("/api/v4")
public class SkillController {
SkillsService skillsService;

@GetMapping("/skills")
List<SkillDTO> getFilteredSkills(@RequestParam(value = "filter-by", required = false, defaultValue = "") String filterBy) {
return skillsService.getFilteredSkills(filterBy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ProofDTO getTalentProof(@PathVariable(value = "proof-id") long proofId,

@GetTalentInformationWithProofsApiDoc
@GetMapping("/{talent-id}/proofs")
@PreAuthorize("hasRole('TALENT')")
@PreAuthorize("hasAnyRole('TALENT','SPONSOR')")
FullProofDTO getTalentInformationWithProofs(Authentication authentication,
@PathVariable("talent-id") Long talentId,
@RequestParam(value = "page", defaultValue = "0") @PositiveOrZero Integer page,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.provedcode.talent.controller;

import com.provedcode.talent.model.dto.ProofSkillsDTO;
import com.provedcode.talent.model.dto.SkillsOnProofDTO;
import com.provedcode.talent.service.TalentSkillsService;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@AllArgsConstructor

@RestController
@RequestMapping("/api/v4/talents")
public class TalentSkillsController {
TalentSkillsService talentSkillsService;

@PostMapping("/{talent-id}/proofs/{proof-id}/skills")
void addSkillOnProof(@PathVariable("talent-id") long talentId,
@PathVariable("proof-id") long proofId,
@RequestBody @Valid ProofSkillsDTO skills,
Authentication authentication) {
talentSkillsService.addSkillsOnProof(talentId, proofId, skills, authentication);
}

@GetMapping("/{talent-id}/proofs/{proof-id}/skills")
SkillsOnProofDTO getAllSkillsOnProof(@PathVariable("talent-id") long talentId,
@PathVariable("proof-id") long proofId,
Authentication authentication) {
return talentSkillsService.getAllSkillsOnProof(talentId, proofId, authentication);
}
@PreAuthorize("hasRole('TALENT')")
@DeleteMapping("/{talent-id}/proofs/{proof-id}/skills/{skill-id}")
void deleteSkillOnProof(@PathVariable("talent-id") long talentId,
@PathVariable("proof-id") long proofId,
@PathVariable("skill-id") long skillId,
Authentication authentication) {
talentSkillsService.deleteSkillOnProof(talentId, proofId, skillId, authentication);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/provedcode/talent/mapper/SkillMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.provedcode.talent.mapper;

import com.provedcode.talent.model.dto.SkillDTO;
import com.provedcode.talent.model.entity.Skills;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ReportingPolicy;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface SkillMapper {
SkillDTO skillToSkillDTO(Skills skills);
}
4 changes: 2 additions & 2 deletions src/main/java/com/provedcode/talent/mapper/TalentMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public interface TalentMapper {
@Mapping(target = "additionalInfo", expression = "java(talent.getTalentDescription() != null ? talent.getTalentDescription().getAdditionalInfo() : null)")
@Mapping(target = "links", expression = "java(talent.getTalentLinks().stream().map(l -> l.getLink()).toList())")
@Mapping(target = "contacts", expression = "java(talent.getTalentContacts().stream().map(c -> c.getContact()).toList())")
@Mapping(target = "talents", expression = "java(talent.getTalentTalents().stream().map(t -> t.getTalentName()).toList())")
// @Mapping(target = "talents", expression = "java(talent.getTalentTalents().stream().map(t -> t.getTalentName()).toList())")
@Mapping(target = "attachedFiles", expression = "java(talent.getTalentAttachedFiles().stream().map(a -> a.getAttachedFile()).toList())")
FullTalentDTO talentToFullTalentDTO(Talent talent);

@Mapping(target = "talents", expression = "java(talent.getTalentTalents().stream().map(t -> t.getTalentName()).toList())")
// @Mapping(target = "talents", expression = "java(talent.getTalentTalents().stream().map(t -> t.getTalentName()).toList())")
ShortTalentDTO talentToShortTalentDTO(Talent talent);
}
13 changes: 13 additions & 0 deletions src/main/java/com/provedcode/talent/model/dto/ProofSkillsDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.provedcode.talent.model.dto;

import jakarta.validation.constraints.NotEmpty;
import lombok.Builder;

import java.util.List;

@Builder
public record ProofSkillsDTO(
@NotEmpty
List<Long> skills
) {
}
7 changes: 7 additions & 0 deletions src/main/java/com/provedcode/talent/model/dto/SkillDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.provedcode.talent.model.dto;

public record SkillDTO(
Long id,
String skill
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.provedcode.talent.model.dto;

import com.provedcode.talent.model.entity.Skills;
import lombok.Builder;

import java.util.Set;

@Builder
public record SkillsOnProofDTO(
Set<Skills> skills
) {
}
34 changes: 34 additions & 0 deletions src/main/java/com/provedcode/talent/model/entity/Skills.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.provedcode.talent.model.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.Hibernate;

import java.util.Objects;

@Getter
@Setter
@Entity
@Table(name = "skill")
public class Skills {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "skill", length = 30)
private String skill;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
Skills skills = (Skills) o;
return getId() != null && Objects.equals(getId(), skills.getId());
}

@Override
public int hashCode() {
return getClass().hashCode();
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/provedcode/talent/model/entity/Talent.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class Talent {
private TalentDescription talentDescription;
@OneToMany(mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
private List<TalentLink> talentLinks = new ArrayList<>();
@OneToMany(mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
private List<TalentTalents> talentTalents = new ArrayList<>();
// @OneToMany(mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
// private List<TalentSkills> talentTalents = new ArrayList<>();
@OneToMany(mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
private List<TalentContact> talentContacts = new ArrayList<>();
@OneToMany(mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.hibernate.validator.constraints.URL;

import java.time.LocalDateTime;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Accessors(chain = true)
@NoArgsConstructor
Expand Down Expand Up @@ -41,4 +43,9 @@ public class TalentProof {
private LocalDateTime created;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "proof", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Kudos> kudos;
@ManyToMany
@JoinTable(name = "talent_skill",
joinColumns = @JoinColumn(name = "proof_id"),
inverseJoinColumns = @JoinColumn(name = "skill_id"))
private Set<Skills> skills = new LinkedHashSet<>();
}
25 changes: 25 additions & 0 deletions src/main/java/com/provedcode/talent/model/entity/TalentSkills.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//package com.provedcode.talent.model.entity;
//
//import jakarta.persistence.*;
//import jakarta.validation.constraints.NotNull;
//import lombok.*;
//
//@NoArgsConstructor
//@AllArgsConstructor
//@Builder
//@Getter
//@Setter
//@Entity
//@Table(name = "talent_talents")
//public class TalentSkills {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// @Column(name = "id", nullable = false)
// private Long id;
// @NotNull
// @ManyToOne
// @JoinColumn(name = "talent_id", updatable = false)
// private Talent talent;
// @Column(name = "talent_name")
// private String talentName;
//}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record EditTalent(
@JsonProperty("additional_info")
String additionalInfo,
String bio,
List<String> talents,
// List<String> talents,
@UrlList
List<String> links,
List<String> contacts,
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/provedcode/talent/repo/SkillsRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.provedcode.talent.repo;

import com.provedcode.talent.model.entity.Skills;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SkillsRepository extends JpaRepository<Skills, Long> {
@Query("select s from Skills s where upper(s.skill) like upper(concat('%', ?1, '%'))")
List<Skills> findBySkillContainsIgnoreCase(String skill);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.provedcode.talent.repo;

import com.provedcode.talent.model.entity.Talent;
import com.provedcode.talent.model.entity.TalentTalents;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface TalentRepository extends JpaRepository<Talent, Long> {
}
25 changes: 25 additions & 0 deletions src/main/java/com/provedcode/talent/service/SkillsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.provedcode.talent.service;

import com.provedcode.talent.mapper.SkillMapper;
import com.provedcode.talent.model.dto.SkillDTO;
import com.provedcode.talent.repo.SkillsRepository;
import com.provedcode.talent.repo.TalentRepository;
import com.provedcode.user.repo.UserInfoRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class SkillsService {
SkillsRepository skillsRepository;
TalentRepository talentRepository;
UserInfoRepository userInfoRepository;
SkillMapper skillMapper;

public List<SkillDTO> getFilteredSkills(String filterBy) {
return skillsRepository.findBySkillContainsIgnoreCase(filterBy).stream()
.map(skillMapper::skillToSkillDTO).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.provedcode.talent.repo.TalentProofRepository;
import com.provedcode.talent.repo.TalentRepository;
import com.provedcode.talent.utill.ValidateTalentForCompliance;
import com.provedcode.user.model.Role;
import com.provedcode.user.model.entity.UserInfo;
import com.provedcode.user.repo.UserInfoRepository;
import lombok.AllArgsConstructor;
Expand All @@ -29,6 +30,7 @@
import java.net.URI;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;

import static org.springframework.http.HttpStatus.FORBIDDEN;
Expand Down Expand Up @@ -81,14 +83,15 @@ public FullProofDTO getTalentProofs(Long talentId, Integer page, Integer size, S
talentId)));
UserInfo userInfo = userInfoRepository.findByLogin(authentication.getName())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
Page<TalentProof> proofs;
PageRequest pageRequest = PageRequest.of(page, size, Sort.Direction.valueOf(direction.toUpperCase()),
sortProperties
);
if (!userInfo.getTalent().getId().equals(talentId)) {
Page<TalentProof> proofs = talentProofRepository.findByTalentId(talentId, pageRequest);
if (authentication.getAuthorities().contains(Role.SPONSOR)) {
proofs = talentProofRepository.findByTalentIdAndStatus(talentId, ProofStatus.PUBLISHED, pageRequest);
}
if (userInfo.getTalent() != null && !userInfo.getTalent().getId().equals(talentId)) {
proofs = talentProofRepository.findByTalentIdAndStatus(talentId, ProofStatus.PUBLISHED, pageRequest);
} else {
proofs = talentProofRepository.findByTalentId(talentId, pageRequest);
}
return FullProofDTO.builder()
.id(talent.getId())
Expand Down
Loading