Skip to content

Commit

Permalink
Merge pull request #17 from Hackathon0704/feat/3
Browse files Browse the repository at this point in the history
[feat/3] 내 꿈 일기 목록
  • Loading branch information
dlguszoo authored Jul 4, 2024
2 parents 5870dcc + 8078980 commit 8ae35e2
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/main/java/com/umc/dream/controller/DreamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import com.umc.dream.converter.FollowConverter;
import com.umc.dream.domain.Dream;
import com.umc.dream.domain.Follow;
import com.umc.dream.dto.AddDreamResponseDto;
import com.umc.dream.dto.DreamRequestDto;
import com.umc.dream.dto.FollowRequestDto;
import com.umc.dream.dto.FollowResponseDto;
import com.umc.dream.dto.*;
import com.umc.dream.service.DreamService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
Expand All @@ -27,4 +24,10 @@ public ApiResponse<AddDreamResponseDto> createDream(@RequestBody DreamRequestDto
AddDreamResponseDto addDreamResponseDto = DreamConverter.toAddDreamResponse(dream);
return ApiResponse.onSuccess(addDreamResponseDto);
}

@GetMapping("/diary/{user_id}")
private ApiResponse<List<GetDreamResponseDto>> GetDream(@RequestParam Long user_id) {
List<GetDreamResponseDto> getDreamResponseDtos = dreamService.getDream(user_id);
return ApiResponse.onSuccess(getDreamResponseDtos);
}
}
15 changes: 12 additions & 3 deletions src/main/java/com/umc/dream/converter/DreamConverter.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package com.umc.dream.converter;

import com.umc.dream.domain.Dream;
import com.umc.dream.domain.Follow;
import com.umc.dream.domain.User;
import com.umc.dream.domain.*;
import com.umc.dream.dto.AddDreamResponseDto;
import com.umc.dream.dto.DreamRequestDto;
import com.umc.dream.dto.FollowResponseDto;
import com.umc.dream.dto.GetDreamResponseDto;

public class DreamConverter {
public static AddDreamResponseDto toAddDreamResponse(Dream dream) {
return AddDreamResponseDto.builder()
.dream_id(dream.getId())
.build();
}
public static GetDreamResponseDto toGetDreamResponse(Dream dream, People people, Place place, Feeling feeling, Hashtag hashtag) {
return GetDreamResponseDto.builder()
.title(dream.getTitle())
.date(dream.getDate())
.people(people.getName())
.place(place.getLocation())
.feeling(feeling.getFeel())
.hashtag(hashtag.getTag())
.build();
}

public static Dream toDream(DreamRequestDto dreamRequestDto, User user) {
return Dream.builder()
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/umc/dream/dto/GetDreamResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.umc.dream.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class GetDreamResponseDto {
private String title;
private LocalDate date;
private String place;
private String people;
private String feeling;
private String hashtag;
}
4 changes: 3 additions & 1 deletion src/main/java/com/umc/dream/repository/DreamRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.umc.dream.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface DreamRepository extends JpaRepository<Dream, Long> {
import java.util.List;

public interface DreamRepository extends JpaRepository<Dream, Long> {
List<Dream> findAllByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface FeelingRepository extends JpaRepository<Feeling, Long> {
Feeling findFirstByDream(Dream dream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface HashtagRepository extends JpaRepository<Hashtag, Long> {
Hashtag findFirstByDream(Dream dream);
}
2 changes: 2 additions & 0 deletions src/main/java/com/umc/dream/repository/PeopleRepository.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.umc.dream.repository;

import com.umc.dream.domain.Dream;
import com.umc.dream.domain.People;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PeopleRepository extends JpaRepository<People, Long> {
People findFirstByDream(Dream dream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface PlaceRepository extends JpaRepository<Place, Long> {
Place findFirstByDream(Dream dream);
}
17 changes: 17 additions & 0 deletions src/main/java/com/umc/dream/service/DreamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.umc.dream.domain.*;
import com.umc.dream.dto.DreamRequestDto;
import com.umc.dream.dto.FollowRequestDto;
import com.umc.dream.dto.GetDreamResponseDto;
import com.umc.dream.repository.*;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -61,4 +62,20 @@ public Dream createDream(DreamRequestDto dreamRequestDto) {

return dream;
}

@Transactional
public List<GetDreamResponseDto> getDream(Long user_id) {
User user = userRepository.findById(user_id)
.orElseThrow(() -> new GeneralException(ErrorStatus._BAD_REQUEST));
List<Dream> dreams = dreamRepository.findAllByUser(user);
List<GetDreamResponseDto> getDreamResponseDtos = new ArrayList<>();
for (Dream d : dreams) {
People people = peopleRepository.findFirstByDream(d);
Place place = placeRepository.findFirstByDream(d);
Feeling feeling = feelingRepository.findFirstByDream(d);
Hashtag hashtag = hashtagRepository.findFirstByDream(d);
getDreamResponseDtos.add(DreamConverter.toGetDreamResponse(d, people, place, feeling, hashtag));
}
return getDreamResponseDtos;
}
}

0 comments on commit 8ae35e2

Please sign in to comment.