-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/Develop' into Prod
- Loading branch information
Showing
26 changed files
with
326 additions
and
52 deletions.
There are no files selected for viewing
4 changes: 1 addition & 3 deletions
4
src/main/java/supernova/whokie/alarm/constants/AlarmConstants.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
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/supernova/whokie/global/annotation/AdminAuthenticate.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 supernova.whokie.global.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface AdminAuthenticate { | ||
|
||
} |
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
36 changes: 36 additions & 0 deletions
36
src/main/java/supernova/whokie/global/resolver/LoginAdminArgumentResolver.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,36 @@ | ||
package supernova.whokie.global.resolver; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
import supernova.whokie.global.annotation.AdminAuthenticate; | ||
import supernova.whokie.global.exception.AuthenticationException; | ||
import supernova.whokie.global.exception.ForbiddenException; | ||
import supernova.whokie.user.Role; | ||
|
||
public class LoginAdminArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return parameter.hasParameterAnnotation(AdminAuthenticate.class); | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, | ||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
String userId = (String) request.getAttribute("userId"); | ||
String role = (String) request.getAttribute("role"); | ||
|
||
if (userId == null) { | ||
throw new AuthenticationException("로그인 후 이용해 주세요."); | ||
} | ||
if (!role.equals(Role.ADMIN.toString())) { | ||
throw new ForbiddenException("관리자만 이용할 수 있습니다."); | ||
} | ||
return Long.parseLong(userId); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/supernova/whokie/group/controller/AdminGroupController.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 supernova.whokie.group.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import supernova.whokie.global.annotation.AdminAuthenticate; | ||
import supernova.whokie.global.dto.PagingResponse; | ||
import supernova.whokie.group.controller.dto.GroupResponse; | ||
import supernova.whokie.group.service.GroupService; | ||
import supernova.whokie.group.service.dto.GroupModel; | ||
|
||
@RestController | ||
@RequestMapping("/api/admin/group") | ||
@RequiredArgsConstructor | ||
public class AdminGroupController { | ||
|
||
private final GroupService groupService; | ||
|
||
@GetMapping("") | ||
public PagingResponse<GroupResponse.Info> getAllGroups( | ||
@AdminAuthenticate Long userId, | ||
@PageableDefault(page = 0, size = 10, sort = "id", direction = Sort.Direction.ASC) Pageable pageable | ||
) { | ||
Page<GroupModel.Info> models = groupService.getAllGroupPaging(pageable); | ||
Page<GroupResponse.Info> response = models.map(GroupResponse.Info::from); | ||
return PagingResponse.from(response); | ||
} | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/supernova/whokie/question/controller/AdminQuestionController.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,43 @@ | ||
package supernova.whokie.question.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.web.bind.annotation.*; | ||
import supernova.whokie.global.annotation.AdminAuthenticate; | ||
import supernova.whokie.global.dto.GlobalResponse; | ||
import supernova.whokie.global.dto.PagingResponse; | ||
import supernova.whokie.question.controller.dto.QuestionRequest; | ||
import supernova.whokie.question.controller.dto.QuestionResponse; | ||
import supernova.whokie.question.service.QuestionService; | ||
import supernova.whokie.question.service.dto.QuestionModel; | ||
|
||
@RestController | ||
@RequestMapping("/api/admin/question") | ||
@RequiredArgsConstructor | ||
public class AdminQuestionController { | ||
|
||
private final QuestionService questionService; | ||
|
||
@GetMapping("") | ||
public PagingResponse<QuestionResponse.Admin> getAllQuestionPaging( | ||
@AdminAuthenticate Long userId, | ||
@PageableDefault(page = 0, size = 10, sort = "id", direction = Sort.Direction.ASC) Pageable pageable | ||
) { | ||
Page<QuestionModel.Admin> models = questionService.getAllQuestionPaging(pageable); | ||
Page<QuestionResponse.Admin> response = models.map(QuestionResponse.Admin::from); | ||
return PagingResponse.from(response); | ||
} | ||
|
||
@PostMapping("") | ||
public GlobalResponse postCommonQuestion( | ||
@AdminAuthenticate Long userId, | ||
@RequestBody @Valid QuestionRequest.CommonCreate request | ||
) { | ||
questionService.createCommonQuestion(userId, request.toCommand()); | ||
return GlobalResponse.builder().message("질문이 등록되ㅐ었습니다.").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
Oops, something went wrong.