Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Beakjiyeon committed Apr 5, 2024
2 parents 6762406 + 0b8fa95 commit 538c224
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 0 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.unit.daybook.domain.common.model;

import java.time.LocalDateTime;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {

@Column(updatable = false)
@CreatedDate
private LocalDateTime createdAt;

@Column @LastModifiedDate
private LocalDateTime updatedAt;
}

Empty file.
74 changes: 74 additions & 0 deletions src/main/java/com/unit/daybook/domain/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.unit.daybook.domain.member.domain;

import java.time.LocalDateTime;

import com.unit.daybook.domain.common.model.BaseTimeEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id")
private Long id;

private String nickname;

@Embedded
private OauthInfo oauthInfo;

@Enumerated(EnumType.STRING)
private MemberStatus status;

@Enumerated(EnumType.STRING)
private MemberRole role;

private LocalDateTime lastLoginAt;


@Builder(access = AccessLevel.PRIVATE)
private Member(
String nickname,
OauthInfo oauthInfo,
MemberStatus status,
MemberRole role,
LocalDateTime lastLoginAt) {
this.nickname = nickname;
this.oauthInfo = oauthInfo;
this.status = status;
this.role = role;
this.lastLoginAt = lastLoginAt;
}

public static Member createNormalMember(OauthInfo oauthInfo, String nickname) {
return Member.builder()
.nickname(nickname)
.oauthInfo(oauthInfo)
.status(MemberStatus.NORMAL)
.role(MemberRole.USER)
.build();
}

public void updateLastLoginAt() {
this.lastLoginAt = LocalDateTime.now();
}

public void updateNickname() {
this.nickname = nickname;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.unit.daybook.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MemberRole {
USER("ROLE_USER"),
ADMIN("ROLE_ADMIN");

private final String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.unit.daybook.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MemberStatus {
NORMAL("NORMAL"),
DELETED("DELETED"),
FORBIDDEN("FORBIDDEN");

private final String value;
}
33 changes: 33 additions & 0 deletions src/main/java/com/unit/daybook/domain/member/domain/OauthInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.unit.daybook.domain.member.domain;

import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OauthInfo {

private String oauthId;
private String oauthProvider;
private String oauthEmail;

@Builder(access = AccessLevel.PRIVATE)
private OauthInfo(String oauthId, String oauthProvider, String oauthEmail) {
this.oauthId = oauthId;
this.oauthProvider = oauthProvider;
this.oauthEmail = oauthEmail;
}

public static OauthInfo createOauthInfo(
String oauthId, String oauthProvider, String oauthEmail) {
return OauthInfo.builder()
.oauthId(oauthId)
.oauthProvider(oauthProvider)
.oauthEmail(oauthEmail)
.build();
}
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.unit.daybook.domain.member.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.unit.daybook.domain.member.domain.Member;

public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.unit.daybook.domain.member.repository;

public interface MemberRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.unit.daybook.domain.member.repository;

import org.springframework.stereotype.Repository;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class MemberRepositoryImpl implements MemberRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.unit.daybook.global.common.response;

import java.time.LocalDateTime;

import com.unit.daybook.global.error.ErrorResponse;

public record GlobalResponse(int status, Object data, LocalDateTime timestamp) {
public static GlobalResponse success(int status, Object data) {
return new GlobalResponse(status, data, LocalDateTime.now());
}

public static GlobalResponse fail(int status, ErrorResponse errorResponse) {
return new GlobalResponse(status, errorResponse, LocalDateTime.now());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.unit.daybook.global.common.response;

import org.springframework.core.MethodParameter;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

import jakarta.servlet.http.HttpServletResponse;

@RestControllerAdvice(basePackages = "com.unit.daybook")
public class GlobalResponseAdvice implements ResponseBodyAdvice {
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
return true;
}

@Override
public Object beforeBodyWrite(
Object body,
MethodParameter returnType,
MediaType selectedContentType,
Class selectedConverterType,
ServerHttpRequest request,
ServerHttpResponse response) {
HttpServletResponse servletResponse =
((ServletServerHttpResponse) response).getServletResponse();
int status = servletResponse.getStatus();
HttpStatus resolve = HttpStatus.resolve(status);
if (resolve == null || body instanceof String) {
return body;
}
if (resolve.is2xxSuccessful()) {
return GlobalResponse.success(status, body);
}
return body;
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/unit/daybook/global/config/QuerydslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.unit.daybook.global.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.querydsl.jpa.JPQLTemplates;
import com.querydsl.jpa.impl.JPAQueryFactory;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

@Configuration
public class QuerydslConfig {

@PersistenceContext
public EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(JPQLTemplates.DEFAULT, entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.unit.daybook.global.error;

public record ErrorResponse(String errorClassName, String message) {

public static ErrorResponse of(String errorClassName, String message) {
return new ErrorResponse(errorClassName, message);
}
}
Loading

0 comments on commit 538c224

Please sign in to comment.