-
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.
* [feat] : #183 캘린더 테이블 카테고리 enum 추가 * [feat] : #183 엔티티 설계 * [feat] : #183 일정 조회 구현 * [fix] : #183 일정추가 및 쿼리DSL 설정 확인 * [fix] : 로컬로 옮기기위한 커밋 * [fix]: #183-calendar 예외처리 불분명 * [fix] : exception 핸들러 하위 에러 처리 오류 해결 * [fix] : 레전드 import 문제 수정 * [fix] : ACL 적용 기능구현(미완성) 원격저장소를 위한 커밋 * [fix] : 권한 처리 * [fix] : 경고제거 * [fix] : 캘린더 조회 방법 수정 * [fix] #224 userId hidden * [fix] : 스테이징 * [fix] : 오타수정 * [fix] #229 질의응답게시판 이메일 발송 임시 * [feat] : 정렬 일자별 * [fix] : 수정,삭제 api 구현 * [feat] : 일정 단건 조회 * [feat] : 페이지네이션 적용 * [fix] #234 질의응답게시판 자치기구 계정 댓글 삭제 권한 추가 * [feat] #232 디스코드 웹훅, 봇 사용자수 알림 --------- Co-authored-by: jinseok <[email protected]> Co-authored-by: beakgugong <[email protected]>
- Loading branch information
1 parent
5c25b2a
commit 239aa01
Showing
42 changed files
with
999 additions
and
45 deletions.
There are no files selected for viewing
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
86 changes: 86 additions & 0 deletions
86
src/main/java/ussum/homepage/application/calendar/controller/CalendarController.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,86 @@ | ||
package ussum.homepage.application.calendar.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import ussum.homepage.application.calendar.service.CalendarService; | ||
import ussum.homepage.application.calendar.service.dto.request.CalendarEventRequest; | ||
import ussum.homepage.application.calendar.service.dto.request.CalendarEventUpdateRequest; | ||
import ussum.homepage.global.ApiResponse; | ||
import ussum.homepage.global.config.auth.UserId; | ||
|
||
@RestController | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RequestMapping("/board") | ||
public class CalendarController { | ||
private final CalendarService calendarService; | ||
|
||
@Operation(description = """ | ||
특정 달의 일정 조회하는 API입니다. boardCode에는 캘린더를 넣어서 보내면 됩니다. 그리고 form-data 년도월(YYYYMM), | ||
queryParam 형식으로 calendarCategory(필터링)에 카테고리를 담아 요청하시면 됩니다. | ||
그리고 일정 생성 권한이 allowedAuthorities이나 deniedAuthorities에 담김.""") | ||
@GetMapping("/{boardCode}") | ||
public ResponseEntity<ApiResponse<?>> getCalendarMonth(@Parameter(hidden = true) @UserId Long userId, | ||
@PathVariable(name = "boardCode") String boardCode, | ||
@RequestParam(value = "page", defaultValue = "0") int page, | ||
@RequestParam(value = "take") int take, | ||
@RequestParam(value = "date") String query, | ||
@RequestParam(value = "calendarCategory",required = false) String calendarCategory) { | ||
return ApiResponse.success(calendarService.getCalenders(userId,query, calendarCategory,boardCode, page, take)); | ||
} | ||
|
||
@Operation(description = """ | ||
일정 단건 조회하는 API입니다. calendarEventId에 조회하고 싶은 일정의 Id를 요청으로 넣어서 보내면 됩니다. | ||
수정, 삭제에 경우 응답으로 내려가는 isAuthor 필드가 false 이면 막아야 합니다.""") | ||
@GetMapping("/{boardCode}/{calendarEventId}") | ||
public ResponseEntity<ApiResponse<?>> getCalendarEvent(@Parameter(hidden = true) @UserId Long userId, | ||
@PathVariable(name = "boardCode") String boardCode, | ||
@PathVariable(name = "calendarEventId") Long calendarEventId){ | ||
return ApiResponse.success(calendarService.getCalendarEvent(userId,calendarEventId)); | ||
} | ||
|
||
@Operation(description = """ | ||
캘린더 일정 생성 API. body에 json 형식으로 CalendarEventRequest를 담아서 보내주시면 됩니다. | ||
카테고리, 시작일, 끝일, 제목까지 null값 없이 요청에 담아 보내주셔야 합니다. 총학생회 계정이나 아지위 계정이 아니라면 403번 에러가 내려갑니다. | ||
만약 일정을 성공적으로 생성했다면 생성된 게시물의 id와 title을 담은 객체가 응답됩니다.""") | ||
@PostMapping("/{boardCode}") | ||
public ResponseEntity<ApiResponse<?>> createCalendarEvent(@Parameter(hidden = true) @UserId Long userId, | ||
@PathVariable(name = "boardCode") String boardCode, | ||
@RequestBody CalendarEventRequest calendarEventRequest) { | ||
return ApiResponse.success(calendarService.createCalendarSchedule(userId, calendarEventRequest)); | ||
} | ||
|
||
@Operation(description = """ | ||
일정 수정하는 API입니다. | ||
""") | ||
@PatchMapping("/{boardCode}/{calendarEventId}") | ||
public ResponseEntity<ApiResponse<?>> editCalendarEvent(@Parameter(hidden = true) @UserId Long userId, | ||
@PathVariable(name = "boardCode") String boardCode, | ||
@PathVariable(name = "calendarEventId") Long calendarEventId, | ||
@RequestBody CalendarEventUpdateRequest calendarEventUpdateRequest) { | ||
return ApiResponse.success(calendarService.updateCalendarEvent(userId, calendarEventId, calendarEventUpdateRequest)); | ||
} | ||
|
||
@Operation(description = """ | ||
일정 삭제하는 API입니다. | ||
""") | ||
@DeleteMapping("/{boardCode}/{calendarEventId}") | ||
public ResponseEntity<ApiResponse<?>> deleteCalendarEvent(@Parameter(hidden = true) @UserId Long userId, | ||
@PathVariable(name = "boardCode") String boardCode, | ||
@PathVariable(name = "calendarEventId") Long calendarEventId){ | ||
calendarService.deleteCalendarEvent(boardCode,calendarEventId); | ||
return ApiResponse.success(null); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/ussum/homepage/application/calendar/service/CalendarService.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,105 @@ | ||
package ussum.homepage.application.calendar.service; | ||
|
||
import jakarta.transaction.Transactional; | ||
import java.time.YearMonth; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import ussum.homepage.application.calendar.service.dto.request.CalendarEventRequest; | ||
import ussum.homepage.application.calendar.service.dto.request.CalendarEventUpdateRequest; | ||
import ussum.homepage.application.calendar.service.dto.response.CalendarEventCreateResponse; | ||
import ussum.homepage.application.calendar.service.dto.response.CalendarEventDetailResponse; | ||
import ussum.homepage.application.calendar.service.dto.response.CalendarEventList; | ||
import ussum.homepage.application.calendar.service.dto.response.CalendarEventResponse; | ||
import ussum.homepage.domain.calender.CalendarEvent; | ||
import ussum.homepage.domain.calender.service.CalendarEventAppender; | ||
import ussum.homepage.domain.calender.service.CalendarEventModifier; | ||
import ussum.homepage.domain.calender.service.CalendarEventReader; | ||
import ussum.homepage.domain.member.Member; | ||
import ussum.homepage.domain.member.service.MemberReader; | ||
import ussum.homepage.domain.post.Board; | ||
import ussum.homepage.domain.post.service.BoardReader; | ||
import ussum.homepage.domain.user.User; | ||
import ussum.homepage.domain.user.service.UserReader; | ||
import ussum.homepage.global.common.PageInfo; | ||
import ussum.homepage.global.error.exception.GeneralException; | ||
import ussum.homepage.global.error.exception.InvalidValueException; | ||
import ussum.homepage.global.error.status.ErrorStatus; | ||
import ussum.homepage.infra.jpa.calendar_event.entity.CalendarCategory; | ||
import ussum.homepage.infra.utils.DateUtils; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CalendarService { | ||
|
||
private final MemberReader memberReader; | ||
private final UserReader userReader; | ||
private final CalendarEventReader calenderReader; | ||
private final CalendarEventAppender calendarEventAppender; | ||
private final CalendarEventModifier calendarEventModifier; | ||
private final BoardReader boardReader; | ||
private final CalendarEventReader calendarEventReader; | ||
|
||
@Transactional | ||
public CalendarEventList<?> getCalenders(Long userId, String query, String category, String boardCode, int page, int take) { | ||
Board board = boardReader.getBoardWithBoardCode(boardCode); | ||
Pageable pageable = PageInfo.of(page,take); | ||
|
||
Page<CalendarEvent> calendarEventList = null; | ||
|
||
if (!board.getName().equals(boardCode)) { | ||
throw new InvalidValueException(ErrorStatus.INVALID_BOARDCODE); | ||
} | ||
|
||
YearMonth yearMonth = DateUtils.parseYearMonthFromString(query); | ||
List<CalendarEventResponse> calendarEventResponseList = null; | ||
|
||
if (category == null) { | ||
calendarEventList = calendarEventReader.getCalenderEventsByYearMonthWithoutCategory(yearMonth,pageable); | ||
}else{ | ||
CalendarCategory calendarCategory = CalendarCategory.getEnumCategoryCodeFromStringCategoryCode(category); | ||
calendarEventList = calendarEventReader.getCalenderEventsByYearMonthWithCategory(yearMonth,calendarCategory,pageable); | ||
} | ||
|
||
calendarEventResponseList = calendarEventList.stream() | ||
.map(CalendarEventResponse::of) | ||
.toList(); | ||
|
||
PageInfo pageInfo = PageInfo.of(calendarEventList); | ||
return CalendarEventList.of(calendarEventResponseList, pageInfo); | ||
} | ||
|
||
@Transactional | ||
public CalendarEventDetailResponse getCalendarEvent(Long userId, Long eventId) { | ||
CalendarEvent calendarEvent = calendarEventReader.getCalendarEventByCalendarEventId(eventId); | ||
boolean isAuthor = calendarEvent.getCreateBy().equals(userId); | ||
|
||
return CalendarEventDetailResponse.of(calendarEvent, isAuthor); | ||
} | ||
|
||
@Transactional | ||
public CalendarEventCreateResponse createCalendarSchedule(Long userId, CalendarEventRequest requestDto) { | ||
User user = userReader.getUserWithId(userId); | ||
List<Member> member = memberReader.getMembersWithUserId(userId); | ||
if (member.stream().noneMatch(m -> m.getGroupId()==2 || m.getGroupId()==3)){ | ||
throw new GeneralException(ErrorStatus._FORBIDDEN); | ||
} | ||
|
||
CalendarEvent calendarEvent = requestDto.toDomain(userId); | ||
calendarEvent = calendarEventAppender.create(calendarEvent); | ||
return CalendarEventCreateResponse.of(calendarEvent.getId(), calendarEvent.getCalendarCategory()); | ||
} | ||
|
||
@Transactional | ||
public Long updateCalendarEvent(Long userId, Long calendarEventId, CalendarEventUpdateRequest requestDto) { | ||
CalendarEvent calendarEvent = calendarEventReader.getCalendarEventByCalendarEventId(calendarEventId); | ||
CalendarEvent newCalendarEvent = calendarEventModifier.updateCalendarEvent(requestDto.toDomain(calendarEvent)); | ||
return newCalendarEvent.getId(); | ||
} | ||
@Transactional | ||
public void deleteCalendarEvent(String boardCode,Long calendarEventId) { | ||
calendarEventModifier.deleteCalendarEvent(boardCode, calendarEventId); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...in/java/ussum/homepage/application/calendar/service/dto/request/CalendarEventRequest.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,26 @@ | ||
package ussum.homepage.application.calendar.service.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import ussum.homepage.domain.calender.CalendarEvent; | ||
|
||
@Builder | ||
public record CalendarEventRequest( | ||
String calendarCategory, | ||
String startDate, | ||
String endDate, | ||
String title | ||
){ | ||
public CalendarEvent toDomain(Long userId) { | ||
return CalendarEvent.of( | ||
null, | ||
title, | ||
userId, | ||
calendarCategory, | ||
startDate, | ||
endDate | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...a/ussum/homepage/application/calendar/service/dto/request/CalendarEventUpdateRequest.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,21 @@ | ||
package ussum.homepage.application.calendar.service.dto.request; | ||
|
||
import ussum.homepage.domain.calender.CalendarEvent; | ||
|
||
public record CalendarEventUpdateRequest( | ||
String calendarCategory, | ||
String startDate, | ||
String endDate, | ||
String title | ||
) { | ||
public CalendarEvent toDomain(CalendarEvent calendarEvent){ | ||
return CalendarEvent.of( | ||
calendarEvent.getId(), | ||
title, | ||
calendarEvent.getCreateBy(), | ||
calendarCategory, | ||
startDate, | ||
endDate | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ussum/homepage/application/calendar/service/dto/response/CalendarEventCreateResponse.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,18 @@ | ||
package ussum.homepage.application.calendar.service.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CalendarEventCreateResponse { | ||
private Long calendarEventId; | ||
private String title; | ||
|
||
public static CalendarEventCreateResponse of(Long id, String title){ | ||
return CalendarEventCreateResponse.builder() | ||
.calendarEventId(id) | ||
.title(title) | ||
.build(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ussum/homepage/application/calendar/service/dto/response/CalendarEventDetailResponse.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,27 @@ | ||
package ussum.homepage.application.calendar.service.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import ussum.homepage.domain.calender.CalendarEvent; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record CalendarEventDetailResponse ( | ||
Long calenderId, | ||
String calendarCategory, | ||
String title, | ||
String startDate, | ||
String endDate, | ||
boolean isAuthor | ||
|
||
) { | ||
public static CalendarEventDetailResponse of(CalendarEvent calendarEvent, boolean isAuthor) { | ||
return CalendarEventDetailResponse.builder() | ||
.calenderId(calendarEvent.getId()) | ||
.calendarCategory(calendarEvent.getCalendarCategory()) | ||
.title(calendarEvent.getTitle()) | ||
.startDate(calendarEvent.getStartDate()) | ||
.endDate(calendarEvent.getEndDate()) | ||
.isAuthor(isAuthor) | ||
.build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...main/java/ussum/homepage/application/calendar/service/dto/response/CalendarEventList.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,23 @@ | ||
package ussum.homepage.application.calendar.service.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
import ussum.homepage.global.common.PageInfo; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record CalendarEventList<T>( | ||
List<T> calendarEventResponseList, | ||
List<String> allowedAuthorities, | ||
List<String> deniedAuthorities, | ||
PageInfo pageInfo | ||
) { | ||
public static <T> CalendarEventList<T> of(List<T> calendarEventResponseList, PageInfo pageInfo) { | ||
return new CalendarEventList<>(calendarEventResponseList, List.of(), List.of(),pageInfo); | ||
} | ||
|
||
public CalendarEventList<T> validAuthorities(List<String> allowedAuthorities, List<String> deniedAuthorities) { | ||
return new CalendarEventList<>(this.calendarEventResponseList, allowedAuthorities, deniedAuthorities,this.pageInfo); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../java/ussum/homepage/application/calendar/service/dto/response/CalendarEventResponse.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,25 @@ | ||
package ussum.homepage.application.calendar.service.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import ussum.homepage.domain.calender.CalendarEvent; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record CalendarEventResponse( | ||
Long calenderId, | ||
String calendarCategory, | ||
String title, | ||
String startDate, | ||
String endDate | ||
|
||
) { | ||
public static CalendarEventResponse of(CalendarEvent calendarEvent) { | ||
return CalendarEventResponse.builder() | ||
.calenderId(calendarEvent.getId()) | ||
.calendarCategory(calendarEvent.getCalendarCategory()) | ||
.title(calendarEvent.getTitle()) | ||
.startDate(calendarEvent.getStartDate()) | ||
.endDate(calendarEvent.getEndDate()) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/ussum/homepage/application/notification/service/DiscordWebhookScheduler.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,16 @@ | ||
package ussum.homepage.application.notification.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DiscordWebhookScheduler { | ||
private final DiscordWebhookService discordWebhookService; | ||
|
||
@Scheduled(cron = "0 0 0 * * ?") | ||
public void sendUserStatisticsPeriodically() { | ||
discordWebhookService.sendToDiscord(); | ||
} | ||
} |
Oops, something went wrong.