-
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 #45 from Nexters/feature/39
Feature/39 : ๊ด๋ฆฌ์ ๋ก๊ทธ์ธ API
- Loading branch information
Showing
21 changed files
with
550 additions
and
25 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
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
5 changes: 4 additions & 1 deletion
5
src/main/java/com/nexters/dailyphrase/admin/domain/repository/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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.nexters.dailyphrase.admin.domain.repository; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.nexters.dailyphrase.admin.domain.Admin; | ||
|
||
public interface AdminRepository extends JpaRepository<Admin, Long> {} | ||
public interface AdminRepository extends JpaRepository<Admin, Long> { | ||
Optional<Admin> findByUserId(String userId); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/nexters/dailyphrase/admin/exception/AdminBadCredentialException.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,13 @@ | ||
package com.nexters.dailyphrase.admin.exception; | ||
|
||
import com.nexters.dailyphrase.common.exception.BaseCodeException; | ||
|
||
public class AdminBadCredentialException extends BaseCodeException { | ||
|
||
public static BaseCodeException EXCEPTION = | ||
new com.nexters.dailyphrase.admin.exception.AdminBadCredentialException(); | ||
|
||
public AdminBadCredentialException() { | ||
super(AdminErrorCode.ADMIN_BAD_CREDENTIALS_EXCEPTION); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/nexters/dailyphrase/admin/exception/AdminErrorCode.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,37 @@ | ||
package com.nexters.dailyphrase.admin.exception; | ||
|
||
import static com.nexters.dailyphrase.common.consts.DailyPhraseStatic.NOT_FOUND; | ||
import static com.nexters.dailyphrase.common.consts.DailyPhraseStatic.UNAUTHORIZED; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Objects; | ||
|
||
import com.nexters.dailyphrase.common.annotation.ExplainError; | ||
import com.nexters.dailyphrase.common.exception.BaseErrorCode; | ||
import com.nexters.dailyphrase.common.exception.ErrorReason; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum AdminErrorCode implements BaseErrorCode { | ||
ADMIN_NOT_FOUND(NOT_FOUND, "ADMIN_404_1", "ํด๋น ๊ด๋ฆฌ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."), | ||
ADMIN_BAD_CREDENTIALS_EXCEPTION(UNAUTHORIZED, "ADMIN_401_1", "์๊ฒฉ์ฆ๋ช ์ด ์์ต๋๋ค. ์์ด๋ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ต๋๋ค."); | ||
|
||
private final Integer status; | ||
private final String code; | ||
private final String reason; | ||
|
||
@Override | ||
public ErrorReason getErrorReason() { | ||
return ErrorReason.builder().reason(reason).code(code).status(status).build(); | ||
} | ||
|
||
@Override | ||
public String getExplainError() throws NoSuchFieldException { | ||
Field field = this.getClass().getField(this.name()); | ||
ExplainError annotation = field.getAnnotation(ExplainError.class); | ||
return Objects.nonNull(annotation) ? annotation.value() : this.getReason(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/nexters/dailyphrase/admin/exception/AdminNotFoundException.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 com.nexters.dailyphrase.admin.exception; | ||
|
||
import com.nexters.dailyphrase.common.exception.BaseCodeException; | ||
|
||
public class AdminNotFoundException extends BaseCodeException { | ||
public static BaseCodeException EXCEPTION = new AdminNotFoundException(); | ||
|
||
public AdminNotFoundException() { | ||
super(AdminErrorCode.ADMIN_NOT_FOUND); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/nexters/dailyphrase/admin/implement/AdminDetailsServiceImpl.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,37 @@ | ||
package com.nexters.dailyphrase.admin.implement; | ||
|
||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.nexters.dailyphrase.admin.domain.Admin; | ||
import com.nexters.dailyphrase.admin.domain.repository.AdminRepository; | ||
import com.nexters.dailyphrase.admin.exception.AdminNotFoundException; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdminDetailsServiceImpl implements UserDetailsService { | ||
|
||
private final AdminRepository adminRepository; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
@Override | ||
public UserDetails loadUserByUsername(String username) throws AdminNotFoundException { | ||
return adminRepository | ||
.findByUserId(username) | ||
.map(this::createUserDetails) | ||
.orElseThrow(() -> AdminNotFoundException.EXCEPTION); | ||
} | ||
|
||
private UserDetails createUserDetails(Admin admin) { | ||
return User.builder() | ||
.username(admin.getUserId()) | ||
.password(passwordEncoder.encode(admin.getPassword())) | ||
.roles(String.valueOf(admin.getRole())) | ||
.build(); | ||
} | ||
} |
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
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.