Skip to content

Commit

Permalink
#1 - Fix: Update User Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
umtuk committed Jul 18, 2023
1 parent f248236 commit 1b27ba5
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Document(collation = "user_profile")
@Document(collection = "user_profile")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@Getter
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class UserProfile {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Document(collation = "user_profile_access")
@Document(collection = "user_profile_access")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@Getter
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class UserProfileAccess {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Repository
public interface UserProfileAccessRepository extends MongoRepository<UserProfileAccess, String> {

List<UserProfileAccess> findAllByBaseUserId(Iterable<String> baseUserIds);
List<UserProfileAccess> findAllByBaseUserIdIn(List<String> baseUserIds);
Optional<UserProfileAccess> findByBaseUserId(String baseUserId);
Boolean existsByBaseUserId(String baseUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Repository
public interface UserProfileRepository extends MongoRepository<UserProfile, String> {

List<UserProfile> findAllByBaseUserId(Iterable<String> baseUserIds);
List<UserProfile> findAllByBaseUserIdIn(List<String> baseUserIds);
Optional<UserProfile> findByBaseUserId(String baseUserId);
Boolean existsByBaseUserId(String baseUserId);
void deleteByBaseUserId(String baseUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

public interface UserProfileAccessService {

List<UserProfileAccess> list(Iterable<String> ids);
List<UserProfileAccess> listByBaseUserId(Iterable<String> baseUserIds);
List<UserProfileAccess> list(List<String> ids);
List<UserProfileAccess> listByBaseUserId(List<String> baseUserIds);
UserProfileAccess details(String id);
UserProfileAccess detailsByBaseUserId(String baseUserId);
UserProfileAccess save(UserProfileAccess userProfileAccess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

public interface UserProfileService {

List<UserProfile> list(Iterable<String> ids);
List<UserProfile> listByBaseUserId(Iterable<String> baseUserIds);
List<UserProfile> list(List<String> ids);
List<UserProfile> listByBaseUserId(List<String> baseUserIds);
UserProfile details(String id);
UserProfile detailsByBaseUserId(String baseUserId);
UserProfile save(UserProfile userProfile);
void delete(String id);
void deleteByBaseUserId(String id);
void deleteByBaseUserId(String baseUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class DefaultUserProfileAccessService implements UserProfileAccessService
private final ROEFactory roeFactory;

@Override
public List<UserProfileAccess> list(Iterable<String> id) {
public List<UserProfileAccess> list(List<String> id) {
return userProfileAccessRepository.findAllById(id);
}

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

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

@Override
public void deleteByBaseUserId(String baseUserId) {
if (!userProfileAccessRepository.existsByBaseUserId(baseUserId)) {
throw roeFactory.get(
InfoErrorCode.ROE_111,
UserProfileErrorDescription.USER_PROFILE_ACCESS_NOT_FOUND,
HttpStatus.NOT_FOUND
);
}
userProfileAccessRepository.deleteById(baseUserId);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package org.routemaster.api.auth.endpoint.user.info.profile.impl.controller;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.util.List;
import java.util.TimeZone;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.routemaster.api.auth.domain.user.jwt.impl.data.UserJwtPayload;
import org.routemaster.api.auth.domain.user.jwt.impl.utils.filter.UserJwtAuthenticationFilter;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.service.UserProfileEndpointService;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.request.UserProfileSaveRequest;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.request.UserProfileTotalSaveRequest;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserNicknameListResponse;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserNicknameResponse;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserProfileDeleteResponse;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserProfileDetailsResponse;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserProfileListResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -17,6 +24,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 @@ -30,50 +38,66 @@ public class UserProfileRestController {
private final UserProfileEndpointService userProfileEndpointService;

@GetMapping("/me")
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserProfileDetailsResponse> details(
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
return null;
UserProfileDetailsResponse response = userProfileEndpointService.details(payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@GetMapping("/{baseUserId}")
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserProfileDetailsResponse> details(@PathVariable Long baseUserId,
public ResponseEntity<UserProfileDetailsResponse> details(@PathVariable String baseUserId,
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
return null;
UserProfileDetailsResponse response = userProfileEndpointService.details(baseUserId, payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@GetMapping("/list")
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserProfileListResponse> list(@RequestParam List<Long> baseUserIds,
public ResponseEntity<UserProfileListResponse> list(@RequestParam List<String> baseUserIds,
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
return null;
UserProfileListResponse response = userProfileEndpointService.list(baseUserIds, payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@GetMapping("/nickname/list")
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserProfileDetailsResponse> nicknames(@RequestParam List<Long> baseUserIds,
public ResponseEntity<UserNicknameListResponse> nicknames(@RequestParam List<String> baseUserIds,
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
return null;
UserNicknameListResponse response = userProfileEndpointService.nicknames(baseUserIds, payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@GetMapping("/nickname/{baseUserId}")
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserProfileListResponse> nickname(@PathVariable Long baseUserId,
public ResponseEntity<UserNicknameResponse> nickname(@PathVariable String baseUserId,
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload) {
return null;
UserNicknameResponse response = userProfileEndpointService.nickname(baseUserId, payload);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@PostMapping
@SecurityRequirement(name = "Bearer Authentication")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<UserProfileDetailsResponse> save(
@RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload,
@RequestBody UserProfileSaveRequest request) {
return null;
@RequestBody UserProfileTotalSaveRequest request) {
UserProfileDetailsResponse response = userProfileEndpointService.save(payload, request);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@DeleteMapping()
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Void> delete() {
return null;
}
// @DeleteMapping
// @SecurityRequirement(name = "Bearer Authentication")
// @PreAuthorize("hasRole('ROLE_USER')")
// public ResponseEntity<Void> delete(
// @RequestAttribute(UserJwtAuthenticationFilter.USER_PAYLOAD) UserJwtPayload payload
// ) {
// UserProfileDeleteResponse response = userProfileEndpointService.delete(payload);
// return new ResponseEntity<>(null, HttpStatus.OK);
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.routemaster.api.auth.endpoint.user.info.profile.impl.service;

import java.util.List;
import org.routemaster.api.auth.domain.user.jwt.impl.data.UserJwtPayload;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.request.UserProfileTotalSaveRequest;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserNicknameListResponse;
Expand All @@ -12,8 +13,8 @@ public interface UserProfileEndpointService {

UserProfileDetailsResponse details(UserJwtPayload payload);
UserProfileDetailsResponse details(String baseUserId, UserJwtPayload payload);
UserProfileListResponse list(Iterable<String> baseUserIds, UserJwtPayload payload);
UserNicknameListResponse nicknames(Iterable<String> baseUserIds, UserJwtPayload payload);
UserProfileListResponse list(List<String> baseUserIds, UserJwtPayload payload);
UserNicknameListResponse nicknames(List<String> baseUserIds, UserJwtPayload payload);
UserNicknameResponse nickname(String baseUserId, UserJwtPayload payload);
UserProfileDetailsResponse save(UserJwtPayload payload, UserProfileTotalSaveRequest request);
UserProfileDeleteResponse delete(UserJwtPayload payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.routemaster.api.auth.domain.user.info.profile.impl.service.UserProfileAccessService;
import org.routemaster.api.auth.domain.user.info.profile.impl.service.UserProfileService;
import org.routemaster.api.auth.domain.user.jwt.impl.data.UserJwtPayload;
import org.routemaster.api.auth.domain.user.jwt.impl.data.UserJwtUnit;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.service.UserProfileEndpointService;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.util.mapper.UserProfileAccessMapper;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.util.mapper.UserProfileMapper;
Expand All @@ -22,6 +23,7 @@
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserProfileDetailsResponse;
import org.routemaster.api.auth.endpoint.user.info.profile.impl.vo.response.UserProfileListResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
Expand Down Expand Up @@ -55,15 +57,15 @@ public UserProfileDetailsResponse details(String baseUserId, UserJwtPayload payl
}

@Override
public UserProfileListResponse list(Iterable<String> baseUserIds, UserJwtPayload payload) {
public UserProfileListResponse list(List<String> baseUserIds, UserJwtPayload payload) {
List<UserProfile> userProfiles = securedUserProfileService.listByBaseUserId(baseUserIds);
return UserProfileListResponse.builder()
.profiles(userProfiles)
.build();
}

@Override
public UserNicknameListResponse nicknames(Iterable<String> baseUserIds, UserJwtPayload payload) {
public UserNicknameListResponse nicknames(List<String> baseUserIds, UserJwtPayload payload) {
List<UserProfile> userProfiles = securedUserProfileService.listByBaseUserId(baseUserIds);
List<UserNicknameResponse> nicknames = new ArrayList<>();
for (UserProfile userProfile : userProfiles) {
Expand All @@ -89,6 +91,7 @@ public UserNicknameResponse nickname(String baseUserId, UserJwtPayload payload)
}

@Override
@Transactional
public UserProfileDetailsResponse save(UserJwtPayload payload,
UserProfileTotalSaveRequest request) {
String baseUserId = payload.getBaseUserId();
Expand Down Expand Up @@ -123,10 +126,15 @@ public UserProfileDetailsResponse save(UserJwtPayload payload,
}

@Override
@Transactional
public UserProfileDeleteResponse delete(UserJwtPayload payload) {
userProfileService.deleteByBaseUserId(payload.getBaseUserId());
userProfileAccessService.deleteByBaseUserId(payload.getBaseUserId());
return UserProfileDeleteResponse.builder()
.build();
}

private void validate(UserJwtPayload payload) {

}
}

0 comments on commit 1b27ba5

Please sign in to comment.