Skip to content

Commit

Permalink
#1 - Fix: Update Privacies
Browse files Browse the repository at this point in the history
  • Loading branch information
umtuk committed Jul 18, 2023
1 parent 1b27ba5 commit 4300e8e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@Builder
@Getter
@ToString
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class Privacy {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@Builder
@Getter
@ToString
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class PrivacyGroup {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
@Builder
@Getter
@ToString
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class UserPrivacy {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface UserPrivacyRepository extends MongoRepository<UserPrivacy, Stri
Optional<UserPrivacy> findByBaseUserIdAndPrivacyGroupId(String baseUserId, String privacyGroupId);
List<UserPrivacy> findAllByBaseUserId(String baseUserId);
Boolean existsAllById(Iterable<String> ids);
void deleteAllByBaseUserId(String baseUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface UserPrivacyService {
List<UserPrivacy> saveAll(Iterable<UserPrivacy> userPrivacies);
void delete(String id);
void deleteAll(Iterable<String> ids);
void deleteAllByBaseUserId(String baseUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void deleteAll(Iterable<String> ids) {
}
userPrivacyRepository.deleteAllById(ids);
}

@Override
public void deleteAllByBaseUserId(String baseUserId) {
userPrivacyRepository.deleteAllByBaseUserId(baseUserId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class DefaultUserProfileService implements UserProfileService {
private final ROEFactory roeFactory;

@Override
public List<UserProfile> list(Iterable<String> ids) {
public List<UserProfile> list(List<String> ids) {
return userProfileRepository.findAllById(ids);
}

@Override
public List<UserProfile> listByBaseUserId(Iterable<String> baseUserIds) {
return userProfileRepository.findAllByBaseUserId(baseUserIds);
public List<UserProfile> listByBaseUserId(List<String> baseUserIds) {
return userProfileRepository.findAllByBaseUserIdIn(baseUserIds);
}

@Override
Expand Down Expand Up @@ -70,13 +70,6 @@ public void delete(String id) {

@Override
public void deleteByBaseUserId(String baseUserId) {
if (!userProfileRepository.existsById(baseUserId)) {
throw roeFactory.get(
InfoErrorCode.ROE_111,
UserProfileErrorDescription.USER_PROFILE_NOT_FOUND,
HttpStatus.NOT_FOUND
);
}
userProfileRepository.deleteByBaseUserId(baseUserId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,4 @@ public ResponseEntity<PrivacyGroupListResponse> list() {
}
return new ResponseEntity<>(response, HttpStatus.OK);
}

@PostMapping("/all")
@PreAuthorize("permitAll()")
public ResponseEntity<List<Privacy>> saveAll(@RequestBody List<Privacy> privacies) {
List<Privacy> response = privacyService.saveAll(privacies);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@PostMapping("/group")
@PreAuthorize("permitAll()")
public ResponseEntity<PrivacyGroup> saveGroup(@RequestBody PrivacyGroup privacyGroup) {
PrivacyGroup response = privacyGroupService.save(privacyGroup);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.routemaster.api.auth.endpoint.user.info.privacy.impl.controller;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -22,6 +23,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -35,6 +37,7 @@ public class UserPrivacyRestController {
private final UserPrivacyEndpointService userPrivacyEndpointService;

@GetMapping("/me")
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserPrivacyListResponse> details(
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
Expand All @@ -43,6 +46,7 @@ public ResponseEntity<UserPrivacyListResponse> details(
}

@PostMapping
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserPrivacySaveResponse> save(
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload,
Expand All @@ -51,28 +55,31 @@ public ResponseEntity<UserPrivacySaveResponse> save(
return new ResponseEntity<>(response, HttpStatus.OK);
}

@PostMapping("/list")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserPrivacySaveResponse> saveAll(
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload,
@RequestBody UserPrivacySaveAllRequest request) {
UserPrivacySaveResponse response = userPrivacyEndpointService.saveAll(payload, request);
return new ResponseEntity<>(response, HttpStatus.OK);
}
// @PostMapping("/list")
// @SecurityRequirement(name = "Bearer Authentication")
// @PreAuthorize("hasRole('ROLE_USER')")
// public ResponseEntity<UserPrivacySaveResponse> saveAll(
// @RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload,
// @RequestBody UserPrivacySaveAllRequest request) {
// UserPrivacySaveResponse response = userPrivacyEndpointService.saveAll(payload, request);
// return new ResponseEntity<>(response, HttpStatus.OK);
// }

@DeleteMapping("/{id}")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserPrivacyDeleteResponse> delete(@PathVariable String id,
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
UserPrivacyDeleteResponse response = userPrivacyEndpointService.delete(id, payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}
// @DeleteMapping("/{id}")
// @SecurityRequirement(name = "Bearer Authentication")
// @PreAuthorize("hasRole('ROLE_USER')")
// public ResponseEntity<UserPrivacyDeleteResponse> delete(@PathVariable String id,
// @RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
// UserPrivacyDeleteResponse response = userPrivacyEndpointService.delete(id, payload);
// return new ResponseEntity<>(response, HttpStatus.OK);
// }

@DeleteMapping("/list")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserPrivacyDeleteResponse> deleteAll(@RequestParam List<String> ids,
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
UserPrivacyDeleteResponse response = userPrivacyEndpointService.deleteAll(ids, payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}
// @DeleteMapping("/list")
// @SecurityRequirement(name = "Bearer Authentication")
// @PreAuthorize("hasRole('ROLE_USER')")
// public ResponseEntity<UserPrivacyDeleteResponse> deleteAll(@RequestParam List<String> ids,
// @RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
// UserPrivacyDeleteResponse response = userPrivacyEndpointService.deleteAll(ids, payload);
// return new ResponseEntity<>(response, HttpStatus.OK);
// }
}

0 comments on commit 4300e8e

Please sign in to comment.