Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.codecrafters.companity.user.adapter.infrastructure.jpa;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QUserEntity is a Querydsl query type for UserEntity
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QUserEntity extends EntityPathBase<UserEntity> {

private static final long serialVersionUID = 1701790324L;

public static final QUserEntity userEntity = new QUserEntity("userEntity");

public final StringPath nickName = createString("nickName");

public final StringPath userId = createString("userId");

public final StringPath userName = createString("userName");

public QUserEntity(String variable) {
super(UserEntity.class, forVariable(variable));
}

public QUserEntity(Path<? extends UserEntity> path) {
super(path.getType(), path.getMetadata());
}

public QUserEntity(PathMetadata metadata) {
super(UserEntity.class, metadata);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.codecrafters.companity.user.adapter.jpa;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.codecrafters.companity.user.adapter.infrastructure.jpa.UserEntity;
import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QUserEntity is a Querydsl query type for UserEntity
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QUserEntity extends EntityPathBase<UserEntity> {

private static final long serialVersionUID = 586088658L;

public static final QUserEntity userEntity = new QUserEntity("userEntity");

public final NumberPath<Long> id = createNumber("id", Long.class);

public final StringPath name = createString("name");

public final StringPath nickName = createString("nickName");

public QUserEntity(String variable) {
super(UserEntity.class, forVariable(variable));
}

public QUserEntity(Path<? extends UserEntity> path) {
super(path.getType(), path.getMetadata());
}

public QUserEntity(PathMetadata metadata) {
super(UserEntity.class, metadata);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.codecrafters.companity.adapter.post.out;
package com.codecrafters.companity.comment.adapter.dto.response;

import com.codecrafters.companity.adapter.user.ResponseUser;
import com.codecrafters.companity.user.adapter.ResponseUser;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.codecrafters.companity.adapter.infrastructure.jpa.comment;
package com.codecrafters.companity.comment.adapter.infrastructure.jpa;

import com.codecrafters.companity.adapter.infrastructure.jpa.common.BaseTimeEntity;
import com.codecrafters.companity.adapter.infrastructure.jpa.post.PostEntity;
import com.codecrafters.companity.adapter.user.infrastructure.jpa.UserEntity;
import com.codecrafters.companity.common.adapter.infrastructure.jpa.BaseTimeEntity;
import com.codecrafters.companity.post.adapter.infrastructure.jpa.PostEntity;
import com.codecrafters.companity.user.adapter.infrastructure.jpa.UserEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Entity(name = "Comment")
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.codecrafters.companity.domain.post;
package com.codecrafters.companity.comment.domain;

import com.codecrafters.companity.domain.user.User;
import com.codecrafters.companity.user.domain.User;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.codecrafters.companity.common.adapter;

import com.codecrafters.companity.common.adapter.dto.response.ExceptionResponse;
import com.codecrafters.companity.exception.CustomException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice(basePackages = "com.codecrafters.companity")
public class ExceptionControllerAdvice {
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<Object> exceptionHandler(IllegalArgumentException e) {
return new ResponseEntity<Object>(e.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(CustomException.class)
public ResponseEntity<ExceptionResponse> exceptionHandler(CustomException e) {

return ExceptionResponse.toResponseEntity(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.codecrafters.companity.adapter.utility;
package com.codecrafters.companity.common.adapter;

import com.codecrafters.companity.application.out.utility.DateTimeProvider;
import com.codecrafters.companity.common.application.DateTimeProvider;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.codecrafters.companity.common.adapter.dto.response;

import com.codecrafters.companity.exception.CustomException;
import lombok.Builder;
import org.springframework.http.ResponseEntity;

@Builder
public class ExceptionResponse {
private String code;
private String msg;

public static ResponseEntity<ExceptionResponse> toResponseEntity(CustomException ex) {
ResultCode errorType = ex.getResultCode();
String message = ex.getMessage();

return ResponseEntity
.status(ex.getStatus())
.body(ExceptionResponse.builder()
.code(errorType.getCode())
.msg(errorType.getMsg())
.build());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codecrafters.companity.common.adapter.dto.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ResultCode {
UNKNOWN("UNKNOWN", "unchecked exception"),
USER_NOT_FOUND("USER_NOT_FOUND", "user not found exception.");

private final String code;
private final String msg;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.codecrafters.companity.adapter.infrastructure.jpa.common;
package com.codecrafters.companity.common.adapter.infrastructure.jpa;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.codecrafters.companity.application.out.utility;
package com.codecrafters.companity.common.application;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.codecrafters.companity.config.mapper;

import com.codecrafters.companity.adapter.post.out.ResponsePost;
import com.codecrafters.companity.domain.enums.City;
import com.codecrafters.companity.domain.enums.Sport;
import com.codecrafters.companity.domain.post.Post;
import com.codecrafters.companity.post.adapter.dto.response.ResponsePost;
import com.codecrafters.companity.post.domain.enums.City;
import com.codecrafters.companity.post.domain.enums.Sport;
import com.codecrafters.companity.post.domain.Post;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
import org.modelmapper.config.Configuration;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.codecrafters.companity.exception;

import com.codecrafters.companity.common.adapter.dto.response.ResultCode;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public class CustomException extends RuntimeException{
private final HttpStatus status;
private final ResultCode resultCode;
private final String message;

public CustomException(HttpStatus status, ResultCode resultCode, String message) {
this.status = status;
this.resultCode = resultCode;
this.message = message;
}

public CustomException(HttpStatus status, ResultCode resultCode, Throwable cause) {
this.status = status;
this.resultCode = resultCode;
this.message = cause.getMessage();
}

public CustomException(HttpStatus status, CustomException customException) {
this.status = status;
this.resultCode = customException.getResultCode();
this.message = customException.getMessage();
}

public CustomException(HttpStatus status, Throwable cause) {
this.status = status;
this.resultCode = ResultCode.UNKNOWN;
this.message = cause.getMessage();
}

public CustomException(Exception exception) {
if (exception.getClass() == CustomException.class) {
CustomException customException = (CustomException) exception;
this.status = customException.getStatus();
this.resultCode = customException.getResultCode();
this.message = customException.getMessage();
} else {
this.status = HttpStatus.BAD_REQUEST;
this.resultCode = ResultCode.UNKNOWN;
this.message = exception.getMessage();
}
}
}
Loading