Skip to content

Commit

Permalink
[BE]FEAT: 연장권 부여기능 추가 admin
Browse files Browse the repository at this point in the history
  • Loading branch information
enaenen committed Oct 15, 2023
1 parent fd17c8c commit 66d0014
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.ftclub.cabinet.dto.LentExtensionPaginationDto;
import org.ftclub.cabinet.dto.LentHistoryPaginationDto;
import org.ftclub.cabinet.lent.service.LentFacadeService;
import org.ftclub.cabinet.user.service.LentExtensionService;
import org.ftclub.cabinet.user.service.UserFacadeService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -30,105 +31,115 @@
@Log4j2
public class AdminUserController {

private final UserFacadeService userFacadeService;
private final LentFacadeService lentFacadeService;
private final UserFacadeService userFacadeService;
private final LentFacadeService lentFacadeService;
private final LentExtensionService lentExtensionService;

/**
* 현재 유저가 차단된 상태일 때, 차단을 해제합니다.
*
* @param userId 유저 고유 아이디
*/
@DeleteMapping("/{userId}/ban-history")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void deleteBanHistoryByUserId(@PathVariable("userId") Long userId) {
log.info("Called deleteBanHistoryByUserId: {}", userId);
userFacadeService.deleteRecentBanHistory(userId, LocalDateTime.now());
}
/**
* 현재 유저가 차단된 상태일 때, 차단을 해제합니다.
*
* @param userId 유저 고유 아이디
*/
@DeleteMapping("/{userId}/ban-history")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void deleteBanHistoryByUserId(@PathVariable("userId") Long userId) {
log.info("Called deleteBanHistoryByUserId: {}", userId);
userFacadeService.deleteRecentBanHistory(userId, LocalDateTime.now());
}

/**
* 유저의 대여 기록을 반환합니다.
*
* @param userId 유저 고유 아이디
* @param page 페이지 번호
* @param size 페이지 당 길이
* @return {@link LentHistoryPaginationDto} 유저의 대여 기록
*/
@GetMapping("/{userId}/lent-histories")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentHistoryPaginationDto getLentHistoriesByUserId(@PathVariable("userId") Long userId,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getLentHistoriesByUserId: {}", userId);
return lentFacadeService.getAllUserLentHistories(userId, page, size);
}
/**
* 유저의 대여 기록을 반환합니다.
*
* @param userId 유저 고유 아이디
* @param page 페이지 번호
* @param size 페이지 당 길이
* @return {@link LentHistoryPaginationDto} 유저의 대여 기록
*/
@GetMapping("/{userId}/lent-histories")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentHistoryPaginationDto getLentHistoriesByUserId(@PathVariable("userId") Long userId,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getLentHistoriesByUserId: {}", userId);
return lentFacadeService.getAllUserLentHistories(userId, page, size);
}

/**
* 유저를 어드민으로 승격시킵니다.
*
* @param email 유저 이메일
* @return redirect:cabi.42seoul.io/admin/login
*/
@GetMapping("/admins/promote")
@AuthGuard(level = AuthLevel.MASTER_ONLY)
public void promoteUserToAdmin(@RequestParam("email") String email) {
log.info("Called promoteUserToAdmin: {}", email);
userFacadeService.promoteUserToAdmin(email);
}
/**
* 유저를 어드민으로 승격시킵니다.
*
* @param email 유저 이메일
* @return redirect:cabi.42seoul.io/admin/login
*/
@GetMapping("/admins/promote")
@AuthGuard(level = AuthLevel.MASTER_ONLY)
public void promoteUserToAdmin(@RequestParam("email") String email) {
log.info("Called promoteUserToAdmin: {}", email);
userFacadeService.promoteUserToAdmin(email);
}

/**
* 동아리 유저를 생성합니다.
*
* @param body
*/
@PostMapping("/club")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void createClubUser(@RequestBody HashMap<String, String> body) {
log.info("Called createClub");
String clubName = body.get("clubName");
userFacadeService.createClubUser(clubName);
}
/**
* 동아리 유저를 생성합니다.
*
* @param body
*/
@PostMapping("/club")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void createClubUser(@RequestBody HashMap<String, String> body) {
log.info("Called createClub");
String clubName = body.get("clubName");
userFacadeService.createClubUser(clubName);
}

/**
* 동아리 유저를 삭제합니다.
*
* @param clubId 동아리 고유 아이디
*/
@DeleteMapping("/club/{clubId}")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void deleteClubUser(@PathVariable("clubId") Long clubId) {
log.info("Called deleteClub");
userFacadeService.deleteClubUser(clubId);
}
/**
* 동아리 유저를 삭제합니다.
*
* @param clubId 동아리 고유 아이디
*/
@DeleteMapping("/club/{clubId}")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void deleteClubUser(@PathVariable("clubId") Long clubId) {
log.info("Called deleteClub");
userFacadeService.deleteClubUser(clubId);
}

@GetMapping("/clubs")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public ClubUserListDto findClubs(@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getClubs");
return userFacadeService.findAllClubUser(page, size);
}
@GetMapping("/clubs")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public ClubUserListDto findClubs(@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getClubs");
return userFacadeService.findAllClubUser(page, size);
}

@PatchMapping("/club/{clubId}")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void updateClubUser(@PathVariable("clubId") Long clubId, @RequestBody HashMap<String, String> body) {
log.info("Called updateClub");
String clubName = body.get("clubName");
userFacadeService.updateClubUser(clubId, clubName);
}
@PatchMapping("/club/{clubId}")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void updateClubUser(@PathVariable("clubId") Long clubId,
@RequestBody HashMap<String, String> body) {
log.info("Called updateClub");
String clubName = body.get("clubName");
userFacadeService.updateClubUser(clubId, clubName);
}

@GetMapping("/lent-extension")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentExtensionPaginationDto getAllLentExtension(@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getAllLentExtension");
return userFacadeService.getAllLentExtension(page, size);
}
@GetMapping("/lent-extension")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentExtensionPaginationDto getAllLentExtension(@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getAllLentExtension");
return userFacadeService.getAllLentExtension(page, size);
}

@GetMapping("/lent-extension/active")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentExtensionPaginationDto getAllActiveLentExtension(@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getAllActiveLentExtension");
return userFacadeService.getAllActiveLentExtension(page, size);
}
@GetMapping("/lent-extension/active")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentExtensionPaginationDto getAllActiveLentExtension(@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
log.info("Called getAllActiveLentExtension");
return userFacadeService.getAllActiveLentExtension(page, size);
}

@PostMapping("/lent-extension/{user}")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void issueLentExtension(@PathVariable("user") String username) {
log.info("Called issueLentExtension");
lentExtensionService.assignLentExtension(username);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.ftclub.cabinet.dto.MyProfileResponseDto;
import org.ftclub.cabinet.dto.UserSessionDto;
import org.ftclub.cabinet.user.domain.UserSession;
import org.ftclub.cabinet.user.service.LentExtensionService;
import org.ftclub.cabinet.user.service.UserFacadeService;
import org.ftclub.cabinet.user.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -24,51 +22,42 @@
@Log4j2
public class UserController {

private final UserFacadeService userFacadeService;
private final UserService userService;
private final LentExtensionService lentExtensionService;

/**
* 현재 로그인한 유저의 프로필을 반환합니다. 전체 사물함 뷰에서 본인의 사물함을 표시하기 위해 사용됩니다.
*
* @param userSessionDto 현재 로그인한 유저의 세션 정보
* @return {@link MyProfileResponseDto} 현재 로그인한 유저의 프로필
*/
@GetMapping("/me")
@AuthGuard(level = AuthLevel.USER_ONLY)
public MyProfileResponseDto getMyProfile(@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyProfile: {}", userSessionDto.getName());
return userFacadeService.getMyProfile(userSessionDto);
}

@GetMapping("/me/lent-extensions")
@AuthGuard(level = AuthLevel.USER_ONLY)
public LentExtensionPaginationDto getMyLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyLentExtension: {}", userSessionDto.getName());
return userFacadeService.getMyLentExtension(userSessionDto);
}

@GetMapping("/me/lent-extensions/active")
@AuthGuard(level = AuthLevel.USER_ONLY)
public LentExtensionPaginationDto getMyActiveLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyActiveLentExtension: {}", userSessionDto.getName());
return userFacadeService.getMyActiveLentExtension(userSessionDto);
}

@GetMapping("/me/lent-extensions/use")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void useLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called useLentExtension");
userFacadeService.useLentExtension(userSessionDto);
}

