Skip to content

Commit

Permalink
Task 16 : Define BaseDomainModel, AlreadyException, NotFoundException…
Browse files Browse the repository at this point in the history
…, EmailAlreadyExistsException and RateLimitExceededException
  • Loading branch information
Rapter1990 committed Jun 29, 2024
1 parent fa1ad62 commit 1daf71f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.springboot.ratelimiter.common.exception;

import org.springframework.http.HttpStatus;

import java.io.Serial;

public abstract class AlreadyException extends RuntimeException {

@Serial
private static final long serialVersionUID = 6091550422939917669L;

public static final HttpStatus STATUS = HttpStatus.CONFLICT;

protected AlreadyException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.springboot.ratelimiter.common.exception;

import org.springframework.http.HttpStatus;

import java.io.Serial;

public abstract class NotFoundException extends RuntimeException {

@Serial
private static final long serialVersionUID = 4846183318086338894L;

public static final HttpStatus STATUS = HttpStatus.NOT_FOUND;

protected NotFoundException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.springboot.ratelimiter.common.exception.ratelimit;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public class RateLimitExceededException extends RuntimeException {
public RateLimitExceededException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.springboot.ratelimiter.common.exception.user;

import com.springboot.ratelimiter.common.exception.AlreadyException;

import java.io.Serial;

public class EmailAlreadyExistsException extends AlreadyException {

@Serial
private static final long serialVersionUID = -6856741036475854853L;

private static final String DEFAULT_MESSAGE =
"The specified email already exists";

private static final String MESSAGE_TEMPLATE =
"Email already exists: ";

public EmailAlreadyExistsException(String email) {
super(MESSAGE_TEMPLATE.concat(email));
}

public EmailAlreadyExistsException() {
super(DEFAULT_MESSAGE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.springboot.ratelimiter.common.model;

import jakarta.persistence.MappedSuperclass;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public abstract class BaseDomainModel {

protected LocalDateTime createdAt;
protected LocalDateTime updatedAt;

}

0 comments on commit 1daf71f

Please sign in to comment.