-
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.
* admin_list * admin_list , detail in Controller -ing * figuring Request * feat : temp commit * figuring JPA Entity Admin * figuring list.html with thymeleaf * figuring list controller & list service * feat : temp commit * figuring detail controller , service & html with thymeleaf * figuring Approve * modify for exception and error * finished approve , detail and list figuring * dev * feat : 테이블 명 수정에 따른 쿼리 변경 * feat : AdminBackEnd완료 * Add Modified admin's BackEnd file approvePicture 메서드에 isSessionUserAdmin 주석처리 --------- Co-authored-by: donsonioc2010 <whddnjs822@gmail.com>
- Loading branch information
1 parent
061bd83
commit 8bcfa93
Showing
14 changed files
with
300 additions
and
12 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
Api/src/main/java/picasso/server/api/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,71 @@ | ||
package picasso.server.api.admin.controller; | ||
|
||
import jakarta.servlet.http.HttpSession; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import picasso.server.api.admin.exception.NotAdminUserException; | ||
import picasso.server.api.admin.service.AdminService; | ||
import picasso.server.domain.domains.member.entity.User; | ||
import picasso.server.domain.domains.member.type.UserRole; | ||
|
||
@Controller | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin") | ||
public class AdminController { | ||
|
||
private final AdminService adminService; | ||
|
||
@PostMapping("/approve/{pictureId}") | ||
public String approvePicture(@PathVariable Long pictureId, HttpSession session) { | ||
// isSessionUserAdmin(session); | ||
adminService.approvePicture(pictureId); | ||
return "redirect:/admin/list"; | ||
} | ||
|
||
/** | ||
* 관리자 페이지 미승인된 게시물 조회 Page | ||
* | ||
* @param model | ||
* @param session | ||
* @return | ||
*/ | ||
@GetMapping("/list") | ||
public String list(Model model, HttpSession session) { | ||
// isSessionUserAdmin(session); | ||
model.addAttribute("pictures", adminService.findAll()); | ||
return "admin/list"; | ||
} | ||
|
||
/** | ||
* 세부 게시물 조회 페이지 | ||
* | ||
* @param pictureId | ||
* @param model | ||
* @param session | ||
* @return | ||
*/ | ||
@GetMapping("/detail/{pictureId}") | ||
public String detail(@PathVariable Long pictureId, Model model, HttpSession session) { | ||
// isSessionUserAdmin(session); | ||
model.addAttribute( | ||
"picture", | ||
adminService.getBeforeApproveStatusPictureDetailById(pictureId) | ||
); | ||
return "admin/detail"; | ||
} | ||
|
||
private void isSessionUserAdmin(HttpSession session) { | ||
User user = (User) session.getAttribute("loginUser"); | ||
if (user == null || !user.getUserRole().equals(UserRole.ADMIN)) { | ||
log.error("ADMIN Auth Not Enough"); | ||
throw NotAdminUserException.EXCEPTION; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Api/src/main/java/picasso/server/api/admin/exception/AlreadyChangePictureException.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,15 @@ | ||
package picasso.server.api.admin.exception; | ||
|
||
import picasso.server.common.exception.BaseException; | ||
|
||
import static picasso.server.common.exception.GlobalException.PICTURE_STATUS_AFTER_APPROVE; | ||
|
||
/** | ||
* 이미 관리자가 승인한 게시물인 경우 발생되는 Exception | ||
*/ | ||
public class AlreadyChangePictureException extends BaseException { | ||
public static final BaseException EXCEPTION = new AlreadyChangePictureException(); | ||
private AlreadyChangePictureException() { | ||
super(PICTURE_STATUS_AFTER_APPROVE); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Api/src/main/java/picasso/server/api/admin/exception/NotAdminUserException.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 picasso.server.api.admin.exception; | ||
|
||
import picasso.server.common.exception.BaseException; | ||
|
||
import static picasso.server.common.exception.GlobalException.NOT_ADMIN; | ||
|
||
public class NotAdminUserException extends BaseException { | ||
public static final BaseException EXCEPTION = new NotAdminUserException(); | ||
|
||
public NotAdminUserException() { | ||
super(NOT_ADMIN); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
Api/src/main/java/picasso/server/api/admin/service/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,64 @@ | ||
package picasso.server.api.admin.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import picasso.server.api.admin.exception.AlreadyChangePictureException; | ||
import picasso.server.common.exception.NotFoundException; | ||
import picasso.server.domain.domains.items.Picture; | ||
import picasso.server.domain.domains.repository.PictureRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static picasso.server.domain.domains.items.PictureStatus.AFTER_APPROVE; | ||
import static picasso.server.domain.domains.items.PictureStatus.BEFORE_APPROVE; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class AdminService { | ||
private final PictureRepository pictureRepository; | ||
|
||
// TODO : 추후 Pagenation으로의 수정 필요함. | ||
@Transactional(readOnly = true) | ||
public List<Picture> findAll() { | ||
return pictureRepository.findAll(); | ||
} | ||
|
||
|
||
public Picture getBeforeApproveStatusPictureDetailById(Long id) { | ||
Optional<Picture> picture = pictureRepository | ||
.findByPictureIdAndPictureStatus(id, BEFORE_APPROVE); | ||
if (picture.isPresent()) { | ||
return picture.get(); | ||
} | ||
throw NotFoundException.EXCEPTION; | ||
} | ||
|
||
|
||
/** | ||
* 관리자 승인전의 게시물을 관리자 승인 상태로 변경하는 기능 | ||
* @param pictureId | ||
*/ | ||
public void approvePicture(Long pictureId) { | ||
Optional<Picture> optionalPicture = pictureRepository.findById(pictureId); | ||
if (optionalPicture.isPresent()) { | ||
Picture picture = optionalPicture.get(); | ||
if (picture.getPictureStatus().equals(BEFORE_APPROVE)) { | ||
picture.setPictureStatus(AFTER_APPROVE); | ||
pictureRepository.save(picture); | ||
log.info("ApprovePicture Success >>> Picture Id : {}, Title : {}", | ||
picture.getPictureId(), picture.getPictureName()); | ||
return; | ||
} | ||
log.warn("ApprovePicture Failure >>> Picture Id : {}, Title : {}", | ||
picture.getPictureId(), picture.getPictureName()); | ||
throw AlreadyChangePictureException.EXCEPTION; | ||
} | ||
log.error("ApprovePicture Failure : Fail Reason Is {} Id is Empty", pictureId); | ||
throw NotFoundException.EXCEPTION; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<title>Picasso - Picture Detail</title> | ||
</head> | ||
<body> | ||
<h1>Picture Detail</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>ID:</th> | ||
<td th:text="${picture.pictureId}"></td> | ||
</tr> | ||
<tr> | ||
<th>그림 URL:</th> | ||
<td th:text="${picture.imgUrl}"></td> | ||
</tr> | ||
<tr> | ||
<th>그림 이름:</th> | ||
<td th:text="${picture.pictureName}"></td> | ||
</tr> | ||
<tr> | ||
<th>화가 이름:</th> | ||
<td th:text="${picture.painterName}"></td> | ||
</tr> | ||
<tr> | ||
<th>그림 설명:</th> | ||
<td th:text="${picture.details}"></td> | ||
</tr> | ||
<tr> | ||
<th>시작 가격:</th> | ||
<td th:text="${picture.startingPrice}"></td> | ||
</tr> | ||
<tr> | ||
<th>최소 입찰 단위:</th> | ||
<td th:text="${picture.incrementAmount}"></td> | ||
</tr> | ||
<tr> | ||
<th>그림 사이즈:</th> | ||
<td th:text="${picture.size}"></td> | ||
</tr> | ||
<tr> | ||
<th>생성일:</th> | ||
<td th:text="${picture.bidStartDate}"></td> | ||
</tr> | ||
|
||
<td> | ||
<form th:action="@{'/admin/approve/' + ${picture.pictureId}}" method="post" > | ||
<button type="submit">Approve</button> | ||
</form> | ||
</td> | ||
|
||
</table> | ||
|
||
</body> | ||
</html> |
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 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<title>Picasso - Approve List</title> | ||
</head> | ||
<body> | ||
<h1>Admin Approve List</h1> | ||
<table border="1"> | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>그림명</th> | ||
<th>시작가</th> | ||
<th>생성일</th> | ||
<th>승인 상태</th> | ||
<th>승인 버튼</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr th:each="picture : ${pictures}" th:if="${#strings.equals(picture.pictureStatus,'BEFORE_APPROVE')}"> | ||
<td> | ||
<a th:href="@{'/admin/detail/' + ${picture.pictureId}}"><span th:text="${picture.pictureId}"></span></a> | ||
</td> | ||
<td> | ||
<a th:href="@{'/admin/detail/' + ${picture.pictureId}}"><span th:text="${picture.pictureName}"></span></a> | ||
</td> | ||
<td th:text="${picture.startingPrice}"></td> | ||
<td th:text="${picture.bidStartDate}"></td> | ||
<td th:text="${picture.pictureStatus}"></td> | ||
<td> | ||
<form th:action="@{'/admin/approve/' + ${picture.pictureId}}" method="post" > | ||
<button type="submit">Approve</button> | ||
</form> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
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
11 changes: 11 additions & 0 deletions
11
Common/src/main/java/picasso/server/common/exception/NotFoundException.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 picasso.server.common.exception; | ||
|
||
import static picasso.server.common.exception.GlobalException.NOT_FOUND_ERROR; | ||
|
||
public class NotFoundException extends BaseException{ | ||
public static final BaseException EXCEPTION = new NotFoundException(); | ||
|
||
private NotFoundException() { | ||
super(NOT_FOUND_ERROR); | ||
} | ||
} |
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.