Compare commits

..

2 Commits

12 changed files with 59 additions and 24 deletions

View File

@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication(scanBasePackages = "com.pablotj")
@EnableJpaRepositories(basePackages = "com.pablotj.portfolio.infrastructure.persistence.repo")
@EntityScan(basePackages = "com.pablotj.portfolio.infrastructure.persistence.entity")
@EnableJpaRepositories(basePackages = { "com.pablotj.portfolio.infrastructure.persistence.project.repo" })
@EntityScan(basePackages = { "com.pablotj.portfolio.infrastructure.persistence.project.entity" })
public class PortfolioApplication {
public static void main(String[] args) {

View File

@ -1,6 +1,9 @@
spring:
application:
name: portfolio-api
web:
resources:
add-mappings: false
jpa:
hibernate:
@ -13,6 +16,8 @@ spring:
server:
port: 8080
servlet:
context-path: /api
---

View File

@ -1,11 +1,11 @@
package com.pablotj.portfolio.infrastructure.persistence.adapter;
package com.pablotj.portfolio.infrastructure.persistence.project.adapter;
import com.pablotj.portfolio.domain.project.Project;
import com.pablotj.portfolio.domain.project.ProjectId;
import com.pablotj.portfolio.domain.project.port.ProjectRepositoryPort;
import com.pablotj.portfolio.infrastructure.persistence.entity.ProjectJpaEntity;
import com.pablotj.portfolio.infrastructure.persistence.mapper.ProjectJpaMapper;
import com.pablotj.portfolio.infrastructure.persistence.repo.SpringDataProjectRepository;
import com.pablotj.portfolio.infrastructure.persistence.project.entity.ProjectJpaEntity;
import com.pablotj.portfolio.infrastructure.persistence.project.mapper.ProjectJpaMapper;
import com.pablotj.portfolio.infrastructure.persistence.project.repo.SpringDataProjectRepository;
import org.springframework.stereotype.Repository;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.pablotj.portfolio.infrastructure.persistence.entity;
package com.pablotj.portfolio.infrastructure.persistence.project.entity;
import jakarta.persistence.*;
import lombok.Getter;

View File

@ -1,8 +1,8 @@
package com.pablotj.portfolio.infrastructure.persistence.mapper;
package com.pablotj.portfolio.infrastructure.persistence.project.mapper;
import com.pablotj.portfolio.domain.project.Project;
import com.pablotj.portfolio.domain.project.ProjectId;
import com.pablotj.portfolio.infrastructure.persistence.entity.ProjectJpaEntity;
import com.pablotj.portfolio.infrastructure.persistence.project.entity.ProjectJpaEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

View File

@ -0,0 +1,6 @@
package com.pablotj.portfolio.infrastructure.persistence.project.repo;
import com.pablotj.portfolio.infrastructure.persistence.project.entity.ProjectJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface SpringDataProjectRepository extends JpaRepository<ProjectJpaEntity, Long> {}

View File

@ -1,6 +0,0 @@
package com.pablotj.portfolio.infrastructure.persistence.repo;
import com.pablotj.portfolio.infrastructure.persistence.entity.ProjectJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface SpringDataProjectRepository extends JpaRepository<ProjectJpaEntity, Long> {}

View File

@ -0,0 +1,30 @@
package com.pablotj.portfolio.infrastructure.rest.config;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.WebRequest;
import java.util.Map;
@Controller
public class ApiErrorController implements ErrorController {
private final ErrorAttributes errorAttributes;
public ApiErrorController(ErrorAttributes errorAttributes) {
this.errorAttributes = errorAttributes;
}
@RequestMapping("/error")
public ResponseEntity<Map<String, Object>> handleError(WebRequest webRequest) {
Map<String, Object> attributes = errorAttributes.getErrorAttributes(webRequest,
ErrorAttributeOptions.defaults());
HttpStatus status = HttpStatus.valueOf((int) attributes.getOrDefault("status", 500));
return new ResponseEntity<>(attributes, status);
}
}

View File

@ -1,10 +1,10 @@
package com.pablotj.portfolio.infrastructure.rest.controller;
package com.pablotj.portfolio.infrastructure.rest.project.controller;
import com.pablotj.portfolio.application.project.CreateProjectUseCase;
import com.pablotj.portfolio.application.project.GetProjectUseCase;
import com.pablotj.portfolio.infrastructure.rest.dto.CreateProjectRequest;
import com.pablotj.portfolio.infrastructure.rest.dto.ProjectDto;
import com.pablotj.portfolio.infrastructure.rest.mapper.ProjectRestMapper;
import com.pablotj.portfolio.infrastructure.rest.project.dto.CreateProjectRequest;
import com.pablotj.portfolio.infrastructure.rest.project.dto.ProjectDto;
import com.pablotj.portfolio.infrastructure.rest.project.mapper.ProjectRestMapper;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@ -13,7 +13,7 @@ import java.net.URI;
import java.util.List;
@RestController
@RequestMapping("/api/projects")
@RequestMapping("/v1/projects")
public class ProjectController {
private final CreateProjectUseCase createUC;

View File

@ -1,4 +1,4 @@
package com.pablotj.portfolio.infrastructure.rest.dto;
package com.pablotj.portfolio.infrastructure.rest.project.dto;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,4 +1,4 @@
package com.pablotj.portfolio.infrastructure.rest.dto;
package com.pablotj.portfolio.infrastructure.rest.project.dto;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,7 +1,7 @@
package com.pablotj.portfolio.infrastructure.rest.mapper;
package com.pablotj.portfolio.infrastructure.rest.project.mapper;
import com.pablotj.portfolio.domain.project.Project;
import com.pablotj.portfolio.infrastructure.rest.dto.ProjectDto;
import com.pablotj.portfolio.infrastructure.rest.project.dto.ProjectDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;