-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/rest/Services/ProjectService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example.rest.Services; | ||
|
||
import com.example.rest.entities.Project; | ||
|
||
public interface ProjectService { | ||
|
||
// para crear projectos | ||
Project createProject(Project project); | ||
|
||
// para editar projectos | ||
Project editProject(Long id, Project project); | ||
|
||
// para eliminar projectos | ||
void deleteProject(Long id); | ||
|
||
// para obtener projecto por id | ||
Project getProjectById(Long id); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/example/rest/Services/ProjectServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.rest.Services; | ||
|
||
import com.example.rest.entities.Project; | ||
import com.example.rest.entities.projectStatus; | ||
import com.example.rest.repositories.ProjectRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class ProjectServiceImpl implements ProjectService { | ||
|
||
private final ProjectRepository projectRepository; | ||
|
||
@Autowired | ||
public ProjectServiceImpl(ProjectRepository projectRepository) { | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Override | ||
public Project createProject(Project project) { | ||
|
||
// Chequear que el projecto no sea nulo y tenga un nombre | ||
if (project == null || project.getName() == null || project.getName().isEmpty()) { | ||
throw new IllegalArgumentException("Invalid project details"); | ||
} | ||
|
||
// Aregarle los atributos por defecto | ||
project.setStatus(projectStatus.ACTIVE); | ||
project.setCreateDate(LocalDateTime.now()); | ||
|
||
// Guardar (?) Preguntar | ||
return projectRepository.save(project); | ||
} | ||
|
||
|
||
@Override | ||
public Project editProject(Long id, Project project) { | ||
|
||
Optional <Project> optionalProject = projectRepository.findById(id); | ||
|
||
if (optionalProject.isPresent()) { | ||
|
||
projectRepository.save(project); | ||
|
||
return project; | ||
} else { | ||
throw new RuntimeException("El proyecto no existe"); // Cambiar por exp personalizada | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteProject(Long id) { | ||
Optional <Project> projectOptional = projectRepository.findById(id); | ||
if(projectOptional.isPresent()){ | ||
projectRepository.deleteById(id); | ||
} else { | ||
throw new RuntimeException("Proyecto con el id: " + id + " no existe."); | ||
} | ||
} | ||
|
||
@Override | ||
public Project getProjectById(Long id) { | ||
Optional <Project> projectOptional = projectRepository.findById(id); | ||
if(projectOptional.isPresent()) { | ||
return projectOptional.get(); | ||
} else { | ||
throw new RuntimeException("Proyecto con el id: " + id + " no existe."); | ||
} | ||
} | ||
|
||
} | ||
|
This file was deleted.
Oops, something went wrong.
28 changes: 17 additions & 11 deletions
28
src/main/java/com/example/rest/controllers/ProjectController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.rest.entities; | ||
|
||
public enum projectStatus { | ||
ACTIVE, | ||
INACTIVE, | ||
PAUSED | ||
} |
10 changes: 9 additions & 1 deletion
10
src/main/java/com/example/rest/repositories/ProjectRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
package com.example.rest.repositories; | ||
|
||
public interface ProjectRepository { | ||
import com.example.rest.entities.Project; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProjectRepository extends JpaRepository<Project, Long> { | ||
|
||
Project findByName(String name); | ||
Project findProjectById(Long id); | ||
} |