Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all user #21

Merged
merged 2 commits into from
Nov 15, 2023
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
1 change: 1 addition & 0 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ COPY --from=builder /app/target/shield**.jar /app
EXPOSE 8080

# Run the application
RUN ["ls", "-a"]
CMD ["java", "-jar", "shield**.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.context.annotation.Configuration;

import com.google.gson.Gson;
import com.splitscale.shield.credential.read.ReadAllCredentialInteractor;
import com.splitscale.shield.credential.read.ReadCredentialInteractor;
import com.splitscale.shield.io.CredentialFileManager;
import com.splitscale.shield.io.PathProvider;
Expand All @@ -19,6 +20,11 @@ ReadCredentialInteractor getReadUserInteractor(CredentialRepository repository)
return new ReadCredentialInteractor(repository);
}

@Bean
ReadAllCredentialInteractor getReadAllUserInteractor(CredentialRepository repository) {
return new ReadAllCredentialInteractor(repository);
}

@Bean
CredentialRepository getUserRepository(CredentialFileManager jsonFileManager) {
return new CredentialRepositoryImpl(jsonFileManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.splitscale.shield.credential.read.ReadAllCredentialInteractor;
import com.splitscale.shield.endpoints.users.get.GetAllUserInfo;
import com.splitscale.shield.repositories.UserInfoRepository;
import com.splitscale.shield.userinfo.getall.GetAllUserInfoInteractor;
Expand All @@ -16,8 +17,9 @@ public GetAllUserInfo getAllUserInfo(GetAllUserInfoWorkflow workflow) {
}

@Bean
public GetAllUserInfoWorkflow getAllUserInfoWorkflow(GetAllUserInfoInteractor interactor) {
return new GetAllUserInfoWorkflow(interactor);
public GetAllUserInfoWorkflow getAllUserInfoWorkflow(GetAllUserInfoInteractor interactor,
ReadAllCredentialInteractor read) {
return new GetAllUserInfoWorkflow(interactor, read);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.splitscale.shield.credential.read;

import java.io.IOException;
import java.util.List;

import com.splitscale.shield.credential.Credential;
import com.splitscale.shield.repositories.CredentialRepository;

public class ReadAllCredentialInteractor {
private CredentialRepository repository;

public ReadAllCredentialInteractor(CredentialRepository repository) {
this.repository = repository;
}

public List<Credential> getAllCredentials() throws IOException {
return repository.getAll();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
package com.splitscale.shield.workflows.updateuserinfo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.splitscale.shield.credential.Credential;
import com.splitscale.shield.credential.read.ReadAllCredentialInteractor;
import com.splitscale.shield.userinfo.UserInfo;
import com.splitscale.shield.userinfo.getall.GetAllUserInfoInteractor;

public class GetAllUserInfoWorkflow {
GetAllUserInfoInteractor getAllUserInfoInteractor;
ReadAllCredentialInteractor readAllCredentialInteractor;

public GetAllUserInfoWorkflow() {
}

public GetAllUserInfoWorkflow(GetAllUserInfoInteractor getAllUserInfoInteractor) {
public GetAllUserInfoWorkflow(GetAllUserInfoInteractor getAllUserInfoInteractor,
ReadAllCredentialInteractor readAllCredentialInteractor) {
this.getAllUserInfoInteractor = getAllUserInfoInteractor;
this.readAllCredentialInteractor = readAllCredentialInteractor;
}

public List<UserInfo> getAll() throws IOException {
return getAllUserInfoInteractor.getAll();
List<UserInfo> userInfos = getAllUserInfoInteractor.getAll();
List<Credential> credentials = readAllCredentialInteractor.getAllCredentials();

for (UserInfo userInfo : userInfos) {
// Find the corresponding Credential for the current UserInfo
Credential credential = findCredentialById(credentials, userInfo.getId());

// Update UserInfo with values from Credential
if (credential != null) {
userInfo.setFirstName(credential.getUsername());
// Update other fields as needed
}
}

return userInfos;
}

private Credential findCredentialById(List<Credential> credentials, String userId) {
for (Credential credential : credentials) {
if (userId.matches(credential.getUserId())) {
return credential;
}
}
return null;
}
}
1 change: 0 additions & 1 deletion src/main/resources/.env

This file was deleted.