-
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.
- Loading branch information
1 parent
d1f0f10
commit 8dcd822
Showing
31 changed files
with
602 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies { | ||
implementation project(":app:domain:alarm-domain") | ||
implementation project(":app:api:common-api") | ||
} |
16 changes: 16 additions & 0 deletions
16
app/api/alarm-api/src/main/java/org/example/config/AlarmApiConfig.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 org.example.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@Import({ | ||
AlarmDomainConfig.class | ||
}) | ||
@ComponentScan(basePackages = "org.example") | ||
@RequiredArgsConstructor | ||
public class AlarmApiConfig { | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
app/api/alarm-api/src/main/java/org/example/controller/ShowAlarmController.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,68 @@ | ||
package org.example.controller; | ||
|
||
import jakarta.validation.constraints.Max; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.controller.dto.param.ShowAlarmPaginationApiParam; | ||
import org.example.controller.dto.response.ShowAlarmActivateApiResponse; | ||
import org.example.dto.response.CursorApiResponse; | ||
import org.example.dto.response.PaginationApiResponse; | ||
import org.example.service.ShowAlarmService; | ||
import org.example.service.dto.request.ShowAlarmsServiceRequest; | ||
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.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/show-alarm") | ||
public class ShowAlarmController { | ||
|
||
private final ShowAlarmService showAlarmService; | ||
|
||
@PostMapping | ||
public ResponseEntity<PaginationApiResponse<ShowAlarmPaginationApiParam>> getShowAlarms( | ||
@RequestParam(value = "fcmToken") String fcmToken, | ||
@RequestParam(value = "cursorId", required = false) UUID cursorId, | ||
@RequestParam(value = "size") @Max(value = 30, message = "조회하는 데이터의 최대 개수는 30입니다.") | ||
Integer size | ||
) { | ||
var response = showAlarmService.getShowAlarms( | ||
ShowAlarmsServiceRequest.builder() | ||
.fcmToken(fcmToken) | ||
.cursorId(cursorId) | ||
.size(size) | ||
.build() | ||
); | ||
var data = response.data().stream() | ||
.map(ShowAlarmPaginationApiParam::from) | ||
.toList(); | ||
|
||
CursorApiResponse cursor = Optional.ofNullable(CursorApiResponse.getLastElement(data)) | ||
.map(element -> CursorApiResponse.toCursorId(element.id())) | ||
.orElse(CursorApiResponse.noneCursor()); | ||
|
||
return ResponseEntity.ok( | ||
PaginationApiResponse.<ShowAlarmPaginationApiParam>builder() | ||
.hasNext(response.hasNext()) | ||
.data(data) | ||
.cursor(cursor) | ||
.build() | ||
); | ||
} | ||
|
||
@GetMapping("/checked") | ||
public ResponseEntity<ShowAlarmActivateApiResponse> getShowAlarmActivate( | ||
@RequestParam(value = "fcmToken") String fcmToken | ||
) { | ||
return ResponseEntity.ok( | ||
ShowAlarmActivateApiResponse.from( | ||
showAlarmService.getShowAlarmActivate(fcmToken) | ||
) | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...alarm-api/src/main/java/org/example/controller/dto/param/ShowAlarmPaginationApiParam.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,24 @@ | ||
package org.example.controller.dto.param; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
import lombok.Builder; | ||
import org.example.service.dto.param.ShowAlarmPaginationServiceParam; | ||
|
||
@Builder | ||
public record ShowAlarmPaginationApiParam( | ||
UUID id, | ||
String title, | ||
String content, | ||
LocalDateTime createAt | ||
) { | ||
|
||
public static ShowAlarmPaginationApiParam from(ShowAlarmPaginationServiceParam param) { | ||
return ShowAlarmPaginationApiParam.builder() | ||
.id(param.id()) | ||
.title(param.title()) | ||
.content(param.content()) | ||
.createAt(param.createAt()) | ||
.build(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...m-api/src/main/java/org/example/controller/dto/response/ShowAlarmActivateApiResponse.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,13 @@ | ||
package org.example.controller.dto.response; | ||
|
||
import org.example.service.dto.response.ShowAlarmActivateServiceResponse; | ||
|
||
public record ShowAlarmActivateApiResponse( | ||
boolean isActivate | ||
) { | ||
|
||
public static ShowAlarmActivateApiResponse from(ShowAlarmActivateServiceResponse response) { | ||
return new ShowAlarmActivateApiResponse(response.isActivate()); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
app/api/alarm-api/src/main/java/org/example/service/ShowAlarmService.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,39 @@ | ||
package org.example.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.dto.request.ShowAlarmsCheckedRequest; | ||
import org.example.dto.response.PaginationServiceResponse; | ||
import org.example.service.dto.param.ShowAlarmPaginationServiceParam; | ||
import org.example.service.dto.request.ShowAlarmsServiceRequest; | ||
import org.example.service.dto.response.ShowAlarmActivateServiceResponse; | ||
import org.example.usecase.ShowAlarmUseCase; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ShowAlarmService { | ||
|
||
private final ShowAlarmUseCase showAlarmUseCase; | ||
|
||
|
||
public PaginationServiceResponse<ShowAlarmPaginationServiceParam> getShowAlarms( | ||
ShowAlarmsServiceRequest request | ||
) { | ||
var response = showAlarmUseCase.findShowAlarms(request.toDomainRequest()); | ||
showAlarmUseCase.updateUncheckedAlarms(response.data().stream() | ||
.map(ShowAlarmsCheckedRequest::from) | ||
.toList() | ||
); | ||
|
||
List<ShowAlarmPaginationServiceParam> data = response.data().stream() | ||
.map(ShowAlarmPaginationServiceParam::from) | ||
.toList(); | ||
|
||
return PaginationServiceResponse.of(data, response.hasNext()); | ||
} | ||
|
||
public ShowAlarmActivateServiceResponse getShowAlarmActivate(String fcmToken) { | ||
return ShowAlarmActivateServiceResponse.from(showAlarmUseCase.hasUncheckedAlarms(fcmToken)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...larm-api/src/main/java/org/example/service/dto/param/ShowAlarmPaginationServiceParam.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,24 @@ | ||
package org.example.service.dto.param; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
import lombok.Builder; | ||
import org.example.dto.response.ShowAlarmDomainResponse; | ||
|
||
@Builder | ||
public record ShowAlarmPaginationServiceParam( | ||
UUID id, | ||
String title, | ||
String content, | ||
LocalDateTime createAt | ||
) { | ||
|
||
public static ShowAlarmPaginationServiceParam from(ShowAlarmDomainResponse response) { | ||
return ShowAlarmPaginationServiceParam.builder() | ||
.id(response.id()) | ||
.title(response.title()) | ||
.content(response.content()) | ||
.createAt(response.createAt()) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...api/alarm-api/src/main/java/org/example/service/dto/request/ShowAlarmsServiceRequest.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 org.example.service.dto.request; | ||
|
||
import java.util.UUID; | ||
import lombok.Builder; | ||
import org.example.dto.request.ShowAlarmsDomainRequest; | ||
|
||
@Builder | ||
public record ShowAlarmsServiceRequest( | ||
String fcmToken, | ||
UUID cursorId, | ||
Integer size | ||
) { | ||
public ShowAlarmsDomainRequest toDomainRequest() { | ||
return ShowAlarmsDomainRequest.builder() | ||
.fcmToken(fcmToken) | ||
.cursorId(cursorId) | ||
.size(size) | ||
.build(); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...-api/src/main/java/org/example/service/dto/response/ShowAlarmActivateServiceResponse.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,11 @@ | ||
package org.example.service.dto.response; | ||
|
||
public record ShowAlarmActivateServiceResponse( | ||
boolean isActivate | ||
) { | ||
|
||
public static ShowAlarmActivateServiceResponse from(boolean hasUncheckedAlarms) { | ||
return new ShowAlarmActivateServiceResponse(hasUncheckedAlarms); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
app/api/common-api/src/main/java/org/example/dto/response/CursorApiResponse.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 org.example.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record CursorApiResponse( | ||
|
||
Object id, | ||
|
||
Object value | ||
) { | ||
|
||
public static CursorApiResponse toCursorResponse(Object id, Object value) { | ||
return new CursorApiResponse(id, value); | ||
} | ||
|
||
public static CursorApiResponse toCursorId(Object id) { | ||
return new CursorApiResponse(id, null); | ||
} | ||
|
||
public static CursorApiResponse noneCursor() { | ||
return new CursorApiResponse(null, null); | ||
} | ||
|
||
public static <T> T getLastElement(List<T> list) { | ||
return list.isEmpty() ? null : list.get(list.size() - 1); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/api/common-api/src/main/java/org/example/dto/response/PaginationApiResponse.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 org.example.dto.response; | ||
|
||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
public record PaginationApiResponse<T>( | ||
int size, | ||
boolean hasNext, | ||
List<T> data, | ||
CursorApiResponse cursor | ||
) { | ||
|
||
@Builder | ||
public PaginationApiResponse( | ||
List<T> data, | ||
boolean hasNext, | ||
CursorApiResponse cursor | ||
) { | ||
this(data.size(), hasNext, data, cursor); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/api/common-api/src/main/java/org/example/dto/response/PaginationServiceResponse.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,20 @@ | ||
package org.example.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record PaginationServiceResponse<T>( | ||
boolean hasNext, | ||
List<T> data | ||
) { | ||
|
||
public static <T> PaginationServiceResponse<T> of( | ||
List<T> data, | ||
boolean hasNext | ||
) { | ||
if (data == null || data.isEmpty()) { | ||
data = List.of(); | ||
} | ||
|
||
return new PaginationServiceResponse<>(hasNext, data); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.