Skip to content

Commit

Permalink
added UUID in MongoUserService.java and ActivityService.java
Browse files Browse the repository at this point in the history
fixed an type error in DayView.tsx
  • Loading branch information
mrg committed Aug 18, 2023
1 parent 7c7a14e commit 4a08ca5
Show file tree
Hide file tree
Showing 5 changed files with 3,020 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.neuefische.backend.IdService;

import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class IdService {

public String generateId() {
return UUID.randomUUID().toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.neuefische.backend.Security;

import de.neuefische.backend.IdService.IdService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -16,6 +17,7 @@
public class MongoUserService implements UserDetailsService {

private final MongoUserRepository mongoUserRepository;
private final IdService idService;

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Expand All @@ -29,7 +31,7 @@ public MongoUser saveUser(MongoUser user){
throw new IllegalArgumentException("Username already taken");
}
PasswordEncoder encoder = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
mongoUserRepository.save(user.withPassword(encoder.encode(user.getPassword()))); // user -> setPassword(encoder(user.getPassword))
mongoUserRepository.save(user.withPassword(encoder.encode(user.getPassword())).withId(idService.generateId())); // user -> setPassword(encoder(user.getPassword))
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;

@Data
@With
@AllArgsConstructor
@NoArgsConstructor
public class Activity {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.neuefische.backend.activity;

import de.neuefische.backend.IdService.IdService;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.stereotype.Service;
Expand All @@ -12,9 +13,10 @@
public class ActivityService {

private ActivityRepository activityRepository;
private IdService idService;

public Activity addActivity(Activity activity) {
return activityRepository.save(activity);
return activityRepository.save(activity.withId(idService.generateId()));
}

public List<Activity> getAllActivities() {
Expand Down
Loading

0 comments on commit 4a08ca5

Please sign in to comment.