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

feat: 멤버 도메인 구현 #13

Merged
merged 11 commits into from
Jan 27, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gdschongik.gdsc.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaConfig {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gdschongik.gdsc.common.config;

import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.csrf(AbstractHttpConfigurer::disable)
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
.authorizeHttpRequests(authorize ->
authorize.requestMatchers(PathRequest.toH2Console()).permitAll())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gdschongik.gdsc.common.model;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

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

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

@Column
@LastModifiedDate
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.gdschongik.gdsc.domain.member.domain;

import com.gdschongik.gdsc.common.model.BaseTimeEntity;
import jakarta.persistence.Column;
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 java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

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

@Enumerated(EnumType.STRING)
private MemberRole role;

@Enumerated(EnumType.STRING)
private MemberStatus status;

private String name;

private String studentId;

private String department;

private String email;

private String phone;

private String discordUsername;

private String nickname;

@Column(nullable = false)
private String oauthId;

private LocalDateTime lastLoginAt;

private String univEmail;

@Builder(access = AccessLevel.PRIVATE)
private Member(
MemberRole role,
MemberStatus status,
String name,
String studentId,
String department,
String email,
String phone,
String discordUsername,
String nickname,
String oauthId,
LocalDateTime lastLoginAt,
String univEmail) {
this.role = role;
this.status = status;
this.name = name;
this.studentId = studentId;
this.department = department;
this.email = email;
this.phone = phone;
this.discordUsername = discordUsername;
this.nickname = nickname;
this.oauthId = oauthId;
this.lastLoginAt = lastLoginAt;
this.univEmail = univEmail;
}

public static Member createGuestMember(String oauthId) {
return Member.builder()
.oauthId(oauthId)
.role(MemberRole.GUEST)
.status(MemberStatus.NORMAL)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.gdschongik.gdsc.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MemberRole {
GUEST("ROLE_GUEST"),
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.gdschongik.gdsc.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

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

private final String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.gdschongik.gdsc.domain.member.domain;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Test;

class MemberTest {

@Test
void 회원가입시_MemberRole은_GUEST이다() {
// given
Member member = Member.createGuestMember("testOauthId");

// when
MemberRole role = member.getRole();

// then
assertThat(role).isEqualTo(MemberRole.GUEST);
}

@Test
void 회원가입시_MemberStatus는_NORMAL이다() {
// given
Member member = Member.createGuestMember("testOauthId");

// when
MemberStatus status = member.getStatus();

// then
assertThat(status).isEqualTo(MemberStatus.NORMAL);
}
}
Loading