From 207c3742ffa8a635c7e97a79aa57ab8f81a28901 Mon Sep 17 00:00:00 2001 From: jeongminkang Date: Thu, 22 Aug 2024 18:30:52 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 로그인을 하면 최초에만 정상적으로 잘 접속이 됬다. 이미 저장되어있는 refreshtoken을 중복으로 저장할수없다고 오류 발생하는 문제를 해결함. --- .../CertisHomepage/domain/ProjectEntity.java | 41 ------------ .../domain/token/TokenBusiness.java | 25 ++++--- .../service/ProjectService.java | 67 ------------------- .../web/controller/HomeController.java | 18 ----- .../web/controller/ProjectController.java | 19 ------ src/main/resources/templates/home.html | 10 --- 6 files changed, 14 insertions(+), 166 deletions(-) delete mode 100644 src/main/java/certis/CertisHomepage/domain/ProjectEntity.java delete mode 100644 src/main/java/certis/CertisHomepage/service/ProjectService.java delete mode 100644 src/main/java/certis/CertisHomepage/web/controller/HomeController.java delete mode 100644 src/main/java/certis/CertisHomepage/web/controller/ProjectController.java delete mode 100644 src/main/resources/templates/home.html diff --git a/src/main/java/certis/CertisHomepage/domain/ProjectEntity.java b/src/main/java/certis/CertisHomepage/domain/ProjectEntity.java deleted file mode 100644 index 429d0ae..0000000 --- a/src/main/java/certis/CertisHomepage/domain/ProjectEntity.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -package certis.CertisHomepage.domain; - - -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; -import java.util.List; - -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Entity -@Table(name = "project") -public class ProjectEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - private String projectName; - - private String content; - - private String writer; - - private LocalDateTime registeredAt; - - private LocalDateTime modifiedAt; - - @OneToMany(mappedBy = "project", cascade = CascadeType.ALL, fetch = FetchType.LAZY) - private List user; //프로젝트 1개에 유저여러명.. - - -} -*/ diff --git a/src/main/java/certis/CertisHomepage/domain/token/TokenBusiness.java b/src/main/java/certis/CertisHomepage/domain/token/TokenBusiness.java index 59ec3f6..0e6fd78 100644 --- a/src/main/java/certis/CertisHomepage/domain/token/TokenBusiness.java +++ b/src/main/java/certis/CertisHomepage/domain/token/TokenBusiness.java @@ -46,18 +46,21 @@ public TokenResponse issueToken(UserEntity userEntity){ //사용자가 가지고있던 기존 리프레쉬 토큰 삭제 refreshTokenRepository.findByUser(userEntity) - .ifPresent(refreshTokenRepository::delete); + .ifPresentOrElse( + existingToken -> { //존재하는 토큰은 + existingToken.setToken(refreshToken.getToken()); + existingToken.setExpiredAt(refreshToken.getExpiredAt()); + refreshTokenRepository.save(existingToken); + }, + () -> { // 없다면 + RefreshTokenEntity refreshTokenEntity = RefreshTokenEntity.builder() + .token(refreshToken.getToken()) + .expiredAt(refreshToken.getExpiredAt()) + .user(userEntity).build(); + refreshTokenRepository.save(refreshTokenEntity); + } + ); - log.info("refreshtoken은 {}",refreshToken.getToken()); - log.info("refreshtoken의 만료시간은 {}",refreshToken.getExpiredAt()); - - - RefreshTokenEntity refreshTokenEntity = RefreshTokenEntity.builder() - .token(refreshToken.getToken()) - .expiredAt(refreshToken.getExpiredAt()) - .user(userEntity).build(); - - refreshTokenRepository.save(refreshTokenEntity); return tokenConverter.toResponse(accessToken, refreshToken); diff --git a/src/main/java/certis/CertisHomepage/service/ProjectService.java b/src/main/java/certis/CertisHomepage/service/ProjectService.java deleted file mode 100644 index 3da88d3..0000000 --- a/src/main/java/certis/CertisHomepage/service/ProjectService.java +++ /dev/null @@ -1,67 +0,0 @@ -/* -package certis.CertisHomepage.service; - -import certis.CertisHomepage.domain.ProjectEntity; -import certis.CertisHomepage.repository.ProjectRepository; -import certis.CertisHomepage.web.dto.project.ProjectDto; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -@RequiredArgsConstructor -@Service -public class ProjectService { - - private final ProjectRepository projectRepository; - - - //전체 프로젝트 찾기 - @Transactional(readOnly = true) - public List getProjects(){ - List projects = projectRepository.findAll(); - List projectDtos = new ArrayList<>(); - projects.forEach(t -> projectDtos.add(ProjectDto.toDto(t))); - - return projectDtos; - } - - - //id값으로 프로젝트 찾기 - @Transactional(readOnly = true) - public ProjectDto getProject(Long id){ - ProjectEntity project = projectRepository.findById(id).orElseThrow(() -> { - return new IllegalArgumentException("Project Id를 찾을 수없음"); - }); - - ProjectDto dto = ProjectDto.toDto(project); - return dto; - } - - - public ProjectEntity register(ProjectDto projectDto){ - - ProjectEntity project = ProjectEntity.builder() - .writer(projectDto.getWriter()) - .projectName(projectDto.getProjectName()) - .content(projectDto.getContent()) - .user(projectDto.getUser()) - .modifiedAt(LocalDateTime.now()) - .registeredAt(LocalDateTime.now()) - .build(); - - return project; - } - - - - - - - - -} -*/ diff --git a/src/main/java/certis/CertisHomepage/web/controller/HomeController.java b/src/main/java/certis/CertisHomepage/web/controller/HomeController.java deleted file mode 100644 index dc738f7..0000000 --- a/src/main/java/certis/CertisHomepage/web/controller/HomeController.java +++ /dev/null @@ -1,18 +0,0 @@ -package certis.CertisHomepage.web.controller; - - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping("/") -public class HomeController { - - @GetMapping("/home") - public String Home(){ - return "home"; - } - - - -} diff --git a/src/main/java/certis/CertisHomepage/web/controller/ProjectController.java b/src/main/java/certis/CertisHomepage/web/controller/ProjectController.java deleted file mode 100644 index 4d057b9..0000000 --- a/src/main/java/certis/CertisHomepage/web/controller/ProjectController.java +++ /dev/null @@ -1,19 +0,0 @@ -/* -package certis.CertisHomepage.web.controller; - - - -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RestController; - -@RequiredArgsConstructor -@RestController -public class ProjectController { - - private final ProjectService projectService; - - - - -} -*/ diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html deleted file mode 100644 index 33613ff..0000000 --- a/src/main/resources/templates/home.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -

HOME

- - \ No newline at end of file