Skip to content

Commit

Permalink
Merge pull request #21 from zireline/get-all-user
Browse files Browse the repository at this point in the history
Get all user
  • Loading branch information
kasutu authored Nov 15, 2023
2 parents daf97e9 + c3a065f commit 83c7f55
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
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.

0 comments on commit 83c7f55

Please sign in to comment.