// @GetMapping("/me/lent-extensions/test")
// public void testIssueLentExtension() {
// log.info("Called testIssueLentExtension");
// lentExtensionService.issueLentExtension();
//// lentExtensionService.deleteLentExtension();
// }
private final UserFacadeService userFacadeService;

/**
* 현재 로그인한 유저의 프로필을 반환합니다. 전체 사물함 뷰에서 본인의 사물함을 표시하기 위해 사용됩니다.
*
* @param userSessionDto 현재 로그인한 유저의 세션 정보
* @return {@link MyProfileResponseDto} 현재 로그인한 유저의 프로필
*/
@GetMapping("/me")
@AuthGuard(level = AuthLevel.USER_ONLY)
public MyProfileResponseDto getMyProfile(@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyProfile: {}", userSessionDto.getName());
return userFacadeService.getMyProfile(userSessionDto);
}

@GetMapping("/me/lent-extensions")
@AuthGuard(level = AuthLevel.USER_ONLY)
public LentExtensionPaginationDto getMyLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyLentExtension: {}", userSessionDto.getName());
return userFacadeService.getMyLentExtension(userSessionDto);
}

@GetMapping("/me/lent-extensions/active")
@AuthGuard(level = AuthLevel.USER_ONLY)
public LentExtensionPaginationDto getMyActiveLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyActiveLentExtension: {}", userSessionDto.getName());
return userFacadeService.getMyActiveLentExtension(userSessionDto);
}

@GetMapping("/me/lent-extensions/use")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void useLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called useLentExtension");
userFacadeService.useLentExtension(userSessionDto);
}
}

0 comments on commit 66d0014

Please sign in to comment.