feat: implement final Resume API
This commit is contained in:
@@ -12,13 +12,6 @@ public interface AboutJpaMapper {
|
||||
@Mapping(target = "id", ignore = true)
|
||||
AboutJpaEntity toEntity(About domain);
|
||||
|
||||
default About toDomain(AboutJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return About.builder()
|
||||
.id(e.getId() == null ? null : new AboutId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
About toDomain(AboutJpaEntity e);
|
||||
}
|
||||
@@ -12,13 +12,6 @@ public interface CertificationJpaMapper {
|
||||
@Mapping(target = "id", ignore = true)
|
||||
CertificationJpaEntity toEntity(Certification domain);
|
||||
|
||||
default Certification toDomain(CertificationJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return Certification.builder()
|
||||
.id(e.getId() == null ? null : new CertificationId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
Certification toDomain(CertificationJpaEntity e);
|
||||
}
|
||||
@@ -12,13 +12,6 @@ public interface ContactJpaMapper {
|
||||
@Mapping(target = "id", ignore = true)
|
||||
ContactJpaEntity toEntity(Contact domain);
|
||||
|
||||
default Contact toDomain(ContactJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return Contact.builder()
|
||||
.id(e.getId() == null ? null : new ContactId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
Contact toDomain(ContactJpaEntity e);
|
||||
}
|
||||
@@ -12,13 +12,6 @@ public interface EducationJpaMapper {
|
||||
@Mapping(target = "id", ignore = true)
|
||||
EducationJpaEntity toEntity(Education domain);
|
||||
|
||||
default Education toDomain(EducationJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return Education.builder()
|
||||
.id(e.getId() == null ? null : new EducationId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
Education toDomain(EducationJpaEntity e);
|
||||
}
|
||||
@@ -12,13 +12,6 @@ public interface ExperienceJpaMapper {
|
||||
@Mapping(target = "id", ignore = true)
|
||||
ExperienceJpaEntity toEntity(Experience domain);
|
||||
|
||||
default Experience toDomain(ExperienceJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return Experience.builder()
|
||||
.id(e.getId() == null ? null : new ExperienceId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
Experience toDomain(ExperienceJpaEntity e);
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.home.adapter;
|
||||
|
||||
import com.pablotj.portfolio.domain.home.Home;
|
||||
import com.pablotj.portfolio.domain.home.HomeId;
|
||||
import com.pablotj.portfolio.domain.home.port.HomeRepositoryPort;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.home.entity.HomeJpaEntity;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.home.mapper.HomeJpaMapper;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.home.repo.SpringDataHomeRepository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class HomeRepositoryAdapter implements HomeRepositoryPort {
|
||||
|
||||
private final SpringDataHomeRepository repo;
|
||||
private final HomeJpaMapper mapper;
|
||||
|
||||
public HomeRepositoryAdapter(SpringDataHomeRepository repo, HomeJpaMapper mapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Home save(Home p) {
|
||||
HomeJpaEntity entity = mapper.toEntity(p);
|
||||
HomeJpaEntity saved = repo.save(entity);
|
||||
return mapper.toDomain(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Home> findById(HomeId id) {
|
||||
return repo.findById(id.value()).map(mapper::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Home> findAll() {
|
||||
return repo.findAll().stream().map(mapper::toDomain).toList();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.home.mapper;
|
||||
|
||||
import com.pablotj.portfolio.domain.home.Home;
|
||||
import com.pablotj.portfolio.domain.home.HomeId;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.home.entity.HomeJpaEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface HomeJpaMapper {
|
||||
|
||||
@Mapping(target = "id", ignore = true)
|
||||
HomeJpaEntity toEntity(Home domain);
|
||||
|
||||
default Home toDomain(HomeJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return Home.builder()
|
||||
.id(e.getId() == null ? null : new HomeId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.home.repo;
|
||||
|
||||
import com.pablotj.portfolio.infrastructure.persistence.home.entity.HomeJpaEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface SpringDataHomeRepository extends JpaRepository<HomeJpaEntity, Long> {
|
||||
}
|
||||
@@ -12,13 +12,6 @@ public interface ProjectJpaMapper {
|
||||
@Mapping(target = "id", ignore = true)
|
||||
ProjectJpaEntity toEntity(Project domain);
|
||||
|
||||
default Project toDomain(ProjectJpaEntity e) {
|
||||
if (e == null) return null;
|
||||
return Project.builder()
|
||||
.id(e.getId() == null ? null : new ProjectId(e.getId()))
|
||||
.title(e.getTitle())
|
||||
.description(e.getDescription())
|
||||
.url(e.getUrl())
|
||||
.build();
|
||||
}
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
Project toDomain(ProjectJpaEntity e);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.resume.adapter;
|
||||
|
||||
import com.pablotj.portfolio.domain.resume.Resume;
|
||||
import com.pablotj.portfolio.domain.resume.ResumeId;
|
||||
import com.pablotj.portfolio.domain.resume.port.ResumeRepositoryPort;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.resume.entity.ResumeJpaEntity;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.resume.mapper.ResumeJpaMapper;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.resume.repo.SpringDataResumeRepository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ResumeRepositoryAdapter implements ResumeRepositoryPort {
|
||||
|
||||
private final SpringDataResumeRepository repo;
|
||||
private final ResumeJpaMapper mapper;
|
||||
|
||||
public ResumeRepositoryAdapter(SpringDataResumeRepository repo, ResumeJpaMapper mapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resume save(Resume p) {
|
||||
ResumeJpaEntity entity = mapper.toEntity(p);
|
||||
ResumeJpaEntity saved = repo.save(entity);
|
||||
return mapper.toDomain(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Resume> findById(ResumeId id) {
|
||||
return repo.findById(id.value()).map(mapper::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resume> findAll() {
|
||||
return repo.findAll().stream().map(mapper::toDomain).toList();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.home.entity;
|
||||
package com.pablotj.portfolio.infrastructure.persistence.resume.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -10,20 +10,28 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "homes")
|
||||
@Table(name = "resumes")
|
||||
@Getter
|
||||
@Setter
|
||||
public class HomeJpaEntity {
|
||||
public class ResumeJpaEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "first_name", nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(name = "last_name", nullable = false)
|
||||
private String surnames;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String title;
|
||||
|
||||
@Column(columnDefinition = "text")
|
||||
private String description;
|
||||
@Column(columnDefinition = "text", nullable = false)
|
||||
private String summary;
|
||||
|
||||
@Column
|
||||
private String icon;
|
||||
|
||||
private String url;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.resume.mapper;
|
||||
|
||||
import com.pablotj.portfolio.domain.resume.Resume;
|
||||
import com.pablotj.portfolio.domain.resume.ResumeId;
|
||||
import com.pablotj.portfolio.infrastructure.persistence.resume.entity.ResumeJpaEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ResumeJpaMapper {
|
||||
|
||||
@Mapping(target = "id", ignore = true)
|
||||
ResumeJpaEntity toEntity(Resume domain);
|
||||
|
||||
@Mapping(target = "id.value", source = "id")
|
||||
Resume toDomain(ResumeJpaEntity e);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.pablotj.portfolio.infrastructure.persistence.resume.repo;
|
||||
|
||||
import com.pablotj.portfolio.infrastructure.persistence.resume.entity.ResumeJpaEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface SpringDataResumeRepository extends JpaRepository<ResumeJpaEntity, Long> {
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.home.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record CreateHomeRequest(
|
||||
@NotBlank String title,
|
||||
String description,
|
||||
String url
|
||||
) {
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.home.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record HomeDto(Long id, @NotBlank String title, String description, String url) {
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.home.mapper;
|
||||
|
||||
import com.pablotj.portfolio.domain.home.Home;
|
||||
import com.pablotj.portfolio.infrastructure.rest.home.dto.HomeDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface HomeRestMapper {
|
||||
|
||||
@Mapping(target = "id", source = "id.value")
|
||||
HomeDto toDto(Home domain);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.home.controller;
|
||||
package com.pablotj.portfolio.infrastructure.rest.resume.controller;
|
||||
|
||||
import com.pablotj.portfolio.application.home.CreateHomeUseCase;
|
||||
import com.pablotj.portfolio.application.home.GetHomeUseCase;
|
||||
import com.pablotj.portfolio.infrastructure.rest.home.dto.CreateHomeRequest;
|
||||
import com.pablotj.portfolio.infrastructure.rest.home.dto.HomeDto;
|
||||
import com.pablotj.portfolio.infrastructure.rest.home.mapper.HomeRestMapper;
|
||||
import com.pablotj.portfolio.application.resume.CreateResumeUseCase;
|
||||
import com.pablotj.portfolio.application.resume.GetResumeUseCase;
|
||||
import com.pablotj.portfolio.infrastructure.rest.resume.dto.ResumeCreateRequest;
|
||||
import com.pablotj.portfolio.infrastructure.rest.resume.dto.ResumeDto;
|
||||
import com.pablotj.portfolio.infrastructure.rest.resume.mapper.ResumeRestMapper;
|
||||
import jakarta.validation.Valid;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
@@ -18,25 +18,25 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v1/homes")
|
||||
public class HomeController {
|
||||
public class ResumeController {
|
||||
|
||||
private final CreateHomeUseCase createUC;
|
||||
private final GetHomeUseCase getUC;
|
||||
private final HomeRestMapper mapper;
|
||||
private final CreateResumeUseCase createUC;
|
||||
private final GetResumeUseCase getUC;
|
||||
private final ResumeRestMapper mapper;
|
||||
|
||||
public HomeController(CreateHomeUseCase createUC, GetHomeUseCase getUC, HomeRestMapper mapper) {
|
||||
public ResumeController(CreateResumeUseCase createUC, GetResumeUseCase getUC, ResumeRestMapper mapper) {
|
||||
this.createUC = createUC;
|
||||
this.getUC = getUC;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<HomeDto> all() {
|
||||
public List<ResumeDto> all() {
|
||||
return getUC.all().stream().map(mapper::toDto).toList();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<HomeDto> byId(@PathVariable Long id) {
|
||||
public ResponseEntity<ResumeDto> byId(@PathVariable Long id) {
|
||||
return getUC.byId(id)
|
||||
.map(mapper::toDto)
|
||||
.map(ResponseEntity::ok)
|
||||
@@ -44,11 +44,13 @@ public class HomeController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<HomeDto> create(@Valid @RequestBody CreateHomeRequest request) {
|
||||
var cmd = new CreateHomeUseCase.Command(
|
||||
public ResponseEntity<ResumeDto> create(@Valid @RequestBody ResumeCreateRequest request) {
|
||||
var cmd = new CreateResumeUseCase.Command(
|
||||
request.name(),
|
||||
request.surnames(),
|
||||
request.title(),
|
||||
request.description(),
|
||||
request.url()
|
||||
request.summary(),
|
||||
request.icon()
|
||||
);
|
||||
var created = createUC.handle(cmd);
|
||||
var body = mapper.toDto(created);
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.resume.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record ResumeCreateRequest(
|
||||
@NotBlank String name,
|
||||
@NotBlank String surnames,
|
||||
@NotBlank String title,
|
||||
@NotBlank String summary,
|
||||
String icon
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.resume.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record ResumeDto(
|
||||
Long id,
|
||||
@NotBlank String name,
|
||||
@NotBlank String surnames,
|
||||
@NotBlank String title,
|
||||
@NotBlank String summary,
|
||||
String icon
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.pablotj.portfolio.infrastructure.rest.resume.mapper;
|
||||
|
||||
import com.pablotj.portfolio.domain.resume.Resume;
|
||||
import com.pablotj.portfolio.infrastructure.rest.resume.dto.ResumeDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ResumeRestMapper {
|
||||
|
||||
@Mapping(target = "id", source = "id.value")
|
||||
ResumeDto toDto(Resume domain);
|
||||
}
|
||||
Reference in New Issue
Block a user