diff --git a/src/main/java/com/mindway/server/v2/domain/Book/entity/Book.java b/src/main/java/com/mindway/server/v2/domain/Book/entity/Book.java new file mode 100644 index 0000000..9326c27 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/Book/entity/Book.java @@ -0,0 +1,34 @@ +package com.mindway.server.v2.domain.Book.entity; + +import com.mindway.server.v2.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +public class Book { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + private String author; + + private String url; + + private LocalDate created_at; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; +} diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java index 050128f..4a15155 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/LogoutServiceImpl.java @@ -4,8 +4,8 @@ import com.mindway.server.v2.domain.auth.exception.ExpiredRefreshTokenException; import com.mindway.server.v2.domain.auth.repository.RefreshRepository; import com.mindway.server.v2.domain.auth.service.LogoutService; -import com.mindway.server.v2.domain.member.entity.Member; -import com.mindway.server.v2.domain.member.util.MemberUtil; +import com.mindway.server.v2.domain.user.entity.User; +import com.mindway.server.v2.domain.user.util.UserUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +16,12 @@ public class LogoutServiceImpl implements LogoutService { private final RefreshRepository refreshRepository; - private final MemberUtil memberUtil; + private final UserUtil userUtil; public void execute() { - Member member = memberUtil.getCurrentMember(); + User user = userUtil.getCurrentUser(); - RefreshToken validRefreshToken = refreshRepository.findByMemberId(member.getId()) + RefreshToken validRefreshToken = refreshRepository.findByMemberId(user.getId()) .orElseThrow(ExpiredRefreshTokenException::new); refreshRepository.deleteById(validRefreshToken.getRefreshToken()); diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java index 24a92ec..f3c1fda 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java @@ -6,11 +6,10 @@ import com.mindway.server.v2.domain.auth.presentation.dto.response.TokenResponse; import com.mindway.server.v2.domain.auth.repository.RefreshRepository; import com.mindway.server.v2.domain.auth.service.ReissueTokenService; -import com.mindway.server.v2.domain.member.entity.Member; -import com.mindway.server.v2.domain.member.repository.MemberRepository; +import com.mindway.server.v2.domain.user.entity.User; +import com.mindway.server.v2.domain.user.repository.UserRepository; import com.mindway.server.v2.global.security.jwt.JwtProvider; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,7 +20,7 @@ public class ReissueTokenServiceImpl implements ReissueTokenService { private final JwtProvider jwtProvider; private final RefreshRepository refreshRepository; - private final MemberRepository memberRepository; + private final UserRepository userRepository; public TokenResponse execute(String refreshToken) { String parseRefreshToken = jwtProvider.parseRefreshToken(refreshToken); @@ -29,11 +28,11 @@ public TokenResponse execute(String refreshToken) { RefreshToken refreshEntity = refreshRepository.findById(parseRefreshToken) .orElseThrow(ExpiredRefreshTokenException::new); - Member member = memberRepository.findById(refreshEntity.getMemberId()) + User user = userRepository.findById(refreshEntity.getMemberId()) .orElseThrow(MemberNotFoundException::new); refreshRepository.deleteById(refreshEntity.getRefreshToken()); - return jwtProvider.generateTokenDto(member.getId()); + return jwtProvider.generateTokenDto(user.getId()); } } diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java index 09d4eb5..038a1dc 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java @@ -5,9 +5,9 @@ import com.mindway.server.v2.domain.auth.presentation.dto.response.TokenResponse; import com.mindway.server.v2.domain.auth.repository.RefreshRepository; import com.mindway.server.v2.domain.auth.service.SignInService; -import com.mindway.server.v2.domain.member.entity.Member; -import com.mindway.server.v2.domain.member.entity.StudentNum; -import com.mindway.server.v2.domain.member.repository.MemberRepository; +import com.mindway.server.v2.domain.user.entity.User; +import com.mindway.server.v2.domain.user.entity.StudentNum; +import com.mindway.server.v2.domain.user.repository.UserRepository; import com.mindway.server.v2.global.security.jwt.JwtProvider; import gauth.GAuth; import gauth.GAuthToken; @@ -30,7 +30,7 @@ public class SignInServiceImpl implements SignInService { private final GAuth gAuth; private final RefreshRepository refreshRepository; - private final MemberRepository memberRepository; + private final UserRepository userRepository; private final JwtProvider jwtProvider; @Value("${gauth.clientId}") @@ -50,12 +50,12 @@ public TokenResponse execute(SignInRequest signInRequest) throws GAuthException{ ); GAuthUserInfo userInfo = gAuth.getUserInfo(gAuthToken.getAccessToken()); - Member member = memberRepository.findByEmail(userInfo.getEmail()) + User user = userRepository.findByEmail(userInfo.getEmail()) .orElseGet(() -> saveMember(userInfo)); - TokenResponse tokenResponse = jwtProvider.generateTokenDto(member.getId()); + TokenResponse tokenResponse = jwtProvider.generateTokenDto(user.getId()); - saveRefreshToken(tokenResponse, member); + saveRefreshToken(tokenResponse, user); return tokenResponse; @@ -68,8 +68,8 @@ public TokenResponse execute(SignInRequest signInRequest) throws GAuthException{ return null; } - private Member saveMember(GAuthUserInfo gAuthUserInfo) { - Member member = Member.builder() + private User saveMember(GAuthUserInfo gAuthUserInfo) { + User user = User.builder() .id(UUID.randomUUID()) .email(gAuthUserInfo.getEmail()) .name(gAuthUserInfo.getName()) @@ -77,15 +77,15 @@ private Member saveMember(GAuthUserInfo gAuthUserInfo) { .role(gAuthUserInfo.getRole()) .build(); - memberRepository.save(member); + userRepository.save(user); - return member; + return user; } - private void saveRefreshToken(TokenResponse tokenResponse, Member member) { + private void saveRefreshToken(TokenResponse tokenResponse, User user) { RefreshToken refreshToken = RefreshToken.builder() .refreshToken(tokenResponse.getRefreshToken()) - .memberId(member.getId()) + .memberId(user.getId()) .expiredAt(tokenResponse.getRefreshTokenExpiresIn()) .build(); diff --git a/src/main/java/com/mindway/server/v2/domain/event/entity/Event.java b/src/main/java/com/mindway/server/v2/domain/event/entity/Event.java new file mode 100644 index 0000000..6baae03 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/event/entity/Event.java @@ -0,0 +1,37 @@ +package com.mindway.server.v2.domain.event.entity; + +import com.mindway.server.v2.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +public class Event { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + private String content; + + private String img_url; + + private LocalDate started_at; + + private LocalDate ended_at; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + +} diff --git a/src/main/java/com/mindway/server/v2/domain/goal/entity/Goal.java b/src/main/java/com/mindway/server/v2/domain/goal/entity/Goal.java new file mode 100644 index 0000000..eea3e39 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/goal/entity/Goal.java @@ -0,0 +1,32 @@ +package com.mindway.server.v2.domain.goal.entity; + +import com.mindway.server.v2.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class Goal { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private LocalDate started_at; + + private LocalDate ended_at; + + private Long goal_count; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; +} diff --git a/src/main/java/com/mindway/server/v2/domain/member/repository/MemberRepository.java b/src/main/java/com/mindway/server/v2/domain/member/repository/MemberRepository.java deleted file mode 100644 index 52f2a20..0000000 --- a/src/main/java/com/mindway/server/v2/domain/member/repository/MemberRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mindway.server.v2.domain.member.repository; - -import com.mindway.server.v2.domain.member.entity.Member; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; -import java.util.UUID; - -public interface MemberRepository extends JpaRepository { - Optional findByEmail(String email); -} diff --git a/src/main/java/com/mindway/server/v2/domain/member/entity/StudentNum.java b/src/main/java/com/mindway/server/v2/domain/user/entity/StudentNum.java similarity index 92% rename from src/main/java/com/mindway/server/v2/domain/member/entity/StudentNum.java rename to src/main/java/com/mindway/server/v2/domain/user/entity/StudentNum.java index 2119f7f..ed2d774 100644 --- a/src/main/java/com/mindway/server/v2/domain/member/entity/StudentNum.java +++ b/src/main/java/com/mindway/server/v2/domain/user/entity/StudentNum.java @@ -1,4 +1,4 @@ -package com.mindway.server.v2.domain.member.entity; +package com.mindway.server.v2.domain.user.entity; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; diff --git a/src/main/java/com/mindway/server/v2/domain/member/entity/Member.java b/src/main/java/com/mindway/server/v2/domain/user/entity/User.java similarity index 80% rename from src/main/java/com/mindway/server/v2/domain/member/entity/Member.java rename to src/main/java/com/mindway/server/v2/domain/user/entity/User.java index f9f0004..f37f347 100644 --- a/src/main/java/com/mindway/server/v2/domain/member/entity/Member.java +++ b/src/main/java/com/mindway/server/v2/domain/user/entity/User.java @@ -1,4 +1,4 @@ -package com.mindway.server.v2.domain.member.entity; +package com.mindway.server.v2.domain.user.entity; import jakarta.persistence.*; import lombok.AllArgsConstructor; @@ -13,11 +13,10 @@ @AllArgsConstructor @Getter @Builder -public class Member { +public class User { @Id @GeneratedValue(generator = "UUID4") - @Column(name = "member_id") private UUID id; private String email; diff --git a/src/main/java/com/mindway/server/v2/domain/user/repository/UserRepository.java b/src/main/java/com/mindway/server/v2/domain/user/repository/UserRepository.java new file mode 100644 index 0000000..cc91cc7 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/user/repository/UserRepository.java @@ -0,0 +1,11 @@ +package com.mindway.server.v2.domain.user.repository; + +import com.mindway.server.v2.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; +import java.util.UUID; + +public interface UserRepository extends JpaRepository { + Optional findByEmail(String email); +} diff --git a/src/main/java/com/mindway/server/v2/domain/member/util/MemberUtil.java b/src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java similarity index 55% rename from src/main/java/com/mindway/server/v2/domain/member/util/MemberUtil.java rename to src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java index 8991d95..7f3d8b3 100644 --- a/src/main/java/com/mindway/server/v2/domain/member/util/MemberUtil.java +++ b/src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java @@ -1,21 +1,21 @@ -package com.mindway.server.v2.domain.member.util; +package com.mindway.server.v2.domain.user.util; import com.mindway.server.v2.domain.auth.exception.MemberNotFoundException; -import com.mindway.server.v2.domain.member.entity.Member; -import com.mindway.server.v2.domain.member.repository.MemberRepository; +import com.mindway.server.v2.domain.user.entity.User; +import com.mindway.server.v2.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor -public class MemberUtil { +public class UserUtil { - private final MemberRepository memberRepository; + private final UserRepository userRepository; - public Member getCurrentMember() { + public User getCurrentUser() { String email = SecurityContextHolder.getContext().getAuthentication().getName(); - return memberRepository.findByEmail(email) + return userRepository.findByEmail(email) .orElseThrow(MemberNotFoundException::new); } } diff --git a/src/main/java/com/mindway/server/v2/global/auth/AuthDetails.java b/src/main/java/com/mindway/server/v2/global/auth/AuthDetails.java index 44596f0..13d67ab 100644 --- a/src/main/java/com/mindway/server/v2/global/auth/AuthDetails.java +++ b/src/main/java/com/mindway/server/v2/global/auth/AuthDetails.java @@ -1,6 +1,6 @@ package com.mindway.server.v2.global.auth; -import com.mindway.server.v2.domain.member.entity.Member; +import com.mindway.server.v2.domain.user.entity.User; import lombok.AllArgsConstructor; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -9,7 +9,7 @@ @AllArgsConstructor public class AuthDetails implements UserDetails { - private Member member; + private User user; @Override public Collection getAuthorities() { @@ -23,7 +23,7 @@ public String getPassword() { @Override public String getUsername() { - return member.getEmail(); + return user.getEmail(); } @Override diff --git a/src/main/java/com/mindway/server/v2/global/auth/AuthDetailsService.java b/src/main/java/com/mindway/server/v2/global/auth/AuthDetailsService.java index 6687629..96143cb 100644 --- a/src/main/java/com/mindway/server/v2/global/auth/AuthDetailsService.java +++ b/src/main/java/com/mindway/server/v2/global/auth/AuthDetailsService.java @@ -1,6 +1,6 @@ package com.mindway.server.v2.global.auth; -import com.mindway.server.v2.domain.member.repository.MemberRepository; +import com.mindway.server.v2.domain.user.repository.UserRepository; import com.mindway.server.v2.global.exception.ErrorCode; import com.mindway.server.v2.global.exception.MindWayException; import lombok.RequiredArgsConstructor; @@ -16,11 +16,11 @@ @RequiredArgsConstructor @Slf4j public class AuthDetailsService implements UserDetailsService { - private final MemberRepository memberRepository; + private final UserRepository userRepository; @Override public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { - return memberRepository.findById(UUID.fromString(id)) + return userRepository.findById(UUID.fromString(id)) .map(AuthDetails::new) .orElseThrow(() -> new MindWayException(ErrorCode.MEMBER_NOT_FOUND)); }