Skip to content

Commit

Permalink
feat: /admin 권한이 필요한 요청을 수행하기 위한 adminController 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxklee committed Jul 21, 2024
1 parent a7e695d commit 877e423
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/main/java/leets/weeth/domain/admin/controller/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package leets.weeth.domain.admin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import leets.weeth.domain.event.attendanceEvent.dto.RequestAttendanceEvent;
import leets.weeth.domain.event.attendanceEvent.service.AttendanceEventService;
import leets.weeth.domain.event.dto.RequestEvent;
import leets.weeth.domain.event.service.EventService;
import leets.weeth.domain.notice.dto.RequestNotice;
import leets.weeth.domain.notice.service.NoticeService;
import leets.weeth.global.auth.annotation.CurrentUser;
import leets.weeth.global.common.error.exception.custom.BusinessLogicException;
import leets.weeth.global.common.response.CommonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static leets.weeth.domain.event.attendanceEvent.enums.ResponseMessage.ATTENDANCE_EVENT_CREATED_SUCCESS;
import static leets.weeth.domain.event.entity.enums.ResponseMessage.*;
import static leets.weeth.domain.notice.enums.ResponseMessage.*;

@Tag(name = "AdminController", description = "어드민 전용 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin")
public class AdminController {
private final EventService eventService;
private final NoticeService noticeService;
private final AttendanceEventService attendanceEventService;

/*
Event 관련 admin api
*/
@Operation(summary = "일정 생성", description = "관리자가 일정을 등록합니다.")
@PostMapping("/event/create")
public CommonResponse<String> createEvent(@RequestBody @Valid RequestEvent requestEvent,
@Parameter(hidden = true) @CurrentUser Long userId) throws BusinessLogicException {
eventService.createEvent(requestEvent, userId);
return CommonResponse.createSuccess(EVENT_CREATED_SUCCESS.getMessage());
}

@Operation(summary = "일정 수정", description = "관리자가 일정을 수정합니다.")
@PatchMapping("/event/{eventId}")
public CommonResponse<String> updateEvent(@PathVariable Long eventId, @RequestBody RequestEvent requestEvent,
@Parameter(hidden = true) @CurrentUser Long userId) throws BusinessLogicException {
eventService.updateEvent(eventId, requestEvent, userId);
return CommonResponse.createSuccess(EVENT_UPDATED_SUCCESS.getMessage());
}

@Operation(summary = "일정 삭제", description = "관리자가 일정을 삭제합니다.")
@DeleteMapping("/event/{eventId}")
public CommonResponse<String> deleteEvent(@PathVariable Long eventId,
@Parameter(hidden = true) @CurrentUser Long userId) throws BusinessLogicException {
eventService.deleteEvent(eventId, userId);
return CommonResponse.createSuccess(EVENT_DELETED_SUCCESS.getMessage());
}

/*
Notice 관련 admin api
*/
@Operation(summary = "공지 생성", description = "관리자가 공지사항을 등록합니다.")
@PostMapping("/notice/create")
public CommonResponse<String> createNotice(@RequestPart(value = "requestNotice") @Valid RequestNotice requestNotice,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@Parameter(hidden = true) @CurrentUser Long userId) throws BusinessLogicException {
noticeService.createNotice(requestNotice, files, userId);
return CommonResponse.createSuccess(NOTICE_CREATED_SUCCESS.getMessage());
}

@Operation(summary = "공지사항 수정", description = "관리자가 공지사항을 수정합니다.")
@PatchMapping("/notice/{noticeId}")
public CommonResponse<String> updateNotice(@RequestPart(value = "requestNotice") @Valid RequestNotice requestNotice,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@Parameter(hidden = true) @CurrentUser Long userId,
@PathVariable Long noticeId) throws BusinessLogicException {
noticeService.updateNotice(noticeId, requestNotice, files, userId);
return CommonResponse.createSuccess(NOTICE_UPDATED_SUCCESS.getMessage());
}

@Operation(summary = "공지사항 삭제", description = "관리자가 공지사항을 삭제합니다.")
@DeleteMapping("/notice/{noticeId}")
public CommonResponse<String> deleteNotice(@PathVariable Long noticeId, @Parameter(hidden = true) @CurrentUser Long userId) throws BusinessLogicException {
noticeService.deleteNotice(noticeId, userId);
return CommonResponse.createSuccess(NOTICE_DELETED_SUCCESS.getMessage());
}

/*
AttendanceEvent 관련 admin api
*/
@Operation(summary = "출석 일정 생성", description = "관리자가 출석일정을 등록합니다.")
@PostMapping("/attendanceEvent/create")
public CommonResponse<String> createAttendanceEvent(@RequestBody @Valid RequestAttendanceEvent requestAttendanceEvent,
@Parameter(hidden = true) @CurrentUser Long userId) {
attendanceEventService.createAttendanceEvent(requestAttendanceEvent, userId);
return CommonResponse.createSuccess(ATTENDANCE_EVENT_CREATED_SUCCESS.getMessage());
}
}

0 comments on commit 877e423

Please sign in to comment.