-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from Sirius506775/main
JWT 토큰 생성 시 사용자 유저 권한 정보 반환
- Loading branch information
Showing
12 changed files
with
159 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/hallym/festival/domain/Users/APIUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.hallym.festival.domain.Users; | ||
|
||
import com.hallym.festival.domain.Users.entity.APIUser; | ||
import com.hallym.festival.domain.Users.entity.MemberRole; | ||
import com.hallym.festival.domain.Users.repository.APIUserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@ToString | ||
@Service | ||
@Log4j2 | ||
public class APIUserService { | ||
|
||
private final APIUserRepository apiUserRepository; | ||
|
||
public String getRoleSetByMid(String mid) { | ||
APIUser apiUser = apiUserRepository.findByUserId(mid); | ||
String role = String.join(",", apiUser.getRoleSet().stream().map(MemberRole::getValue).collect(Collectors.toList())); | ||
|
||
log.info("해당 유저는 " + role + " 권한을 가지고 있습니다."); | ||
|
||
if (apiUser != null) { | ||
return role; | ||
} else { | ||
return "apiUser 정보를 제대로 가져오지 못했습니다"; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
src/main/java/com/hallym/festival/domain/Users/entity/MemberRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
package com.hallym.festival.domain.Users.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@RequiredArgsConstructor | ||
public enum MemberRole { | ||
|
||
USER("ROLE_USER"), //부스 운영 관리자 | ||
ADMIN("ROLE_ADMIN"), ; //축제 준비 위원회(총 관리자) | ||
|
||
private String value; | ||
|
||
MemberRole(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/com/hallym/festival/repository/UserImportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.hallym.festival.repository; | ||
|
||
import com.hallym.festival.domain.Users.dto.APIUserDTO; | ||
import com.hallym.festival.domain.Users.entity.APIUser; | ||
import com.hallym.festival.domain.Users.repository.APIUserRepository; | ||
import com.opencsv.CSVReader; | ||
import com.opencsv.CSVReaderBuilder; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import javax.transaction.Transactional; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest | ||
@Transactional | ||
public class UserImportTest { | ||
|
||
@Autowired | ||
private APIUserRepository apiUserRepository; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
apiUserRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
public void testCsvReader() throws IOException { | ||
// csv 파일을 읽어올 InputStream 생성 | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
File file = new File(classLoader.getResource("test.csv").getFile()); | ||
FileInputStream inputStream = new FileInputStream(file); | ||
|
||
// CSVReader 생성 | ||
InputStreamReader streamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); | ||
CSVReader reader = new CSVReaderBuilder(streamReader).withSkipLines(1).build(); | ||
|
||
// CSV에서 읽어온 데이터를 APIUser 엔티티로 변환하여 DB에 저장 | ||
String[] line; | ||
while ((line = reader.readNext()) != null) { | ||
APIUserDTO apiUserDTO = new APIUserDTO(); | ||
apiUserDTO.setMid(line[0]); | ||
apiUserDTO.setName(line[1]); | ||
apiUserDTO.setDepartment(line[2]); | ||
apiUserDTO.setPhone(line[3]); | ||
// apiUserRepository.save(apiUser); | ||
} | ||
|
||
// DB에 저장된 데이터 확인 | ||
List<APIUser> apiUsers = apiUserRepository.findAll(); | ||
Assertions.assertEquals(3, apiUsers.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters