From 7ebdead9bc0dfc2340198779dbedf01d4008b3d5 Mon Sep 17 00:00:00 2001 From: dongheonlee Date: Sun, 7 May 2023 22:57:34 +0900 Subject: [PATCH 1/6] =?UTF-8?q?refactor=20:=20content=20=EC=BB=AC=EB=9F=BC?= =?UTF-8?q?=20=EA=B8=B8=EC=9D=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hallym/festival/domain/booth/entity/Booth.java | 2 +- .../java/com/hallym/festival/domain/notice/entity/Notice.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hallym/festival/domain/booth/entity/Booth.java b/src/main/java/com/hallym/festival/domain/booth/entity/Booth.java index 1e6aa31..0047228 100644 --- a/src/main/java/com/hallym/festival/domain/booth/entity/Booth.java +++ b/src/main/java/com/hallym/festival/domain/booth/entity/Booth.java @@ -33,7 +33,7 @@ public class Booth extends BaseTimeEntity { private String booth_title; @NonNull - @Column(length = 500) + @Column(length = 1000) private String booth_content; @NonNull diff --git a/src/main/java/com/hallym/festival/domain/notice/entity/Notice.java b/src/main/java/com/hallym/festival/domain/notice/entity/Notice.java index d7518e1..e026581 100644 --- a/src/main/java/com/hallym/festival/domain/notice/entity/Notice.java +++ b/src/main/java/com/hallym/festival/domain/notice/entity/Notice.java @@ -21,7 +21,9 @@ public class Notice extends BaseTimeEntity { private Long nno; @NotNull private String title; + @NotNull + @Column(length = 1000) private String content; @ColumnDefault("false") From a12b423f001ef0f74a75285dc818f8c0a9c9a56b Mon Sep 17 00:00:00 2001 From: dongheonlee Date: Sun, 7 May 2023 22:58:04 +0900 Subject: [PATCH 2/6] =?UTF-8?q?test=20:=20=EB=B6=80=EC=8A=A4,=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EC=83=9D=EC=84=B1=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/APIUserRepositoryTests.java | 8 ++--- .../festival/service/BoothServiceTests.java | 32 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/hallym/festival/repository/APIUserRepositoryTests.java b/src/test/java/com/hallym/festival/repository/APIUserRepositoryTests.java index dcef55c..34934f8 100644 --- a/src/test/java/com/hallym/festival/repository/APIUserRepositoryTests.java +++ b/src/test/java/com/hallym/festival/repository/APIUserRepositoryTests.java @@ -41,15 +41,15 @@ public void testInserts() { }); } - @DisplayName("가상 아이디 1생성 테스트") + @DisplayName("가상 관리자 아이디 생성 테스트") @Test - public void testInsertsOnes() { + public void testInsertAdminOnes() { APIUser apiUser = APIUser.builder() - .mid("20154341") + .mid("admin") .password( passwordEncoder.encode("1111") ) .club("소속부스") .department("축제준비위원회") - .name("홍길동") + .name("박철수") .phone("010-5213-1231") .build(); diff --git a/src/test/java/com/hallym/festival/service/BoothServiceTests.java b/src/test/java/com/hallym/festival/service/BoothServiceTests.java index 3749806..06b62ea 100644 --- a/src/test/java/com/hallym/festival/service/BoothServiceTests.java +++ b/src/test/java/com/hallym/festival/service/BoothServiceTests.java @@ -13,6 +13,7 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; +import java.util.stream.IntStream; @SpringBootTest @Log4j2 @@ -24,20 +25,21 @@ public class BoothServiceTests { @DisplayName("부스 데이터 등록 테스트") @Test - public void testRegister(){ - - BoothDTO boothDTO = BoothDTO.builder() - .booth_title("타코야끼") - .booth_content("새벽 4시 45분") - .writer("주펄") - .booth_type(BoothType.푸드트럭) - .dayNight(DayNight.DAY) - .openDay("[2,3]") - .build(); - - Long bno = boothService.register(boothDTO); - - log.info("bno: " + bno); + public void testRegister() { + IntStream.rangeClosed(1, 10).forEach(i -> { + BoothDTO boothDTO = BoothDTO.builder() + .booth_title("부스 제목"+i) + .booth_content("부스 콘텐츠"+i) + .writer("2015434"+i) + .booth_type(BoothType.주점) + .dayNight(DayNight.DAY) + .openDay("[1,2,3]") + .build(); + + Long bno = boothService.register(boothDTO); + + log.info("bno: " + bno); + }); } @DisplayName("이미지를 포함한 등록 테스트") @@ -49,7 +51,7 @@ public void testRegisterWithImages() { BoothDTO boothDTO = BoothDTO.builder() .booth_title("파일 첨부 게시글2") .booth_content("테스트입니다.") - .writer("user99") + .writer("20154342") .booth_type(BoothType.플리마켓) .dayNight(DayNight.NIGHT) .openDay("[2,3]") From 02e0c08421777b0ff0d20922ea66265dffd95ff1 Mon Sep 17 00:00:00 2001 From: dongheonlee Date: Mon, 8 May 2023 01:53:11 +0900 Subject: [PATCH 3/6] =?UTF-8?q?refactor=20:=20JWT=20=EB=B0=9C=ED=96=89=20?= =?UTF-8?q?=EC=8B=9C=20payload=EC=97=90=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?-=20enum=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1=20-=20JWTUt?= =?UTF-8?q?il=20=ED=81=B4=EB=9E=98=EC=8A=A4=EC=97=90=20payload=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EC=97=90=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=A0=95=EB=B3=B4=20=EC=A3=BC=EC=9E=85=20-=20Repos?= =?UTF-8?q?itory=EC=97=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/domain/Users/entity/APIUser.java | 4 ++++ .../festival/domain/Users/entity/MemberRole.java | 11 +++++++++-- .../domain/Users/repository/APIUserRepository.java | 10 +++++++--- .../festival/global/security/util/JWTUtil.java | 13 +++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/hallym/festival/domain/Users/entity/APIUser.java b/src/main/java/com/hallym/festival/domain/Users/entity/APIUser.java index 7c035a1..f1fde4f 100644 --- a/src/main/java/com/hallym/festival/domain/Users/entity/APIUser.java +++ b/src/main/java/com/hallym/festival/domain/Users/entity/APIUser.java @@ -35,6 +35,10 @@ public class APIUser { @Column(name = "phone") private String phone; + public Set getRoleSet() { + return roleSet; + } + @ElementCollection(fetch = FetchType.EAGER) @Builder.Default private Set roleSet = new HashSet<>(); //권한 정보 diff --git a/src/main/java/com/hallym/festival/domain/Users/entity/MemberRole.java b/src/main/java/com/hallym/festival/domain/Users/entity/MemberRole.java index 2a56305..772a413 100644 --- a/src/main/java/com/hallym/festival/domain/Users/entity/MemberRole.java +++ b/src/main/java/com/hallym/festival/domain/Users/entity/MemberRole.java @@ -1,10 +1,10 @@ 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"), //부스 운영 관리자 @@ -12,4 +12,11 @@ public enum MemberRole { private String value; + MemberRole(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } diff --git a/src/main/java/com/hallym/festival/domain/Users/repository/APIUserRepository.java b/src/main/java/com/hallym/festival/domain/Users/repository/APIUserRepository.java index 5e24077..961f4e3 100644 --- a/src/main/java/com/hallym/festival/domain/Users/repository/APIUserRepository.java +++ b/src/main/java/com/hallym/festival/domain/Users/repository/APIUserRepository.java @@ -10,8 +10,12 @@ public interface APIUserRepository extends JpaRepository { - @EntityGraph(attributePaths = "roleSet") - @Query("select m from APIUser m where m.mid = :mid") - Optional getWithRoles(@Param("mid") String mid); //로그인 시 Role도 같이 로딩 +// @EntityGraph(attributePaths = "roleSet") +// @Query("select m from APIUser m where m.mid = :mid") +// Optional getWithRoles(@Param("mid") String mid); //로그인 시 Role도 같이 로딩 + + @Query("SELECT u FROM APIUser u WHERE u.mid = :mid") //ID에 해당하는 사용자 정보 반환 + APIUser findByUserId(@Param("mid") String mid); + } diff --git a/src/main/java/com/hallym/festival/global/security/util/JWTUtil.java b/src/main/java/com/hallym/festival/global/security/util/JWTUtil.java index 3d96f2a..6f02050 100644 --- a/src/main/java/com/hallym/festival/global/security/util/JWTUtil.java +++ b/src/main/java/com/hallym/festival/global/security/util/JWTUtil.java @@ -1,9 +1,11 @@ package com.hallym.festival.global.security.util; +import com.hallym.festival.domain.Users.APIUserService; import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -16,6 +18,9 @@ @Log4j2 public class JWTUtil { + @Autowired + private APIUserService apiUserService; + @Value("${com.hallym.festival.jwt.secret}") private String key; @@ -23,6 +28,13 @@ public String generateToken(Map valueMap, int days){ //토큰을 log.info("----------generateKey... 시크릿키 : " + key); + String mid = (String) valueMap.get("mid"); + + log.info(mid); + + String roleSet = apiUserService.getRoleSetByMid(mid); + log.info("----------------" + roleSet); + //헤더 부분 Map headers = new HashMap<>(); headers.put("typ","JWT"); @@ -31,6 +43,7 @@ public String generateToken(Map valueMap, int days){ //토큰을 //payload 부분 설정 Map payloads = new HashMap<>(); payloads.putAll(valueMap); + payloads.put("role", roleSet); // role_set 정보 추가 //테스트 시에는 짧은 유효 기간 int time = (60*24) * days; //테스트는 분단위로 나중에 60*24 (일)단위변경 From 98a3c39935cb938cc7102acb00192fe47e57a76b Mon Sep 17 00:00:00 2001 From: dongheonlee Date: Mon, 8 May 2023 01:56:04 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor=20:=20JWT=20=EB=B0=9C=ED=96=89=20?= =?UTF-8?q?=EC=8B=9C=20=EB=B0=9B=EC=95=84=EC=98=A8=20ID=EC=99=80=20?= =?UTF-8?q?=EC=9D=BC=EC=B9=98=ED=95=98=EB=8A=94=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8A=94=20service=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20-=20Repository=EC=97=90=20ID=EC=99=80=20=EC=9D=BC?= =?UTF-8?q?=EC=B9=98=ED=95=98=EB=8A=94=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/domain/Users/APIUserService.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/hallym/festival/domain/Users/APIUserService.java diff --git a/src/main/java/com/hallym/festival/domain/Users/APIUserService.java b/src/main/java/com/hallym/festival/domain/Users/APIUserService.java new file mode 100644 index 0000000..759a0d9 --- /dev/null +++ b/src/main/java/com/hallym/festival/domain/Users/APIUserService.java @@ -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 정보를 제대로 가져오지 못했습니다"; + } + } + + + +} From 4389a4772c011fe11996458c3b3eb34cfc0e2b54 Mon Sep 17 00:00:00 2001 From: dongheonlee Date: Mon, 8 May 2023 01:57:25 +0900 Subject: [PATCH 5/6] =?UTF-8?q?chore=20:=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festival/domain/booth/controller/UploadController.java | 4 +++- .../festival/global/security/filter/RefreshTokenFilter.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hallym/festival/domain/booth/controller/UploadController.java b/src/main/java/com/hallym/festival/domain/booth/controller/UploadController.java index cb8f5f2..6db47ec 100644 --- a/src/main/java/com/hallym/festival/domain/booth/controller/UploadController.java +++ b/src/main/java/com/hallym/festival/domain/booth/controller/UploadController.java @@ -52,6 +52,8 @@ public List upload(UploadFileDTO uploadFileDTO) { try { multipartFile.transferTo(savePath); + log.info("Saved file path: " + savePath); + //이미지 파일의 종류라면 if(Files.probeContentType(savePath).startsWith("image")){ @@ -59,7 +61,7 @@ public List upload(UploadFileDTO uploadFileDTO) { File thumbFile = new File(uploadPath, "s_" + uuid+"_"+ originalName); - Thumbnailator.createThumbnail(savePath.toFile(), thumbFile, 200,200); + Thumbnailator.createThumbnail(savePath.toFile(), thumbFile, 400,400); } } catch (IOException e) { diff --git a/src/main/java/com/hallym/festival/global/security/filter/RefreshTokenFilter.java b/src/main/java/com/hallym/festival/global/security/filter/RefreshTokenFilter.java index 7d0ae9d..19b787d 100644 --- a/src/main/java/com/hallym/festival/global/security/filter/RefreshTokenFilter.java +++ b/src/main/java/com/hallym/festival/global/security/filter/RefreshTokenFilter.java @@ -36,7 +36,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse String path = request.getRequestURI(); if (!path.equals(refreshPath)) { - log.info("skip refresh token filter....."); +// log.info("skip refresh token filter....."); filterChain.doFilter(request, response); return; } From 090b4c61af5abfcbe239731d80ebf9c13083ed2b Mon Sep 17 00:00:00 2001 From: dongheonlee Date: Mon, 8 May 2023 01:58:54 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat=20:=20CSV=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=84=20=ED=8C=8C=EC=8B=B1=20test=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 + .../festival/repository/UserImportTest.java | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/test/java/com/hallym/festival/repository/UserImportTest.java diff --git a/build.gradle b/build.gradle index 5632941..ae4dbff 100644 --- a/build.gradle +++ b/build.gradle @@ -84,6 +84,9 @@ dependencies { //jwt 라이브러리 추가 - 가장 많이 사용되는 0.9.1 implementation 'io.jsonwebtoken:jjwt:0.9.1' + + //CSV 파일을 파싱하는 Java 라이브러리 + implementation 'com.opencsv:opencsv:5.5.2' } tasks.named('test') { diff --git a/src/test/java/com/hallym/festival/repository/UserImportTest.java b/src/test/java/com/hallym/festival/repository/UserImportTest.java new file mode 100644 index 0000000..52e2853 --- /dev/null +++ b/src/test/java/com/hallym/festival/repository/UserImportTest.java @@ -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 apiUsers = apiUserRepository.findAll(); + Assertions.assertEquals(3, apiUsers.size()); + } +} \ No newline at end of file