-
Notifications
You must be signed in to change notification settings - Fork 1
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 #14 from Hackathon0704/feat/3
[feat/3] 꿈 일기 생성
- Loading branch information
Showing
17 changed files
with
272 additions
and
7 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/umc/dream/controller/DreamController.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,30 @@ | ||
package com.umc.dream.controller; | ||
|
||
import com.umc.dream.apiPayload.ApiResponse; | ||
import com.umc.dream.converter.DreamConverter; | ||
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.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; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
public class DreamController { | ||
|
||
private DreamService dreamService; | ||
|
||
@PostMapping("/diary") | ||
public ApiResponse<AddDreamResponseDto> createDream(@RequestBody DreamRequestDto dreamRequestDto) { | ||
Dream dream = dreamService.createDream(dreamRequestDto); | ||
AddDreamResponseDto addDreamResponseDto = DreamConverter.toAddDreamResponse(dream); | ||
return ApiResponse.onSuccess(addDreamResponseDto); | ||
} | ||
} |
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,28 @@ | ||
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.dto.AddDreamResponseDto; | ||
import com.umc.dream.dto.DreamRequestDto; | ||
import com.umc.dream.dto.FollowResponseDto; | ||
|
||
public class DreamConverter { | ||
public static AddDreamResponseDto toAddDreamResponse(Dream dream) { | ||
return AddDreamResponseDto.builder() | ||
.dream_id(dream.getId()) | ||
.build(); | ||
} | ||
|
||
public static Dream toDream(DreamRequestDto dreamRequestDto, User user) { | ||
return Dream.builder() | ||
.user(user) | ||
.date(dreamRequestDto.getDate()) | ||
.sleepTime(dreamRequestDto.getSleepTime()) | ||
.wakeUpTime(dreamRequestDto.getWakeUpTime()) | ||
.title(dreamRequestDto.getTitle()) | ||
.content(dreamRequestDto.getContent()) | ||
.category(dreamRequestDto.getCategory()) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/umc/dream/converter/FeelingConverter.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,14 @@ | ||
package com.umc.dream.converter; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.Feeling; | ||
import com.umc.dream.domain.Hashtag; | ||
|
||
public class FeelingConverter { | ||
public static Feeling toFeeling(String feel, Dream dream) { | ||
return Feeling.builder() | ||
.feel(feel) | ||
.dream(dream) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/umc/dream/converter/HashtagConverter.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,14 @@ | ||
package com.umc.dream.converter; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.Hashtag; | ||
import com.umc.dream.domain.People; | ||
|
||
public class HashtagConverter { | ||
public static Hashtag toHashtag(String tag, Dream dream) { | ||
return Hashtag.builder() | ||
.tag(tag) | ||
.dream(dream) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/umc/dream/converter/PeopleConverter.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,15 @@ | ||
package com.umc.dream.converter; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.People; | ||
import com.umc.dream.domain.User; | ||
import com.umc.dream.dto.DreamRequestDto; | ||
|
||
public class PeopleConverter { | ||
public static People toPeople(String name, Dream dream) { | ||
return People.builder() | ||
.name(name) | ||
.dream(dream) | ||
.build(); | ||
} | ||
} |
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,14 @@ | ||
package com.umc.dream.converter; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.Feeling; | ||
import com.umc.dream.domain.Place; | ||
|
||
public class PlaceConverter { | ||
public static Place toPlace(String location, Dream dream) { | ||
return Place.builder() | ||
.location(location) | ||
.dream(dream) | ||
.build(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.umc.dream.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AddDreamResponseDto { | ||
private Long dream_id; | ||
} |
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,31 @@ | ||
package com.umc.dream.dto; | ||
|
||
import com.umc.dream.domain.Feeling; | ||
import com.umc.dream.domain.Hashtag; | ||
import com.umc.dream.domain.People; | ||
import com.umc.dream.domain.Place; | ||
import com.umc.dream.domain.enums.DreamCategory; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.sql.Time; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class DreamRequestDto { | ||
private Long users_id; | ||
private LocalDate date; | ||
private LocalDateTime sleepTime; | ||
private LocalDateTime wakeUpTime; | ||
private String title; | ||
private String content; | ||
private DreamCategory category; | ||
private List<String> people; | ||
private List<String> place; | ||
private List<String> feeling; | ||
private List<String> hashtag; | ||
} |
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,9 @@ | ||
package com.umc.dream.repository; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface DreamRepository extends JpaRepository<Dream, Long> { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/umc/dream/repository/FeelingRepository.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,8 @@ | ||
package com.umc.dream.repository; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.Feeling; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FeelingRepository extends JpaRepository<Feeling, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/umc/dream/repository/HashtagRepository.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,8 @@ | ||
package com.umc.dream.repository; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.Hashtag; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface HashtagRepository extends JpaRepository<Hashtag, Long> { | ||
} |
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,7 @@ | ||
package com.umc.dream.repository; | ||
|
||
import com.umc.dream.domain.People; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PeopleRepository extends JpaRepository<People, Long> { | ||
} |
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,8 @@ | ||
package com.umc.dream.repository; | ||
|
||
import com.umc.dream.domain.Dream; | ||
import com.umc.dream.domain.Place; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PlaceRepository extends JpaRepository<Place, Long> { | ||
} |
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,64 @@ | ||
package com.umc.dream.service; | ||
|
||
import com.umc.dream.apiPayload.code.status.ErrorStatus; | ||
import com.umc.dream.apiPayload.exception.GeneralException; | ||
import com.umc.dream.converter.*; | ||
import com.umc.dream.domain.*; | ||
import com.umc.dream.dto.DreamRequestDto; | ||
import com.umc.dream.dto.FollowRequestDto; | ||
import com.umc.dream.repository.*; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DreamService { | ||
private final DreamRepository dreamRepository; | ||
private final UserRepository userRepository; | ||
private final PeopleRepository peopleRepository; | ||
private final PlaceRepository placeRepository; | ||
private final HashtagRepository hashtagRepository; | ||
private final FeelingRepository feelingRepository; | ||
|
||
@Transactional | ||
public Dream createDream(DreamRequestDto dreamRequestDto) { | ||
User user = userRepository.findById(dreamRequestDto.getUsers_id()) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._BAD_REQUEST)); | ||
Dream dream = DreamConverter.toDream(dreamRequestDto, user); | ||
dreamRepository.save(dream); | ||
|
||
List<People> peopleList = new ArrayList<>(); | ||
for (String s : dreamRequestDto.getPeople()) { | ||
People people = PeopleConverter.toPeople(s, dream); | ||
peopleList.add(people); | ||
} | ||
peopleRepository.saveAll(peopleList); | ||
|
||
List<Hashtag> hashtagList = new ArrayList<>(); | ||
for (String s : dreamRequestDto.getHashtag()) { | ||
Hashtag hashtag = HashtagConverter.toHashtag(s, dream); | ||
hashtagList.add(hashtag); | ||
} | ||
hashtagRepository.saveAll(hashtagList); | ||
|
||
List<Feeling> feelings = new ArrayList<>(); | ||
for (String s : dreamRequestDto.getFeeling()) { | ||
Feeling feeling = FeelingConverter.toFeeling(s, dream); | ||
feelings.add(feeling); | ||
} | ||
feelingRepository.saveAll(feelings); | ||
|
||
List<Place> placeList = new ArrayList<>(); | ||
for (String s : dreamRequestDto.getPlace()) { | ||
Place place = PlaceConverter.toPlace(s, dream); | ||
placeList.add(place); | ||
} | ||
placeRepository.saveAll(placeList); | ||
|
||
return dream; | ||
} | ||
} |