diff --git a/pom.xml b/pom.xml
index 728f88c..64ee618 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,19 +10,13 @@
com.provedcodedemo
- 0.0.1-SNAPSHOT
+ 0.1.1-SNAPSHOTProvedCodeDemo project for Spring Boot17
-
-
- org.springdoc
- springdoc-openapi-starter-webmvc-ui
- 2.0.0
- org.springframework.bootspring-boot-starter-data-jpa
@@ -74,20 +68,45 @@
spring-security-testtest
+
+ org.postgresql
+ postgresql
+ 42.6.0
+
+
+ org.mapstruct
+ mapstruct
+ 1.5.3.Final
+
+
- org.springframework.boot
- spring-boot-maven-plugin
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.11.0
-
-
+ 17
+ 17
+
+ org.projectlomboklombok
-
-
+ 1.18.26
+
+
+ org.mapstruct
+ mapstruct-processor
+ 1.5.3.Final
+
+
+ org.projectlombok
+ lombok-mapstruct-binding
+ 0.2.0
+
+
diff --git a/src/main/java/com/provedcode/ProvedCodeApplication.java b/src/main/java/com/provedcode/ProvedCodeApplication.java
index fc86627..e780cab 100644
--- a/src/main/java/com/provedcode/ProvedCodeApplication.java
+++ b/src/main/java/com/provedcode/ProvedCodeApplication.java
@@ -6,7 +6,7 @@
@SpringBootApplication
@ConfigurationPropertiesScan
-public class ProvedCodeApplication {
+public class ProvedCodeApplication {
public static void main(String[] args) {
SpringApplication.run(ProvedCodeApplication.class, args);
diff --git a/src/main/java/com/provedcode/config/SecurityConfig.java b/src/main/java/com/provedcode/config/SecurityConfig.java
index 1893ca3..13c0ee8 100644
--- a/src/main/java/com/provedcode/config/SecurityConfig.java
+++ b/src/main/java/com/provedcode/config/SecurityConfig.java
@@ -5,8 +5,11 @@
import com.nimbusds.jose.jwk.source.ImmutableJWKSet;
import com.provedcode.user.mapper.UserInfoMapper;
import com.provedcode.user.repo.UserInfoRepository;
+import jakarta.servlet.http.HttpServletRequest;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpStatus;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -25,6 +28,8 @@
import org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationEntryPoint;
import org.springframework.security.oauth2.server.resource.web.access.BearerTokenAccessDeniedHandler;
import org.springframework.security.web.SecurityFilterChain;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
@@ -34,37 +39,74 @@
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
import static org.springframework.security.web.util.matcher.AntPathRequestMatcher.antMatcher;
+@Slf4j
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
- //http://localhost:8080/swagger-ui/index.html
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(c -> c
.requestMatchers("/actuator/health").permitAll() // for DevOps
.requestMatchers(antMatcher("/h2/**")).permitAll()
.requestMatchers(antMatcher("/api/talents/**")).permitAll()
- .requestMatchers(antMatcher("/v3/api-docs/**")).permitAll() // for openAPI
- .requestMatchers(antMatcher("/swagger-ui/**")).permitAll() // for openAPI
- .requestMatchers(antMatcher("/swagger-ui.html")).permitAll() // for openAPI
+ .requestMatchers(antMatcher("/error")).permitAll()
.anyRequest().authenticated()
);
+ http.exceptionHandling(c -> c
+ .authenticationEntryPoint((request, response, authException) -> {
+ log.info("Authentication failed {}, message:{}",
+ describe(request),
+ authException.getMessage());
+ response.sendError(
+ HttpStatus.UNAUTHORIZED.value(),
+ authException.getMessage());
+ }
+ )
+ .accessDeniedHandler((request, response, accessDeniedException) -> {
+ log.info("Authorization failed {},message: {}",
+ describe(request),
+ accessDeniedException.getMessage());
+ response.sendError(HttpStatus.FORBIDDEN.value(),
+ accessDeniedException.getMessage());
+ }
+ )
+ );
+
http.httpBasic(Customizer.withDefaults());
http.csrf().disable().headers().disable();
+ http.cors();
+
http.sessionManagement().sessionCreationPolicy(STATELESS);
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
- .exceptionHandling(c -> c
- .authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
- .accessDeniedHandler(new BearerTokenAccessDeniedHandler())
- );
+ .exceptionHandling(c -> c
+ .authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
+ .accessDeniedHandler(new BearerTokenAccessDeniedHandler())
+ );
return http.build();
}
+ @Bean
+ public WebMvcConfigurer corsConfigurer() {
+ return new WebMvcConfigurer() {
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/**")
+ .allowedOrigins("*")
+ .allowedMethods("*")
+ .allowedHeaders("*");
+ }
+ };
+ }
+
+ public String describe(HttpServletRequest request) {
+ return request.getRequestURI();
+ }
+
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
@@ -93,8 +135,8 @@ UserDetailsService userDetailsService(
UserInfoMapper mapper
) {
return login -> repository.findByLogin(login)
- .map(mapper::toUserDetails)
- .orElseThrow(() -> new UsernameNotFoundException(login + " not found"));
+ .map(mapper::toUserDetails)
+ .orElseThrow(() -> new UsernameNotFoundException(login + " not found"));
}
@Bean
diff --git a/src/main/java/com/provedcode/talent/TalentController.java b/src/main/java/com/provedcode/talent/controller/TalentController.java
similarity index 71%
rename from src/main/java/com/provedcode/talent/TalentController.java
rename to src/main/java/com/provedcode/talent/controller/TalentController.java
index b1e5f8d..e009148 100644
--- a/src/main/java/com/provedcode/talent/TalentController.java
+++ b/src/main/java/com/provedcode/talent/controller/TalentController.java
@@ -1,5 +1,6 @@
-package com.provedcode.talent;
+package com.provedcode.talent.controller;
+import com.provedcode.talent.mapper.TalentMapper;
import com.provedcode.talent.model.dto.FullTalentDTO;
import com.provedcode.talent.model.dto.ShortTalentDTO;
import com.provedcode.talent.service.TalentService;
@@ -18,23 +19,24 @@
@Slf4j
@RestController
@AllArgsConstructor
-@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT,
- RequestMethod.DELETE})
@RequestMapping("/api")
public class TalentController {
TalentService talentService;
+ TalentMapper talentMapper;
@PreAuthorize("hasRole('TALENT')")
@GetMapping("/talents/{id}")
- FullTalentDTO getTalent(@PathVariable("id") long id) {
- return talentService.getTalentById(id);
+ FullTalentDTO getTalent(@PathVariable("id") long id, Authentication authentication) {
+ log.info("get-talent auth = {}", authentication);
+ log.info("get-talent auth.name = {}", authentication.getAuthorities());
+ return talentMapper.talentToFullTalentDTO(talentService.getTalentById(id));
}
@GetMapping("/talents")
@ResponseStatus(HttpStatus.OK)
Page getTalents(@RequestParam(value = "page") Optional page,
@RequestParam(value = "size") Optional size) {
- return talentService.getTalentsPage(page, size);
+ return talentService.getTalentsPage(page, size).map(talentMapper::talentToShortTalentDTO);
}
@PreAuthorize("hasRole('TALENT')")
@@ -42,7 +44,7 @@ Page getTalents(@RequestParam(value = "page") Optional
FullTalentDTO editTalent(@PathVariable("talent-id") long id,
@RequestBody @Valid FullTalentDTO fullTalent,
Authentication authentication) {
- return talentService.editTalent(id, fullTalent, authentication);
+ return talentMapper.talentToFullTalentDTO(talentService.editTalent(id, fullTalent, authentication));
}
@PreAuthorize("hasRole('TALENT')")
diff --git a/src/main/java/com/provedcode/talent/controller/TalentProofController.java b/src/main/java/com/provedcode/talent/controller/TalentProofController.java
new file mode 100644
index 0000000..f9a2101
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/controller/TalentProofController.java
@@ -0,0 +1,27 @@
+package com.provedcode.talent.controller;
+
+import com.provedcode.talent.mapper.TalentProofMapper;
+import com.provedcode.talent.model.dto.ProofDTO;
+import com.provedcode.talent.service.TalentProofService;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+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.Optional;
+
+@RestController
+@AllArgsConstructor
+@RequestMapping("/api/talents")
+public class TalentProofController {
+ TalentProofService talentProofService;
+ TalentProofMapper talentProofMapper;
+
+ @GetMapping("/proofs")
+ Page getAllProofs(@RequestParam(value = "page") Optional page,
+ @RequestParam(value = "size") Optional size) {
+ return talentProofService.getAllProofsPage(page, size).map(talentProofMapper::toProofDTO);
+ }
+}
diff --git a/src/main/java/com/provedcode/talent/mapper/TalentMapper.java b/src/main/java/com/provedcode/talent/mapper/TalentMapper.java
index a3818a7..b3d25e2 100644
--- a/src/main/java/com/provedcode/talent/mapper/TalentMapper.java
+++ b/src/main/java/com/provedcode/talent/mapper/TalentMapper.java
@@ -3,10 +3,30 @@
import com.provedcode.talent.model.dto.FullTalentDTO;
import com.provedcode.talent.model.dto.ShortTalentDTO;
import com.provedcode.talent.model.entity.*;
+import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
+import org.mapstruct.ReportingPolicy;
+@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface TalentMapper {
+ default FullTalentDTO talentToFullTalentDTO(Talent talent) {
+ return FullTalentDTO.builder()
+ .id(talent.getId())
+ .firstName(talent.getFirstName())
+ .lastName(talent.getLastName())
+ .bio(talent.getTalentDescription() != null ? talent.getTalentDescription().getBio() : null)
+ .additionalInfo(talent.getTalentDescription() != null ? talent.getTalentDescription()
+ .getAdditionalInfo() : null)
+ .image(talent.getImage())
+ .specialization(talent.getSpecialization())
+ .links(talent.getTalentLinks().stream().map(TalentLink::getLink).toList())
+ .contacts(talent.getTalentContacts().stream().map(TalentContact::getContact).toList())
+ .talents(talent.getTalentTalents().stream().map(TalentTalents::getTalentName).toList())
+ .attachedFiles(
+ talent.getTalentAttachedFiles().stream().map(TalentAttachedFile::getAttachedFile)
+ .toList())
+ .build();
+ }
ShortTalentDTO talentToShortTalentDTO(Talent talent);
- FullTalentDTO talentToFullTalentDTO(Talent talent);
-
}
diff --git a/src/main/java/com/provedcode/talent/mapper/TalentProofMapper.java b/src/main/java/com/provedcode/talent/mapper/TalentProofMapper.java
new file mode 100644
index 0000000..89f636f
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/mapper/TalentProofMapper.java
@@ -0,0 +1,20 @@
+package com.provedcode.talent.mapper;
+
+import com.provedcode.talent.model.dto.ProofDTO;
+import com.provedcode.talent.model.entity.TalentProof;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
+import org.mapstruct.ReportingPolicy;
+
+@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
+public interface TalentProofMapper {
+ @Mapping(source = "talentId", target = "id")
+ @Mapping(source = "created", target = "created", dateFormat = "dd-MM-yyyy HH:mm:ss")
+ ProofDTO toProofDTO(TalentProof talentProof);
+
+ @Mapping(source = "id", target = "talentId")
+ @Mapping(target = "id", ignore = true)
+ @Mapping(source = "created", target = "created", dateFormat = "dd-MM-yyyy HH:mm:ss")
+ TalentProof toTalentProof(ProofDTO proofDTO);
+}
diff --git a/src/main/java/com/provedcode/talent/mapper/impl/TalentMapperImpl.java b/src/main/java/com/provedcode/talent/mapper/impl/TalentMapperImpl.java
index 2b0794b..6a404d4 100644
--- a/src/main/java/com/provedcode/talent/mapper/impl/TalentMapperImpl.java
+++ b/src/main/java/com/provedcode/talent/mapper/impl/TalentMapperImpl.java
@@ -1,42 +1,42 @@
-package com.provedcode.talent.mapper.impl;
-
-import com.provedcode.talent.mapper.TalentMapper;
-import com.provedcode.talent.model.dto.FullTalentDTO;
-import com.provedcode.talent.model.dto.ShortTalentDTO;
-import com.provedcode.talent.model.entity.*;
-import org.springframework.stereotype.Component;
-
-@Component
-public class TalentMapperImpl implements TalentMapper {
- @Override
- public ShortTalentDTO talentToShortTalentDTO(Talent talent) {
- return ShortTalentDTO.builder()
- .id(talent.getId())
- .image(talent.getImage())
- .firstName(talent.getFirstName())
- .lastName(talent.getLastName())
- .specialization(talent.getSpecialization())
- .skills(talent.getTalentSkills().stream().map(TalentSkill::getSkill).toList())
- .build();
- }
-
- @Override
- public FullTalentDTO talentToFullTalentDTO(Talent talent) {
- return FullTalentDTO.builder()
- .id(talent.getId())
- .firstName(talent.getFirstName())
- .lastName(talent.getLastName())
- .bio(talent.getTalentDescription() != null ? talent.getTalentDescription().getBio() : null)
- .additionalInfo(talent.getTalentDescription() != null ? talent.getTalentDescription()
- .getAdditionalInfo() : null)
- .image(talent.getImage())
- .specialization(talent.getSpecialization())
- .links(talent.getTalentLinks().stream().map(TalentLink::getLink).toList())
- .contacts(talent.getTalentContacts().stream().map(TalentContact::getContact).toList())
- .skills(talent.getTalentSkills().stream().map(TalentSkill::getSkill).toList())
- .attachedFiles(
- talent.getTalentAttachedFiles().stream().map(TalentAttachedFile::getAttachedFile)
- .toList())
- .build();
- }
-}
+//package com.provedcode.talent.mapper.impl;
+//
+//import com.provedcode.talent.mapper.TalentMapper;
+//import com.provedcode.talent.model.dto.FullTalentDTO;
+//import com.provedcode.talent.model.dto.ShortTalentDTO;
+//import com.provedcode.talent.model.entity.*;
+//import org.springframework.stereotype.Component;
+//
+//@Component
+//public class TalentMapperImpl implements TalentMapper {
+// @Override
+// public ShortTalentDTO talentToShortTalentDTO(Talent talent) {
+// return ShortTalentDTO.builder()
+// .id(talent.getId())
+// .image(talent.getImage())
+// .firstName(talent.getFirstName())
+// .lastName(talent.getLastName())
+// .specialization(talent.getSpecialization())
+// .talents(talent.getTalentTalents().stream().map(TalentTalents::getTalentName).toList())
+// .build();
+// }
+//
+// @Override
+// public FullTalentDTO talentToFullTalentDTO(Talent talent) {
+// return FullTalentDTO.builder()
+// .id(talent.getId())
+// .firstName(talent.getFirstName())
+// .lastName(talent.getLastName())
+// .bio(talent.getTalentDescription() != null ? talent.getTalentDescription().getBio() : null)
+// .additionalInfo(talent.getTalentDescription() != null ? talent.getTalentDescription()
+// .getAdditionalInfo() : null)
+// .image(talent.getImage())
+// .specialization(talent.getSpecialization())
+// .links(talent.getTalentLinks().stream().map(TalentLink::getLink).toList())
+// .contacts(talent.getTalentContacts().stream().map(TalentContact::getContact).toList())
+// .talents(talent.getTalentTalents().stream().map(TalentTalents::getTalentName).toList())
+// .attachedFiles(
+// talent.getTalentAttachedFiles().stream().map(TalentAttachedFile::getAttachedFile)
+// .toList())
+// .build();
+// }
+//}
diff --git a/src/main/java/com/provedcode/talent/mapper/impl/TalentProofMapperImpl.java b/src/main/java/com/provedcode/talent/mapper/impl/TalentProofMapperImpl.java
new file mode 100644
index 0000000..aa1361d
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/mapper/impl/TalentProofMapperImpl.java
@@ -0,0 +1,15 @@
+//package com.provedcode.talent.mapper.impl;
+//
+//import com.provedcode.talent.model.dto.ProofDTO;
+//import com.provedcode.talent.model.entity.TalentProof;
+//import org.springframework.stereotype.Component;
+//
+//@Component
+//public class TalentProofMapperImpl {
+// public ProofDTO toProofDTO(TalentProof talentProof) {
+// return ProofDTO.builder()
+// .id(talentProof.getTalentId())
+// .proof(talentProof.getProof())
+// .build();
+// }
+//}
diff --git a/src/main/java/com/provedcode/talent/model/ProofStatus.java b/src/main/java/com/provedcode/talent/model/ProofStatus.java
new file mode 100644
index 0000000..d98204e
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/model/ProofStatus.java
@@ -0,0 +1,7 @@
+package com.provedcode.talent.model;
+
+public enum ProofStatus {
+ DRAFT,
+ PUBLISHED,
+ HIDDEN
+}
diff --git a/src/main/java/com/provedcode/talent/model/dto/FullTalentDTO.java b/src/main/java/com/provedcode/talent/model/dto/FullTalentDTO.java
index dc5d09b..54fb184 100644
--- a/src/main/java/com/provedcode/talent/model/dto/FullTalentDTO.java
+++ b/src/main/java/com/provedcode/talent/model/dto/FullTalentDTO.java
@@ -3,9 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.provedcode.annotations.UrlList;
import jakarta.validation.constraints.NotEmpty;
-import jakarta.validation.constraints.NotNull;
import lombok.Builder;
-import org.hibernate.validator.constraints.URL;
import java.util.List;
@@ -24,7 +22,7 @@ public record FullTalentDTO(
@JsonProperty("additional_info")
String additionalInfo,
String bio,
- List skills,
+ List talents,
@UrlList
List links,
List contacts,
diff --git a/src/main/java/com/provedcode/talent/model/dto/ProofDTO.java b/src/main/java/com/provedcode/talent/model/dto/ProofDTO.java
new file mode 100644
index 0000000..b88739a
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/model/dto/ProofDTO.java
@@ -0,0 +1,17 @@
+package com.provedcode.talent.model.dto;
+
+import com.provedcode.talent.model.ProofStatus;
+import lombok.Builder;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+
+@Builder
+public record ProofDTO(
+ long id,
+ String link,
+ String text,
+ ProofStatus status,
+ String created
+) {
+}
diff --git a/src/main/java/com/provedcode/talent/model/dto/ShortTalentDTO.java b/src/main/java/com/provedcode/talent/model/dto/ShortTalentDTO.java
index 491bcdb..d252bcd 100644
--- a/src/main/java/com/provedcode/talent/model/dto/ShortTalentDTO.java
+++ b/src/main/java/com/provedcode/talent/model/dto/ShortTalentDTO.java
@@ -11,6 +11,6 @@ public record ShortTalentDTO(
String firstName,
String lastName,
String specialization,
- List skills
+ List talents
) {
}
diff --git a/src/main/java/com/provedcode/talent/model/entity/Talent.java b/src/main/java/com/provedcode/talent/model/entity/Talent.java
index 9acd78d..28cf24c 100644
--- a/src/main/java/com/provedcode/talent/model/entity/Talent.java
+++ b/src/main/java/com/provedcode/talent/model/entity/Talent.java
@@ -39,17 +39,9 @@ public class Talent {
@OneToMany(fetch = FetchType.EAGER, mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
private List talentLinks = new ArrayList<>();
@OneToMany(fetch = FetchType.EAGER, mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
- private List talentSkills = new ArrayList<>();
+ private List talentTalents = new ArrayList<>();
@OneToMany(fetch = FetchType.EAGER, mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
private List talentContacts = new ArrayList<>();
@OneToMany(fetch = FetchType.EAGER, mappedBy = "talent", cascade = CascadeType.ALL, orphanRemoval = true)
private List talentAttachedFiles = new ArrayList<>();
-
- public void addTalentSkill(TalentSkill talentSkill) {
- talentSkills.add(talentSkill);
- }
-
- public void removeTalentSkill(TalentSkill talentSkill) {
- talentSkills.remove(talentSkill);
- }
}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/model/entity/TalentProof.java b/src/main/java/com/provedcode/talent/model/entity/TalentProof.java
new file mode 100644
index 0000000..942e56a
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/model/entity/TalentProof.java
@@ -0,0 +1,41 @@
+package com.provedcode.talent.model.entity;
+
+import com.provedcode.talent.model.ProofStatus;
+import jakarta.persistence.*;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import lombok.*;
+import org.hibernate.validator.constraints.URL;
+
+import java.time.LocalDateTime;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Getter
+@Setter
+@Entity
+@Table(name = "talent_proofs")
+public class TalentProof {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id", nullable = false)
+ private Long id;
+ @NotNull
+ @Column(name = "talent_id", nullable = false)
+ private Long talentId;
+ @NotEmpty
+ @URL
+ @Column(name = "link", length = 100)
+ private String link;
+ private String text;
+ @NotNull
+ @Enumerated(EnumType.STRING)
+ @Column(length = 20)
+ private ProofStatus status;
+ private LocalDateTime created;
+ @NotNull
+ @ManyToOne
+ @JoinColumn(name = "talent_id", insertable = false, updatable = false)
+ private Talent talent;
+}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/model/entity/TalentSkill.java b/src/main/java/com/provedcode/talent/model/entity/TalentTalents.java
similarity index 81%
rename from src/main/java/com/provedcode/talent/model/entity/TalentSkill.java
rename to src/main/java/com/provedcode/talent/model/entity/TalentTalents.java
index 884fb87..0eef149 100644
--- a/src/main/java/com/provedcode/talent/model/entity/TalentSkill.java
+++ b/src/main/java/com/provedcode/talent/model/entity/TalentTalents.java
@@ -10,8 +10,8 @@
@Getter
@Setter
@Entity
-@Table(name = "talent_skill")
-public class TalentSkill {
+@Table(name = "talent_talents")
+public class TalentTalents {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
@@ -19,8 +19,8 @@ public class TalentSkill {
@NotNull
@Column(name = "talent_id", nullable = false)
private Long talentId;
- @Column(name = "skill")
- private String skill;
+ @Column(name = "talent_name")
+ private String talentName;
@NotNull
@ManyToOne
@JoinColumn(name = "talent_id", insertable = false, updatable = false)
diff --git a/src/main/java/com/provedcode/talent/model/response/ShortTalent.java b/src/main/java/com/provedcode/talent/model/response/ShortTalent.java
index 532ff26..c8f5e93 100644
--- a/src/main/java/com/provedcode/talent/model/response/ShortTalent.java
+++ b/src/main/java/com/provedcode/talent/model/response/ShortTalent.java
@@ -1,7 +1,5 @@
package com.provedcode.talent.model.response;
-import com.provedcode.talent.model.entity.TalentSkill;
-
import java.util.List;
public record ShortTalent(
diff --git a/src/main/java/com/provedcode/talent/repo/TalentProofRepository.java b/src/main/java/com/provedcode/talent/repo/TalentProofRepository.java
new file mode 100644
index 0000000..8db70e6
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/repo/TalentProofRepository.java
@@ -0,0 +1,11 @@
+package com.provedcode.talent.repo;
+
+import com.provedcode.talent.model.ProofStatus;
+import com.provedcode.talent.model.entity.TalentProof;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface TalentProofRepository extends JpaRepository {
+ Page findByStatus(ProofStatus status, Pageable pageable);
+}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/repo/TalentRepository.java b/src/main/java/com/provedcode/talent/repo/TalentRepository.java
index 57723f6..e0359c3 100644
--- a/src/main/java/com/provedcode/talent/repo/TalentRepository.java
+++ b/src/main/java/com/provedcode/talent/repo/TalentRepository.java
@@ -1,16 +1,11 @@
package com.provedcode.talent.repo;
import com.provedcode.talent.model.entity.Talent;
-import com.provedcode.talent.model.entity.TalentSkill;
+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 {
- @Transactional
- @Modifying
- @Query("update Talent t set t.talentSkills = ?1")
- int updateTalentSkillsBy(TalentSkill talentSkills);
+public interface TalentRepository extends JpaRepository {
}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/repo/TalentSkillRepository.java b/src/main/java/com/provedcode/talent/repo/TalentSkillRepository.java
deleted file mode 100644
index 2c0648e..0000000
--- a/src/main/java/com/provedcode/talent/repo/TalentSkillRepository.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.provedcode.talent.repo;
-
-import com.provedcode.talent.model.entity.Talent;
-import com.provedcode.talent.model.entity.TalentSkill;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-import java.util.List;
-
-public interface TalentSkillRepository extends JpaRepository {
- List deleteByTalent(Talent talent);
-}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java b/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java
deleted file mode 100644
index e3fa4a9..0000000
--- a/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.provedcode.talent.repo.db;
-
-import com.provedcode.talent.model.entity.Talent;
-import com.provedcode.talent.repo.TalentRepository;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.Optional;
-
-public interface TalentEntityRepository extends
- JpaRepository,
- TalentRepository {
- @Transactional(readOnly = true)
- Page findAll(Pageable pageable);
- @Override
- @Transactional(readOnly = true)
- Optional findById(Long aLong);
-}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/service/TalentProofService.java b/src/main/java/com/provedcode/talent/service/TalentProofService.java
new file mode 100644
index 0000000..a4d817a
--- /dev/null
+++ b/src/main/java/com/provedcode/talent/service/TalentProofService.java
@@ -0,0 +1,36 @@
+package com.provedcode.talent.service;
+
+import com.provedcode.config.PageProperties;
+import com.provedcode.talent.model.ProofStatus;
+import com.provedcode.talent.model.entity.TalentProof;
+import com.provedcode.talent.repo.TalentProofRepository;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+import org.springframework.web.server.ResponseStatusException;
+
+import java.util.Optional;
+
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+
+@Service
+@AllArgsConstructor
+public class TalentProofService {
+ TalentProofRepository talentProofRepository;
+ PageProperties pageProperties;
+
+ public Page getAllProofsPage(Optional page, Optional size) {
+ if (page.orElse(pageProperties.defaultPageNum()) < 0) {
+ throw new ResponseStatusException(BAD_REQUEST, "'page' query parameter must be greater than or equal to 0");
+ }
+ if (size.orElse(pageProperties.defaultPageSize()) <= 0) {
+ throw new ResponseStatusException(BAD_REQUEST, "'size' query parameter must be greater than or equal to 1");
+ }
+ return talentProofRepository.findByStatus(ProofStatus.PUBLISHED,
+ PageRequest.of(page.orElse(
+ pageProperties.defaultPageNum()),
+ size.orElse(
+ pageProperties.defaultPageSize())));
+ }
+}
diff --git a/src/main/java/com/provedcode/talent/service/TalentService.java b/src/main/java/com/provedcode/talent/service/TalentService.java
index 838f74d..afc058b 100644
--- a/src/main/java/com/provedcode/talent/service/TalentService.java
+++ b/src/main/java/com/provedcode/talent/service/TalentService.java
@@ -1,20 +1,21 @@
package com.provedcode.talent.service;
-import com.provedcode.talent.model.dto.FullTalentDTO;
import com.provedcode.talent.model.dto.ShortTalentDTO;
+import com.provedcode.talent.model.entity.Talent;
import com.provedcode.user.model.dto.SessionInfoDTO;
import org.springframework.security.core.Authentication;
import org.springframework.data.domain.Page;
+import com.provedcode.talent.model.dto.FullTalentDTO;
import java.util.Optional;
public interface TalentService {
- Page getTalentsPage(Optional page, Optional size);
+ Page getTalentsPage(Optional page, Optional size);
- FullTalentDTO getTalentById(long id);
+ Talent getTalentById(long id);
- FullTalentDTO editTalent(long id, FullTalentDTO fullTalent, Authentication authentication);
+ Talent editTalent(long id, FullTalentDTO fullTalent, Authentication authentication);
SessionInfoDTO deleteTalentById(long id, Authentication authentication);
}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java b/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java
index 900920f..fd3b24b 100644
--- a/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java
+++ b/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java
@@ -1,16 +1,12 @@
package com.provedcode.talent.service.impl;
import com.provedcode.config.PageProperties;
-import com.provedcode.talent.mapper.TalentMapper;
import com.provedcode.talent.model.dto.FullTalentDTO;
-import com.provedcode.talent.model.dto.ShortTalentDTO;
import com.provedcode.talent.model.entity.*;
import com.provedcode.talent.repo.TalentRepository;
-import com.provedcode.talent.repo.TalentSkillRepository;
import com.provedcode.talent.service.TalentService;
import com.provedcode.user.model.dto.SessionInfoDTO;
import com.provedcode.user.model.entity.UserInfo;
-import com.provedcode.user.repo.AuthorityRepository;
import com.provedcode.user.repo.UserInfoRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -31,18 +27,14 @@
@AllArgsConstructor
@Transactional
public class TalentServiceImpl implements TalentService {
- private final AuthorityRepository authorityRepository;
- TalentMapper talentMapper;
TalentRepository talentRepository;
- TalentSkillRepository talentSkillRepository;
UserInfoRepository userInfoRepository;
PageProperties pageProperties;
- TalentRepository talentEntityRepository;
@Override
@Transactional(readOnly = true)
- public Page getTalentsPage(Optional page, Optional size) {
+ public Page getTalentsPage(Optional page, Optional size) {
if (page.orElse(pageProperties.defaultPageNum()) < 0) {
throw new ResponseStatusException(BAD_REQUEST, "'page' query parameter must be greater than or equal to 0");
}
@@ -50,92 +42,100 @@ public Page getTalentsPage(Optional page, Optional talent = talentRepository.findById(id);
if (talent.isEmpty()) {
throw new ResponseStatusException(NOT_FOUND, String.format("talent with id = %d not found", id));
}
- return talentMapper.talentToFullTalentDTO(talent.get());
+ return talent.get();
}
@Override
- public FullTalentDTO editTalent(long id, FullTalentDTO fullTalent, Authentication authentication) {
+ public Talent editTalent(long id, FullTalentDTO fullTalent, Authentication authentication) {
Optional talent = talentRepository.findById(id);
Optional userInfo = userInfoRepository.findByLogin(authentication.getName());
- if (talent.isEmpty() || userInfo.isEmpty()) {
- throw new ResponseStatusException(NOT_FOUND, String.format("talent with id = %d not found", id));
- }
- if (userInfo.get().getTalent().getId() != id) {
- throw new ResponseStatusException(FORBIDDEN, "you can`t update another user");
- }
+ userVerification(talent, userInfo, id);
Talent oldTalent = talent.get();
long oldTalentId = oldTalent.getId();
TalentDescription oldTalentDescription = oldTalent.getTalentDescription();
+ List oldTalentTalents = oldTalent.getTalentTalents();
+ List oldTalentLinks = oldTalent.getTalentLinks();
+ List oldTalentContacts = oldTalent.getTalentContacts();
+ List oldTalentAttachedFile = oldTalent.getTalentAttachedFiles();
+
if (oldTalentDescription != null) {
oldTalentDescription
.setAdditionalInfo(fullTalent.additionalInfo())
.setBio(fullTalent.bio());
} else {
oldTalentDescription = TalentDescription.builder()
- .talentId(oldTalentId)
- .additionalInfo(fullTalent.additionalInfo())
- .bio(fullTalent.bio())
- .talent(oldTalent)
- .build();
+ .talentId(oldTalentId)
+ .additionalInfo(fullTalent.additionalInfo())
+ .bio(fullTalent.bio())
+ .talent(oldTalent)
+ .build();
}
- List oldTalentSkills = oldTalent.getTalentSkills();
- oldTalentSkills.clear();
- oldTalentSkills.addAll(fullTalent.skills().stream().map(s -> TalentSkill.builder()
- .talentId(oldTalentId)
- .talent(oldTalent)
- .skill(s).build()).toList());
+ oldTalentTalents.clear();
+ if (fullTalent.talents() != null) {
+ oldTalentTalents.addAll(fullTalent.talents().stream().map(s -> TalentTalents.builder()
+ .talentId(oldTalentId)
+ .talent(oldTalent)
+ .talentName(s)
+ .build()).toList());
+ }
- List oldTalentLinks = oldTalent.getTalentLinks();
oldTalentLinks.clear();
- oldTalentLinks.addAll(fullTalent.links().stream().map(l -> TalentLink.builder()
- .talentId(oldTalentId)
- .talent(oldTalent)
- .link(l).build()).toList());
+ if (fullTalent.links() != null) {
+ oldTalentLinks.addAll(fullTalent.links().stream().map(l -> TalentLink.builder()
+ .talentId(oldTalentId)
+ .talent(oldTalent)
+ .link(l)
+ .build()).toList());
+ }
- List oldTalentContacts = oldTalent.getTalentContacts();
oldTalentContacts.clear();
- oldTalentContacts.addAll(fullTalent.contacts().stream().map(s -> TalentContact.builder()
- .talentId(oldTalentId)
- .talent(oldTalent)
- .contact(s).build()).toList());
- List oldTalentAttachedFile = oldTalent.getTalentAttachedFiles();
+ if (fullTalent.contacts() != null) {
+ oldTalentContacts.addAll(fullTalent.contacts().stream().map(s -> TalentContact.builder()
+ .talentId(oldTalentId)
+ .talent(oldTalent)
+ .contact(s)
+ .build()).toList());
+ }
+
oldTalentAttachedFile.clear();
- oldTalentAttachedFile.addAll(fullTalent.attachedFiles().stream().map(s -> TalentAttachedFile.builder()
- .talentId(
- oldTalentId)
- .talent(oldTalent)
- .attachedFile(s)
- .build()).toList());
+ if (fullTalent.attachedFiles() != null) {
+ oldTalentAttachedFile.addAll(fullTalent.attachedFiles().stream().map(s -> TalentAttachedFile.builder()
+ .talentId(
+ oldTalentId)
+ .talent(oldTalent)
+ .attachedFile(s)
+ .build())
+ .toList());
+ }
oldTalent.setFirstName(fullTalent.firstName())
.setLastName(fullTalent.lastName())
.setSpecialization(fullTalent.specialization())
.setImage(fullTalent.image())
.setTalentDescription(oldTalentDescription)
- .setTalentSkills(oldTalentSkills)
+ .setTalentTalents(oldTalentTalents)
.setTalentLinks(oldTalentLinks)
.setTalentContacts(oldTalentContacts)
.setTalentAttachedFiles(oldTalentAttachedFile);
- talentRepository.save(oldTalent);
+ Talent newTalent = talentRepository.save(oldTalent);
- return talentMapper.talentToFullTalentDTO(oldTalent);
+ return newTalent;
}
@Override
@@ -143,24 +143,19 @@ public SessionInfoDTO deleteTalentById(long id, Authentication authentication) {
Optional talent = talentRepository.findById(id);
Optional userInfo = userInfoRepository.findByLogin(authentication.getName());
+ userVerification(talent, userInfo, id);
+
+ userInfoRepository.delete(userInfo.orElseThrow(() -> new ResponseStatusException(NOT_IMPLEMENTED)));
+ talentRepository.delete(talent.orElseThrow(() -> new ResponseStatusException(NOT_IMPLEMENTED)));
+ return new SessionInfoDTO("deleted", "null");
+ }
+
+ private void userVerification(Optional talent, Optional userInfo, long id) {
if (talent.isEmpty() || userInfo.isEmpty()) {
throw new ResponseStatusException(NOT_FOUND, String.format("talent with id = %d not found", id));
}
if (userInfo.get().getTalent().getId() != id) {
- throw new ResponseStatusException(FORBIDDEN, "you can`t delete another user");
+ throw new ResponseStatusException(FORBIDDEN, "you can`t delete/update another user");
}
-
- userInfoRepository.delete(userInfo.get());
- talentRepository.deleteById(id);
- return new SessionInfoDTO("deleted", "null");
}
-
-// public void userVerification(Optional talent, Optional userInfo, long id) {
-// if (talent.isEmpty()) {
-// throw new ResponseStatusException(NOT_FOUND, String.format("talent with id = %d not found", id));
-// }
-// if (userInfo.get().getTalent().getId() != id) {
-// throw new ResponseStatusException(UNAUTHORIZED);
-// }
-// }
}
diff --git a/src/main/java/com/provedcode/user/controller/AuthenticationController.java b/src/main/java/com/provedcode/user/controller/AuthenticationController.java
index 4bd9bd0..2a04c69 100644
--- a/src/main/java/com/provedcode/user/controller/AuthenticationController.java
+++ b/src/main/java/com/provedcode/user/controller/AuthenticationController.java
@@ -14,7 +14,6 @@
@AllArgsConstructor
@Slf4j
@RequestMapping("/api/talents")
-@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
public class AuthenticationController {
AuthenticationService authenticationService;
diff --git a/src/main/java/com/provedcode/user/mapper/UserInfoMapper.java b/src/main/java/com/provedcode/user/mapper/UserInfoMapper.java
index d7138b4..7cbca7b 100644
--- a/src/main/java/com/provedcode/user/mapper/UserInfoMapper.java
+++ b/src/main/java/com/provedcode/user/mapper/UserInfoMapper.java
@@ -1,8 +1,23 @@
package com.provedcode.user.mapper;
+import com.provedcode.user.model.entity.Authority;
import com.provedcode.user.model.entity.UserInfo;
+import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
+import org.mapstruct.ReportingPolicy;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
+@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface UserInfoMapper {
- UserDetails toUserDetails(UserInfo user);
+ default UserDetails toUserDetails(UserInfo user) {
+ return User.withUsername(user.getLogin())
+ .password(user.getPassword())
+ .authorities(user.getAuthorities()
+ .stream()
+ .map(Authority::getAuthority)
+ .toList())
+ .build();
+ }
}
diff --git a/src/main/java/com/provedcode/user/mapper/impl/UserInfoMapperImpl.java b/src/main/java/com/provedcode/user/mapper/impl/UserInfoMapperImpl.java
index 9db05e9..e2b6bc4 100644
--- a/src/main/java/com/provedcode/user/mapper/impl/UserInfoMapperImpl.java
+++ b/src/main/java/com/provedcode/user/mapper/impl/UserInfoMapperImpl.java
@@ -1,24 +1,24 @@
-package com.provedcode.user.mapper.impl;
-
-import com.provedcode.user.mapper.UserInfoMapper;
-import com.provedcode.user.model.entity.UserInfo;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.userdetails.User;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.stereotype.Component;
-
-@Component
-public class UserInfoMapperImpl implements UserInfoMapper {
- @Override
- public UserDetails toUserDetails(UserInfo user) {
- return User.withUsername(user.getLogin())
- .password(user.getPassword())
- .authorities(user.getUserAuthorities()
- .stream()
- .map(i -> new SimpleGrantedAuthority(
- i.getAuthority()
- .getAuthority()))
- .toList())
- .build();
- }
-}
+//package com.provedcode.user.mapper.impl;
+//
+//import com.provedcode.user.mapper.UserInfoMapper;
+//import com.provedcode.user.model.entity.UserInfo;
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.security.core.authority.SimpleGrantedAuthority;
+//import org.springframework.security.core.userdetails.User;
+//import org.springframework.security.core.userdetails.UserDetails;
+//import org.springframework.stereotype.Component;
+//
+//@Component
+//@Slf4j
+//public class UserInfoMapperImpl implements UserInfoMapper {
+// @Override
+// public UserDetails toUserDetails(UserInfo user) {
+// return User.withUsername(user.getLogin())
+// .password(user.getPassword())
+// .authorities(user.getAuthorities()
+// .stream()
+// .map(i -> new SimpleGrantedAuthority(i.getAuthority()))
+// .toList())
+// .build();
+// }
+//}
diff --git a/src/main/java/com/provedcode/user/model/Role.java b/src/main/java/com/provedcode/user/model/Role.java
index d1f1e35..d63f679 100644
--- a/src/main/java/com/provedcode/user/model/Role.java
+++ b/src/main/java/com/provedcode/user/model/Role.java
@@ -1,6 +1,8 @@
package com.provedcode.user.model;
-public enum Role {
+import org.springframework.security.core.GrantedAuthority;
+
+public enum Role implements GrantedAuthority {
TALENT("ROLE_TALENT");
private final String userRole;
@@ -9,7 +11,7 @@ public enum Role {
}
@Override
- public String toString() {
+ public String getAuthority() {
return this.userRole;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/user/model/entity/Authority.java b/src/main/java/com/provedcode/user/model/entity/Authority.java
index dc8a965..36f2471 100644
--- a/src/main/java/com/provedcode/user/model/entity/Authority.java
+++ b/src/main/java/com/provedcode/user/model/entity/Authority.java
@@ -1,11 +1,15 @@
package com.provedcode.user.model.entity;
+import com.provedcode.user.model.Role;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
@Getter
@Setter
@Entity
@@ -15,8 +19,11 @@ public class Authority {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
+ @Enumerated(EnumType.STRING)
@NotEmpty
@NotNull
@Column(name = "authority", length = 20)
- private String authority;
+ private Role authority;
+ @ManyToMany(fetch = FetchType.EAGER, mappedBy = "authorities", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
+ private Set userInfoes = new LinkedHashSet<>();
}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/user/model/entity/UserAuthority.java b/src/main/java/com/provedcode/user/model/entity/UserAuthority.java
deleted file mode 100644
index d8bbcf7..0000000
--- a/src/main/java/com/provedcode/user/model/entity/UserAuthority.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.provedcode.user.model.entity;
-
-import jakarta.persistence.*;
-import jakarta.validation.constraints.NotNull;
-import lombok.*;
-
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-@Getter
-@Setter
-@Entity
-@Table(name = "user_authority")
-public class UserAuthority {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "id", nullable = false)
- private Long id;
- @NotNull
- @ManyToOne
- @JoinColumn(name = "user_id")
- private UserInfo userInfo;
- @NotNull
- @ManyToOne
- @JoinColumn(name = "authority_id")
- private Authority authority;
-}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/user/model/entity/UserInfo.java b/src/main/java/com/provedcode/user/model/entity/UserInfo.java
index 2f7efca..38b1d33 100644
--- a/src/main/java/com/provedcode/user/model/entity/UserInfo.java
+++ b/src/main/java/com/provedcode/user/model/entity/UserInfo.java
@@ -22,8 +22,8 @@ public class UserInfo {
@Column(name = "id", nullable = false)
private Long id;
@NotNull
- @Column(name = "user_id")
- private Long userId;
+ @Column(name = "talent_id")
+ private Long talentId;
@NotEmpty
@NotNull
@Column(name = "login", length = 100)
@@ -32,9 +32,12 @@ public class UserInfo {
@NotNull
@Column(name = "password")
private String password;
- @OneToOne(orphanRemoval = true)
- @JoinColumn(name = "user_id", insertable = false, updatable = false)
+ @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
+ @JoinColumn(name = "talent_id", insertable = false, updatable = false)
private Talent talent;
- @OneToMany(mappedBy = "userInfo", orphanRemoval = true, fetch = FetchType.EAGER)
- private Set userAuthorities = new LinkedHashSet<>();
+ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
+ @JoinTable(name = "user_authorities",
+ joinColumns = @JoinColumn(name = "user_id"),
+ inverseJoinColumns = @JoinColumn(name = "authority_id"))
+ private Set authorities = new LinkedHashSet<>();
}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/user/repo/AuthorityRepository.java b/src/main/java/com/provedcode/user/repo/AuthorityRepository.java
index dbb713e..9ad9a0f 100644
--- a/src/main/java/com/provedcode/user/repo/AuthorityRepository.java
+++ b/src/main/java/com/provedcode/user/repo/AuthorityRepository.java
@@ -1,10 +1,11 @@
package com.provedcode.user.repo;
+import com.provedcode.user.model.Role;
import com.provedcode.user.model.entity.Authority;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
public interface AuthorityRepository extends JpaRepository {
- Optional findByAuthority(String authority);
+ Optional findByAuthority(Role authority);
}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/user/repo/UserAuthorityRepository.java b/src/main/java/com/provedcode/user/repo/UserAuthorityRepository.java
deleted file mode 100644
index ef91bfc..0000000
--- a/src/main/java/com/provedcode/user/repo/UserAuthorityRepository.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.provedcode.user.repo;
-
-import com.provedcode.user.model.entity.UserAuthority;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-import java.util.Optional;
-import java.util.Set;
-
-public interface UserAuthorityRepository extends JpaRepository {
-}
\ No newline at end of file
diff --git a/src/main/java/com/provedcode/user/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/provedcode/user/service/impl/AuthenticationServiceImpl.java
index 45fc34f..8911bb6 100644
--- a/src/main/java/com/provedcode/user/service/impl/AuthenticationServiceImpl.java
+++ b/src/main/java/com/provedcode/user/service/impl/AuthenticationServiceImpl.java
@@ -5,17 +5,15 @@
import com.provedcode.user.model.Role;
import com.provedcode.user.model.dto.RegistrationDTO;
import com.provedcode.user.model.dto.SessionInfoDTO;
-import com.provedcode.user.model.entity.UserAuthority;
+import com.provedcode.user.model.entity.Authority;
import com.provedcode.user.model.entity.UserInfo;
import com.provedcode.user.repo.AuthorityRepository;
-import com.provedcode.user.repo.UserAuthorityRepository;
import com.provedcode.user.repo.UserInfoRepository;
import com.provedcode.user.service.AuthenticationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.jwt.JwtClaimsSet;
import org.springframework.security.oauth2.jwt.JwtEncoder;
@@ -38,7 +36,6 @@ public class AuthenticationServiceImpl implements AuthenticationService {
JwtEncoder jwtEncoder;
UserInfoRepository userInfoRepository;
TalentRepository talentEntityRepository;
- UserAuthorityRepository userAuthorityRepository;
AuthorityRepository authorityRepository;
PasswordEncoder passwordEncoder;
@@ -51,36 +48,32 @@ public SessionInfoDTO login(String name, Collection extends GrantedAuthority>
public SessionInfoDTO register(RegistrationDTO user) {
if (userInfoRepository.existsByLogin(user.login())) {
throw new ResponseStatusException(HttpStatus.CONFLICT,
- String.format("user with login = {%s} already exists", user.login()));
+ String.format("user with login = {%s} already exists", user.login()));
}
Talent talent = Talent.builder()
- .firstName(user.firstName())
- .lastName(user.lastName())
- .specialization(user.specialization())
- .build();
+ .firstName(user.firstName())
+ .lastName(user.lastName())
+ .specialization(user.specialization())
+ .build();
talentEntityRepository.save(talent);
UserInfo userInfo = UserInfo.builder()
- .userId(talent.getId())
- .login(user.login())
- .password(passwordEncoder.encode(user.password()))
- .build();
- UserAuthority userAuthority = UserAuthority.builder()
- .userInfo(userInfo)
- .authority(authorityRepository.findByAuthority(Role.TALENT.toString())
- .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "this authority does`t exist")))
- .build();
+ .talentId(talent.getId())
+ .login(user.login())
+ .password(passwordEncoder.encode(user.password()))
+ .build();
+ userInfo.setAuthorities(Set.of(authorityRepository.findByAuthority(Role.TALENT).orElseThrow()));
- userInfo.setUserAuthorities(Set.of(userAuthority));
- userAuthority.setUserInfo(userInfoRepository.save(userInfo));
- userAuthorityRepository.save(userAuthority);
+ userInfoRepository.save(userInfo);
String userLogin = userInfo.getLogin();
- Collection extends GrantedAuthority> userAuthorities = userInfo.getUserAuthorities().stream().map(i -> new SimpleGrantedAuthority(i.getAuthority().getAuthority())).toList();
+ Collection extends GrantedAuthority> userAuthorities = userInfo.getAuthorities().stream().map(
+ Authority::getAuthority).toList();
log.info("user with login {%s} was saved, his authorities: %s".formatted(userLogin, userAuthorities));
- return new SessionInfoDTO("User: {%s} was registered".formatted(userLogin), generateJWTToken(userLogin, userAuthorities));
+ return new SessionInfoDTO("User: {%s} was registered".formatted(userLogin),
+ generateJWTToken(userLogin, userAuthorities));
}
private String generateJWTToken(String name, Collection extends GrantedAuthority> authorities) {
@@ -88,12 +81,13 @@ private String generateJWTToken(String name, Collection extends GrantedAuthori
log.info("=== POST /login === auth = {}", authorities);
var now = Instant.now();
var claims = JwtClaimsSet.builder()
- .issuer("self")
- .issuedAt(now)
- .expiresAt(now.plus(5, MINUTES))
- .subject(name)
- .claim("scope", authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.joining(" ")))
- .build();
+ .issuer("self")
+ .issuedAt(now)
+ .expiresAt(now.plus(60, MINUTES))
+ .subject(name)
+ .claim("scope", authorities.stream().map(GrantedAuthority::getAuthority)
+ .collect(Collectors.joining(" ")))
+ .build();
return jwtEncoder.encode(JwtEncoderParameters.from(claims)).getTokenValue();
}
diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties
index c8b0f61..52a6e52 100644
--- a/src/main/resources/application-dev.properties
+++ b/src/main/resources/application-dev.properties
@@ -1,4 +1,6 @@
spring.datasource.username=sa
-spring.datasource.url=jdbc:h2:mem:../sampleDB
-logging.level.web=DEBUG
-logging.level.sql=DEBUG
\ No newline at end of file
+spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL
+#logging.level.web=DEBUG
+#logging.level.sql=DEBUG
+spring.jpa.hibernate.ddl-auto=none
+spring.sql.init.mode=always
\ No newline at end of file
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index 3eb12be..810d9a1 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -1,6 +1,5 @@
spring.datasource.username=${DB_LOGIN}
spring.datasource.password=${DB_PASSWORD}
-spring.datasource.url=${DB_URL}
+spring.datasource.url=jdbc:postgresql://${DB_URL}
spring.jpa.hibernate.ddl-auto=none
-spring.sql.init.mode=always
-spring.sql.init.platform=h2
\ No newline at end of file
+spring.sql.init.mode=always
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index c9f8e06..ec6f1ce 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -4,9 +4,7 @@ server.port=8080
##
spring.jackson.property-naming-strategy=SNAKE_CASE
##
-logging.level.cinema.controller=info
-##
-spring.datasource.driverClassName=org.h2.Driver
+spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.jpa.hibernate.ddl-auto=update
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 7e1c2fb..494a7af 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -1,11 +1,10 @@
insert into authority (id, authority)
-values (1, 'ROLE_TALENT');
--- FOR USER AUTHORITY
--- SELECT USER_INFO.ID , LOGIN , PASSWORD, USER_ID , AUTHORITY FROM
--- USER_INFO
--- JOIN USER_AUTHORITY ON USER_ID = USER_INFO.ID
--- JOIN AUTHORITY ON AUTHORITY.ID = AUTHORITY_ID
-
+values (1, 'TALENT');
+-- -- FOR USER AUTHORITY
+-- -- SELECT USER_INFO.ID , LOGIN , PASSWORD, talent_id , AUTHORITY FROM
+-- -- USER_INFO
+-- -- JOIN user_authorities ON talent_id = USER_INFO.ID
+-- -- JOIN AUTHORITY ON AUTHORITY.ID = id
insert into talent (first_name, last_name, specialization, image)
values ('Serhii', 'Soloviov', 'Java-Developer', 'https://i.pinimg.com/564x/e1/08/49/e10849923a8b2e85a7adf494ebd063e6.jpg');
@@ -17,13 +16,13 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Java Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Spring Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Spring boot');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'H2 Database');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'first_contact');
@@ -32,15 +31,21 @@ values ((select id from talent order by id desc limit 1), 'second_contact');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://first_link', 'text to first proof', 'PUBLISHED', '2023-06-04 16:00:19');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://second_link', 'text to second proof', 'DRAFT', '2023-06-04 16:00:19');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://third_link', 'text to third proof', 'DRAFT', '2023-06-04 16:00:19');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'SerhiiSoloviov', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -54,13 +59,13 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://MykhailoOrdyntsev_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://MykhailoOrdyntsev_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Java Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Hibernate');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Spring Boot');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_first_contact');
@@ -69,15 +74,21 @@ values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_sec
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://first_link', 'text to first proof', 'DRAFT', '2023-06-04 16:00:19');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://second_link', 'text to second proof', 'DRAFT', '2023-06-04 16:00:19');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://third_link', 'text to third proof', 'DRAFT', '2023-06-04 16:00:19');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -91,11 +102,11 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://DenisBoyko_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://DenisBoyko_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Java Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Spring Security');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Spring Core');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'DenisBoyko_first_contact');
@@ -104,15 +115,21 @@ values ((select id from talent order by id desc limit 1), 'DenisBoyko_second_con
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'DenisBoyko_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DenisBoyko_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DenisBoyko_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DenisBoyko_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://first_link', 'text to first proof', 'DRAFT', '2023-06-04 16:00:19');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://second_link', 'text to second proof', 'DRAFT', '2023-06-04 16:00:19');
+insert into talent_proofs (talent_id, link, text, status, created)
+values ((select id from talent order by id desc limit 1), 'http://third_link', 'text to third proof', 'DRAFT', '2023-06-04 16:00:19');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'DenisBoyko', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -126,9 +143,9 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://IhorShchurenko_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://IhorShchurenko_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Java Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'REST API');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'IhorShchurenko_first_contact');
@@ -137,15 +154,15 @@ values ((select id from talent order by id desc limit 1), 'IhorShchurenko_second
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'IhorShchurenko_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'IhorShchurenko_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'IhorShchurenko_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'IhorShchurenko_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'DmytroUzun', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -159,11 +176,11 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://DmytroUzun_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://DmytroUzun_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Docker');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Mentor');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'DmytroUzun_first_contact');
@@ -172,15 +189,15 @@ values ((select id from talent order by id desc limit 1), 'DmytroUzun_second_con
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'DmytroUzun_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DmytroUzun_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DmytroUzun_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DmytroUzun_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'DmytroUzun', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -194,9 +211,9 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://ViktorVoloshko_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://ViktorVoloshko_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Docker');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_first_contact');
@@ -205,15 +222,15 @@ values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_second
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'ViktorVoloshko', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -227,11 +244,11 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://OlhaMoiseienko_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://OlhaMoiseienko_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Jira');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'QA');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_first_contact');
@@ -240,15 +257,15 @@ values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_second
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko _third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -262,9 +279,9 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://MaximKiyashko_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://MaximKiyashko_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'QA');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'MaximKiyashko_first_contact');
@@ -273,15 +290,15 @@ values ((select id from talent order by id desc limit 1), 'MaximKiyashko_second_
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'MaximKiyashko_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'MaximKiyashko_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'MaximKiyashko_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'MaximKiyashko_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'MaximKiyashko', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -295,12 +312,12 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://NikolaievOleksii_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://NikolaievOleksii_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'QA');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
-insert into talent_skill (talent_id, skill)
-values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_third_skill');
+insert into talent_talents (talent_id, talent_name)
+values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_third_talents');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_first_contact');
insert into talent_contact (talent_id, contact)
@@ -308,15 +325,15 @@ values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_seco
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'NikolaievOleksiio_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'NikolaievOleksiio', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -330,9 +347,9 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://ArtemLytvynenko_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://ArtemLytvynenko_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'QA');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Git');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_first_contact');
@@ -341,15 +358,15 @@ values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_secon
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -363,9 +380,9 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://DaniilYevtukhov_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://DaniilYevtukhov_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'JavaScript Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'React');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_first_contact');
@@ -374,15 +391,15 @@ values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_secon
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -396,11 +413,11 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://RuslanMorozov_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://RuslanMorozov_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'JavaScript Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'React');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Node.js');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'RuslanMorozov_first_contact');
@@ -409,15 +426,15 @@ values ((select id from talent order by id desc limit 1), 'RuslanMorozov_second_
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'RuslanMorozov_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'RuslanMorozov_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'RuslanMorozov_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'RuslanMorozov_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'RuslanMorozov', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
@@ -431,11 +448,11 @@ insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://IhorKopieichykov_second_link');
insert into talent_link (talent_id, link)
values ((select id from talent order by id desc limit 1), 'http://IhorKopieichykov_third_link');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'JavaScript Core');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'React');
-insert into talent_skill (talent_id, skill)
+insert into talent_talents (talent_id, talent_name)
values ((select id from talent order by id desc limit 1), 'Angular');
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_first_contact');
@@ -444,14 +461,14 @@ values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_seco
insert into talent_contact (talent_id, contact)
values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_third_contact');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_first_file');
+values ((select id from talent order by id desc limit 1), 'http://first_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_second_file');
+values ((select id from talent order by id desc limit 1), 'http://second_file');
insert into talent_attached_file (talent_id, attached_file)
-values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_third_file');
+values ((select id from talent order by id desc limit 1), 'http://third_file');
-insert into user_info (user_id, login, password)
+insert into user_info (talent_id, login, password)
values ((select id from talent order by id desc limit 1), 'IhorKopieichykov', 'password');
-insert into user_authority (user_id, authority_id)
+insert into user_authorities (user_id, authority_id)
values ((select id from user_info order by id desc limit 1),
(select authority.id from authority where id = 1));
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql
index 2166cfd..d666401 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema.sql
@@ -3,9 +3,10 @@ drop table IF EXISTS talent_description CASCADE ;
drop table IF EXISTS talent_link CASCADE ;
drop table IF EXISTS talent_contact CASCADE ;
drop table IF EXISTS talent_attached_file CASCADE ;
-drop table IF EXISTS talent_skill CASCADE ;
-drop table IF EXISTS user_authority CASCADE ;
+drop table IF EXISTS talent_talents CASCADE ;
drop table IF EXISTS user_info CASCADE ;
+drop table IF EXISTS user_authorities CASCADE ;
+drop table IF EXISTS talent_talents CASCADE ;
drop table IF EXISTS authority CASCADE ;
create TABLE talent (
@@ -36,14 +37,16 @@ create TABLE talent_link (
alter table talent_link add CONSTRAINT FK_TALENT_LINK_ON_TALENT FOREIGN KEY (talent_id) REFERENCES talent (id);
-create TABLE talent_skill (
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- talent_id BIGINT NOT NULL,
- skill VARCHAR(255) NOT NULL,
- CONSTRAINT pk_talent_skill PRIMARY KEY (id)
+CREATE TABLE talent_talents
+(
+ id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
+ talent_id BIGINT NOT NULL,
+ talent_name VARCHAR(255),
+ CONSTRAINT pk_talent_talents PRIMARY KEY (id)
);
-alter table talent_skill add CONSTRAINT FK_TALENT_SKILL_ON_TALENT FOREIGN KEY (talent_id) REFERENCES talent (id);
+ALTER TABLE talent_talents
+ ADD CONSTRAINT FK_TALENT_TALENTS_ON_TALENT FOREIGN KEY (talent_id) REFERENCES talent (id);
create TABLE talent_contact (
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
@@ -63,30 +66,43 @@ create TABLE talent_attached_file (
alter table talent_attached_file add CONSTRAINT FK_TALENT_ATTACHED_FILE_ON_TALENT FOREIGN KEY (talent_id) REFERENCES talent (id);
---user tables--
-create TABLE user_info (
- id BIGINT AUTO_INCREMENT NOT NULL,
- user_id BIGINT NOT NULL,
- login VARCHAR(100) NOT NULL,
- password VARCHAR(255) NOT NULL,
- CONSTRAINT pk_user_info PRIMARY KEY (id)
+CREATE TABLE talent_proofs (
+ id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
+ talent_id BIGINT NOT NULL,
+ link VARCHAR(100),
+ text VARCHAR(255),
+ status VARCHAR(20),
+ created TIMESTAMP,
+ CONSTRAINT pk_talent_proofs PRIMARY KEY (id)
);
-alter table user_info add CONSTRAINT FK_USER_INFO_ON_USER FOREIGN KEY (user_id) REFERENCES talent (id);
+ALTER TABLE talent_proofs ADD CONSTRAINT FK_TALENT_PROOFS_ON_TALENT FOREIGN KEY (talent_id) REFERENCES talent (id);
+--user tables--
+CREATE TABLE authority
+(
+ id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
+ authority VARCHAR(20) NOT NULL,
+ CONSTRAINT pk_authority PRIMARY KEY (id)
+);
-create TABLE authority (
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- authority VARCHAR(20) NOT NULL,
- CONSTRAINT pk_authority PRIMARY KEY (id)
+CREATE TABLE user_info
+(
+ id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
+ talent_id BIGINT NOT NULL,
+ login VARCHAR(100) NOT NULL,
+ password VARCHAR(255) NOT NULL,
+ CONSTRAINT pk_user_info PRIMARY KEY (id)
);
-create TABLE user_authority (
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- user_id BIGINT,
- authority_id BIGINT,
- CONSTRAINT pk_user_authority PRIMARY KEY (id)
+CREATE TABLE user_authorities
+(
+ user_id BIGINT NOT NULL,
+ authority_id BIGINT NOT NULL,
+ CONSTRAINT pk_user_authorities PRIMARY KEY (user_id, authority_id)
);
-alter table user_authority add CONSTRAINT FK_USER_AUTHORITY_ON_AUTHORITY FOREIGN KEY (authority_id) REFERENCES authority (id);
+ALTER TABLE user_info ADD CONSTRAINT FK_USER_INFO_ON_USER_ID FOREIGN KEY (talent_id) REFERENCES talent (id);
+
+ALTER TABLE user_authorities ADD CONSTRAINT fk_useaut_on_authority FOREIGN KEY (authority_id) REFERENCES authority (id);
-alter table user_authority add CONSTRAINT FK_USER_AUTHORITY_ON_USER FOREIGN KEY (user_id) REFERENCES user_info (id);
\ No newline at end of file
+ALTER TABLE user_authorities ADD CONSTRAINT fk_useaut_on_user_info FOREIGN KEY (user_id) REFERENCES user_info (id);