-
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.
Browse files
Browse the repository at this point in the history
Feature/#56
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/com/umc/DongnaeFriend/domain/scrap/controller/ScrapController.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,23 @@ | ||
package com.umc.DongnaeFriend.domain.scrap.controller; | ||
|
||
import com.umc.DongnaeFriend.domain.scrap.dto.ReqScrapDto; | ||
import com.umc.DongnaeFriend.domain.scrap.service.ScrapService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/scrap") | ||
public class ScrapController { | ||
private final ScrapService scrapService; | ||
|
||
// 스크랩 | ||
@PostMapping("") | ||
public String postScrap(@RequestBody ReqScrapDto reqScrapDto) { | ||
scrapService.newScrap(reqScrapDto); | ||
return ""; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/umc/DongnaeFriend/domain/scrap/dto/ReqScrapDto.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,13 @@ | ||
package com.umc.DongnaeFriend.domain.scrap.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReqScrapDto { | ||
Long townInformationId; | ||
Long accountBookId; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/umc/DongnaeFriend/domain/scrap/repository/ScrapRepository.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,18 @@ | ||
package com.umc.DongnaeFriend.domain.scrap.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard; | ||
import com.umc.DongnaeFriend.domain.scrap.entity.Scrap; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ScrapRepository extends JpaRepository<Scrap, Long> { | ||
@Query("SELECT u FROM User u WHERE u.id = :user_id") | ||
User findByUserId(@Param("user_id") Long user_id); | ||
@Query("SELECT sb FROM SharingBoard sb WHERE sb.id = :sharing_board_id") | ||
SharingBoard findBySharingBoardId(@Param("sharing_board_id") Long sharing_board_id); | ||
@Query("SELECT db FROM DongnaeBoard db WHERE db.id = :dongnae_board_id") | ||
DongnaeBoard findByDongnaeBoardId(@Param("dongnae_board_id") Long dongnae_board_id); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/umc/DongnaeFriend/domain/scrap/service/ScrapService.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,53 @@ | ||
package com.umc.DongnaeFriend.domain.scrap.service; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; | ||
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard; | ||
import com.umc.DongnaeFriend.domain.scrap.dto.ReqScrapDto; | ||
import com.umc.DongnaeFriend.domain.scrap.entity.Scrap; | ||
import com.umc.DongnaeFriend.domain.scrap.repository.ScrapRepository; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class ScrapService { | ||
private final ScrapRepository scrapRepository; | ||
|
||
public String newScrap(ReqScrapDto reqScrapDto) { | ||
// !임시! 유저 가져오기 | ||
User user = scrapRepository.findByUserId(1L); | ||
|
||
// 가계부 공유 | ||
if (!(reqScrapDto.getAccountBookId() == null)) { | ||
SharingBoard sharingBoard = scrapRepository.findBySharingBoardId(reqScrapDto.getAccountBookId()); | ||
|
||
// 스크랩 정보 저장 | ||
Scrap scrap = Scrap.builder() | ||
.sharingBoard(sharingBoard) | ||
.user(user) | ||
.build(); | ||
|
||
scrapRepository.save(scrap); | ||
} | ||
|
||
// 동네정보 | ||
else if (!(reqScrapDto.getTownInformationId() == null)) { | ||
DongnaeBoard dongnaeBoard = scrapRepository.findByDongnaeBoardId(reqScrapDto.getTownInformationId()); | ||
|
||
// 스크랩 정보 저장 | ||
Scrap scrap = Scrap.builder() | ||
.dongnaeBoard(dongnaeBoard) | ||
.user(user) | ||
.build(); | ||
|
||
scrapRepository.save(scrap); | ||
} | ||
|
||
else { | ||
return "스크랩 실패"; | ||
} | ||
|
||
return "스크랩 성공"; | ||
} | ||
} |