diff --git a/build.gradle b/build.gradle index 7f67c89..c578c7e 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,13 @@ repositories { } dependencies { + //OpenFeign + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.3' + //JWT + implementation 'io.jsonwebtoken:jjwt-api:0.12.3' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' diff --git a/src/main/java/com/dnd/dndtravel/DndTravelProjectApplication.java b/src/main/java/com/dnd/dndtravel/DndTravelProjectApplication.java index 977265d..1fbdb5e 100644 --- a/src/main/java/com/dnd/dndtravel/DndTravelProjectApplication.java +++ b/src/main/java/com/dnd/dndtravel/DndTravelProjectApplication.java @@ -2,7 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing +@EnableFeignClients @SpringBootApplication public class DndTravelProjectApplication { diff --git a/src/main/java/com/dnd/dndtravel/member/domain/Member.java b/src/main/java/com/dnd/dndtravel/member/domain/Member.java new file mode 100644 index 0000000..97e92a1 --- /dev/null +++ b/src/main/java/com/dnd/dndtravel/member/domain/Member.java @@ -0,0 +1,36 @@ +package com.dnd.dndtravel.member.domain; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Entity +public class Member { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private String email; + + @Builder + private Member(String name, String email){ + this.name = name; + this.email = email; + } + + public static Member of(String name, String email){ + return Member.builder() + .name(name) + .email(email) + .build(); + } +} diff --git a/src/main/java/com/dnd/dndtravel/member/repository/MemberRepository.java b/src/main/java/com/dnd/dndtravel/member/repository/MemberRepository.java new file mode 100644 index 0000000..4ff8c21 --- /dev/null +++ b/src/main/java/com/dnd/dndtravel/member/repository/MemberRepository.java @@ -0,0 +1,11 @@ +package com.dnd.dndtravel.member.repository; + +import com.dnd.dndtravel.member.domain.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface MemberRepository extends JpaRepository { + + Optional findByEmail(final String email); +} diff --git a/src/main/java/com/dnd/dndtravel/member/service/MemberService.java b/src/main/java/com/dnd/dndtravel/member/service/MemberService.java new file mode 100644 index 0000000..4c99b5b --- /dev/null +++ b/src/main/java/com/dnd/dndtravel/member/service/MemberService.java @@ -0,0 +1,20 @@ +package com.dnd.dndtravel.member.service; + +import com.dnd.dndtravel.member.domain.Member; +import com.dnd.dndtravel.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional(readOnly = true) +@Service +public class MemberService { + + private final MemberRepository memberRepository; + + public Member saveMember(String name, String email) { + return memberRepository.findByEmail(email) + .orElseGet(() -> memberRepository.save(Member.of(name, email))); + } +}