From 9eb9ea659b4909f4fd53ffdfebd2d0e010eec3a5 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Thu, 23 Mar 2023 20:33:29 +0100 Subject: [PATCH 1/8] Updated project structure --- .../{PageConfig.java => PageProperties.java} | 9 +- .../com/provedcode/config/PropsConfig.java | 11 + .../talent/mapper/TalentMapper.java | 27 +- .../talent/mapper/impl/TalentMapperImpl.java | 30 ++ .../talent/repo/TalentRepository.java | 5 +- .../repo/db/TalentEntityRepository.java | 9 +- .../service/impl/TalentServiceImpl.java | 12 +- .../service/mock/TalentServiceMock.java | 12 +- src/main/resources/application.properties | 4 +- src/main/resources/data.sql | 290 ++++++++++++++++-- src/main/resources/pagination.properties | 3 + 11 files changed, 341 insertions(+), 71 deletions(-) rename src/main/java/com/provedcode/config/{PageConfig.java => PageProperties.java} (63%) create mode 100644 src/main/java/com/provedcode/config/PropsConfig.java diff --git a/src/main/java/com/provedcode/config/PageConfig.java b/src/main/java/com/provedcode/config/PageProperties.java similarity index 63% rename from src/main/java/com/provedcode/config/PageConfig.java rename to src/main/java/com/provedcode/config/PageProperties.java index 1922716..48ab911 100644 --- a/src/main/java/com/provedcode/config/PageConfig.java +++ b/src/main/java/com/provedcode/config/PageProperties.java @@ -1,15 +1,20 @@ package com.provedcode.config; import jakarta.annotation.PostConstruct; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; -@EnableConfigurationProperties +@Validated @ConfigurationProperties(prefix = "page-config") @Slf4j -public record PageConfig( +public record PageProperties( int defaultPageNum, int defaultPageSize ) { diff --git a/src/main/java/com/provedcode/config/PropsConfig.java b/src/main/java/com/provedcode/config/PropsConfig.java new file mode 100644 index 0000000..5161d40 --- /dev/null +++ b/src/main/java/com/provedcode/config/PropsConfig.java @@ -0,0 +1,11 @@ +package com.provedcode.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@EnableConfigurationProperties(PageProperties.class) +@PropertySource("pagination.properties") +@Configuration +public class PropsConfig { +} diff --git a/src/main/java/com/provedcode/talent/mapper/TalentMapper.java b/src/main/java/com/provedcode/talent/mapper/TalentMapper.java index ca767a4..a3818a7 100644 --- a/src/main/java/com/provedcode/talent/mapper/TalentMapper.java +++ b/src/main/java/com/provedcode/talent/mapper/TalentMapper.java @@ -5,31 +5,8 @@ import com.provedcode.talent.model.entity.*; public interface TalentMapper { - default 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(); - } - default FullTalentDTO talentToFullTalentDTO(Talent talent) { - return FullTalentDTO.builder() - .id(talent.getId()) - .firstname(talent.getFirstName()) - .lastname(talent.getLastName()) - .bio(talent.getTalentDescription().getBio()) - .additionalInfo(talent.getTalentDescription().getAdditionalInfo()) - .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(); - } + ShortTalentDTO talentToShortTalentDTO(Talent talent); + FullTalentDTO talentToFullTalentDTO(Talent talent); } 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 6dc6a03..90516ac 100644 --- a/src/main/java/com/provedcode/talent/mapper/impl/TalentMapperImpl.java +++ b/src/main/java/com/provedcode/talent/mapper/impl/TalentMapperImpl.java @@ -1,8 +1,38 @@ 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().getBio()) + .additionalInfo(talent.getTalentDescription().getAdditionalInfo()) + .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(); + } } diff --git a/src/main/java/com/provedcode/talent/repo/TalentRepository.java b/src/main/java/com/provedcode/talent/repo/TalentRepository.java index b2fe0de..c1fc666 100644 --- a/src/main/java/com/provedcode/talent/repo/TalentRepository.java +++ b/src/main/java/com/provedcode/talent/repo/TalentRepository.java @@ -1,16 +1,15 @@ package com.provedcode.talent.repo; import com.provedcode.talent.model.entity.Talent; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; public interface TalentRepository { - List getTalentsPage(PageRequest page); + List findTalentsPage(PageRequest page); Optional findById(Long aLong); } \ 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 index aaa9688..6bd7a40 100644 --- a/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java +++ b/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java @@ -4,7 +4,6 @@ import com.provedcode.talent.repo.TalentRepository; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; @@ -12,14 +11,8 @@ public interface TalentEntityRepository extends JpaRepository, TalentRepository { - @Transactional(readOnly = true) - default List getTalents() { - return findAll(); - } - @Override - @Transactional(readOnly = true) - default List getTalentsPage(PageRequest page) { + default List findTalentsPage(PageRequest page) { return findAll(page).stream().toList(); } 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 5f23955..2e4d4cc 100644 --- a/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java +++ b/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java @@ -1,6 +1,6 @@ package com.provedcode.talent.service.impl; -import com.provedcode.config.PageConfig; +import com.provedcode.config.PageProperties; import com.provedcode.talent.service.TalentService; import com.provedcode.talent.mapper.TalentMapper; import com.provedcode.talent.model.dto.FullTalentDTO; @@ -25,18 +25,18 @@ public class TalentServiceImpl implements TalentService { TalentMapper talentMapper; TalentRepository talentRepository; - PageConfig pageConfig; + PageProperties pageProperties; @Override public List getTalentsPage(Optional page, Optional size) { - if (page.orElse(pageConfig.defaultPageNum()) < 0) { + 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(pageConfig.defaultPageSize()) <= 0) { + if (size.orElse(pageProperties.defaultPageSize()) <= 0) { throw new ResponseStatusException(BAD_REQUEST, "'size' query parameter must be greater than or equal to 1"); } - return talentRepository.getTalentsPage( - PageRequest.of(page.orElse(pageConfig.defaultPageNum()), size.orElse(pageConfig.defaultPageSize()))) + return talentRepository.findTalentsPage( + PageRequest.of(page.orElse(pageProperties.defaultPageNum()), size.orElse(pageProperties.defaultPageSize()))) .stream().map(i -> talentMapper.talentToShortTalentDTO(i)) .toList(); } diff --git a/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java b/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java index 84ba719..466baf0 100644 --- a/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java +++ b/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java @@ -1,6 +1,6 @@ package com.provedcode.talent.service.mock; -import com.provedcode.config.PageConfig; +import com.provedcode.config.PageProperties; import com.provedcode.talent.service.TalentService; import com.provedcode.talent.mapper.TalentMapper; import com.provedcode.talent.model.dto.FullTalentDTO; @@ -24,18 +24,18 @@ public class TalentServiceMock implements TalentService { TalentMapper talentMapper; TalentRepository talentRepository; - PageConfig pageConfig; + PageProperties pageProperties; @Override public List getTalentsPage(Optional page, Optional size) { - if (page.orElse(pageConfig.defaultPageNum()) < 0) { + 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(pageConfig.defaultPageSize()) <= 0) { + if (size.orElse(pageProperties.defaultPageSize()) <= 0) { throw new ResponseStatusException(BAD_REQUEST, "'size' query parameter must be greater than or equal to 1"); } - return talentRepository.getTalentsPage( - PageRequest.of(page.orElse(pageConfig.defaultPageNum()), size.orElse(pageConfig.defaultPageSize()))) + return talentRepository.findTalentsPage( + PageRequest.of(page.orElse(pageProperties.defaultPageNum()), size.orElse(pageProperties.defaultPageSize()))) .stream().map(i -> talentMapper.talentToShortTalentDTO(i)) .toList(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4d1a553..b28eb6d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -12,6 +12,4 @@ spring.h2.console.enabled=true spring.h2.console.path=/h2 ## spring.jpa.hibernate.ddl-auto=none -## BUG WAS HERE -page-config.default-page-num=0 -page-config.default-page-size=5 \ No newline at end of file + diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 5604d04..6b0f1ae 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,7 +1,7 @@ insert into talent (first_name, last_name, specialization, image) -values ('Serhii', 'Soloviov', 'Java-Developer', 'http://image'); +values ('Serhii', 'Soloviov', 'Java-Developer', 'https://i.pinimg.com/564x/e1/08/49/e10849923a8b2e85a7adf494ebd063e6.jpg'); insert into talent_description (talent_id, BIO, addition_info) -values((select id from talent order by id desc limit 1), 'Default bio', 'Default addition info'); +values((select id from talent order by id desc limit 1), 'Serhii Soloviov bio', 'Serhii Soloviov addition info'); insert into talent_link (talent_id, link) values ((select id from talent order by id desc limit 1), 'http://first_link'); insert into talent_link (talent_id, link) @@ -9,11 +9,13 @@ 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) -values ((select id from talent order by id desc limit 1), 'first_skill'); +values ((select id from talent order by id desc limit 1), 'Java Core'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'second_skill'); +values ((select id from talent order by id desc limit 1), 'Spring Core'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'third_skill'); +values ((select id from talent order by id desc limit 1), 'Spring boot'); +insert into talent_skill (talent_id, skill) +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'); insert into talent_contact (talent_id, contact) @@ -28,7 +30,7 @@ insert into talent_attached_file (talent_id, attached_file) values ((select id from talent order by id desc limit 1), 'third_file'); insert into talent (first_name, last_name, specialization, image) -values ('Mykhailo', 'Ordyntsev', 'Java-Developer', 'http://MykhailoOrdyntsevImage'); +values ('Mykhailo', 'Ordyntsev', 'Java-Developer', 'https://i.pinimg.com/564x/c2/41/31/c24131fe00218467721ba5bacdf0a256.jpg'); insert into talent_description (talent_id, BIO, addition_info) values((select id from talent order by id desc limit 1), 'Mykhailo Ordyntsev bio', 'Mykhailo Ordyntsev addition info'); insert into talent_link (talent_id, link) @@ -38,11 +40,13 @@ values ((select id from talent order by id desc limit 1), 'http://MykhailoOrdynt 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) -values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_first_skill'); +values ((select id from talent order by id desc limit 1), 'Java Core'); +insert into talent_skill (talent_id, skill) +values ((select id from talent order by id desc limit 1), 'Hibernate'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_second_skill'); +values ((select id from talent order by id desc limit 1), 'Spring Boot'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_third_skill'); +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'); insert into talent_contact (talent_id, contact) @@ -57,7 +61,7 @@ insert into talent_attached_file (talent_id, attached_file) values ((select id from talent order by id desc limit 1), 'MykhailoOrdyntsev_third_file'); insert into talent (first_name, last_name, specialization, image) -values ('Denis', 'Boyko', 'Java-Developer', 'http://DenisBoykoImage'); +values ('Denis', 'Boyko', 'Java-Developer', 'https://i.pinimg.com/564x/2a/0c/08/2a0c08c421e253ca895c3fdc8c9e08d9.jpg'); insert into talent_description (talent_id, BIO, addition_info) values((select id from talent order by id desc limit 1), 'Denis Boyko bio', 'Denis Boyko addition info'); insert into talent_link (talent_id, link) @@ -67,11 +71,11 @@ values ((select id from talent order by id desc limit 1), 'http://DenisBoyko_sec 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) -values ((select id from talent order by id desc limit 1), 'DenisBoyko_first_skill'); +values ((select id from talent order by id desc limit 1), 'Java Core'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'DenisBoyko_second_skill'); +values ((select id from talent order by id desc limit 1), 'Spring Security'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'DenisBoyko_third_skill'); +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'); insert into talent_contact (talent_id, contact) @@ -86,7 +90,7 @@ insert into talent_attached_file (talent_id, attached_file) values ((select id from talent order by id desc limit 1), 'DenisBoyko_third_file'); insert into talent (first_name, last_name, specialization, image) -values ('Ihor', 'Schurenko', 'Java-Developer', 'http://IhorShchurenkoImage'); +values ('Ihor', 'Schurenko', 'Java-Developer', 'https://i.pinimg.com/564x/e1/11/2f/e1112f0b7b63644dc3e313084936dedb.jpg'); insert into talent_description (talent_id, BIO, addition_info) values((select id from talent order by id desc limit 1), 'Ihor Shchurenko bio', 'Ihor Shchurenko addition info'); insert into talent_link (talent_id, link) @@ -96,11 +100,9 @@ values ((select id from talent order by id desc limit 1), 'http://IhorShchurenko 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) -values ((select id from talent order by id desc limit 1), 'IhorShchurenko_first_skill'); -insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'IhorShchurenko_second_skill'); +values ((select id from talent order by id desc limit 1), 'Java Core'); insert into talent_skill (talent_id, skill) -values ((select id from talent order by id desc limit 1), 'IhorShchurenko_third_skill'); +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'); insert into talent_contact (talent_id, contact) @@ -113,3 +115,255 @@ insert into talent_attached_file (talent_id, attached_file) values ((select id from talent order by id desc limit 1), 'IhorShchurenko_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'); +insert into talent (first_name, last_name, specialization, image) +values ('Dmytro', 'Uzun', 'Dev-Ops', 'https://i.pinimg.com/564x/1c/af/87/1caf8771ef3edf351f6f2bf6f1c0a276.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Dmytro Uzun bio', 'Dmytro Uzun addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://DmytroUzun_first_link'); +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) +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), 'Docker'); +insert into talent_skill (talent_id, skill) +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'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'DmytroUzun_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'DmytroUzun_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Viktor', 'Voloshko', 'Dev-Ops', 'https://i.pinimg.com/564x/a9/51/ab/a951ab682413b89617235e65564c1e5e.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Viktor Voloshko bio', 'Viktor Voloshko addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://ViktorVoloshko_first_link'); +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) +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), 'Docker'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_first_contact'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'ViktorVoloshko_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Olha', 'Moiseienko', 'QA', 'https://i.pinimg.com/564x/6d/9d/43/6d9d437baf4db114c047d927307beb84.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Olha Moiseienko bio', 'Olha Moiseienko addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://OlhaMoiseienko_first_link'); +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) +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), 'Jira'); +insert into talent_skill (talent_id, skill) +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'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'OlhaMoiseienko_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Maxim', 'Kiyashko', 'QA', 'https://i.pinimg.com/564x/80/2d/58/802d58b0302985f9486893d499d3634d.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Maxim Kiyashko', 'Ihor Shchurenko addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://MaximKiyashko_first_link'); +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) +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), 'QA'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'MaximKiyashko_first_contact'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'MaximKiyashko_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'MaximKiyashko_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Nikolaiev', 'Oleksii', 'QA', 'https://i.pinimg.com/564x/54/d1/0d/54d10dfce64afefabc9fbbce5de82c87.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Nikolaiev Oleksii bio', 'Nikolaiev Oleksii addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://NikolaievOleksii_first_link'); +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) +values ((select id from talent order by id desc limit 1), 'QA'); +insert into talent_skill (talent_id, skill) +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_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) +values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'NikolaievOleksii_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Artem', 'Lytvynenko', 'QA', 'https://i.pinimg.com/564x/87/63/55/87635509c5fa7ee496ec351fa7e67eaa.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Artem Lytvynenko bio', 'Artem Lytvynenko addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://ArtemLytvynenko_first_link'); +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) +values ((select id from talent order by id desc limit 1), 'QA'); +insert into talent_skill (talent_id, skill) +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'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'ArtemLytvynenko_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Daniil', 'Yevtukhov', 'Java-Script-Developer', 'https://i.pinimg.com/564x/fe/b1/37/feb137d88a3d1c8fb28796db6cbc576f.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Daniil Yevtukhov bio', 'Daniil Yevtukhov addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://DaniilYevtukhov_first_link'); +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) +values ((select id from talent order by id desc limit 1), 'JavaScript Core'); +insert into talent_skill (talent_id, skill) +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'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'DaniilYevtukhov_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Ruslan', 'Morozov', 'Java-Script-Developer', 'https://i.pinimg.com/736x/36/ae/0e/36ae0ea4aad656f7c3d3175bc33b8399.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Ruslan Morozov bio', 'Ruslan Morozov addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://RuslanMorozov_first_link'); +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) +values ((select id from talent order by id desc limit 1), 'JavaScript Core'); +insert into talent_skill (talent_id, skill) +values ((select id from talent order by id desc limit 1), 'React'); +insert into talent_skill (talent_id, skill) +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'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'RuslanMorozov_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'RuslanMorozov_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'); + +insert into talent (first_name, last_name, specialization, image) +values ('Ihor', 'Kopieichykov', 'Java-Script-Developer', 'https://i.pinimg.com/564x/0d/f0/83/0df083121bac75f64e3d93c7c5682d04.jpg'); +insert into talent_description (talent_id, BIO, addition_info) +values((select id from talent order by id desc limit 1), 'Ihor Kopieichykov bio', 'Ihor Kopieichykov addition info'); +insert into talent_link (talent_id, link) +values ((select id from talent order by id desc limit 1), 'http://IhorKopieichykov_first_link'); +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) +values ((select id from talent order by id desc limit 1), 'JavaScript Core'); +insert into talent_skill (talent_id, skill) +values ((select id from talent order by id desc limit 1), 'React'); +insert into talent_skill (talent_id, skill) +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'); +insert into talent_contact (talent_id, contact) +values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_second_contact'); +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'); +insert into talent_attached_file (talent_id, attached_file) +values ((select id from talent order by id desc limit 1), 'IhorKopieichykov_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'); \ No newline at end of file diff --git a/src/main/resources/pagination.properties b/src/main/resources/pagination.properties index e69de29..81dce8f 100644 --- a/src/main/resources/pagination.properties +++ b/src/main/resources/pagination.properties @@ -0,0 +1,3 @@ +## DEFAULT PAGE VALUES +page-config.default-page-num=0 +page-config.default-page-size=5 \ No newline at end of file From 1f835629b3d533ac814241bafd882b00c2632a67 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 13:06:46 +0100 Subject: [PATCH 2/8] Refactored code --- .../provedcode/talent/repo/TalentRepository.java | 5 ++--- .../talent/repo/db/TalentEntityRepository.java | 13 ++++++------- .../talent/service/impl/TalentServiceImpl.java | 5 ++--- .../talent/service/mock/TalentServiceMock.java | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/provedcode/talent/repo/TalentRepository.java b/src/main/java/com/provedcode/talent/repo/TalentRepository.java index c1fc666..c077eb8 100644 --- a/src/main/java/com/provedcode/talent/repo/TalentRepository.java +++ b/src/main/java/com/provedcode/talent/repo/TalentRepository.java @@ -2,14 +2,13 @@ import com.provedcode.talent.model.entity.Talent; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; -import java.util.List; import java.util.Optional; public interface TalentRepository { - List findTalentsPage(PageRequest page); + Page findAll(Pageable pageable); Optional findById(Long aLong); } \ 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 index 6bd7a40..e3fa4a9 100644 --- a/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java +++ b/src/main/java/com/provedcode/talent/repo/db/TalentEntityRepository.java @@ -2,20 +2,19 @@ import com.provedcode.talent.model.entity.Talent; import com.provedcode.talent.repo.TalentRepository; -import org.springframework.data.domain.PageRequest; +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.List; import java.util.Optional; public interface TalentEntityRepository extends JpaRepository, TalentRepository { + @Transactional(readOnly = true) + Page findAll(Pageable pageable); @Override - default List findTalentsPage(PageRequest page) { - return findAll(page).stream().toList(); - } - - @Override + @Transactional(readOnly = true) Optional findById(Long aLong); } \ 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 2e4d4cc..100db06 100644 --- a/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java +++ b/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java @@ -35,10 +35,9 @@ public List getTalentsPage(Optional page, Optional talentMapper.talentToShortTalentDTO(i)) - .toList(); + .stream().map(i -> talentMapper.talentToShortTalentDTO(i)).toList(); } @Override diff --git a/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java b/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java index 466baf0..118b950 100644 --- a/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java +++ b/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java @@ -34,9 +34,9 @@ public List getTalentsPage(Optional page, Optional talentMapper.talentToShortTalentDTO(i)) + .stream().map(talentMapper::talentToShortTalentDTO) .toList(); } From 9a9aa141846179070252b18775fbe12892dd24b4 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 14:52:39 +0100 Subject: [PATCH 3/8] Added profiles --- src/main/resources/application-dev.properties | 16 ++++++++++++++++ src/main/resources/application-prod.properties | 3 +++ src/main/resources/application.properties | 8 ++++---- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/application-dev.properties create mode 100644 src/main/resources/application-prod.properties diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..1f9c5ef --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,16 @@ +spring.datasource.username=sa +spring.datasource.url=jdbc:h2:mem:/sampleDB +## +server.port=28852 +management.endpoints.web.exposure.include=* +management.endpoint.shutdown.enabled=true +## +spring.jackson.property-naming-strategy=SNAKE_CASE +## +logging.level.cinema.controller=info +## +spring.datasource.driverClassName=org.h2.Driver +spring.h2.console.enabled=true +spring.h2.console.path=/h2 +## +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..71b89d7 --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,3 @@ +spring.datasource.username=${DB_LOGIN} +spring.datasource.password=${DB_PASSWORD} +spring.datasource.url=${DB_URL} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b28eb6d..90c4a98 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,6 @@ -server.port=28852 +spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev} +## +server.port=8080 management.endpoints.web.exposure.include=* management.endpoint.shutdown.enabled=true ## @@ -7,9 +9,7 @@ spring.jackson.property-naming-strategy=SNAKE_CASE logging.level.cinema.controller=info ## spring.datasource.driverClassName=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:/sampleDB spring.h2.console.enabled=true spring.h2.console.path=/h2 ## -spring.jpa.hibernate.ddl-auto=none - +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file From dc57c7bad925bdbd31821d634445e24b35d0f538 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 16:02:50 +0100 Subject: [PATCH 4/8] Removed bug --- pom.xml | 5 +++++ .../com/provedcode/ProvedCodeApplication.java | 2 ++ .../com/provedcode/config/SecurityConfig.java | 3 ++- .../com/provedcode/talent/TalentController.java | 3 ++- .../provedcode/talent/service/TalentService.java | 3 ++- .../talent/service/impl/TalentServiceImpl.java | 11 +++++++---- .../talent/service/mock/TalentServiceMock.java | 9 +++++---- src/main/resources/application-dev.properties | 15 +-------------- src/main/resources/application-prod.properties | 2 +- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 9d74fdc..d7aa5be 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,11 @@ spring-security-test test + + org.springdoc + springdoc-openapi-ui + 1.6.15 + diff --git a/src/main/java/com/provedcode/ProvedCodeApplication.java b/src/main/java/com/provedcode/ProvedCodeApplication.java index fc86627..edacc91 100644 --- a/src/main/java/com/provedcode/ProvedCodeApplication.java +++ b/src/main/java/com/provedcode/ProvedCodeApplication.java @@ -1,11 +1,13 @@ package com.provedcode; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @SpringBootApplication @ConfigurationPropertiesScan +@OpenAPIDefinition public class ProvedCodeApplication { public static void main(String[] args) { diff --git a/src/main/java/com/provedcode/config/SecurityConfig.java b/src/main/java/com/provedcode/config/SecurityConfig.java index 3d2d942..c1f8aa8 100644 --- a/src/main/java/com/provedcode/config/SecurityConfig.java +++ b/src/main/java/com/provedcode/config/SecurityConfig.java @@ -17,9 +17,10 @@ public class SecurityConfig { @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/**")).permitAll() - .anyRequest().denyAll() + .anyRequest().permitAll() ); http.csrf().disable().headers().frameOptions().disable(); http.sessionManagement().sessionCreationPolicy(STATELESS); diff --git a/src/main/java/com/provedcode/talent/TalentController.java b/src/main/java/com/provedcode/talent/TalentController.java index 0ca8e61..4ff1a81 100644 --- a/src/main/java/com/provedcode/talent/TalentController.java +++ b/src/main/java/com/provedcode/talent/TalentController.java @@ -4,6 +4,7 @@ import com.provedcode.talent.model.dto.FullTalentDTO; import com.provedcode.talent.model.dto.ShortTalentDTO; import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -22,7 +23,7 @@ FullTalentDTO getTalent(@PathVariable("id") long id) { @GetMapping("/api/talents") @ResponseStatus(HttpStatus.OK) - List getTalents(@RequestParam(value = "page") Optional page, + Page getTalents(@RequestParam(value = "page") Optional page, @RequestParam(value = "size") Optional size) { return talentService.getTalentsPage(page, size); } diff --git a/src/main/java/com/provedcode/talent/service/TalentService.java b/src/main/java/com/provedcode/talent/service/TalentService.java index 3b1147a..e583ff2 100644 --- a/src/main/java/com/provedcode/talent/service/TalentService.java +++ b/src/main/java/com/provedcode/talent/service/TalentService.java @@ -2,13 +2,14 @@ import com.provedcode.talent.model.dto.FullTalentDTO; import com.provedcode.talent.model.dto.ShortTalentDTO; +import org.springframework.data.domain.Page; import java.util.List; import java.util.Optional; public interface TalentService { - List getTalentsPage(Optional page, Optional size); + Page getTalentsPage(Optional page, Optional size); FullTalentDTO getTalentById(long id); } \ 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 100db06..af20a7f 100644 --- a/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java +++ b/src/main/java/com/provedcode/talent/service/impl/TalentServiceImpl.java @@ -9,12 +9,15 @@ import com.provedcode.talent.repo.TalentRepository; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.NOT_FOUND; @@ -28,16 +31,16 @@ public class TalentServiceImpl implements TalentService { PageProperties pageProperties; @Override - public List 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"); } if (size.orElse(pageProperties.defaultPageSize()) <= 0) { throw new ResponseStatusException(BAD_REQUEST, "'size' query parameter must be greater than or equal to 1"); } - return talentRepository.findAll( - PageRequest.of(page.orElse(pageProperties.defaultPageNum()), size.orElse(pageProperties.defaultPageSize()))) - .stream().map(i -> talentMapper.talentToShortTalentDTO(i)).toList(); + return talentRepository.findAll(PageRequest.of(page.orElse(pageProperties.defaultPageNum()), size.orElse(pageProperties.defaultPageSize()))) + .map(talentMapper::talentToShortTalentDTO); + } @Override diff --git a/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java b/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java index 118b950..b305f3a 100644 --- a/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java +++ b/src/main/java/com/provedcode/talent/service/mock/TalentServiceMock.java @@ -9,10 +9,11 @@ import com.provedcode.talent.repo.TalentRepository; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.web.server.ResponseStatusException; -import java.util.List; import java.util.Optional; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -27,17 +28,17 @@ public class TalentServiceMock implements TalentService { PageProperties pageProperties; @Override - public List 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"); } if (size.orElse(pageProperties.defaultPageSize()) <= 0) { throw new ResponseStatusException(BAD_REQUEST, "'size' query parameter must be greater than or equal to 1"); } - return talentRepository.findAll( + return new PageImpl<>(talentRepository.findAll( PageRequest.of(page.orElse(pageProperties.defaultPageNum()), size.orElse(pageProperties.defaultPageSize()))) .stream().map(talentMapper::talentToShortTalentDTO) - .toList(); + .toList()); } @Override diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 1f9c5ef..9e4b086 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,16 +1,3 @@ spring.datasource.username=sa spring.datasource.url=jdbc:h2:mem:/sampleDB -## -server.port=28852 -management.endpoints.web.exposure.include=* -management.endpoint.shutdown.enabled=true -## -spring.jackson.property-naming-strategy=SNAKE_CASE -## -logging.level.cinema.controller=info -## -spring.datasource.driverClassName=org.h2.Driver -spring.h2.console.enabled=true -spring.h2.console.path=/h2 -## -spring.jpa.hibernate.ddl-auto=update \ No newline at end of file +springdoc.swagger-ui.operationsSorter=method \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 71b89d7..bd904ab 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,3 +1,3 @@ spring.datasource.username=${DB_LOGIN} spring.datasource.password=${DB_PASSWORD} -spring.datasource.url=${DB_URL} +spring.datasource.url=${DB_URL} \ No newline at end of file From c75e438a2f880ed707717a8c3fea2be9aaefbaa5 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 17:12:16 +0100 Subject: [PATCH 5/8] Removed unused library --- pom.xml | 6 ------ src/main/java/com/provedcode/ProvedCodeApplication.java | 2 -- src/main/resources/application-dev.properties | 3 +-- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index d7aa5be..9cff8df 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,6 @@ org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-devtools @@ -69,11 +68,6 @@ spring-security-test test - - org.springdoc - springdoc-openapi-ui - 1.6.15 - diff --git a/src/main/java/com/provedcode/ProvedCodeApplication.java b/src/main/java/com/provedcode/ProvedCodeApplication.java index edacc91..fc86627 100644 --- a/src/main/java/com/provedcode/ProvedCodeApplication.java +++ b/src/main/java/com/provedcode/ProvedCodeApplication.java @@ -1,13 +1,11 @@ package com.provedcode; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @SpringBootApplication @ConfigurationPropertiesScan -@OpenAPIDefinition public class ProvedCodeApplication { public static void main(String[] args) { diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 9e4b086..e71d147 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,3 +1,2 @@ spring.datasource.username=sa -spring.datasource.url=jdbc:h2:mem:/sampleDB -springdoc.swagger-ui.operationsSorter=method \ No newline at end of file +spring.datasource.url=jdbc:h2:mem:/sampleDB \ No newline at end of file From 758598c6f0cce3819018eb50285153333c286660 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 17:14:41 +0100 Subject: [PATCH 6/8] bugfix --- src/main/java/com/provedcode/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/provedcode/config/SecurityConfig.java b/src/main/java/com/provedcode/config/SecurityConfig.java index c1f8aa8..819c2af 100644 --- a/src/main/java/com/provedcode/config/SecurityConfig.java +++ b/src/main/java/com/provedcode/config/SecurityConfig.java @@ -20,7 +20,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/actuator/health").permitAll() // for DevOps .requestMatchers(antMatcher("/h2/**")).permitAll() .requestMatchers(antMatcher("/api/**")).permitAll() - .anyRequest().permitAll() + .anyRequest().denyAll() ); http.csrf().disable().headers().frameOptions().disable(); http.sessionManagement().sessionCreationPolicy(STATELESS); From 569c85981eba76db28c38d699aca79800ba26900 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 19:43:16 +0100 Subject: [PATCH 7/8] bugfix --- .../java/com/provedcode/talent/TalentController.java | 1 - src/main/resources/application-dev.properties | 2 +- src/main/resources/application-prod.properties | 5 ++++- src/main/resources/application.properties | 3 --- src/main/resources/schema.sql | 11 ++++++++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/provedcode/talent/TalentController.java b/src/main/java/com/provedcode/talent/TalentController.java index 4ff1a81..9abf1b4 100644 --- a/src/main/java/com/provedcode/talent/TalentController.java +++ b/src/main/java/com/provedcode/talent/TalentController.java @@ -8,7 +8,6 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import java.util.List; import java.util.Optional; @RestController diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index e71d147..584e38f 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,2 +1,2 @@ spring.datasource.username=sa -spring.datasource.url=jdbc:h2:mem:/sampleDB \ No newline at end of file +spring.datasource.url=jdbc:h2:mem:../sampleDB diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index bd904ab..3eb12be 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,3 +1,6 @@ spring.datasource.username=${DB_LOGIN} spring.datasource.password=${DB_PASSWORD} -spring.datasource.url=${DB_URL} \ No newline at end of file +spring.datasource.url=${DB_URL} +spring.jpa.hibernate.ddl-auto=none +spring.sql.init.mode=always +spring.sql.init.platform=h2 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 90c4a98..55ff623 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,6 @@ spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev} ## server.port=8080 -management.endpoints.web.exposure.include=* -management.endpoint.shutdown.enabled=true ## spring.jackson.property-naming-strategy=SNAKE_CASE ## @@ -11,5 +9,4 @@ logging.level.cinema.controller=info spring.datasource.driverClassName=org.h2.Driver spring.h2.console.enabled=true spring.h2.console.path=/h2 -## spring.jpa.hibernate.ddl-auto=update \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 06f6c86..17047b4 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,4 +1,13 @@ ---talent tables-- +DROP TABLE talent CASCADE ; +DROP TABLE talent_description CASCADE ; +DROP TABLE talent_link CASCADE ; +DROP TABLE talent_contact CASCADE ; +DROP TABLE talent_attached_file CASCADE ; +DROP TABLE talent_skill CASCADE ; +DROP TABLE user_authority CASCADE ; +DROP TABLE user_info CASCADE ; +DROP TABLE authority CASCADE ; + CREATE TABLE talent ( id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, first_name VARCHAR(20) NOT NULL, From 50b6cdf84ee19bded9de785db12ffe0c2a11f690 Mon Sep 17 00:00:00 2001 From: Maslyna Date: Fri, 24 Mar 2023 20:24:40 +0100 Subject: [PATCH 8/8] bugfix 2 --- src/main/resources/schema.sql | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 17047b4..05c6a9e 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,12 +1,12 @@ -DROP TABLE talent CASCADE ; -DROP TABLE talent_description CASCADE ; -DROP TABLE talent_link CASCADE ; -DROP TABLE talent_contact CASCADE ; -DROP TABLE talent_attached_file CASCADE ; -DROP TABLE talent_skill CASCADE ; -DROP TABLE user_authority CASCADE ; -DROP TABLE user_info CASCADE ; -DROP TABLE authority CASCADE ; +DROP TABLE IF EXISTS talent CASCADE ; +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 user_info CASCADE ; +DROP TABLE IF EXISTS authority CASCADE ; CREATE TABLE talent ( id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,