Skip to content

Commit 53c02bc

Browse files
authored
Merge pull request #46 from TeamMemeSphere/main
#11 Feat: 알림 등록, 등록한 알림 조회 API
2 parents 078d09a + 3ffef13 commit 53c02bc

File tree

12 files changed

+193
-68
lines changed

12 files changed

+193
-68
lines changed

src/main/java/com/memesphere/domain/memecoin/repository/MemeCoinRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.springframework.data.repository.query.Param;
1010
import org.springframework.lang.NonNull;
1111

12+
import java.util.Optional;
13+
1214
public interface MemeCoinRepository extends JpaRepository<MemeCoin, Long> {
1315
@Query("SELECT m FROM MemeCoin m " +
1416
"JOIN m.chartDataList c " +
@@ -28,4 +30,9 @@ Page<MemeCoin> findWithLatestChartDataSorted(
2830
@EntityGraph(attributePaths = {"chartData"})
2931
@NonNull
3032
Page<MemeCoin> findAll(@NonNull Pageable pageable);
33+
34+
@EntityGraph(attributePaths = {"chartData"})
35+
Page<MemeCoin> findByNameContainingIgnoreCaseOrSymbolContainingIgnoreCaseOrKeywordsContainingIgnoreCase(String name, String symbol, String keyword, Pageable pageable);
36+
37+
Optional<MemeCoin> findByName(String name);
3138
}

src/main/java/com/memesphere/domain/notification/controller/CoinNotificationController.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.memesphere.domain.notification.controller;
22

33

4-
import com.memesphere.domain.notification.dto.NotificationDTO;
5-
import com.memesphere.domain.notification.service.CoinNotificationService;
64
import com.memesphere.global.apipayload.ApiResponse;
5+
import com.memesphere.domain.notification.dto.request.NotificationRequest;
6+
import com.memesphere.domain.notification.dto.response.NotificationListResponse;
7+
import com.memesphere.domain.notification.dto.response.NotificationResponse;
8+
import com.memesphere.domain.notification.service.CoinNotificationService;
79
import io.swagger.v3.oas.annotations.Operation;
810
import io.swagger.v3.oas.annotations.tags.Tag;
911
import lombok.RequiredArgsConstructor;
1012
import org.springframework.web.bind.annotation.*;
1113

1214
@Tag(name="알림", description = "알림 관련 API")
1315
@RestController
14-
@RequestMapping("/notifications")
16+
@RequestMapping("/notification")
1517
@RequiredArgsConstructor
1618
public class CoinNotificationController {
1719

1820
final private CoinNotificationService coinNotificationService;
1921

20-
@GetMapping
21-
@Operation(summary = "등록한 알림 조회 API",
22+
@GetMapping("/list")
23+
@Operation(summary = "등록한 알림 리스트 조회 API",
2224
description = """
2325
사용자가 등록해 놓은 알림 리스트를 보여줍니다. \n
2426
@@ -35,11 +37,11 @@ public class CoinNotificationController {
3537
- "is_rising": 상승(true) 또는 하락(false)
3638
- "is_on": 알림 on(true) 또는 off(false)
3739
```""")
38-
public ApiResponse<NotificationDTO.NotificationListResponse> getNotificationList() {
40+
public ApiResponse<NotificationListResponse> getNotificationList() {
3941
return ApiResponse.onSuccess(coinNotificationService.findNotificationList());
4042
}
4143

42-
@PostMapping
44+
@PostMapping("/enroll")
4345
@Operation(summary = "알림 등록 API",
4446
description = """
4547
사용자가 직접 필드를 입력하여 알림을 등록합니다. \n
@@ -63,7 +65,7 @@ public ApiResponse<NotificationDTO.NotificationListResponse> getNotificationList
6365
- "is_rising": 상승(true) 또는 하락(false)
6466
- "is_on": 알림 on(true) 또는 off(false)
6567
```""")
66-
public ApiResponse<NotificationDTO.NoticeForm> postNotification(@RequestBody NotificationDTO.NotificationRequest request) {
68+
public ApiResponse<NotificationResponse> postNotification(@RequestBody NotificationRequest request) {
6769
return ApiResponse.onSuccess(coinNotificationService.addNotification(request));
6870
}
6971

@@ -81,7 +83,7 @@ public ApiResponse<NotificationDTO.NoticeForm> postNotification(@RequestBody Not
8183
```
8284
알림 등록 API 응답 형식과 동일
8385
```""")
84-
public ApiResponse<NotificationDTO.NoticeForm> updateNotificationStatus(@PathVariable("notification-id") Long id) {
86+
public ApiResponse<NotificationResponse> updateNotificationStatus(@PathVariable("notification-id") Long id) {
8587
return ApiResponse.onSuccess(coinNotificationService.modifyNotification(id));
8688
}
8789

@@ -99,7 +101,7 @@ public ApiResponse<NotificationDTO.NoticeForm> updateNotificationStatus(@PathVar
99101
```
100102
등록한 알림 조회 API 응답 형식과 동일
101103
```""")
102-
public ApiResponse<NotificationDTO.NotificationListResponse> deleteNotification(@PathVariable("notification-id") Long id) {
104+
public ApiResponse<NotificationListResponse> deleteNotification(@PathVariable("notification-id") Long id) {
103105
return ApiResponse.onSuccess(coinNotificationService.removeNotification(id));
104106
}
105107
}

src/main/java/com/memesphere/domain/notification/controller/PushNotificationController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.memesphere.domain.notification.controller;
22

3-
import com.memesphere.domain.notification.dto.NotificationDTO;
43
import com.memesphere.global.apipayload.ApiResponse;
4+
import com.memesphere.domain.notification.dto.response.NotificationListResponse;
55
import io.swagger.v3.oas.annotations.Operation;
66
import io.swagger.v3.oas.annotations.tags.Tag;
77
import lombok.RequiredArgsConstructor;
@@ -23,7 +23,7 @@ public class PushNotificationController {
2323
읽음 여부를 확인해야 한다면 푸시 알림 테이블을 만드는게 맞을까요? \n
2424
푸시 알림 기능이 어떻게 작동되는지 몰라서 컨트롤러만 두었습니다. \n
2525
응답 형식은 일단 무시해주세요.""")
26-
public ApiResponse<NotificationDTO.NotificationListResponse> getPushList() {
26+
public ApiResponse<NotificationListResponse> getPushList() {
2727
return ApiResponse.onSuccess(null);
2828
}
2929

@@ -33,7 +33,7 @@ public ApiResponse<NotificationDTO.NotificationListResponse> getPushList() {
3333
푸시된 알림 리스트를 삭제? 확인?합니다. \n
3434
이 기능은 푸시 알림 기능을 더 정의한 후에 수정해야 할 듯 보입니다.
3535
""")
36-
public ApiResponse<NotificationDTO.NotificationListResponse> deletePushNotification() {
36+
public ApiResponse<NotificationListResponse> deletePushNotification() {
3737
return ApiResponse.onSuccess(null);
3838
}
3939
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.memesphere.domain.notification.converter;
2+
3+
import com.memesphere.domain.memecoin.entity.MemeCoin;
4+
import com.memesphere.domain.notification.dto.request.NotificationRequest;
5+
import com.memesphere.domain.notification.dto.response.NotificationListResponse;
6+
import com.memesphere.domain.notification.dto.response.NotificationResponse;
7+
import com.memesphere.domain.notification.entity.Notification;
8+
9+
import java.util.List;
10+
11+
public class NotificationConverter {
12+
13+
public static Notification toNotification(NotificationRequest notificationRequest, MemeCoin memeCoin) {
14+
return Notification.builder()
15+
.memeCoin(memeCoin)
16+
.volatility(notificationRequest.getVolatility())
17+
.stTime(notificationRequest.getStTime())
18+
.isRising(notificationRequest.getIsRising())
19+
.build();
20+
}
21+
22+
public static NotificationResponse toNotificationCreateResponse(Notification notification, MemeCoin memeCoin) {
23+
return NotificationResponse.builder()
24+
.notificationId(notification.getId())
25+
.name(memeCoin.getName())
26+
.symbol(memeCoin.getSymbol())
27+
.volatility(notification.getVolatility())
28+
.stTime(notification.getStTime())
29+
.isRising(notification.getIsRising())
30+
.build();
31+
}
32+
33+
public static NotificationListResponse toNotificationListResponse(List<NotificationResponse> notificationResponses) {
34+
return NotificationListResponse.builder()
35+
.notificationList(notificationResponses)
36+
.build();
37+
}
38+
}

src/main/java/com/memesphere/domain/notification/dto/NotificationDTO.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.memesphere.domain.notification.dto.request;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@Builder
9+
public class NotificationRequest {
10+
11+
@Schema(description = "코인 이름", example = "DOGE")
12+
private String name;
13+
14+
@Schema(description = "코인 심볼", example = "DOGE/USDT")
15+
private String symbol;
16+
17+
@Schema(description = "변동성", example = "5")
18+
private Integer volatility;
19+
20+
@Schema(description = "기준 시간", example = "10")
21+
private Integer stTime;
22+
23+
@Schema(description = "상승 또는 하락", example = "True")
24+
private Boolean isRising;
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.memesphere.domain.notification.dto.response;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Builder
10+
public class NotificationListResponse {
11+
12+
private List<NotificationResponse> notificationList;
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.memesphere.domain.notification.dto.response;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@Builder
9+
public class NotificationResponse {
10+
11+
@Schema(description = "알림 아이디", example = "1")
12+
private Long notificationId;
13+
14+
@Schema(description = "코인 이름", example = "DOGE")
15+
private String name;
16+
17+
@Schema(description = "코인 심볼", example = "DOGE/USDT")
18+
private String symbol;
19+
20+
@Schema(description = "변동성", example = "5")
21+
private Integer volatility;
22+
23+
@Schema(description = "기준 시간", example = "10")
24+
private Integer stTime;
25+
26+
@Schema(description = "상승 또는 하락", example = "True")
27+
private Boolean isRising;
28+
29+
@Schema(description = "알림 켜기/끄기", example = "True")
30+
private Boolean isOn;
31+
}

src/main/java/com/memesphere/domain/notification/entity/Notification.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public class Notification extends BaseEntity {
2323
private Long id;
2424

2525
@Column(nullable = false)
26-
private Integer volatility;
26+
private Integer volatility; // 변동성
2727

2828
@Column(nullable = false)
29-
private Integer st_time;
29+
private Integer stTime; // 기준 시간
3030

3131
@Column(nullable = false)
32-
private Boolean is_rising;
32+
private Boolean isRising; // 상승 또는 하락
3333

34-
@Column(nullable = false)
35-
private Boolean is_on;
34+
@Column(columnDefinition = "BOOLEAN DEFAULT true")
35+
private Boolean isOn; // 알람 on/off
3636

3737
@ManyToOne(fetch=FetchType.LAZY)
3838
@JoinColumn(name="user_id")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.memesphere.domain.notification.repository;
2+
3+
import com.memesphere.domain.notification.entity.Notification;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface NotificationRepository extends JpaRepository<Notification, Long> {
7+
}

0 commit comments

Comments
 (0)