Skip to content

Commit

Permalink
Refactor: domain entity 분리 (#29)
Browse files Browse the repository at this point in the history
* Fix: domain entity 분리

* Fix: member 도메인을 사용하도록 수정

* Test: member repository 테스트 추가

* Test: entity test 추가
  • Loading branch information
WonSteps authored Aug 5, 2024
1 parent 2b023fa commit a4777e1
Show file tree
Hide file tree
Showing 45 changed files with 773 additions and 342 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.dnd.runus.auth.userdetails;

import com.dnd.runus.auth.exception.AuthException;
import com.dnd.runus.domain.member.entity.Member;
import com.dnd.runus.domain.member.repository.MemberRepository;
import com.dnd.runus.domain.member.Member;
import com.dnd.runus.domain.member.MemberRepository;
import com.dnd.runus.global.exception.type.ErrorType;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -25,7 +25,7 @@ public UserDetails loadUserByUsername(String identity) throws UsernameNotFoundEx
.findById(memberId)
.orElseThrow(
() -> new AuthException(ErrorType.FAILED_AUTHENTICATION, "Member not found: " + memberId));
return AuthUserDetails.of(memberId, member.getRole());
return AuthUserDetails.of(memberId, member.role());
} catch (NumberFormatException exception) {
throw new UsernameNotFoundException(identity);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/dnd/runus/domain/badge/Badge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.dnd.runus.domain.badge;

import com.dnd.runus.global.constant.BadgeType;

public record Badge(
long badgeId, String name, String description, String imageUrl, BadgeType type, int requiredValue) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dnd.runus.domain.badge;

import com.dnd.runus.domain.member.Member;

import java.time.OffsetDateTime;

public record BadgeAchievement(Badge badge, Member member, OffsetDateTime createdAt, OffsetDateTime updatedAt) {}

This file was deleted.

24 changes: 14 additions & 10 deletions src/main/java/com/dnd/runus/domain/common/BaseTimeEntity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.dnd.runus.domain.common;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.Instant;
import java.time.OffsetDateTime;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {
@CreatedDate
private Instant createdAt;
private OffsetDateTime createdAt;
private OffsetDateTime updatedAt;

@LastModifiedDate
private Instant updatedAt;
@PrePersist
public void prePersist() {
createdAt = updatedAt = OffsetDateTime.now();
}

@PreUpdate
public void preUpdate() {
updatedAt = OffsetDateTime.now();
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/dnd/runus/domain/common/Coordinate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dnd.runus.domain.common;

/**
* @param longitude 경도
* @param latitude 위도
* @param altitude 고도
*/
public record Coordinate(double longitude, double latitude, double altitude) {
public static final double NULL_ORDINATE = Double.NaN;

public Coordinate(double longitude, double latitude) {
this(longitude, latitude, NULL_ORDINATE);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/dnd/runus/domain/level/Level.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.dnd.runus.domain.level;

public record Level(long levelId, int requiredExp) {}
20 changes: 20 additions & 0 deletions src/main/java/com/dnd/runus/domain/member/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.dnd.runus.domain.member;

import com.dnd.runus.domain.badge.Badge;
import com.dnd.runus.domain.level.Level;
import com.dnd.runus.global.constant.MemberRole;
import lombok.Builder;

import java.time.OffsetDateTime;

@Builder
public record Member(
long memberId,
OffsetDateTime createdAt,
OffsetDateTime updatedAt,
MemberRole role,
String nickname,
Badge mainBadge,
int weightKg,
Level level,
int currentExp) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.dnd.runus.domain.member;

import java.util.Optional;

public interface MemberRepository {
Optional<Member> findById(long id);

Member save(Member member);
}
8 changes: 8 additions & 0 deletions src/main/java/com/dnd/runus/domain/member/SocialProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.dnd.runus.domain.member;

import com.dnd.runus.global.constant.SocialType;
import lombok.Builder;

@Builder
public record SocialProfile(
long socialProfileId, SocialType socialType, String oauthId, String oauthEmail, long memberId) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dnd.runus.domain.member;

import com.dnd.runus.global.constant.SocialType;

import java.util.Optional;

public interface SocialProfileRepository {
Optional<SocialProfile> findById(Long socialProfileId);

Optional<SocialProfile> findBySocialTypeAndOauthId(SocialType socialType, String oauthId);

SocialProfile save(SocialProfile socialProfile);

void updateOauthEmail(long socialProfileId, String oauthEmail);
}
44 changes: 0 additions & 44 deletions src/main/java/com/dnd/runus/domain/member/entity/Member.java

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
Expand Up @@ -27,7 +27,7 @@ public class OauthController {
@ApiErrorType({ErrorType.UNSUPPORTED_SOCIAL_TYPE, ErrorType.MALFORMED_ACCESS_TOKEN, ErrorType.UNSUPPORTED_JWT_TOKEN
})
@PostMapping
public TokenResponse SignIn(@Valid @RequestBody OauthRequest request) {
return oauthService.SignIn(request);
public TokenResponse signIn(@Valid @RequestBody OauthRequest request) {
return oauthService.signIn(request);
}
}
Loading

0 comments on commit a4777e1

Please sign in to comment.