From 3ea3b78338751c8642c0847e865c442e4bd34f8f Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 03:59:49 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[FEAT]=20=EC=95=8C=EB=A6=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/common/ResponseMessage.java | 6 ++- .../controller/web/AlarmController.java | 42 +++++++++++++++++++ .../operation/dto/alarm/AlarmRequestDTO.java | 6 ++- .../makers/operation/entity/alarm/Alarm.java | 13 ++++-- .../operation/repository/AlarmRepository.java | 7 ++++ .../operation/service/AlarmService.java | 7 ++++ .../operation/service/AlarmServiceImpl.java | 23 ++++++++++ 7 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java create mode 100644 src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java create mode 100644 src/main/java/org/sopt/makers/operation/service/AlarmService.java create mode 100644 src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java diff --git a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java index cdb62d00..1666d20f 100644 --- a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java +++ b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java @@ -32,7 +32,11 @@ public enum ResponseMessage { SUCCESS_GET_LECTURE("세션 상세 조회 성공"), SUCCESS_START_ATTENDANCE("출석 시작 성공"), SUCCESS_GET_MEMBERS("유저 리스트 조회 성공"), - SUCCESS_DELETE_LECTURE("세션 삭제 성공"); + SUCCESS_DELETE_LECTURE("세션 삭제 성공"), + + /** alarm **/ + SUCCESS_CREATE_ALARM("알림 생성 성공") + ; private final String message; } diff --git a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java new file mode 100644 index 00000000..01a2e31c --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java @@ -0,0 +1,42 @@ +package org.sopt.makers.operation.controller.web; + +import static org.sopt.makers.operation.common.ResponseMessage.*; + +import java.net.URI; + +import org.sopt.makers.operation.common.ApiResponse; +import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; +import org.sopt.makers.operation.service.AlarmService; +import org.springframework.http.ResponseEntity; +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.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import io.swagger.annotations.ApiOperation; +import lombok.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/alarms") +public class AlarmController { + private final AlarmService alarmService; + + @ApiOperation("알림 생성") + @PostMapping + public ResponseEntity createAlarm(@RequestBody AlarmRequestDTO requestDTO) { + val alarmId = alarmService.createAlarm(requestDTO); + return ResponseEntity + .created(getURI(alarmId)) + .body(ApiResponse.success(SUCCESS_CREATE_ALARM.getMessage(), alarmId)); + } + + private URI getURI(Long alarmId) { + return ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{alarmId}") + .buildAndExpand(alarmId) + .toUri(); + } +} diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java index b0ce3e9a..dc6998a2 100644 --- a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java @@ -3,6 +3,7 @@ import java.util.List; import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Alarm; import org.sopt.makers.operation.entity.alarm.Attribute; import org.sopt.makers.operation.entity.alarm.Status; @@ -12,9 +13,12 @@ public record AlarmRequestDTO( String title, String content, String link, - boolean isActive, + Boolean isActive, Part part, List targetList, Status status ) { + public Alarm toEntity() { + return new Alarm(this); + } } diff --git a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java index 7777c18d..761bf2d9 100644 --- a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java +++ b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java @@ -1,5 +1,6 @@ package org.sopt.makers.operation.entity.alarm; +import static java.util.Objects.*; import static javax.persistence.EnumType.*; import static javax.persistence.GenerationType.*; @@ -43,7 +44,7 @@ public class Alarm extends BaseEntity { private String link; - private boolean isActive; + private Boolean isActive; @Enumerated(value = STRING) private Part part; @@ -64,8 +65,12 @@ public Alarm(AlarmRequestDTO requestDTO) { this.title = requestDTO.title(); this.content = requestDTO.content(); this.link = requestDTO.link(); - this.isActive = requestDTO.isActive(); - this.part = requestDTO.part(); - this.targetList = requestDTO.targetList(); + if (nonNull(requestDTO.isActive()) && nonNull(requestDTO.part())) { + this.isActive = requestDTO.isActive(); + this.part = requestDTO.part(); + } + if (nonNull(requestDTO.targetList())) { + this.targetList = requestDTO.targetList(); + } } } diff --git a/src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java b/src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java new file mode 100644 index 00000000..9713ded3 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java @@ -0,0 +1,7 @@ +package org.sopt.makers.operation.repository; + +import org.sopt.makers.operation.entity.alarm.Alarm; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AlarmRepository extends JpaRepository { +} diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmService.java b/src/main/java/org/sopt/makers/operation/service/AlarmService.java new file mode 100644 index 00000000..95c394a5 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/service/AlarmService.java @@ -0,0 +1,7 @@ +package org.sopt.makers.operation.service; + +import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; + +public interface AlarmService { + Long createAlarm(AlarmRequestDTO requestDTO); +} diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java new file mode 100644 index 00000000..4a27c78b --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java @@ -0,0 +1,23 @@ +package org.sopt.makers.operation.service; + +import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; +import org.sopt.makers.operation.entity.alarm.Alarm; +import org.sopt.makers.operation.repository.AlarmRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import lombok.*; + +@Service +@RequiredArgsConstructor +public class AlarmServiceImpl implements AlarmService { + private final AlarmRepository alarmRepository; + + @Override + @Transactional + public Long createAlarm(AlarmRequestDTO requestDTO) { + val alarmEntity = requestDTO.toEntity(); + val savedAlarm = alarmRepository.save(alarmEntity); + return savedAlarm.getId(); + } +} From 5bf894f96c8342f39ff06012f0cdf907f94e9f4f Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 04:27:01 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[FEAT]=20=EC=95=8C=EB=A6=BC=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/common/ResponseMessage.java | 3 +- .../controller/web/AlarmController.java | 16 ++++++ .../dto/alarm/AlarmsResponseDTO.java | 40 ++++++++++++++ .../alarm/AlarmCustomRepository.java | 12 +++++ .../{ => alarm}/AlarmRepository.java | 4 +- .../repository/alarm/AlarmRepositoryImpl.java | 54 +++++++++++++++++++ .../operation/service/AlarmService.java | 5 ++ .../operation/service/AlarmServiceImpl.java | 13 ++++- 8 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java create mode 100644 src/main/java/org/sopt/makers/operation/repository/alarm/AlarmCustomRepository.java rename src/main/java/org/sopt/makers/operation/repository/{ => alarm}/AlarmRepository.java (69%) create mode 100644 src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java diff --git a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java index 1666d20f..d69d2385 100644 --- a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java +++ b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java @@ -35,7 +35,8 @@ public enum ResponseMessage { SUCCESS_DELETE_LECTURE("세션 삭제 성공"), /** alarm **/ - SUCCESS_CREATE_ALARM("알림 생성 성공") + SUCCESS_CREATE_ALARM("알림 생성 성공"), + SUCCESS_GET_ALARMS("알림 리스트 조회 성공") ; private final String message; diff --git a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java index 01a2e31c..daab4342 100644 --- a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java +++ b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java @@ -6,11 +6,16 @@ import org.sopt.makers.operation.common.ApiResponse; import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; +import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Status; import org.sopt.makers.operation.service.AlarmService; +import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; 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 org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -32,6 +37,17 @@ public ResponseEntity createAlarm(@RequestBody AlarmRequestDTO requ .body(ApiResponse.success(SUCCESS_CREATE_ALARM.getMessage(), alarmId)); } + @GetMapping + public ResponseEntity getAlarms( + @RequestParam Integer generation, + @RequestParam Part part, + @RequestParam Status status, + Pageable pageable + ) { + val response = alarmService.getAlarms(generation, part, status, pageable); + return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_ALARMS.getMessage(), response)); + } + private URI getURI(Long alarmId) { return ServletUriComponentsBuilder .fromCurrentRequest() diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java new file mode 100644 index 00000000..1428db09 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java @@ -0,0 +1,40 @@ +package org.sopt.makers.operation.dto.alarm; + +import static java.util.Objects.*; + +import java.util.List; + +import org.sopt.makers.operation.entity.alarm.Alarm; + +import lombok.Builder; + +public record AlarmsResponseDTO( + List alarms +) { + public static AlarmsResponseDTO of(List alarms) { + return new AlarmsResponseDTO(alarms.stream().map(AlarmVO::of).toList()); + } + + @Builder + record AlarmVO( + Long alarmId, + String part, + String attribute, + String title, + String content, + String sendAt, + String status + ) { + static AlarmVO of(Alarm alarm) { + return AlarmVO.builder() + .alarmId(alarm.getId()) + .part(alarm.getPart().getName()) + .attribute(alarm.getAttribute().getName()) + .title(alarm.getTitle()) + .content(alarm.getContent()) + .sendAt(nonNull(alarm.getSendAt()) ? alarm.getSendAt().toString() : null) + .status(alarm.getStatus().getName()) + .build(); + } + } +} diff --git a/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmCustomRepository.java b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmCustomRepository.java new file mode 100644 index 00000000..0ecd4e53 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmCustomRepository.java @@ -0,0 +1,12 @@ +package org.sopt.makers.operation.repository.alarm; + +import java.util.List; + +import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Alarm; +import org.sopt.makers.operation.entity.alarm.Status; +import org.springframework.data.domain.Pageable; + +public interface AlarmCustomRepository { + List getAlarms(Integer generation, Part part, Status status, Pageable pageable); +} diff --git a/src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepository.java similarity index 69% rename from src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java rename to src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepository.java index 9713ded3..9ca5e9d4 100644 --- a/src/main/java/org/sopt/makers/operation/repository/AlarmRepository.java +++ b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepository.java @@ -1,7 +1,7 @@ -package org.sopt.makers.operation.repository; +package org.sopt.makers.operation.repository.alarm; import org.sopt.makers.operation.entity.alarm.Alarm; import org.springframework.data.jpa.repository.JpaRepository; -public interface AlarmRepository extends JpaRepository { +public interface AlarmRepository extends JpaRepository, AlarmCustomRepository { } diff --git a/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java new file mode 100644 index 00000000..8c382f36 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java @@ -0,0 +1,54 @@ +package org.sopt.makers.operation.repository.alarm; + +import static java.util.Objects.*; +import static org.sopt.makers.operation.entity.Part.*; +import static org.sopt.makers.operation.entity.QMember.*; +import static org.sopt.makers.operation.entity.alarm.QAlarm.*; + +import java.util.List; +import java.util.Objects; + +import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Alarm; +import org.sopt.makers.operation.entity.alarm.QAlarm; +import org.sopt.makers.operation.entity.alarm.Status; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class AlarmRepositoryImpl implements AlarmCustomRepository { + private final JPAQueryFactory queryFactory; + + @Override + public List getAlarms(Integer generation, Part part, Status status, Pageable pageable) { + return queryFactory + .selectFrom(alarm) + .where( + generationEq(generation), + partEq(part), + statusEq(status) + ) + .orderBy(alarm.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + } + + private BooleanExpression generationEq(Integer generation) { + return nonNull(generation) ? alarm.generation.eq(generation) : null; + } + + private BooleanExpression partEq(Part part) { + return (nonNull(part) && !part.equals(ALL)) ? alarm.part.eq(part) : null; + } + + private BooleanExpression statusEq(Status status) { + return nonNull(status) ? alarm.status.eq(status) : null; + } +} diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmService.java b/src/main/java/org/sopt/makers/operation/service/AlarmService.java index 95c394a5..74a0584b 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmService.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmService.java @@ -1,7 +1,12 @@ package org.sopt.makers.operation.service; import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; +import org.sopt.makers.operation.dto.alarm.AlarmsResponseDTO; +import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Status; +import org.springframework.data.domain.Pageable; public interface AlarmService { Long createAlarm(AlarmRequestDTO requestDTO); + AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, Pageable pageable); } diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java index 4a27c78b..5da42305 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java @@ -1,8 +1,11 @@ package org.sopt.makers.operation.service; import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; -import org.sopt.makers.operation.entity.alarm.Alarm; -import org.sopt.makers.operation.repository.AlarmRepository; +import org.sopt.makers.operation.dto.alarm.AlarmsResponseDTO; +import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Status; +import org.sopt.makers.operation.repository.alarm.AlarmRepository; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,4 +23,10 @@ public Long createAlarm(AlarmRequestDTO requestDTO) { val savedAlarm = alarmRepository.save(alarmEntity); return savedAlarm.getId(); } + + @Override + public AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, Pageable pageable) { + val alarms = alarmRepository.getAlarms(generation, part, status, pageable); + return AlarmsResponseDTO.of(alarms); + } } From ca2a9fa47340452d8d74024253e81dc3896329fc Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 04:34:56 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[FEAT]=20=EC=95=8C=EB=A6=BC=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/common/ExceptionMessage.java | 3 +- .../operation/common/ResponseMessage.java | 3 +- .../controller/web/AlarmController.java | 16 ++++++++-- .../operation/dto/alarm/AlarmResponseDTO.java | 30 +++++++++++++++++++ .../operation/service/AlarmService.java | 3 ++ .../operation/service/AlarmServiceImpl.java | 12 ++++++++ 6 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java diff --git a/src/main/java/org/sopt/makers/operation/common/ExceptionMessage.java b/src/main/java/org/sopt/makers/operation/common/ExceptionMessage.java index 89bee636..dce46c71 100644 --- a/src/main/java/org/sopt/makers/operation/common/ExceptionMessage.java +++ b/src/main/java/org/sopt/makers/operation/common/ExceptionMessage.java @@ -26,7 +26,8 @@ public enum ExceptionMessage { END_LECTURE("이미 종료된 세션입니다."), NO_SUB_LECTURE_EQUAL_ROUND("해당 라운드와 일치하는 출석 세션이 없습니다."), FAULT_DATE_FORMATTER("잘못된 날짜 형식입니다."), - DUPLICATED_MEMBER("이미 존재하는 회원입니다."); + DUPLICATED_MEMBER("이미 존재하는 회원입니다."), + INVALID_ALARM("존재하지 않는 알림입니다."); private final String name; } diff --git a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java index d69d2385..497e72d9 100644 --- a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java +++ b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java @@ -36,7 +36,8 @@ public enum ResponseMessage { /** alarm **/ SUCCESS_CREATE_ALARM("알림 생성 성공"), - SUCCESS_GET_ALARMS("알림 리스트 조회 성공") + SUCCESS_GET_ALARMS("알림 리스트 조회 성공"), + SUCCESS_GET_ALARM("알림 상세 조회 성공") ; private final String message; diff --git a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java index daab4342..5e5bedfc 100644 --- a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java +++ b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java @@ -1,5 +1,6 @@ package org.sopt.makers.operation.controller.web; +import static org.sopt.makers.operation.common.ApiResponse.*; import static org.sopt.makers.operation.common.ResponseMessage.*; import java.net.URI; @@ -12,6 +13,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; 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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.*; @@ -34,9 +37,10 @@ public ResponseEntity createAlarm(@RequestBody AlarmRequestDTO requ val alarmId = alarmService.createAlarm(requestDTO); return ResponseEntity .created(getURI(alarmId)) - .body(ApiResponse.success(SUCCESS_CREATE_ALARM.getMessage(), alarmId)); + .body(success(SUCCESS_CREATE_ALARM.getMessage(), alarmId)); } + @ApiOperation("알림 리스트 조회") @GetMapping public ResponseEntity getAlarms( @RequestParam Integer generation, @@ -45,9 +49,17 @@ public ResponseEntity getAlarms( Pageable pageable ) { val response = alarmService.getAlarms(generation, part, status, pageable); - return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_ALARMS.getMessage(), response)); + return ResponseEntity.ok(success(SUCCESS_GET_ALARMS.getMessage(), response)); } + @ApiOperation("알림 상세 조회") + @GetMapping("/{alarmId}") + public ResponseEntity getAlarm(@PathVariable Long alarmId) { + val response = alarmService.getAlarm(alarmId); + return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_ALARM.getMessage(), response)); + } + + private URI getURI(Long alarmId) { return ServletUriComponentsBuilder .fromCurrentRequest() diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java new file mode 100644 index 00000000..95015f82 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java @@ -0,0 +1,30 @@ +package org.sopt.makers.operation.dto.alarm; + +import org.sopt.makers.operation.entity.alarm.Alarm; + +import lombok.Builder; + +@Builder +public record AlarmResponseDTO( + String attribute, + String part, + Boolean isActive, + String title, + String content, + String link, + String createdAt, + String sendAt +) { + public static AlarmResponseDTO of(Alarm alarm) { + return AlarmResponseDTO.builder() + .attribute(alarm.getAttribute().getName()) + .part(alarm.getPart().getName()) + .isActive(alarm.getIsActive()) + .title(alarm.getTitle()) + .content(alarm.getContent()) + .link(alarm.getLink()) + .createdAt(alarm.getCreatedDate().toString()) + .sendAt(alarm.getSendAt().toString()) + .build(); + } +} diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmService.java b/src/main/java/org/sopt/makers/operation/service/AlarmService.java index 74a0584b..db131d98 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmService.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmService.java @@ -1,6 +1,7 @@ package org.sopt.makers.operation.service; import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; +import org.sopt.makers.operation.dto.alarm.AlarmResponseDTO; import org.sopt.makers.operation.dto.alarm.AlarmsResponseDTO; import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.entity.alarm.Status; @@ -9,4 +10,6 @@ public interface AlarmService { Long createAlarm(AlarmRequestDTO requestDTO); AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, Pageable pageable); + + AlarmResponseDTO getAlarm(Long alarmId); } diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java index 5da42305..25f0729f 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java @@ -1,6 +1,11 @@ package org.sopt.makers.operation.service; +import static org.sopt.makers.operation.common.ExceptionMessage.*; + +import javax.persistence.EntityNotFoundException; + import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; +import org.sopt.makers.operation.dto.alarm.AlarmResponseDTO; import org.sopt.makers.operation.dto.alarm.AlarmsResponseDTO; import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.entity.alarm.Status; @@ -29,4 +34,11 @@ public AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, val alarms = alarmRepository.getAlarms(generation, part, status, pageable); return AlarmsResponseDTO.of(alarms); } + + @Override + public AlarmResponseDTO getAlarm(Long alarmId) { + val alarm = alarmRepository.findById(alarmId) + .orElseThrow(() -> new EntityNotFoundException(INVALID_ALARM.getName())); + return AlarmResponseDTO.of(alarm); + } } From 5da21503f40faece09d0ac8a72cdba4c9c584073 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 04:38:21 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[FEAT]=20=EC=95=8C=EB=A6=BC=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makers/operation/common/ResponseMessage.java | 3 ++- .../controller/web/AlarmController.java | 10 ++++++++-- .../makers/operation/service/AlarmService.java | 2 ++ .../operation/service/AlarmServiceImpl.java | 16 ++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java index 497e72d9..26d7391c 100644 --- a/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java +++ b/src/main/java/org/sopt/makers/operation/common/ResponseMessage.java @@ -37,7 +37,8 @@ public enum ResponseMessage { /** alarm **/ SUCCESS_CREATE_ALARM("알림 생성 성공"), SUCCESS_GET_ALARMS("알림 리스트 조회 성공"), - SUCCESS_GET_ALARM("알림 상세 조회 성공") + SUCCESS_GET_ALARM("알림 상세 조회 성공"), + SUCCESS_DELETE_ALARM("알림 삭제 성공") ; private final String message; diff --git a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java index 5e5bedfc..d015a511 100644 --- a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java +++ b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java @@ -12,6 +12,7 @@ import org.sopt.makers.operation.service.AlarmService; import org.springframework.data.domain.Pageable; 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.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -21,7 +22,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; -import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.*; @@ -56,9 +56,15 @@ public ResponseEntity getAlarms( @GetMapping("/{alarmId}") public ResponseEntity getAlarm(@PathVariable Long alarmId) { val response = alarmService.getAlarm(alarmId); - return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_ALARM.getMessage(), response)); + return ResponseEntity.ok(success(SUCCESS_GET_ALARM.getMessage(), response)); } + @ApiOperation("알림 삭제") + @DeleteMapping("/{alarmId}") + public ResponseEntity deleteAlarm(@PathVariable Long alarmId) { + alarmService.deleteAlarm(alarmId); + return ResponseEntity.ok(success(SUCCESS_DELETE_ALARM.getMessage())); + } private URI getURI(Long alarmId) { return ServletUriComponentsBuilder diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmService.java b/src/main/java/org/sopt/makers/operation/service/AlarmService.java index db131d98..72bfae7e 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmService.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmService.java @@ -12,4 +12,6 @@ public interface AlarmService { AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, Pageable pageable); AlarmResponseDTO getAlarm(Long alarmId); + + void deleteAlarm(Long alarmId); } diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java index 25f0729f..c87ccbd5 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmServiceImpl.java @@ -8,6 +8,7 @@ import org.sopt.makers.operation.dto.alarm.AlarmResponseDTO; import org.sopt.makers.operation.dto.alarm.AlarmsResponseDTO; import org.sopt.makers.operation.entity.Part; +import org.sopt.makers.operation.entity.alarm.Alarm; import org.sopt.makers.operation.entity.alarm.Status; import org.sopt.makers.operation.repository.alarm.AlarmRepository; import org.springframework.data.domain.Pageable; @@ -37,8 +38,19 @@ public AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, @Override public AlarmResponseDTO getAlarm(Long alarmId) { - val alarm = alarmRepository.findById(alarmId) - .orElseThrow(() -> new EntityNotFoundException(INVALID_ALARM.getName())); + val alarm = findAlarm(alarmId); return AlarmResponseDTO.of(alarm); } + + @Override + @Transactional + public void deleteAlarm(Long alarmId) { + val alarm = findAlarm(alarmId); + alarmRepository.delete(alarm); + } + + private Alarm findAlarm(Long alarmId) { + return alarmRepository.findById(alarmId) + .orElseThrow(() -> new EntityNotFoundException(INVALID_ALARM.getName())); + } } From 0e6fb74aebfc2b883d6de85dc8dcbf133780aa83 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 04:39:24 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[CHORE]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EC=9E=84=ED=8F=AC=ED=84=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makers/operation/repository/alarm/AlarmRepositoryImpl.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java index 8c382f36..966b4b5f 100644 --- a/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java +++ b/src/main/java/org/sopt/makers/operation/repository/alarm/AlarmRepositoryImpl.java @@ -2,15 +2,12 @@ import static java.util.Objects.*; import static org.sopt.makers.operation.entity.Part.*; -import static org.sopt.makers.operation.entity.QMember.*; import static org.sopt.makers.operation.entity.alarm.QAlarm.*; import java.util.List; -import java.util.Objects; import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.entity.alarm.Alarm; -import org.sopt.makers.operation.entity.alarm.QAlarm; import org.sopt.makers.operation.entity.alarm.Status; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; From 52221b4ccf8c9a1fa0aaa61008d26fb91b1f6448 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 16:51:30 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[FIX]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makers/operation/controller/web/AlarmController.java | 6 +++--- .../sopt/makers/operation/dto/alarm/AlarmRequestDTO.java | 3 +-- .../sopt/makers/operation/dto/alarm/AlarmResponseDTO.java | 4 +++- .../sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java | 2 +- .../java/org/sopt/makers/operation/entity/alarm/Alarm.java | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java index d015a511..b731ae1d 100644 --- a/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java +++ b/src/main/java/org/sopt/makers/operation/controller/web/AlarmController.java @@ -43,9 +43,9 @@ public ResponseEntity createAlarm(@RequestBody AlarmRequestDTO requ @ApiOperation("알림 리스트 조회") @GetMapping public ResponseEntity getAlarms( - @RequestParam Integer generation, - @RequestParam Part part, - @RequestParam Status status, + @RequestParam(required = false) Integer generation, + @RequestParam(required = false) Part part, + @RequestParam(required = false) Status status, Pageable pageable ) { val response = alarmService.getAlarms(generation, part, status, pageable); diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java index dc6998a2..281b2f01 100644 --- a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java @@ -15,8 +15,7 @@ public record AlarmRequestDTO( String link, Boolean isActive, Part part, - List targetList, - Status status + List targetList ) { public Alarm toEntity() { return new Alarm(this); diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java index 95015f82..c7149f41 100644 --- a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmResponseDTO.java @@ -1,5 +1,7 @@ package org.sopt.makers.operation.dto.alarm; +import static java.util.Objects.*; + import org.sopt.makers.operation.entity.alarm.Alarm; import lombok.Builder; @@ -24,7 +26,7 @@ public static AlarmResponseDTO of(Alarm alarm) { .content(alarm.getContent()) .link(alarm.getLink()) .createdAt(alarm.getCreatedDate().toString()) - .sendAt(alarm.getSendAt().toString()) + .sendAt(nonNull(alarm.getSendAt()) ? alarm.getSendAt().toString() : null) .build(); } } diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java index 1428db09..31dd3110 100644 --- a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmsResponseDTO.java @@ -28,7 +28,7 @@ record AlarmVO( static AlarmVO of(Alarm alarm) { return AlarmVO.builder() .alarmId(alarm.getId()) - .part(alarm.getPart().getName()) + .part(nonNull(alarm.getPart()) ? alarm.getPart().getName() : null) .attribute(alarm.getAttribute().getName()) .title(alarm.getTitle()) .content(alarm.getContent()) diff --git a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java index 761bf2d9..1b6cbc28 100644 --- a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java +++ b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java @@ -72,5 +72,6 @@ public Alarm(AlarmRequestDTO requestDTO) { if (nonNull(requestDTO.targetList())) { this.targetList = requestDTO.targetList(); } + this.status = Status.BEFORE; } } From 62cafb719cdc9b43445e873babd216dc3f079e78 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 25 Oct 2023 16:58:27 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[DEL]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=95=9C=20=EC=A4=84=20=EB=9D=84=EC=96=B4=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/makers/operation/service/AlarmService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/sopt/makers/operation/service/AlarmService.java b/src/main/java/org/sopt/makers/operation/service/AlarmService.java index 72bfae7e..9574b811 100644 --- a/src/main/java/org/sopt/makers/operation/service/AlarmService.java +++ b/src/main/java/org/sopt/makers/operation/service/AlarmService.java @@ -10,8 +10,6 @@ public interface AlarmService { Long createAlarm(AlarmRequestDTO requestDTO); AlarmsResponseDTO getAlarms(Integer generation, Part part, Status status, Pageable pageable); - AlarmResponseDTO getAlarm(Long alarmId); - void deleteAlarm(Long alarmId); } From 6eff718672c7eceba9dc21e8b055772c4601e078 Mon Sep 17 00:00:00 2001 From: thguss Date: Thu, 26 Oct 2023 13:43:38 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[FIX]=20targetList=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java index 1b6cbc28..813a952c 100644 --- a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java +++ b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java @@ -51,7 +51,7 @@ public class Alarm extends BaseEntity { @Column(columnDefinition = "TEXT") @Convert(converter = LongListConverter.class) - private List targetList; + private List targetList; @Column(nullable = false) @Enumerated(value = STRING)