-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 회원의 랭킹 redis에 추가 및 삭제, 업데이트 기능 추가 * test: 회원 정보 변경 및 삭제 추가에 따른 랭킹 참여, 제외 테스트 코드 추가 * feat: 랭킹시스템 API 추가 및 랭킹 조회 기능 추가 * feat: 랭킹 조회 테스트 코드 추가 및 랭킹 업데이트 로직 각 업데이트 -> 스케쥴러 * style: checkstyle 에러 fix * refactor: 응답 객체명 변경 TopRankingInfoResponse -> TopRankingInfo * fix: 랭킹 업데이트 시간 15분 매초마다 동작하는 방식 -> 15분에 한 번만 실행되도록 변경 * refactor: 랭킹 응답 반환 객체 변수면 s 제거 Co-authored-by: Kim Heebin <blowhuiee@gmail.com> * refactor: ToprankingResponses 응답 객체 반환명 TopRankingResponse로 변경 * fix: ObjectMapper에러 수정 * fix: objectMapper 삭제 추가 * feat: 어드민 서비스 로그인 기능 추가 * refactor: 어드민 config 업데이트 * fix: test application.yml 수정 * test: stub에서의 타입 오류 해결 * style: 변수면 변경 --------- Co-authored-by: Kim Heebin <blowhuiee@gmail.com>
- Loading branch information
Showing
19 changed files
with
265 additions
and
26 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moabam/admin/application/admin/AdminMapper.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 com.moabam.admin.application.admin; | ||
|
||
import com.moabam.admin.domain.admin.Admin; | ||
|
||
public class AdminMapper { | ||
|
||
public static Admin toAdmin(Long socialId) { | ||
return Admin.builder() | ||
.socialId(String.valueOf(socialId)) | ||
.build(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/moabam/admin/application/admin/AdminService.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,56 @@ | ||
package com.moabam.admin.application.admin; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.admin.domain.admin.Admin; | ||
import com.moabam.admin.domain.admin.AdminRepository; | ||
import com.moabam.api.application.auth.AuthorizationService; | ||
import com.moabam.api.application.auth.mapper.AuthMapper; | ||
import com.moabam.api.dto.auth.AuthorizationTokenInfoResponse; | ||
import com.moabam.api.dto.auth.LoginResponse; | ||
import com.moabam.global.error.exception.BadRequestException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdminService { | ||
|
||
@Value("${admin}") | ||
private String adminLoginKey; | ||
|
||
private final AuthorizationService authorizationService; | ||
private final AdminRepository adminRepository; | ||
|
||
public void validate(String state) { | ||
if (!adminLoginKey.equals(state)) { | ||
throw new BadRequestException(ErrorMessage.LOGIN_FAILED_ADMIN_KEY); | ||
} | ||
} | ||
|
||
public LoginResponse signUpOrLogin(HttpServletResponse httpServletResponse, | ||
AuthorizationTokenInfoResponse authorizationTokenInfoResponse) { | ||
LoginResponse loginResponse = login(authorizationTokenInfoResponse); | ||
authorizationService.issueServiceToken(httpServletResponse, loginResponse.publicClaim()); | ||
|
||
return loginResponse; | ||
} | ||
|
||
private LoginResponse login(AuthorizationTokenInfoResponse authorizationTokenInfoResponse) { | ||
Optional<Admin> admin = adminRepository.findBySocialId(String.valueOf(authorizationTokenInfoResponse.id())); | ||
Admin loginMember = admin.orElseGet(() -> signUp(authorizationTokenInfoResponse.id())); | ||
|
||
return AuthMapper.toLoginResponse(loginMember, admin.isEmpty()); | ||
} | ||
|
||
private Admin signUp(Long socialId) { | ||
Admin admin = AdminMapper.toAdmin(socialId); | ||
|
||
return adminRepository.save(admin); | ||
} | ||
} |
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 com.moabam.admin.domain.admin; | ||
|
||
import static com.moabam.global.common.util.RandomUtils.*; | ||
import static java.util.Objects.*; | ||
|
||
import org.hibernate.annotations.ColumnDefault; | ||
|
||
import com.moabam.api.domain.member.Role; | ||
import com.moabam.global.common.entity.BaseTimeEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Admin extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "nickname", unique = true) | ||
private String nickname; | ||
|
||
@Column(name = "social_id", nullable = false, unique = true) | ||
private String socialId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "role", nullable = false) | ||
@ColumnDefault("'USER'") | ||
private Role role; | ||
|
||
@Builder | ||
private Admin(String socialId) { | ||
this.socialId = requireNonNull(socialId); | ||
this.nickname = createNickName(); | ||
this.role = Role.ADMIN; | ||
} | ||
|
||
private String createNickName() { | ||
return "오목눈이#" + randomStringValues(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/moabam/admin/domain/admin/AdminRepository.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 com.moabam.admin.domain.admin; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AdminRepository extends JpaRepository<Admin, Long> { | ||
|
||
Optional<Admin> findBySocialId(String socialId); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/moabam/admin/presentation/admin/AdminController.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,39 @@ | ||
package com.moabam.admin.presentation.admin; | ||
|
||
import org.springframework.http.HttpStatus; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.moabam.admin.application.admin.AdminService; | ||
import com.moabam.api.application.auth.AuthorizationService; | ||
import com.moabam.api.dto.auth.AuthorizationCodeResponse; | ||
import com.moabam.api.dto.auth.AuthorizationTokenInfoResponse; | ||
import com.moabam.api.dto.auth.AuthorizationTokenResponse; | ||
import com.moabam.api.dto.auth.LoginResponse; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/admins") | ||
@RequiredArgsConstructor | ||
public class AdminController { | ||
|
||
private final AuthorizationService authorizationService; | ||
private final AdminService adminService; | ||
|
||
@PostMapping("/login/kakao/oauth") | ||
@ResponseStatus(HttpStatus.OK) | ||
public LoginResponse authorizationTokenIssue(@RequestBody AuthorizationCodeResponse authorizationCodeResponse, | ||
HttpServletResponse httpServletResponse) { | ||
adminService.validate(authorizationCodeResponse.state()); | ||
AuthorizationTokenResponse tokenResponse = authorizationService.requestAdminToken(authorizationCodeResponse); | ||
AuthorizationTokenInfoResponse authorizationTokenInfoResponse = authorizationService.requestTokenInfo( | ||
tokenResponse); | ||
|
||
return adminService.signUpOrLogin(httpServletResponse, authorizationTokenInfoResponse); | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moabam/global/config/AllowOriginConfig.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 com.moabam.global.config; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "allows") | ||
public record AllowOriginConfig( | ||
List<String> origin | ||
) { | ||
|
||
} |
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
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
Oops, something went wrong.