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
20 changes: 20 additions & 0 deletions src/main/java/io/pakland/mdas/githubstats/FetchUsersFromTeam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.pakland.mdas.githubstats;

import io.pakland.mdas.githubstats.application.dto.UserDTO;
import io.pakland.mdas.githubstats.application.exceptions.HttpException;
import io.pakland.mdas.githubstats.domain.repository.UserExternalRepository;

import java.util.List;

public class FetchUsersFromTeam {
private UserExternalRepository userExternalRepository;


public FetchUsersFromTeam(UserExternalRepository userExternalRepository) {
this.userExternalRepository = userExternalRepository;
}

public List<UserDTO> execute(Integer organizationId, Integer teamId) throws HttpException {
return this.userExternalRepository.fetchUsersFromTeam(organizationId, teamId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

public class FetchAvailableOrganizations {

private OrganizationExternalRepository organizationRESTRepository;
private final OrganizationExternalRepository organizationRESTRepository;

public FetchAvailableOrganizations(OrganizationExternalRepository organizationRESTRepository) {
this.organizationRESTRepository = organizationRESTRepository;
}

public List<OrganizationDTO> fetch() throws HttpException {
public List<OrganizationDTO> execute() throws HttpException {
return organizationRESTRepository.fetchAvailableOrganizations();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.pakland.mdas.githubstats.application;

import io.pakland.mdas.githubstats.application.dto.RepositoryDTO;
import io.pakland.mdas.githubstats.application.exceptions.HttpException;
import io.pakland.mdas.githubstats.domain.repository.RepositoryExternalRepository;

import java.util.List;

public class FetchRepositoriesFromTeam {

private final RepositoryExternalRepository repositoryExternalRepository;

public FetchRepositoriesFromTeam(RepositoryExternalRepository repositoryExternalRepository) {
this.repositoryExternalRepository = repositoryExternalRepository;
}

public List<RepositoryDTO> execute(Integer organizationId, Integer teamId) throws HttpException {
return this.repositoryExternalRepository.fetchTeamRepositories(organizationId, teamId);
}
Comment thread
mikededo marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import java.util.List;

public class FetchTeamsFromOrganization {
private TeamExternalRepository teamRESTRepository;
private final TeamExternalRepository teamRESTRepository;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I forgot to rename this variables. Could you do it? Rename the teamRESTRepository for teamExternalRepository.


public FetchTeamsFromOrganization(TeamExternalRepository teamRESTRepository) {
this.teamRESTRepository = teamRESTRepository;
}

public List<TeamDTO> execute(String organizationName) throws HttpException {
return teamRESTRepository.fetchTeamsFromOrganization(organizationName);
public List<TeamDTO> execute(Integer organizationId) throws HttpException {
return teamRESTRepository.fetchTeamsFromOrganization(organizationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GetOrganizationFromId(OrganizationRepository organizationRepository) {

// For tests sake, we return boolean to know if the code works properly
@Transactional(readOnly = true)
public boolean execute(Long id) throws OrganizationNotFound {
public boolean execute(Integer id) throws OrganizationNotFound {
Optional<Organization> org = organizationRepository.findById(id);
if (org.isPresent()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GetOrganizationFromTeamName(TeamRepository teamRepo) {
}

public Organization execute(String teamName) throws TeamNotFound {
Optional<Team> maybeTeam = teamRepository.findTeamByName(teamName);
Optional<Team> maybeTeam = teamRepository.findTeamBySlug(teamName);
if (maybeTeam.isEmpty()) {
throw new TeamNotFound(teamName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.pakland.mdas.githubstats.application.exceptions;

public class OrganizationNotFound extends Exception {
public OrganizationNotFound(Long id) {
public OrganizationNotFound(Integer id) {
super("Organization with id: " + id + " not found");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public class RepositoryMapper {
public static Repository dtoToEntity(RepositoryDTO dto) {
return Repository.builder().id(dto.getId().longValue()).name(dto.getName()).build();
return Repository.builder().id(dto.getId()).name(dto.getName()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public final class TeamMapper {
public static Team dtoToEntity(TeamDTO teamDTO) {
return Team.builder().id(teamDTO.getId().longValue()).name(teamDTO.getName()).slug(teamDTO.getSlug()).build();
return Team.builder().id(teamDTO.getId()).slug(teamDTO.getSlug()).build();
Comment thread
mikededo marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public class UserMapper {
public static User dtoToEntity(UserDTO dto) {
return User.builder().id(dto.getId().longValue()).login(dto.getLogin()).build();
return User.builder().id(dto.getId()).login(dto.getLogin()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Comment {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@ManyToOne(fetch = FetchType.LAZY)
private UserReview userReview;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Commit {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@ManyToOne(fetch = FetchType.LAZY)
private User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HistoricQueries {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@ManyToOne(fetch = FetchType.LAZY)
private Team team;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Organization {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PullRequest {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@OneToMany(
mappedBy = "pullRequest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Repository {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

private String name;

Expand Down
13 changes: 5 additions & 8 deletions src/main/java/io/pakland/mdas/githubstats/domain/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ public class Team {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

private String slug;

@Column(name = "member_url")
private String memberUrl;

@Column
private String name;

@ManyToOne(fetch = FetchType.LAZY)
private Organization organization;

Expand All @@ -54,12 +51,12 @@ public class Team {
)
private List<HistoricQueries> queries = new ArrayList<>();

public void setName(String name) {
this.name = name;
public void setSlug(String slug) {
this.slug = slug;
Comment thread
mikededo marked this conversation as resolved.
}

public String getName() {
return this.name;
public String getSlug() {
return this.slug;
}

public void addUser(User user) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/pakland/mdas/githubstats/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class User {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

private String login;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class UserReview {
@Id
@Column(updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@ManyToOne(fetch = FetchType.LAZY)
private User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/

@Repository
public interface CommentRepository extends JpaRepository<Comment,Long> {
public interface CommentRepository extends JpaRepository<Comment,Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/

@Repository
public interface CommitRepository extends JpaRepository<Commit,Long> {
public interface CommitRepository extends JpaRepository<Commit,Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import io.pakland.mdas.githubstats.domain.HistoricQueries;
import org.springframework.data.jpa.repository.JpaRepository;

public interface HistoricQueriesRepository extends JpaRepository<HistoricQueries, Long> {
public interface HistoricQueriesRepository extends JpaRepository<HistoricQueries, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/

@Repository
public interface OrganizationRepository extends JpaRepository<Organization,Long> {
public interface OrganizationRepository extends JpaRepository<Organization,Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@


@Repository
public interface PullRequestsRepository extends JpaRepository<PullRequest,Long> {
public interface PullRequestsRepository extends JpaRepository<PullRequest,Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.List;

public interface RepositoryExternalRepository {
List<RepositoryDTO> fetchTeamRepositories(Integer orgId, Integer teamId) throws HttpException;
List<RepositoryDTO> fetchTeamRepositories(Integer organizationId, Integer teamId) throws HttpException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

/**
* Add jdoc about the rep
*/

@Repository
public interface RepositoryRepository extends JpaRepository<io.pakland.mdas.githubstats.domain.Repository,Long> {
public interface RepositoryRepository extends JpaRepository<io.pakland.mdas.githubstats.domain.Repository, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
import java.util.List;

public interface TeamExternalRepository {
List<TeamDTO> fetchTeamsFromOrganization(String organizationName) throws HttpException;
List<UserDTO> fetchMembersOfTeam(String orgName, String teamSlug) throws HttpException;
List<TeamDTO> fetchTeamsFromOrganization(Integer organizationId) throws HttpException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
*/

@Repository
public interface TeamRepository extends JpaRepository<Team,Long> {
Optional<Team> findTeamByName(String name);
public interface TeamRepository extends JpaRepository<Team,Integer> {
Optional<Team> findTeamBySlug(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.List;

public interface UserExternalRepository {
List<UserDTO> fetchUsersFromTeam(String organizationName, String teamSlug) throws HttpException;
List<UserDTO> fetchUsersFromTeam(Integer organizationId, Integer teamId) throws HttpException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*/

@Repository
public interface UserRepository extends JpaRepository<User,Long> {
public interface UserRepository extends JpaRepository<User,Integer> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/

@Repository
public interface UserReviewRepository extends JpaRepository<UserReview,Long> {
public interface UserReviewRepository extends JpaRepository<UserReview,Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public TeamGitHubRepository(WebClientConfiguration webClientConfiguration) {
}

@Override
public List<TeamDTO> fetchTeamsFromOrganization(String organizationName) throws HttpException {
public List<TeamDTO> fetchTeamsFromOrganization(Integer organizationId) throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/orgs/%s/teams", organizationName))
.uri(String.format("/orgs/%s/teams", organizationId))
.retrieve()
.bodyToFlux(TeamDTO.class)
.collectList()
Expand All @@ -33,19 +33,4 @@ public List<TeamDTO> fetchTeamsFromOrganization(String organizationName) throws
throw new HttpException(ex.getRawStatusCode(), ex.getMessage());
}
}

@Override
public List<UserDTO> fetchMembersOfTeam(String orgName, String teamSlug) throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/orgs/%s/teams/%s/members", orgName, teamSlug))
.retrieve()
.bodyToFlux(UserDTO.class)
.collectList()
.block();
} catch (WebClientResponseException ex) {
logger.error(ex.toString());
throw new HttpException(ex.getRawStatusCode(), ex.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public UserGitHubRepository(WebClientConfiguration webClientConfiguration) {
}

@Override
public List<UserDTO> fetchUsersFromTeam(String organizationName, String teamSlug) throws HttpException {
public List<UserDTO> fetchUsersFromTeam(Integer organizationId, Integer teamId) throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/orgs/%s/teams/%s/members", organizationName, teamSlug))
.uri(String.format("/orgs/%s/teams/%s/members", organizationId, teamId))
.retrieve()
.bodyToFlux(UserDTO.class)
.collectList()
Expand Down
Loading