Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Set User roles to eager #743

Merged
merged 1 commit into from
Sep 6, 2021
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
2 changes: 1 addition & 1 deletion backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
mysql:
image: mysql:latest
platform: linux/amd64
# platform: linux/amd64 # uncomment this if using Apple silicon
hostname: mysql
restart: always
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public void deleteCurrentUser(@RequestBody UserToDeleteDto user) {

@PostMapping("/update-password")
@ResponseStatus(HttpStatus.OK)
public User updatePassword(@RequestParam("currentPassword") String currentPassword,
public boolean updatePassword(@RequestParam("currentPassword") String currentPassword,
@RequestParam("newPassword") String newPassword) {
User user = userService.getCurrentUser();

if (passwordEncoder.matches(currentPassword, user.getPassword())) {
userService.changeUserPassword(user, newPassword);
return user;
return true;
} else {
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ License, or (at your option) any later version.
package com.karankumar.bookproject.backend.model.account;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ License, or (at your option) any later version.

package com.karankumar.bookproject.backend.model.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -33,6 +34,7 @@ License, or (at your option) any later version.
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand All @@ -51,6 +53,7 @@ License, or (at your option) any later version.
@Entity
@Builder
@Data
@JsonIgnoreProperties(value = {"id"})
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@EqualsAndHashCode
Expand Down Expand Up @@ -79,11 +82,18 @@ public class User {
@NotNull
private boolean active;

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
// Fetch type can be eager as there are not many roles
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
@JoinTable(
name = "user_role",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id")
joinColumns = @JoinColumn(
name = "user_id", referencedColumnName = "id",
foreignKey = @ForeignKey(name = "user_role_user_id_fk")
),
inverseJoinColumns = @JoinColumn(
name = "role_id", referencedColumnName = "id",
foreignKey = @ForeignKey(name = "user_role_role_id_fk")
)
)
private Set<Role> roles;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ License, or (at your option) any later version.
import java.util.Optional;
import java.util.Set;


@Service
public class UserService {
private final UserRepository userRepository;
Expand Down