Skip to content

Commit 55a4826

Browse files
committed
fix bugs add validate
1 parent 37e46df commit 55a4826

17 files changed

+93
-149
lines changed

WeatherCastApp/schema-loader/load-schemas.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,20 @@ set -euo pipefail
44
SR_URL="${SCHEMA_REGISTRY_URL:-http://schema-registry:8081}"
55
SCHEMA_DIR="${SCHEMA_DIR:-/schemas}"
66

7-
echo "---> Waiting until Schema Registry ($SR_URL) is up..."
87
until curl -fsS "$SR_URL/subjects" >/dev/null 2>&1; do
98
sleep 1
109
done
11-
echo "---> Schema Registry reachable at $SR_URL"
12-
echo
1310

1411
declare -A MAPPING=(
1512
["WeatherResponseKafkaDTO"]="weather-subscribers"
1613
)
1714

18-
echo "---> Registering local *.avsc → subject according to topic mapping"
1915
for file in "$SCHEMA_DIR"/*.avsc; do
2016
[ -e "$file" ] || { echo "No .avsc found in $SCHEMA_DIR"; exit 0; }
2117

2218
base="$(basename "$file" .avsc)"
2319

2420
if [[ -z "${MAPPING[$base]:-}" ]]; then
25-
echo " [WARN] No topic mapping for '$base' → skipping"
2621
continue
2722
fi
2823

@@ -31,13 +26,10 @@ for file in "$SCHEMA_DIR"/*.avsc; do
3126

3227
schema_str=$(jq -Rs . <"$file")
3328

34-
echo " → Registering $file as subject '$subj'..."
3529
curl -sS -X POST \
3630
-H "Content-Type: application/vnd.schemaregistry.v1+json" \
3731
--data "{\"schema\":${schema_str}}" \
3832
"$SR_URL/subjects/$subj/versions" \
3933
&& echo " [ok] $subj registered" \
4034
|| echo " [error] failed to register $subj"
4135
done
42-
43-
echo "All done."

WeatherCastApp/src/main/java/tb/wca/dto/SubscriptionRequestDTO.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ public record SubscriptionRequestDTO(
1414
@NotBlank(message = "City name must not be blank")
1515
String cityName,
1616

17-
@NotNull(message = "Notification time must not be null")
1817
LocalTime notificationTime,
1918

2019
String timeZone
2120
) {
21+
@AssertTrue(message = "notificationTime must be in HH:mm format")
22+
private boolean isNotificationTimeValid() {
23+
if (notificationTime == null) return false;
24+
return notificationTime.getSecond() == 0
25+
&& notificationTime.getNano() == 0;
26+
}
27+
2228
@AssertTrue(message = "timeZone must be provided and must be a valid ZoneId")
2329
private boolean isTimeZoneValid() {
2430
if (timeZone == null || timeZone.isBlank()) {
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
package tb.wca.dto;
22

33
import lombok.Builder;
4-
import lombok.Setter;
4+
import tb.wca.entity.SubscriptionEntity;
5+
import tb.wca.util.TimeCalculator;
56

67
import java.time.Instant;
8+
import java.time.LocalDateTime;
79

810
@Builder
911
public record SubscriptionResponseDTO(
10-
Instant expectedNextNotificationDateTime
11-
) { }
12+
Instant expectedNextNotificationDateTime,
13+
LocalDateTime expectedNextNotificationDateTimeFormatted,
14+
String message
15+
) {
16+
public static SubscriptionResponseDTO of(SubscriptionEntity subscription) {
17+
18+
Instant nextInstant = TimeCalculator.calculateNextNotification(subscription);
19+
LocalDateTime nextLocal = TimeCalculator.instantToLocalDateTime(
20+
nextInstant, subscription.getTimeZone()
21+
);
22+
23+
return new SubscriptionResponseDTO(nextInstant, nextLocal, "Success subscribe");
24+
}
25+
26+
public static SubscriptionResponseDTO message(String msg) {
27+
return new SubscriptionResponseDTO(null, null, msg);
28+
}
29+
}

WeatherCastApp/src/main/java/tb/wca/exceptions/GlobalExceptionHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public ResponseEntity<ExceptionResponse> handleNotFoundDataException(NotFoundDat
5555
return buildErrorResponse(ex.getErrorCode(), ex.getMessage());
5656
}
5757

58+
@ExceptionHandler(SubscriptionNotFoundException.class)
59+
public ResponseEntity<ExceptionResponse> handleSubscriptionNotFoundException(SubscriptionNotFoundException ex) {
60+
return buildErrorResponse(ex.getErrorCode(), ex.getMessage());
61+
}
62+
63+
@ExceptionHandler(UserNotFoundException.class)
64+
public ResponseEntity<ExceptionResponse> handleUserNotFoundException(UserNotFoundException ex) {
65+
return buildErrorResponse(ex.getErrorCode(), ex.getMessage());
66+
}
67+
5868
@ExceptionHandler(MethodArgumentNotValidException.class)
5969
public ResponseEntity<ExceptionResponse> handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
6070
String details = ex.getBindingResult()
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package tb.wca.exceptions;
22

3-
public class SubscriptionNotFoundException extends RuntimeException {
4-
public SubscriptionNotFoundException(Long teleramId) {
5-
super("Subscription for user with teleramId = " + telegramId + " not found");
3+
import tb.wca.exceptions.enums.BusinessErrorCodes;
4+
5+
public class SubscriptionNotFoundException extends BusinessException {
6+
public SubscriptionNotFoundException(Long telegramId)
7+
{
8+
super(BusinessErrorCodes.SUBSCRIPTION_NOT_FOUND);
9+
}
10+
public SubscriptionNotFoundException(String additionalMessage) {
11+
super(BusinessErrorCodes.SUBSCRIPTION_NOT_FOUND, additionalMessage);
612
}
713
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package tb.wca.exceptions;
22

3-
public class UserNotFoundException extends RuntimeException {
3+
import tb.wca.exceptions.enums.BusinessErrorCodes;
4+
5+
public class UserNotFoundException extends BusinessException {
46
public UserNotFoundException(Long telegramId) {
5-
super("User with telegramId=" + telegramId + " not found");
7+
super(BusinessErrorCodes.USER_NOT_FOUND);
8+
}
9+
public UserNotFoundException(String additionalMessage) {
10+
super(BusinessErrorCodes.NOT_FOUND_DATA, additionalMessage);
611
}
712
}
813

WeatherCastApp/src/main/java/tb/wca/exceptions/enums/BusinessErrorCodes.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public enum BusinessErrorCodes {
1919
INVALID_ARGUMENTS(400, HttpStatus.BAD_REQUEST, "Invalid arguments"),
2020
CONSTRAINT_VIOLATION(400, HttpStatus.BAD_REQUEST, "Constraint violation"),
2121
DATA_INTEGRITY_VIOLATION(400, HttpStatus.BAD_REQUEST, "Data integrity violation"),
22-
INVALID_FORMAT(400, HttpStatus.BAD_REQUEST, "Invalid JSON format");
22+
INVALID_FORMAT(400, HttpStatus.BAD_REQUEST, "Invalid JSON format"),
23+
USER_NOT_FOUND(403, HttpStatus.NOT_FOUND, "User not found"),
24+
SUBSCRIPTION_NOT_FOUND(403, HttpStatus.NOT_FOUND, "Subscription not found");
2325

2426
private final int code;
2527
private final HttpStatus httpStatus;

WeatherCastApp/src/main/java/tb/wca/mapper/SubscriptionMapper.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

WeatherCastApp/src/main/java/tb/wca/mapper/WeatherRequestMapper.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

WeatherCastApp/src/main/java/tb/wca/model/SubscriptionModel.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)