Skip to content

Commit

Permalink
Merge pull request #33 from KNU-HAEDAL-Website/feat-change-role-issue-5
Browse files Browse the repository at this point in the history
feat: role 종류 변경과 유저 상태 컬럼 추가 (#5)
  • Loading branch information
tfer2442 authored May 14, 2024
2 parents 4a6147e + a050f72 commit 6950121
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
http
.authorizeHttpRequests((auth) -> auth
.requestMatchers("/login", "/", "/join/**", "/reissue", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
.requestMatchers("/admin").hasRole("CANDIDATE")
.requestMatchers("/admin").hasRole("ADMIN")
.anyRequest().authenticated());

//JWTFilter 등록
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/haedal/haedalweb/domain/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public enum Role {
ROLE_ADMIN("관리자"),
ROLE_STAFF("해구르르"),
ROLE_TEAM_LEADER("팀장"),
ROLE_MEMBER("일반"),
ROLE_CANDIDATE("예비");
ROLE_MEMBER("일반");

private final String label;

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/haedal/haedalweb/domain/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.haedal.haedalweb.domain;

import lombok.Getter;

@Getter
public enum Status {
ACTIVE("활동"),
INACTIVE("대기"),
DELETED("삭제");

private final String label;

Status(String label) {
this.label = label;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/haedal/haedalweb/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class User {
@NonNull
private Role role;

@Column(name = "status")
@Enumerated(EnumType.STRING)
@NonNull
private Status status;

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "profile_id")
@NonNull
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/haedal/haedalweb/service/JoinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.haedal.haedalweb.domain.Profile;
import com.haedal.haedalweb.domain.Role;
import com.haedal.haedalweb.domain.Sns;
import com.haedal.haedalweb.domain.Status;
import com.haedal.haedalweb.domain.User;
import com.haedal.haedalweb.dto.JoinDTO;
import com.haedal.haedalweb.exception.BusinessException;
Expand All @@ -11,13 +12,15 @@
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class JoinService {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;

@Transactional
public void createUserAccount(JoinDTO joinDTO) {
String userId = joinDTO.getUserId();
String password = joinDTO.getPassword();
Expand All @@ -31,7 +34,8 @@ public void createUserAccount(JoinDTO joinDTO) {
.password(passwordEncoder.encode(password))
.name(userName)
.studentNumber(studentNumber)
.role(Role.ROLE_CANDIDATE)
.role(Role.ROLE_MEMBER)
.status(Status.INACTIVE)
.profile(createProfileWithSns())
.build();

Expand Down

0 comments on commit 6950121

Please sign in to comment.