Skip to content

Commit

Permalink
Writing to mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
Josiah Kotey committed Aug 6, 2024
1 parent ef14180 commit 65ab276
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
public class Users {

@Id
private Long id;

private Long user_id;

private String name;
private String email;
private String accountType;
private Boolean pendingDelete;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.joe.trading.shared.dtos.UserEventDto;
import com.joe.trading.shared.events.Event;
import com.joe.trading.shared.nats.NatsService;
import com.trading.joe.reportservice.entities.Users;
import com.trading.joe.reportservice.exceptions.ResourceNotFoundException;
import com.trading.joe.reportservice.repository.PortfolioRepository;
import com.trading.joe.reportservice.repository.UserRepository;
Expand All @@ -22,20 +23,35 @@ public class ReportingServiceImpl implements ReportingService{
public void userCreatedEvent() throws ResourceNotFoundException {
System.out.println("Testing nats subscribe");
try {
natsService.subscribe(Event.USER_CREATED, UserEventDto.class, System.out::println);
natsService.subscribe(Event.USER_CREATED, UserEventDto.class, this::saveEvent);
} catch (Exception e) {
throw new ResourceNotFoundException("Could not fetch from Nats Service");
}
}
public void saveEvent(UserEventDto userEventDto){
userRepository.save(user(userEventDto));
}

@Override
public void createUser() throws ResourceNotFoundException {
try{
natsService.subscribe(Event.USER_CREATED, UserEventDto.class, System.out::println);
//userRepository.save()
natsService.subscribe(Event.USER_CREATED, UserEventDto.class,this::saveEvent);
} catch (Exception e) {
throw new ResourceNotFoundException("Could not fetch from Nats Service");
}
}

public Users user(UserEventDto userEventDto){
Users user = new Users();
user.setUser_id(userEventDto.getId());
user.setName(userEventDto.getName());
user.setEmail(userEventDto.getEmail());
user.setAccountType(user.getAccountType());
user.setPendingDelete(userEventDto.getPendingDelete());
user.setCreatedAt(userEventDto.getCreatedAt());
user.setUpdatedAt(userEventDto.getUpdatedAt());

return user;
}

}

0 comments on commit 65ab276

Please sign in to comment.