Skip to content

Commit

Permalink
[FEAT/A1] 샘플 데이터 추가 및 회원 상태 정지 구현, html 수정 (#70)
Browse files Browse the repository at this point in the history
* 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 주석처리

* Add , modify frontEnd css&html

list.html수정 , adminlist.css ,관리자 계정 생성을 위한 form.html
추가

* Add list of Admin and etc for using it

관리자 명단 조회를 위한 메소드 추가

* Add Admin Account form & list

관리자 계정 생성 및 리스트

* feat: modal, index header, footer 수정 #45

* Modify html & css, need to revise detail.html&css

html , css 파일 수정 , detail.html&css 개선 필요

* Modify for dependency

의존성 해결을 위한 수정

* feat : Login, Join Link 추가

* Modify code reviewing

사용할 Dto 만 적용가능 하게끔 SignUpAdminRequestDto 작성후 적용
Build패턴-> 해당 Dto만 적용
높은 가시성을 위한 메서드 네이밍 및 경로 재설정

* 안ìì�안쓰는 ì�의존설성 정리

* feat : footer 링크 추가 및 Project 정보 추가

* feat : Header수정, 및 Bootstrap파일 변경을 위해서 Bootstrap 직접 static에서 가져오도록 변경, 관리자 계정 쿼리 추가

* feat : 관리자 UI작업중

* style : footer size 변경

* feat : 로그아웃 li 추가, 로그인시 사용자 닉네임과 포인트 출력 추가

* style : UI Header, 관리자 컷

* feat : 메인페이지 UI
- 경매품 이미지 출력 및 Detail페이지로 이동 할 수 있게 a태그 설정.
- 출력할 물품이 없는 경우에 맞는 Block추가
- More 버튼 이벤트 추가
    - Vanila Javascript Function 생성 및 인자값에 따라 다르게 가져 올 수 있도록 생성.

* Modify front_end & admincontroller

컨트롤러 불필요 코드 제거 , html 규격에 맞게 수정중(아직 미완)

* Modify Admin HTML

html 파일 규격에 맞게끔 수정

* feat : index 누락 태그 추가

* Modify & Add

-

* Modify error from memberlist.html & Start to add pagenation with JPA

memberlist 에러 해결 및 JPA pagenation 구현작업시작

* Add ExamData

예시 데이터 추가

* Modify Example Data

샘플 데이터 수정

* Try to resolve conflicts

충돌 해결 노력

* Modify error

에러수정

---------

Co-authored-by: donsonioc2010 <whddnjs822@gmail.com>
Co-authored-by: bongsh0112 <bongsh0112@gmail.com>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent 92efab8 commit 42dfda3
Show file tree
Hide file tree
Showing 17 changed files with 898 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
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 org.springframework.web.bind.annotation.*;
import picasso.server.api.admin.exception.NotAdminUserException;
import picasso.server.api.admin.service.AdminService;
import picasso.server.api.user.vo.request.SignUpAdminRequestDto;
import picasso.server.api.admin.request.SignUpAdminRequestDto;
import picasso.server.domain.domains.user.entity.User;
import picasso.server.domain.domains.user.repository.UserRepository;
import picasso.server.domain.domains.user.type.UserRole;

import java.util.List;

import static java.time.LocalDateTime.now;


@Controller
Expand All @@ -34,7 +28,7 @@ public class AdminController {
public String approvePicture(@PathVariable Long pictureId, HttpSession session) {
isSessionUserAdmin(session);
adminService.approvePicture(pictureId);
return "redirect:/admin/list";
return "redirect:/admin/approvelist";
}

/**
Expand All @@ -45,11 +39,11 @@ public String approvePicture(@PathVariable Long pictureId, HttpSession session)
* @return
*/

@GetMapping("/list")
public String list(Model model, HttpSession session) {
@GetMapping("/approvelist")
public String approvelist(Model model, HttpSession session) {
isSessionUserAdmin(session);
model.addAttribute("pictures", adminService.findAll());
return "admin/list";
model.addAttribute("pictures", adminService.findAllPicture());
return "admin/approvelist";
}

/**
Expand All @@ -71,10 +65,6 @@ public String detail(@PathVariable Long pictureId, Model model, HttpSession sess
}


/**
* Session에 현재 로그인된 사용자가 관리자인지를 판단한다.
* @param session
*/
private void isSessionUserAdmin(HttpSession session) {
User user = (User) session.getAttribute("loginUser");
if (user == null || !user.getUserRole().equals(UserRole.ADMIN)) {
Expand All @@ -86,7 +76,7 @@ private void isSessionUserAdmin(HttpSession session) {

@GetMapping("/form")
public String AdminForm(HttpSession session) {
// isSessionUserAdmin(session);
isSessionUserAdmin(session);
return "admin/form";
}

Expand All @@ -99,36 +89,51 @@ public String AdminForm(HttpSession session) {
*/
@PostMapping("/form")
public String addAdmin(SignUpAdminRequestDto dto, HttpSession session) {
// isSessionUserAdmin(session);
isSessionUserAdmin(session);
User user = User.builder()
.email(dto.getEmail())
.password(dto.getPassword())
.nickName(dto.getNickName())
.userRole(UserRole.ADMIN)
.updatedAt(now())
.createdAt(now())
.loginAt(now())
.profile("https://www.example.com/default-profile-image.jpg")
.build();

userRepository.save(user);

return "auth/login";
}

/**
* 관리자 계정 조회
*
* @param model
* @param session
* @param userRole
* @return
*/


@GetMapping("/user/list")
public String AdminList(HttpSession session, Model model) {
public String adminUserList(@RequestParam(name = "userRole", defaultValue = "ADMIN") String userRole, HttpSession session, Model model) {
isSessionUserAdmin(session);
List<User> adminUsers = adminService.findAllAdmin();
model.addAttribute("users", adminUsers);

if ("ADMIN".equals(userRole)) {
model.addAttribute("users", adminService.findAllAdmin());
} else if ("USER".equals(userRole)) {
model.addAttribute("users", adminService.findAllUser());
}

return "admin/memberList";
}
}


@PostMapping("/suspend/{userId}")

public String suspendUser(@PathVariable Long userId, HttpSession session) {
isSessionUserAdmin(session);
adminService.suspendUser(userId);
return "redirect:/admin/user/list?status=USER";


}

}
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 java.io.NotActiveException;

import static picasso.server.common.exception.GlobalException.USER_STATUS_NOT_ACTIVE;

public class NotActiveStatusException extends BaseException {
public static final BaseException EXCEPTION = new NotActiveStatusException();
private NotActiveStatusException() {super (USER_STATUS_NOT_ACTIVE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package picasso.server.api.admin.exception;

import picasso.server.common.exception.BaseException;

import static picasso.server.common.exception.GlobalException.NOT_FOUND_USER_ERROR;

public class NotFoundUserException extends BaseException {
public static final BaseException EXCEPTION = new NotFoundUserException();

public NotFoundUserException() { super(NOT_FOUND_USER_ERROR);}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package picasso.server.api.user.vo.request;
package picasso.server.api.admin.request;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import picasso.server.api.admin.exception.AlreadyChangePictureException;
import picasso.server.api.admin.exception.NotActiveStatusException;
import picasso.server.api.admin.exception.NotFoundUserException;
import picasso.server.api.mail.service.SendMailService;
import picasso.server.common.exception.NotFoundException;
import picasso.server.domain.domains.picture.items.Picture;
Expand All @@ -18,6 +20,8 @@

import static picasso.server.domain.domains.picture.items.PictureStatus.AFTER_APPROVE;
import static picasso.server.domain.domains.picture.items.PictureStatus.BEFORE_APPROVE;
import static picasso.server.domain.domains.user.type.UserStatus.ACTIVE;
import static picasso.server.domain.domains.user.type.UserStatus.SUSPENSION;

@Slf4j
@Service
Expand All @@ -30,7 +34,7 @@ public class AdminService {

// TODO : 추후 Pagenation으로의 수정 필요함.
@Transactional(readOnly = true)
public List<Picture> findAll() {
public List<Picture> findAllPicture() {
return pictureRepository.findAll();
}

Expand All @@ -47,6 +51,7 @@ public Picture getBeforeApproveStatusPictureDetailById(Long id) {

/**
* 관리자 승인전의 게시물을 관리자 승인 상태로 변경 하는 기능
*
* @param pictureId
*/
public void approvePicture(Long pictureId) {
Expand All @@ -69,11 +74,39 @@ public void approvePicture(Long pictureId) {
throw NotFoundException.EXCEPTION;
}


@Transactional(readOnly = true)
public List<User> findAllAdmin() {
return userRepository.findByUserRole(UserRole.ADMIN);
}
@Transactional(readOnly = true)
public List<User> findAllUser() {
return userRepository.findByUserRole(UserRole.USER);
}

/**
* 관리자가 멤버의 상태를 정지로 변환시킬 수 있는 기능
*
* @param userId
*/
public void suspendUser(Long userId) {
Optional<User> optionalUser = userRepository.findById(userId);
if (optionalUser.isPresent()) {
User user = optionalUser.get();
if (user.getUserStatus().equals(ACTIVE)) {
user.setUserStatus(SUSPENSION);
userRepository.save(user);
log.info("SuspendUser Success >>> User ID : {}, Title : {}",
user.getId(), user.getEmail());
return;

} log.warn("SuspendUser Failure >>> User Id : {}, Title : {}",
user.getId(), user.getEmail());
throw NotActiveStatusException.EXCEPTION;
}
throw NotFoundUserException.EXCEPTION;
}


}


Expand Down
7 changes: 7 additions & 0 deletions Api/src/main/resources/static/css/adminform.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ body {
margin: 20px;
}



h2 {
color: #333;
}
Expand All @@ -29,13 +31,18 @@ input {
}

button {
display: block;
margin: 20px auto;
padding: 10px 20px;
font-size: 18px;
padding: 10px 20px;
background-color: #3498db;
border: none;
color: white;
cursor: pointer;
}


button:hover {
background-color: #2980b9;
}
3 changes: 2 additions & 1 deletion Api/src/main/resources/static/css/adminlist.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ div.admin-title-row{

form>div.row {
margin-bottom: 5px;
}
}

11 changes: 11 additions & 0 deletions Api/src/main/resources/static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ swiper-slide.no-pictures{
align-items: center;
}

swiper-slide.no-pictures{
width:936px;
height:600px;
text-align: center;
font-size: 18px;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
}

swiper-slide div.box {
width: 100%;
height: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1>관리자 대쉬보드</h1>
<td th:text="${picture.pictureStatus}"></td>
<td>
<form th:action="@{'/admin/approve/' + ${picture.pictureId}}" method="post">
<button type="submit">Approve</button>
<button type="submit" class="btn btn-success" >Approve</button>
</form>
</td>
</tr>
Expand Down
Loading

0 comments on commit 42dfda3

Please sign in to comment.