-
Notifications
You must be signed in to change notification settings - Fork 2
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 #173 from Team-HMH/develop
deploy: main <- develop
- Loading branch information
Showing
71 changed files
with
911 additions
and
409 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/sopt/org/hmh/domain/admin/controller/AdminApi.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,24 @@ | ||
package sopt.org.hmh.domain.admin.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.springframework.http.ResponseEntity; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminDailyChallengeRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; | ||
import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; | ||
import sopt.org.hmh.global.common.response.BaseResponse; | ||
|
||
public interface AdminApi { | ||
@Operation(summary = "κ΄λ¦¬μ λ‘κ·ΈμΈ") | ||
ResponseEntity<BaseResponse<AdminTokenResponse>> orderAdminLogin(AdminLoginRequest request); | ||
|
||
@Operation(summary = "κ΄λ¦¬μ κΆνμΌλ‘ μ μ μ¦μ μμ ") | ||
ResponseEntity<Void> orderAdminWithdrawImmediately(AdminUserIdRequest request); | ||
|
||
@Operation(summary = "κ΄λ¦¬μ κΆνμΌλ‘ μ μ μ 보 λ³κ²½") | ||
ResponseEntity<Void> orderAdminChangeUserInfo(AdminUserInfoRequest request); | ||
|
||
@Operation(summary = "κ΄λ¦¬μ κΆνμΌλ‘ μ μ μ±λ¦°μ§ μ 보 λ³κ²½") | ||
ResponseEntity<Void> orderAdminChangeDailyChallengeInfo(AdminDailyChallengeRequest request); | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/sopt/org/hmh/domain/admin/controller/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,67 @@ | ||
package sopt.org.hmh.domain.admin.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
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 sopt.org.hmh.domain.admin.dto.request.AdminDailyChallengeRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminLoginRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminUserIdRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; | ||
import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; | ||
import sopt.org.hmh.domain.admin.exception.AdminSuccess; | ||
import sopt.org.hmh.domain.admin.service.AdminFacade; | ||
import sopt.org.hmh.global.common.response.BaseResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/admin") | ||
public class AdminController implements AdminApi { | ||
|
||
private final AdminFacade adminFacade; | ||
|
||
@Override | ||
@PostMapping("/login") | ||
public ResponseEntity<BaseResponse<AdminTokenResponse>> orderAdminLogin( | ||
@RequestBody final AdminLoginRequest request) { | ||
return ResponseEntity | ||
.status(AdminSuccess.ADMIN_LOGIN_SUCCESS.getHttpStatus()) | ||
.body(BaseResponse.success(AdminSuccess.ADMIN_LOGIN_SUCCESS, | ||
adminFacade.adminLogin(request.authCode()))); | ||
} | ||
|
||
@Override | ||
@DeleteMapping("/user") | ||
public ResponseEntity<Void> orderAdminWithdrawImmediately( | ||
@RequestBody @Valid final AdminUserIdRequest request) { | ||
adminFacade.withdrawImmediately(request.userId()); | ||
return ResponseEntity | ||
.noContent() | ||
.build(); | ||
} | ||
|
||
@Override | ||
@PatchMapping("/user") | ||
public ResponseEntity<Void> orderAdminChangeUserInfo( | ||
@RequestBody @Valid final AdminUserInfoRequest request) { | ||
adminFacade.changeUserInfo(request); | ||
return ResponseEntity | ||
.noContent() | ||
.build(); | ||
} | ||
|
||
@Override | ||
@PatchMapping("/challenge/daily") | ||
public ResponseEntity<Void> orderAdminChangeDailyChallengeInfo( | ||
@RequestBody @Valid final AdminDailyChallengeRequest request) { | ||
adminFacade.changeDailyChallengeInfo(request); | ||
return ResponseEntity | ||
.noContent() | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminDailyChallengeRequest.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 sopt.org.hmh.domain.admin.dto.request; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import sopt.org.hmh.domain.dailychallenge.domain.Status; | ||
|
||
public record AdminDailyChallengeRequest( | ||
Long userId, | ||
LocalDate startDate, | ||
List<Status> statuses | ||
) { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminLoginRequest.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,7 @@ | ||
package sopt.org.hmh.domain.admin.dto.request; | ||
|
||
public record AdminLoginRequest( | ||
String authCode | ||
) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserIdRequest.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,7 @@ | ||
package sopt.org.hmh.domain.admin.dto.request; | ||
|
||
public record AdminUserIdRequest( | ||
Long userId | ||
) { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/sopt/org/hmh/domain/admin/dto/request/AdminUserInfoRequest.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,9 @@ | ||
package sopt.org.hmh.domain.admin.dto.request; | ||
|
||
public record AdminUserInfoRequest( | ||
Long userId, | ||
String name, | ||
Integer point | ||
) { | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/sopt/org/hmh/domain/admin/dto/response/AdminTokenResponse.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,6 @@ | ||
package sopt.org.hmh.domain.admin.dto.response; | ||
|
||
public record AdminTokenResponse( | ||
String accessToken | ||
) { | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/sopt/org/hmh/domain/admin/exception/AdminError.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 sopt.org.hmh.domain.admin.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import sopt.org.hmh.global.common.exception.base.ErrorBase; | ||
|
||
@AllArgsConstructor | ||
public enum AdminError implements ErrorBase { | ||
|
||
// 401 UNAUTHORIZED | ||
INVALID_ADMIN_AUTH_CODE(HttpStatus.UNAUTHORIZED, "κ΄λ¦¬μ μΈμ¦ λ²νΈκ° μΌμΉνμ§ μμ΅λλ€."), | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String errorMessage; | ||
|
||
@Override | ||
public int getHttpStatusCode() { | ||
return this.status.value(); | ||
} | ||
|
||
@Override | ||
public HttpStatus getHttpStatus() { | ||
return this.status; | ||
} | ||
|
||
@Override | ||
public String getErrorMessage() { | ||
return this.errorMessage; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/sopt/org/hmh/domain/admin/exception/AdminException.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 sopt.org.hmh.domain.admin.exception; | ||
|
||
import sopt.org.hmh.global.common.exception.base.ExceptionBase; | ||
|
||
public class AdminException extends ExceptionBase { | ||
|
||
public AdminException(AdminError errorBase) { | ||
super(errorBase); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/sopt/org/hmh/domain/admin/exception/AdminSuccess.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,34 @@ | ||
package sopt.org.hmh.domain.admin.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import sopt.org.hmh.global.common.exception.base.SuccessBase; | ||
|
||
@AllArgsConstructor | ||
public enum AdminSuccess implements SuccessBase { | ||
|
||
// 200 OK | ||
ADMIN_LOGIN_SUCCESS(HttpStatus.OK, "κ΄λ¦¬μ λ‘κ·ΈμΈμ μ±κ³΅νμ΅λλ€."), | ||
|
||
// 204 NO CONTENT | ||
ADMIN_WITHDRAW_IMMEDIATELY_SUCCESS(HttpStatus.NO_CONTENT, "κ΄λ¦¬μ κΆνμΌλ‘ μ μ μ¦μ μμ μ μ±κ³΅νμ΅λλ€."), | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String successMessage; | ||
|
||
@Override | ||
public int getHttpStatusCode() { | ||
return this.status.value(); | ||
} | ||
|
||
@Override | ||
public HttpStatus getHttpStatus() { | ||
return this.status; | ||
} | ||
|
||
@Override | ||
public String getSuccessMessage() { | ||
return this.successMessage; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/sopt/org/hmh/domain/admin/service/AdminFacade.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,81 @@ | ||
package sopt.org.hmh.domain.admin.service; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminDailyChallengeRequest; | ||
import sopt.org.hmh.domain.admin.dto.request.AdminUserInfoRequest; | ||
import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse; | ||
import sopt.org.hmh.domain.admin.exception.AdminError; | ||
import sopt.org.hmh.domain.admin.exception.AdminException; | ||
import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError; | ||
import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException; | ||
import sopt.org.hmh.domain.challenge.service.ChallengeService; | ||
import sopt.org.hmh.domain.dailychallenge.domain.Status; | ||
import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService; | ||
import sopt.org.hmh.domain.user.domain.User; | ||
import sopt.org.hmh.domain.user.service.UserService; | ||
import sopt.org.hmh.global.auth.jwt.TokenService; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdminFacade { | ||
|
||
@Value("${jwt.admin-auth-code}") | ||
private String adminAuthCode; | ||
|
||
private final UserService userService; | ||
private final TokenService tokenService; | ||
private final ChallengeService challengeService; | ||
private final DailyChallengeService dailyChallengeService; | ||
|
||
public AdminTokenResponse adminLogin(String authCode) { | ||
validateAdminAuthCode(authCode); | ||
return new AdminTokenResponse(tokenService.issueAdminToken()); | ||
} | ||
|
||
private void validateAdminAuthCode(String authCode) { | ||
if (!adminAuthCode.equals(authCode)) { | ||
throw new AdminException(AdminError.INVALID_ADMIN_AUTH_CODE); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void withdrawImmediately(Long userId) { | ||
userService.checkIsExistUserId(userId); | ||
challengeService.deleteChallengeRelatedByUserId(userId); | ||
userService.withdrawImmediately(userId); | ||
} | ||
|
||
@Transactional | ||
public void changeUserInfo(AdminUserInfoRequest request) { | ||
User user = userService.findByIdOrThrowException(request.userId()); | ||
if (Objects.nonNull(request.point())) { | ||
user.changePoint(request.point()); | ||
} | ||
if (Objects.nonNull(request.name())) { | ||
user.changeName(request.name()); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void changeDailyChallengeInfo(AdminDailyChallengeRequest request) { | ||
Long currentChallengeId = userService.getCurrentChallengeIdByUserId(request.userId()); | ||
List<Status> statuses = request.statuses(); | ||
LocalDate challengeDate = request.startDate(); | ||
|
||
validateStatusesPeriod(currentChallengeId, statuses); | ||
dailyChallengeService.changeInfoOfDailyChallenges(currentChallengeId, statuses, challengeDate); | ||
} | ||
|
||
private void validateStatusesPeriod(Long challengeId, List<Status> statuses) { | ||
Integer challengePeriod = challengeService.getChallengePeriod(challengeId); | ||
if (challengePeriod != statuses.size()) { | ||
throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC); | ||
} | ||
} | ||
} |
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
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
3 changes: 3 additions & 0 deletions
3
src/main/java/sopt/org/hmh/domain/app/dto/request/AppRemoveRequest.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package sopt.org.hmh.domain.app.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record AppRemoveRequest( | ||
@NotNull(message = "μ± μ½λλ nullμΌ μ μμ΅λλ€.") | ||
String appCode | ||
) { | ||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/sopt/org/hmh/domain/app/dto/request/ChallengeAppArrayRequest.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package sopt.org.hmh.domain.app.dto.request; | ||
|
||
import jakarta.validation.Valid; | ||
import java.util.List; | ||
|
||
public record ChallengeAppArrayRequest( | ||
List<ChallengeAppRequest> apps | ||
List<@Valid ChallengeAppRequest> apps | ||
) { | ||
} |
Oops, something went wrong.