Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -37,5 +37,4 @@ public String delete(@PathVariable String filename) {
public List<String> getAllFiles() {
return s3Service.listAllFiles();
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/com/provedcode/config/AWSProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public record AWSProperties(
void postCreate() {
log.info("aws-props = {}", this);
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/com/provedcode/config/PropsConfig.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/java/com/provedcode/config/S3Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -31,4 +30,4 @@ public AmazonS3 s3() {
void test() {
log.info("S3Config: %s %s %s".formatted(awsProperties.accessKey(), awsProperties.secretKey(), awsProperties.region()));
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/provedcode/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
http.authorizeHttpRequests(c -> c
.requestMatchers("/actuator/health").permitAll() // for DevOps
.requestMatchers(antMatcher("/h2/**")).permitAll()
.requestMatchers(antMatcher("/api/talents/**")).permitAll()
.requestMatchers(antMatcher("/api/*/talents/**")).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
Expand Up @@ -3,6 +3,7 @@
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.request.EditTalent;
import com.provedcode.talent.service.TalentService;
import com.provedcode.user.model.dto.SessionInfoDTO;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -26,59 +27,59 @@
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/api")
@RequestMapping("/api/v2")
@Tag(name = "talent", description = "Talent API")
public class TalentController {
TalentService talentService;
TalentMapper talentMapper;

@Operation(summary = "Get talent",
description = "As a talent I want to have an opportunity to see the full information about the talent")
@Operation(summary = "Get all talents",
description = "As a guest I want to see a page with a list of all “talents” cards displayed with a short description about them")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "SUCCESS",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = FullTalentDTO.class))),
schema = @Schema(implementation = Page.class, subTypes = {ShortTalentDTO.class}))),
@ApiResponse(responseCode = "404",
description = "NOT FOUND",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "UNAUTHORIZED",
content = @Content),
responseCode = "400",
description = "BAD_REQUEST (parameter: page or size are incorrect)",
content = @Content)
})
@PreAuthorize("hasRole('TALENT')")
@GetMapping("/talents/{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<ShortTalentDTO> getTalents(@RequestParam(value = "page") Optional<Integer> page,
@RequestParam(value = "size") Optional<Integer> size) {
return talentService.getTalentsPage(page, size).map(talentMapper::talentToShortTalentDTO);
}

