Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#10 feat: Member Entity, Service, Repository 추가 #13

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/dnd/dndtravel/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.dnd.dndtravel.member.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
min-0 marked this conversation as resolved.
Show resolved Hide resolved
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String name;

@Column(nullable = false)
private String email;

public static Member from(String name, String email){
return Member.builder()
.name(name)
.email(email)
.build();
min-0 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -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<Member, Long> {

Optional<Member> findByEmail(final String email);
}
21 changes: 21 additions & 0 deletions src/main/java/com/dnd/dndtravel/member/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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)
min-0 marked this conversation as resolved.
Show resolved Hide resolved
@Service
public class MemberService {

private final MemberRepository memberRepository;

@Transactional
public Member saveMember(String name, String email) {
return memberRepository.findByEmail(email)
.orElseGet(() -> memberRepository.save(Member.from(name, email)));
}
}
Loading