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

부산대_2조_네모_7주차 #55

Merged
merged 26 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
85fc431
refactor: AlbumService 예외처리 이름 변경
won0104 Oct 18, 2023
2e89bdc
refactor: Auth Service 예외처리 이름 변경
won0104 Oct 18, 2023
7b64066
feat: AlbumPage 엔티티 임시 생성
won0104 Oct 18, 2023
23f6ed2
feat: Trashs 엔티티 생성
won0104 Oct 18, 2023
c4cf4dd
refactor: 주석 추가
won0104 Oct 18, 2023
4b68fc3
feat: Trashs 컨트롤러 생성
won0104 Oct 18, 2023
d12643a
feat: 휴지통 조회 메서드 생성
won0104 Oct 18, 2023
7b2a9df
feat: TrashsFindResponseDTO 디티오 생성
won0104 Oct 18, 2023
ebffb32
refactor: trashs -> trash로 변경
won0104 Oct 18, 2023
a2bfebc
refactor: trashService 파일 생성
won0104 Oct 20, 2023
4a1acf2
refactor: 변수 명 수정
Choi-Jungbin Oct 20, 2023
0588c3e
feat: 휴지통 조회 응답 DTO 수정
Choi-Jungbin Oct 20, 2023
af22c89
feat: 휴지통 레포지토리 작성
Choi-Jungbin Oct 21, 2023
e7ee6bb
feat: #52 휴지통 조회 메서드 작성
Choi-Jungbin Oct 21, 2023
26771e6
feat: #52 휴지통 조회 컨트롤러 메서드 작성
Choi-Jungbin Oct 21, 2023
198a75d
feat: #52 앨범 페이지 복구 메서드 작성
Choi-Jungbin Oct 21, 2023
24f4af5
feat: #52 앨범 페이지 복구 컨트롤러 메서드 작성
Choi-Jungbin Oct 21, 2023
4ab858a
refactor: 휴지통 서비스 이름 수정
Choi-Jungbin Oct 21, 2023
778227d
refactor: 휴지통 조회 메서드 이름 수정
Choi-Jungbin Oct 21, 2023
6049e6c
refactor: #52 휴지통 이미지 설정 수정
Choi-Jungbin Oct 21, 2023
c724ac6
refactor: #52 테이블 네임 삭제
Choi-Jungbin Oct 22, 2023
b857b02
refactor: #52 엔트 포인트 수정
Choi-Jungbin Oct 23, 2023
69bc59d
refactor: #52 변수 명 통일
Choi-Jungbin Oct 23, 2023
5b66aea
refactor: #52 트랜잭션 처리
Choi-Jungbin Oct 23, 2023
52bb647
Merge pull request #53 from Step3-kakao-tech-campus/feat/trashs
Choi-Jungbin Oct 23, 2023
f01e43b
Merge pull request #54 from Step3-kakao-tech-campus/weekly
Choi-Jungbin Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/example/team2_be/album/AlbumService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.example.team2_be.album.dto.AlbumCreateRequestDTO;
import com.example.team2_be.album.dto.AlbumFindAllResponseDTO;
import com.example.team2_be.album.dto.AlbumUpdaterequestDTO;
import com.example.team2_be.core.error.exception.Exception404;
import com.example.team2_be.core.error.exception.NotFoundException;
import com.example.team2_be.user.User;
import com.example.team2_be.user.UserJPARepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -38,7 +38,7 @@ public Album createAlbum(AlbumCreateRequestDTO requestDTO){
@Transactional
public Album updateAlbum(AlbumUpdaterequestDTO requestDTO, Long AlbumId) {
Album album = albumJPARepository.findById(AlbumId)
.orElseThrow(() -> new Exception404("해당 id값을 가진 앨범을 찾을 수 없습니다. : " + AlbumId));
.orElseThrow(() -> new NotFoundException("해당 id값을 가진 앨범을 찾을 수 없습니다. : " + AlbumId));

String updatedAlbumName = requestDTO.getAlbumName() != null ? requestDTO.getAlbumName() : album.getAlbumName();
String updatedDescription = requestDTO.getDescription() != null ? requestDTO.getDescription() : album.getDescription();
Expand All @@ -52,7 +52,7 @@ public Album updateAlbum(AlbumUpdaterequestDTO requestDTO, Long AlbumId) {
// 앨범 조회 기능
public AlbumFindAllResponseDTO findAllAlbum (Long userId){
User findUser = userJPARepository.findById(userId)
.orElseThrow(() -> new Exception404("해당 유저를 찾을 수 없습니다."));
.orElseThrow(() -> new NotFoundException("해당 유저를 찾을 수 없습니다."));

List<Album> albums = albumJPARepository.findAllByUserId(userId);

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/example/team2_be/album/page/AlbumPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.team2_be.album.page;

import com.example.team2_be.BaseEntity;
import com.example.team2_be.album.Album;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Getter
@ToString
@NoArgsConstructor
public class AlbumPage extends BaseEntity {
@ManyToOne
@JoinColumn(name = "album_id")
private Album album;
}
50 changes: 25 additions & 25 deletions src/main/java/com/example/team2_be/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ private KakaoTokenDTO getKakaoAccessToken(String code){
} catch (HttpStatusCodeException e){
switch (e.getStatusCode().value()){
case 400:
throw new Exception400("잘못된 요청입니다");
throw new BadRequestException("잘못된 요청입니다");
case 401:
throw new Exception401("인증되지 않은 사용자입니다");
throw new UnauthorizedException("인증되지 않은 사용자입니다");
case 403:
throw new Exception403("접근이 허용되지 않습니다");
throw new ForbiddenException("접근이 허용되지 않습니다");
case 404:
throw new Exception404("해당 사용자를 찾을 수 없습니다");
throw new NotFoundException("해당 사용자를 찾을 수 없습니다");
default:
throw new Exception500("토큰 발급 오류입니다");
throw new InternalSeverErrorException("토큰 발급 오류입니다");
}
}
catch (Exception e) {
throw new Exception500("토큰 발급 오류입니다");
throw new InternalSeverErrorException("토큰 발급 오류입니다");
}
}

Expand All @@ -94,19 +94,19 @@ public String kakaoLogin(String code){
} catch (HttpStatusCodeException e){
switch (e.getStatusCode().value()){
case 400:
throw new Exception400("잘못된 요청입니다");
throw new BadRequestException("잘못된 요청입니다");
case 401:
throw new Exception401("인증되지 않은 사용자입니다");
throw new UnauthorizedException("인증되지 않은 사용자입니다");
case 403:
throw new Exception403("접근이 허용되지 않습니다");
throw new ForbiddenException("접근이 허용되지 않습니다");
case 404:
throw new Exception404("해당 사용자를 찾을 수 없습니다");
throw new NotFoundException("해당 사용자를 찾을 수 없습니다");
default:
throw new Exception500("유저 정보 확인 오류입니다");
throw new InternalSeverErrorException("유저 정보 확인 오류입니다");
}
}
catch (Exception e) {
throw new Exception500("유저 정보 확인 오류입니다");
throw new InternalSeverErrorException("유저 정보 확인 오류입니다");
}

User user = userService.getUser(userAccount);
Expand All @@ -124,19 +124,19 @@ public String googleLogin(String code){
} catch (HttpStatusCodeException e){
switch (e.getStatusCode().value()){
case 400:
throw new Exception400("잘못된 요청입니다");
throw new BadRequestException("잘못된 요청입니다");
case 401:
throw new Exception401("인증되지 않은 사용자입니다");
throw new UnauthorizedException("인증되지 않은 사용자입니다");
case 403:
throw new Exception403("접근이 허용되지 않습니다");
throw new ForbiddenException("접근이 허용되지 않습니다");
case 404:
throw new Exception404("해당 사용자를 찾을 수 없습니다");
throw new NotFoundException("해당 사용자를 찾을 수 없습니다");
default:
throw new Exception500("유저 정보 확인 오류입니다");
throw new InternalSeverErrorException("유저 정보 확인 오류입니다");
}
}
catch (Exception e) {
throw new Exception500("유저 정보 확인 오류입니다");
throw new InternalSeverErrorException("유저 정보 확인 오류입니다");
}

User user = userService.getUser(userAccount);
Expand All @@ -156,19 +156,19 @@ private GoogleTokenDTO getGoogleAccessToken(String code){
} catch (HttpStatusCodeException e){
switch (e.getStatusCode().value()){
case 400:
throw new Exception400("잘못된 요청입니다");
throw new BadRequestException("잘못된 요청입니다");
case 401:
throw new Exception401("인증되지 않은 사용자입니다");
throw new UnauthorizedException("인증되지 않은 사용자입니다");
case 403:
throw new Exception403("접근이 허용되지 않습니다");
throw new ForbiddenException("접근이 허용되지 않습니다");
case 404:
throw new Exception404("해당 사용자를 찾을 수 없습니다");
throw new NotFoundException("해당 사용자를 찾을 수 없습니다");
default:
throw new Exception500("토큰 발급 오류입니다");
throw new InternalSeverErrorException("토큰 발급 오류입니다");
}
}
catch (Exception e) {
throw new Exception500("토큰 발급 오류입니다");
throw new InternalSeverErrorException("토큰 발급 오류입니다");
}
}

Expand All @@ -177,7 +177,7 @@ private String decoding(String code){
try {
decodedCode = java.net.URLDecoder.decode(code, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new Exception400("잘못된 요청입니다");
throw new BadRequestException("잘못된 요청입니다");
}
return decodedCode;
}
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/example/team2_be/trash/Trash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.team2_be.trash;

import com.example.team2_be.BaseEntity;
import com.example.team2_be.album.page.AlbumPage;
import com.example.team2_be.user.User;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Getter
@ToString
@NoArgsConstructor
public class Trash extends BaseEntity {
@ManyToOne
@JoinColumn(name = "user_id",nullable = false)
private User user;

@ManyToOne
@JoinColumn (name ="albumPage_id",nullable = false)
private AlbumPage albumPage;


@Column (nullable = false)
private LocalDateTime deleteAt;

@Builder
public Trash(Long id, User user, AlbumPage albumPage) {
super(id);
this.user = user;
this.albumPage =albumPage;
// 앨범 페이지 삭제 시간 - 여기서 할지 serviced에서 할지 테스트 필요
this.deleteAt = this.getCreateAt().plusDays(7);
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/example/team2_be/trash/TrashController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.team2_be.trash;

import com.example.team2_be.core.utils.ApiUtils;
import com.example.team2_be.trash.dto.TrashesFindResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/albums/{albumId}/trashes")
public class TrashController {

private final TrashService trashService;

//휴지통 조회 GET
@GetMapping
public ResponseEntity<ApiUtils.ApiResult<TrashesFindResponseDTO>> findTrashes (@PathVariable Long albumId){
TrashesFindResponseDTO findDTO = trashService.findTrashes(albumId);

return ResponseEntity.ok(ApiUtils.success(findDTO));
}

@PostMapping("/{trashId}")
public ResponseEntity<ApiUtils.ApiResult<Void>> restoreTrash(@PathVariable String albumId, @PathVariable Long trashId){
trashService.restoreTrash(trashId);

return ResponseEntity.ok(ApiUtils.success(null));
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/team2_be/trash/TrashJPARepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.team2_be.trash;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TrashJPARepository extends JpaRepository<Trash, Long> {
@Query("select t from Trash t where t.albumPage.album.id = :albumId")
List<Trash> findAllByAlbumId(@Param("albumId") Long albumId);
}
31 changes: 31 additions & 0 deletions src/main/java/com/example/team2_be/trash/TrashService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.team2_be.trash;

import com.example.team2_be.core.error.exception.NotFoundException;
import com.example.team2_be.trash.dto.TrashesFindResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class TrashService {

private final TrashJPARepository trashJPARepository;

public TrashesFindResponseDTO findTrashes(Long albumId){
List<Trash> trashes = trashJPARepository.findAllByAlbumId(albumId);

return new TrashesFindResponseDTO(albumId, trashes);
}

@Transactional
public void restoreTrash(Long trashId){
Trash trash = trashJPARepository.findById(trashId)
.orElseThrow(() -> new NotFoundException("해당 페이지가 휴지통 내에 존재하지 않습니다."));

trashJPARepository.delete(trash);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.team2_be.trash.dto;

import com.example.team2_be.trash.Trash;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Getter
public class TrashesFindResponseDTO {
private Long albumId;
private List<TrashDTO> trashes;


public TrashesFindResponseDTO(Long albumId, List<Trash> trashes){
this.albumId = albumId;
this.trashes = trashes.stream()
.map(TrashDTO::new)
.collect((Collectors.toList()));
}

@Getter
public static class TrashDTO{
private Long trashId;
private String image;
private String deleter;
private LocalDateTime createAt;
private LocalDateTime deleteAt;

public TrashDTO(Trash trash) {
this.trashId = trash.getId();
// 휴지통 페이지 미리보기 이미지 추가
this.deleter = trash.getUser().getNickname();
this.createAt = trash.getCreateAt();
this.deleteAt = trash.getDeleteAt();
}
}
}