-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from YAPP-Github/feat/PC-380-admin-profile-read
[PC-380] 어드민 유저 프로필 조회 기능
- Loading branch information
Showing
94 changed files
with
2,103 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.yapp; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class AdminApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AdminApplication.class, args); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.yapp.auth.application; | ||
|
||
public enum AdminRole { | ||
ADMIN, | ||
ROLE_ADMIN; | ||
} |
40 changes: 40 additions & 0 deletions
40
admin/src/main/java/org/yapp/auth/application/AuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.yapp.auth.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.yapp.auth.AuthToken; | ||
import org.yapp.auth.AuthTokenGenerator; | ||
import org.yapp.auth.application.dto.LoginDto; | ||
import org.yapp.domain.user.User; | ||
import org.yapp.error.code.auth.AuthErrorCode; | ||
import org.yapp.error.exception.ApplicationException; | ||
import org.yapp.user.application.UserService; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthService { | ||
|
||
private final UserService userService; | ||
|
||
private final AuthTokenGenerator authTokenGenerator; | ||
|
||
@Value("${admin.password}") | ||
private String PWD; | ||
|
||
public AuthToken login(LoginDto loginDto) { | ||
String oauthId = loginDto.oauthId(); | ||
String password = loginDto.password(); | ||
|
||
User loginUser = userService.getUserByOauthId(oauthId); | ||
|
||
if (password.equals(PWD) && loginUser.getRole().equals(AdminRole.ADMIN.toString())) { | ||
return authTokenGenerator.generate(loginUser.getId(), null, | ||
AdminRole.ROLE_ADMIN.toString()); | ||
} else { | ||
throw new ApplicationException(AuthErrorCode.ACCESS_DENIED); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
admin/src/main/java/org/yapp/auth/application/dto/LoginDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.yapp.auth.application.dto; | ||
|
||
public record LoginDto(String oauthId, String password) { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
admin/src/main/java/org/yapp/auth/presentation/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.yapp.auth.presentation; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.yapp.auth.AuthToken; | ||
import org.yapp.auth.application.AuthService; | ||
import org.yapp.auth.presentation.request.LoginRequest; | ||
import org.yapp.util.CommonResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin/v1/auth/") | ||
public class AuthController { | ||
|
||
private final AuthService authService; | ||
|
||
@PostMapping("/login") | ||
public ResponseEntity<CommonResponse<AuthToken>> login( | ||
@RequestBody @Valid LoginRequest loginRequest) { | ||
AuthToken authToken = authService.login(loginRequest.toDto()); | ||
return ResponseEntity.ok(CommonResponse.createSuccess(authToken)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
admin/src/main/java/org/yapp/auth/presentation/request/LoginRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.yapp.auth.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import org.yapp.auth.application.dto.LoginDto; | ||
|
||
public record LoginRequest(@NotNull String loginId, @NotNull String password) { | ||
|
||
public LoginDto toDto() { | ||
return new LoginDto(loginId, password); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
admin/src/main/java/org/yapp/block/application/UserBlockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.yapp.block.application; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Service; | ||
import org.yapp.block.dao.UserBlockRepository; | ||
import org.yapp.block.presentation.response.UserBlockResponse; | ||
import org.yapp.domain.block.UserBlock; | ||
import org.yapp.domain.user.User; | ||
import org.yapp.util.PageResponse; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserBlockService { | ||
|
||
private final UserBlockRepository userBlockRepository; | ||
|
||
public PageResponse<UserBlockResponse> getUserBlockPageResponse(int page, int size) { | ||
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")); | ||
|
||
Page<UserBlock> userBlockPage = userBlockRepository.findAll(pageable); | ||
|
||
List<UserBlockResponse> content = userBlockPage.getContent().stream() | ||
.map(userBlock -> { | ||
User blockingUser = userBlock.getBlockingUser(); | ||
User blockedUser = userBlock.getBlockedUser(); | ||
|
||
return new UserBlockResponse( | ||
blockedUser.getId(), | ||
blockedUser.getProfile().getProfileBasic().getNickname(), | ||
blockedUser.getName(), | ||
blockedUser.getProfile().getProfileBasic().getBirthdate(), | ||
blockingUser.getId(), | ||
blockingUser.getProfile().getProfileBasic().getNickname(), | ||
blockingUser.getName(), | ||
userBlock.getCreatedAt().toLocalDate()); | ||
}).toList(); | ||
|
||
return new PageResponse<>( | ||
content, | ||
userBlockPage.getNumber(), | ||
userBlockPage.getSize(), | ||
userBlockPage.getTotalPages(), | ||
userBlockPage.getTotalElements(), | ||
userBlockPage.isFirst(), | ||
userBlockPage.isLast() | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
admin/src/main/java/org/yapp/block/dao/UserBlockRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.yapp.block.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import org.yapp.domain.block.UserBlock; | ||
|
||
@Repository | ||
public interface UserBlockRepository extends JpaRepository<UserBlock, Long> { | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
admin/src/main/java/org/yapp/block/presentation/UserBlockController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.yapp.block.presentation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.yapp.block.application.UserBlockService; | ||
import org.yapp.block.presentation.response.UserBlockResponse; | ||
import org.yapp.util.CommonResponse; | ||
import org.yapp.util.PageResponse; | ||
|
||
@RestController() | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin/v1/blocks") | ||
public class UserBlockController { | ||
|
||
private final UserBlockService userBlockService; | ||
|
||
@GetMapping("") | ||
public ResponseEntity<CommonResponse<PageResponse<UserBlockResponse>>> getUsers( | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "10") int size) { | ||
|
||
PageResponse<UserBlockResponse> userBlockPageResponse = userBlockService.getUserBlockPageResponse( | ||
page, size); | ||
|
||
return ResponseEntity.ok(CommonResponse.createSuccess(userBlockPageResponse)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
admin/src/main/java/org/yapp/block/presentation/response/UserBlockResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.yapp.block.presentation.response; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record UserBlockResponse( | ||
Long blockedUserId, | ||
String BlockedUserNickname, String BlockedUserName, | ||
LocalDate blockedUserBirthdate, Long blockingUserId, | ||
String blockingUserNickname, | ||
String blockingUserName, LocalDate BlockedDate) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.yapp.config; | ||
|
||
import static org.springframework.security.web.util.matcher.AntPathRequestMatcher.antMatcher; | ||
|
||
import java.util.Collections; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
import org.springframework.security.web.util.matcher.RequestMatchers; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.yapp.jwt.JwtFilter; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
public class SecurityConfig { | ||
|
||
private final JwtFilter jwtFilter; | ||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
return http.csrf(AbstractHttpConfigurer::disable) | ||
.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource())) | ||
.httpBasic(AbstractHttpConfigurer::disable) | ||
.sessionManagement(configurer -> configurer.sessionCreationPolicy( | ||
SessionCreationPolicy.STATELESS)) | ||
.authorizeHttpRequests(registry -> registry | ||
.requestMatchers(getMatcherForAnyone()) | ||
.permitAll() | ||
.anyRequest() | ||
.hasAnyRole("ADMIN")) | ||
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class) | ||
.build(); | ||
} | ||
|
||
private CorsConfigurationSource corsConfigurationSource() { | ||
return request -> { | ||
CorsConfiguration config = new CorsConfiguration(); | ||
config.setAllowedHeaders(Collections.singletonList("*")); | ||
config.setAllowedMethods(Collections.singletonList("*")); | ||
config.setAllowedOriginPatterns(Collections.singletonList("*")); | ||
return config; | ||
}; | ||
} | ||
|
||
private RequestMatcher getMatcherForAnyone() { | ||
return RequestMatchers.anyOf(antMatcher("/admin/v1/auth/login/**")); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
admin/src/main/java/org/yapp/profile/application/AdminProfileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.yapp.profile.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.yapp.domain.profile.Profile; | ||
import org.yapp.domain.profile.ProfileRejectHistory; | ||
import org.yapp.domain.profile.ProfileStatus; | ||
import org.yapp.domain.user.RoleStatus; | ||
import org.yapp.domain.user.User; | ||
import org.yapp.error.dto.ProfileErrorCode; | ||
import org.yapp.error.exception.ApplicationException; | ||
import org.yapp.profile.dao.ProfileRejectHistoryRepository; | ||
import org.yapp.user.application.UserService; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdminProfileService { | ||
|
||
private final ProfileRejectHistoryRepository profileRejectHistoryRepository; | ||
private final UserService userService; | ||
|
||
@Transactional | ||
public void updateProfileStatus(Long userId, boolean reasonImage, boolean reasonDescription) { | ||
User user = userService.getUserById(userId); | ||
Profile profile = user.getProfile(); | ||
|
||
if (profile == null) { | ||
throw new ApplicationException(ProfileErrorCode.NOTFOUND_PROFILE); | ||
} | ||
|
||
if (reasonImage || reasonDescription) { | ||
rejectProfile(user.getProfile(), reasonImage, reasonDescription); | ||
} else { | ||
passProfile(profile); | ||
} | ||
} | ||
|
||
private void rejectProfile(Profile profile, boolean reasonImage, boolean reasonDescription) { | ||
profileRejectHistoryRepository.save(ProfileRejectHistory.builder() | ||
.user(profile.getUser()) | ||
.reasonImage(reasonImage) | ||
.reasonDescription(reasonDescription) | ||
.build()); | ||
|
||
profile.updateProfileStatus(ProfileStatus.REJECTED); | ||
profile.getUser().updateUserRole(RoleStatus.PENDING.getStatus()); | ||
} | ||
|
||
private void passProfile(Profile profile) { | ||
profile.updateProfileStatus(ProfileStatus.APPROVED); | ||
profile.getUser().updateUserRole(RoleStatus.USER.getStatus()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
admin/src/main/java/org/yapp/profile/dao/ProfileRejectHistoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.yapp.profile.dao; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import org.yapp.domain.profile.ProfileRejectHistory; | ||
|
||
@Repository | ||
public interface ProfileRejectHistoryRepository extends JpaRepository<ProfileRejectHistory, Long> { | ||
|
||
Optional<ProfileRejectHistory> findTopByUserIdOrderByCreatedAtDesc(Long userId); | ||
} |
18 changes: 18 additions & 0 deletions
18
admin/src/main/java/org/yapp/profile/dao/ProfileValueTalkRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.yapp.profile.dao; | ||
|
||
import io.lettuce.core.dynamic.annotation.Param; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
import org.yapp.domain.profile.ProfileValueTalk; | ||
|
||
@Repository | ||
public interface ProfileValueTalkRepository extends JpaRepository<ProfileValueTalk, Long> { | ||
|
||
@Query("SELECT pvt FROM ProfileValueTalk pvt " + | ||
"JOIN FETCH pvt.valueTalk vt " + | ||
"WHERE vt.isActive = true AND pvt.profile.id = :profileId") | ||
List<ProfileValueTalk> findActiveProfileValueTalksByProfileId( | ||
@Param("profileId") Long profileId); | ||
} |
Oops, something went wrong.