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
@@ -0,0 +1,15 @@
package dev.flima.application.auth.dtos.request;

import dev.flima.domain.users.Password;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record LoginDTORequest(
@NotNull(message = "{username.not_null}")
@NotBlank(message = "{username.not_null}")
String username,

@Valid
Password password
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.flima.application.auth.dtos.response;

import dev.flima.domain.users.Role;

public record LoginDTOResponse(
String username,
Role role,
String token
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dev.flima.application.auth.usecases;

import dev.flima.application.auth.dtos.request.LoginDTORequest;
import dev.flima.application.auth.dtos.response.LoginDTOResponse;
import dev.flima.domain.exceptions.EntityNotFoundException;
import dev.flima.domain.security.PasswordHasher;
import dev.flima.domain.security.TokenGenerator;
import dev.flima.domain.users.Password;
import dev.flima.domain.users.User;
import dev.flima.domain.users.UserRepository;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.ResourceBundle;

@ApplicationScoped
public class LoginUseCase {

private final UserRepository userRepository;
private final PasswordHasher passwordHasher;
private final TokenGenerator tokenGenerator;
private final ResourceBundle messages = ResourceBundle.getBundle("messages");

public LoginUseCase(UserRepository userRepository, PasswordHasher passwordHasher, TokenGenerator tokenGenerator) {
this.userRepository = userRepository;
this.passwordHasher = passwordHasher;
this.tokenGenerator = tokenGenerator;
}

public LoginDTOResponse execute(LoginDTORequest loginDTO) {
User user = userRepository.getUsername(loginDTO.username())
.orElseThrow(() -> new EntityNotFoundException(messages.getString("auth.login_failed")));


if(!passwordHasher.verify(new Password(loginDTO.password().password()), new Password(user.getPassword().password()))) {
throw new EntityNotFoundException(messages.getString("auth.login_failed"));
}

String token = tokenGenerator.generateToken(user.getUsername(), user.getRole().name());

return new LoginDTOResponse(
user.getUsername(),
user.getRole(),
token
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.flima.application.contents.dtos;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record SectionContentDTO(
@NotNull(message = "{title.not_null_or_empty}")
@NotBlank(message = "{title.not_null_or_empty}")
String title,

@NotNull(message = "{subtitle.not_null_or_empty}")
@NotBlank(message = "{subtitle.not_null_or_empty}")
String subtitle
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.flima.application.contents.dtos.request;

import dev.flima.application.contents.dtos.SectionContentDTO;
import dev.flima.domain.contents.SectionType;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;

public record ContentDTORequest(
@NotNull(message = "{content.section_type.not_null}")
SectionType sectionType,

@Valid
SectionContentDTO sectionContent
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.flima.application.contents.dtos.response;

import dev.flima.application.contents.dtos.SectionContentDTO;
import dev.flima.domain.contents.SectionType;

import java.util.UUID;

public record ContentDTOResponse(
UUID id,
SectionType sectionType,
SectionContentDTO sectionContent
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.flima.application.contents.dtos.response;

import java.util.UUID;

public record CreateContentDTOResponse(
UUID id,
String sectionContent
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.flima.application.contents.usecases;

import dev.flima.application.contents.dtos.request.ContentDTORequest;
import dev.flima.application.contents.dtos.response.CreateContentDTOResponse;
import dev.flima.domain.contents.Content;
import dev.flima.domain.contents.ContentRepository;
import dev.flima.domain.contents.SectionContent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;

@ApplicationScoped
public class CreateContentUseCase {

private final ContentRepository contentRepository;

public CreateContentUseCase(ContentRepository contentRepository) {
this.contentRepository = contentRepository;
}

@Transactional
public CreateContentDTOResponse execute(ContentDTORequest contentDTO) {
SectionContent sectionContent = new SectionContent(contentDTO.sectionContent().title(), contentDTO.sectionContent().subtitle());

Content content = new Content(contentDTO.sectionType(), sectionContent);

contentRepository.save(content);

return new CreateContentDTOResponse(
content.getId(),
sectionContent.title()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.flima.application.contents.usecases;

import dev.flima.domain.contents.Content;
import dev.flima.domain.contents.ContentRepository;
import dev.flima.domain.exceptions.EntityNotFoundException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotFoundException;

import java.util.ResourceBundle;
import java.util.UUID;

@ApplicationScoped
public class DeleteContentUseCase {

private final ContentRepository contentRepository;
private final ResourceBundle messages = ResourceBundle.getBundle("messages");

public DeleteContentUseCase(ContentRepository contentRepository) {
this.contentRepository = contentRepository;
}

@Transactional
public void execute(UUID id) {
Content content = contentRepository.getById(id)
.orElseThrow(() -> new EntityNotFoundException(messages.getString("content.not_found")));

contentRepository.remove(content);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.flima.application.contents.usecases;

import dev.flima.application.contents.dtos.SectionContentDTO;
import dev.flima.application.contents.dtos.response.ContentDTOResponse;
import dev.flima.domain.contents.Content;
import dev.flima.domain.contents.ContentRepository;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.List;

@ApplicationScoped
public class GetAllContentUseCase {

private final ContentRepository contentRepository;

public GetAllContentUseCase(ContentRepository contentRepository) {
this.contentRepository = contentRepository;
}

public List<ContentDTOResponse> execute() {
List<Content> contents = contentRepository.getAll();

return contents.stream()
.map(content -> new ContentDTOResponse(
content.getId(),
content.getSectionType(),
new SectionContentDTO(
content.getSectionContent().title(),
content.getSectionContent().subtitle()
)
))
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.flima.application.contents.usecases;

import dev.flima.application.contents.dtos.SectionContentDTO;
import dev.flima.application.contents.dtos.response.ContentDTOResponse;
import dev.flima.domain.contents.Content;
import dev.flima.domain.contents.ContentRepository;
import dev.flima.domain.exceptions.EntityNotFoundException;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.ResourceBundle;
import java.util.UUID;

@ApplicationScoped
public class GetContentUseCase {

private final ContentRepository contentRepository;
private final ResourceBundle messages = ResourceBundle.getBundle("messages");

public GetContentUseCase(ContentRepository contentRepository) {
this.contentRepository = contentRepository;
}

public ContentDTOResponse execute(UUID id) {
Content content = contentRepository.getById(id)
.orElseThrow(() -> new EntityNotFoundException(messages.getString("content.not_found")));

return new ContentDTOResponse(
content.getId(),
content.getSectionType(),
new SectionContentDTO(
content.getSectionContent().title(),
content.getSectionContent().subtitle()
)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.flima.application.contents.usecases;

import dev.flima.application.contents.dtos.SectionContentDTO;
import dev.flima.application.contents.dtos.request.ContentDTORequest;
import dev.flima.application.contents.dtos.response.ContentDTOResponse;
import dev.flima.domain.contents.Content;
import dev.flima.domain.contents.ContentRepository;
import dev.flima.domain.contents.SectionContent;
import dev.flima.domain.exceptions.EntityNotFoundException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotFoundException;

import java.util.ResourceBundle;
import java.util.UUID;

@ApplicationScoped
public class UpdateContentUseCase {

private final ContentRepository contentRepository;
private final ResourceBundle messages = ResourceBundle.getBundle("messages");

public UpdateContentUseCase(ContentRepository contentRepository) {
this.contentRepository = contentRepository;
}

@Transactional
public ContentDTOResponse execute(UUID id, ContentDTORequest contentDTO) {
Content content = contentRepository.getById(id)
.orElseThrow(() -> new EntityNotFoundException(messages.getString("content.not_found")));

content.setSectionType(contentDTO.sectionType());
content.setSectionContent(new SectionContent(contentDTO.sectionContent().title(), contentDTO.sectionContent().subtitle()));

contentRepository.modify(content);

return new ContentDTOResponse(
content.getId(),
content.getSectionType(),
new SectionContentDTO(
content.getSectionContent().title(),
content.getSectionContent().subtitle()
)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.flima.application.educations.dtos.request;

import dev.flima.domain.educations.TypeEducation;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import java.util.List;

public record EducationDTORequest(
@NotNull(message = "{ducation.type_education.not_null}")
TypeEducation typeEducation,

@NotNull(message = "{ducation.type_education.not_null}")
@NotBlank(message = "{ducation.type_education.not_null}")
String degree,

@NotNull(message = "{title.not_null_or_empty}")
@NotBlank(message = "{title.not_null_or_empty}")
String title,

@NotNull(message = "{education.institution.not_null}")
@NotBlank(message = "{education.institution.not_null}")
String institution,

@NotNull(message = "{period.not_null_or_empty}")
@NotBlank(message = "{period.not_null_or_empty}")
String period,

String specialization,
List<String> skills,
List<String> architectures
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.flima.application.educations.dtos.response;

import java.util.UUID;

public record CreateEducationDTOResponse(
UUID id,
String title
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.flima.application.educations.dtos.response;

import dev.flima.domain.educations.TypeEducation;

import java.util.List;
import java.util.UUID;

public record EducationDTOResponse(
UUID id,
TypeEducation typeEducation,
String degree,
String title,
String institution,
String period,
String specialization,
List<String>skills,
List<String> architectures
) {}
Loading