Skip to content
Open
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
3 changes: 3 additions & 0 deletions UserFront/src/main/java/com/userFront/domain/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class Appointment {

Expand All @@ -22,6 +24,7 @@ public class Appointment {

@ManyToOne
@JoinColumn(name = "user_id")
@JsonIgnore
private User user;

public Long getId() {
Expand Down
7 changes: 3 additions & 4 deletions UserFront/src/main/java/com/userFront/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class User implements UserDetails{
private List<Appointment> appointmentList;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonIgnore
private List<Recipient> recipientList;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
Expand Down Expand Up @@ -129,6 +130,8 @@ public void setRecipientList(List<Recipient> recipientList) {
this.recipientList = recipientList;
}

@JsonIgnore
@Override
public String getPassword() {
return password;
}
Expand Down Expand Up @@ -162,14 +165,10 @@ public String toString() {
return "User{" +
"userId=" + userId +
", username='" + username + '\'' +
", password='" + password + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
", phone='" + phone + '\'' +
", appointmentList=" + appointmentList +
", recipientList=" + recipientList +
", userRoles=" + userRoles +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.userFront.resource;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.userFront.domain.Appointment;
import com.userFront.resource.dto.AdminAppointmentView;
import com.userFront.service.AppointmentService;

@RestController
Expand All @@ -20,10 +21,10 @@ public class AppointmentResource {
private AppointmentService appointmentService;

@RequestMapping("/all")
public List<Appointment> findAppointmentList() {
List<Appointment> appointmentList = appointmentService.findAll();

return appointmentList;
public List<AdminAppointmentView> findAppointmentList() {
return appointmentService.findAll().stream()
.map(AdminAppointmentView::new)
.collect(Collectors.toList());
}

@RequestMapping("/{id}/confirm")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.userFront.resource;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
Expand All @@ -12,7 +13,7 @@

import com.userFront.domain.PrimaryTransaction;
import com.userFront.domain.SavingsTransaction;
import com.userFront.domain.User;
import com.userFront.resource.dto.AdminUserView;
import com.userFront.service.TransactionService;
import com.userFront.service.UserService;

Expand All @@ -28,8 +29,10 @@ public class UserResource {
private TransactionService transactionService;

@RequestMapping(value = "/user/all", method = RequestMethod.GET)
public List<User> userList() {
return userService.findUserList();
public List<AdminUserView> userList() {
return userService.findUserList().stream()
.map(AdminUserView::new)
.collect(Collectors.toList());
}

@RequestMapping(value = "/user/primary/transaction", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.userFront.resource.dto;

import java.util.Date;

import com.userFront.domain.Appointment;
import com.userFront.domain.User;

public class AdminAppointmentView {

private final Long id;
private final Date date;
private final String location;
private final String description;
private final boolean confirmed;
private final AppointmentUserView user;

public AdminAppointmentView(Appointment appointment) {
this.id = appointment.getId();
this.date = appointment.getDate();
this.location = appointment.getLocation();
this.description = appointment.getDescription();
this.confirmed = appointment.isConfirmed();
User owner = appointment.getUser();
this.user = owner == null ? null : new AppointmentUserView(owner.getUsername());
}

public Long getId() {
return id;
}

public Date getDate() {
return date;
}

public String getLocation() {
return location;
}

public String getDescription() {
return description;
}

public boolean isConfirmed() {
return confirmed;
}

public AppointmentUserView getUser() {
return user;
}

public static class AppointmentUserView {

private final String username;

public AppointmentUserView(String username) {
this.username = username;
}

public String getUsername() {
return username;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.userFront.resource.dto;

import java.math.BigDecimal;

import com.userFront.domain.PrimaryAccount;
import com.userFront.domain.SavingsAccount;
import com.userFront.domain.User;

public class AdminUserView {

private final Long userId;
private final String username;
private final String firstName;
private final String lastName;
private final String email;
private final String phone;
private final boolean enabled;
private final AccountBalanceView primaryAccount;
private final AccountBalanceView savingsAccount;

public AdminUserView(User user) {
this.userId = user.getUserId();
this.username = user.getUsername();
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
this.email = user.getEmail();
this.phone = user.getPhone();
this.enabled = user.isEnabled();
PrimaryAccount primary = user.getPrimaryAccount();
SavingsAccount savings = user.getSavingsAccount();
this.primaryAccount = primary == null ? null : new AccountBalanceView(primary.getAccountBalance());
this.savingsAccount = savings == null ? null : new AccountBalanceView(savings.getAccountBalance());
}

public Long getUserId() {
return userId;
}

public String getUsername() {
return username;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getEmail() {
return email;
}

public String getPhone() {
return phone;
}

public boolean isEnabled() {
return enabled;
}

public AccountBalanceView getPrimaryAccount() {
return primaryAccount;
}

public AccountBalanceView getSavingsAccount() {
return savingsAccount;
}

public static class AccountBalanceView {

private final BigDecimal accountBalance;

public AccountBalanceView(BigDecimal accountBalance) {
this.accountBalance = accountBalance;
}

public BigDecimal getAccountBalance() {
return accountBalance;
}
}
}
Loading