@Operation(summary = "Get all talents",
description = "As a guest I want to see a page with a list of all “talents” cards displayed with a short description about them")
@Operation(summary = "Get talent",
description = "As a talent I want to have an opportunity to see the full information about the talent")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "SUCCESS",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = Page.class, subTypes = {ShortTalentDTO.class}))),
schema = @Schema(implementation = FullTalentDTO.class))),
@ApiResponse(responseCode = "404",
description = "NOT FOUND",
content = @Content),
@ApiResponse(
responseCode = "400",
description = "BAD_REQUEST (parameter: page or size are incorrect)",
content = @Content)
responseCode = "401",
description = "UNAUTHORIZED",
content = @Content),
})
@GetMapping("/talents")
@ResponseStatus(HttpStatus.OK)
Page<ShortTalentDTO> getTalents(@RequestParam(value = "page") Optional<Integer> page,
@RequestParam(value = "size") Optional<Integer> size) {
return talentService.getTalentsPage(page, size).map(talentMapper::talentToShortTalentDTO);
@PreAuthorize("hasRole('TALENT')")
@GetMapping("/talents/{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));
}

@Operation(summary = "Edit information about talent",
description = "As a talent I want to have an opportunity to edit my personal profile by adding new information, changing already existing information")
description = "As a talent I want to have an opportunity to edit my personal profile by adding new information, changing already existing information")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "SUCCESS",
Expand All @@ -103,9 +104,9 @@ Page<ShortTalentDTO> getTalents(@RequestParam(value = "page") Optional<Integer>
@PreAuthorize("hasRole('TALENT')")
@PatchMapping("/talents/{talent-id}")
FullTalentDTO editTalent(@PathVariable("talent-id") long id,
@RequestBody @Valid FullTalentDTO fullTalent,
@RequestBody @Valid EditTalent editTalent,
Authentication authentication) {
return talentMapper.talentToFullTalentDTO(talentService.editTalent(id, fullTalent, authentication));
return talentMapper.talentToFullTalentDTO(talentService.editTalent(id, editTalent, authentication));
}

@Operation(summary = "Delete talent",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.provedcode.talent.controller;

import com.provedcode.talent.mapper.TalentProofMapper;
import com.provedcode.talent.model.dto.*;
import com.provedcode.talent.model.dto.FullProofDTO;
import com.provedcode.talent.model.dto.ProofDTO;
import com.provedcode.talent.model.dto.StatusDTO;
import com.provedcode.talent.model.request.AddProof;
import com.provedcode.talent.service.TalentProofService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
Expand All @@ -22,7 +25,7 @@

@RestController
@AllArgsConstructor
@RequestMapping("/api/talents")
@RequestMapping("/api/v2/talents")
public class TalentProofController {
TalentProofService talentProofService;
TalentProofMapper talentProofMapper;
Expand All @@ -45,8 +48,9 @@ public class TalentProofController {
@GetMapping("/proofs")
Page<ProofDTO> getAllProofs(@RequestParam(value = "page") Optional<Integer> page,
@RequestParam(value = "size") Optional<Integer> size,
@RequestParam(value = "order-by") Optional<String> orderBy) {
return talentProofService.getAllProofsPage(page, size, orderBy).map(talentProofMapper::toProofDTO);
@RequestParam(value = "order-by") Optional<String> orderBy,
@RequestParam(value = "sort-by", defaultValue = "created") String... sortBy) {
return talentProofService.getAllProofsPage(page, size, orderBy, sortBy).map(talentProofMapper::toProofDTO);
}

@Operation(summary = "Get proof")
Expand Down Expand Up @@ -134,9 +138,9 @@ FullProofDTO getTalentInformationWithProofs(Authentication authentication,
@PostMapping("/{talent-id}/proofs")
@PreAuthorize("hasRole('TALENT')")
ResponseEntity<?> addProof(@PathVariable(value = "talent-id") long talentId,
@RequestBody AddProofDTO addProofDTO,
@RequestBody @Valid AddProof addProof,
Authentication authentication) {
return talentProofService.addProof(addProofDTO, talentId, authentication);
return talentProofService.addProof(addProof, talentId, authentication);
}

@Operation(summary = "Edit information about proof",
Expand Down Expand Up @@ -193,7 +197,7 @@ ProofDTO editProof(Authentication authentication,
@ApiResponse(
responseCode = "403",
description = "FORBIDDEN (if not the owner wants to delete the proof or " +
"impossible change proofs status from DRAFT to HIDDEN, it should be PUBLISHED)",
"impossible change proofs status from DRAFT to HIDDEN, it should be PUBLISHED)",
content = @Content)
})
@DeleteMapping("/{talent-id}/proofs/{proof-id}")
Expand Down
29 changes: 9 additions & 20 deletions src/main/java/com/provedcode/talent/mapper/TalentMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,22 @@

import com.provedcode.talent.model.dto.FullTalentDTO;
import com.provedcode.talent.model.dto.ShortTalentDTO;
import com.provedcode.talent.model.entity.*;
import com.provedcode.talent.model.entity.Talent;
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 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();
}
@Mapping(target = "bio", expression = "java(talent.getTalentDescription() != null ? talent.getTalentDescription().getBio() : null)")
@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 = "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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public interface TalentProofMapper {
@Mapping(target = "id", ignore = true)
@Mapping(source = "created", target = "created", dateFormat = "dd-MM-yyyy HH:mm:ss")
TalentProof toTalentProof(ProofDTO proofDTO);
}
}
10 changes: 0 additions & 10 deletions src/main/java/com/provedcode/talent/model/dto/AddProofDTO.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ public record FullTalentDTO(
@JsonProperty("attached_files")
List<String> attachedFiles
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public record ProofDTO(
ProofStatus status,
String created
) {
}
}
2 changes: 0 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 @@ -7,9 +7,7 @@
import org.hibernate.validator.constraints.URL;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Builder
@Accessors(chain = true)
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/provedcode/talent/model/request/AddProof.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.provedcode.talent.model.request;

import jakarta.validation.constraints.NotEmpty;
import org.hibernate.validator.constraints.URL;

public record AddProof(
@URL
@NotEmpty
String link,
@NotEmpty
String text
) {
}
29 changes: 29 additions & 0 deletions src/main/java/com/provedcode/talent/model/request/EditTalent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.provedcode.talent.model.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.provedcode.annotations.UrlList;
import jakarta.validation.constraints.NotEmpty;
import lombok.Builder;

import java.util.List;

@Builder
public record EditTalent(
@JsonProperty("first_name")
String firstName,
@JsonProperty("last_name")
String lastName,
String image,
String specialization,
@JsonProperty("additional_info")
String additionalInfo,
String bio,
List<String> talents,
@UrlList
List<String> links,
List<String> contacts,
@UrlList
@JsonProperty("attached_files")
List<String> attachedFiles
) {
}
16 changes: 0 additions & 16 deletions src/main/java/com/provedcode/talent/model/response/FullTalent.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface TalentProofRepository extends JpaRepository<TalentProof, Long> {
Page<TalentProof> findByTalentIdAndStatus(Long talentId, ProofStatus status, Pageable pageable);
Page<TalentProof> findByTalentId(Long talentId, Pageable pageable);

List<TalentProof> deleteByTalentId(Long talentId);
Page<TalentProof> findByTalentId(Long talentId, Pageable pageable);

Page<TalentProof> findByStatus(ProofStatus status, Pageable pageable);
}
Loading