-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 내가 올린 스팟 조회 및 내 정보 조회하기
- Loading branch information
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/umc/hackaton/snapspot/mypage/controller/MypageController.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,27 @@ | ||
package com.umc.hackaton.snapspot.mypage.controller; | ||
|
||
import com.umc.hackaton.snapspot.mypage.dto.MypageDto; | ||
import com.umc.hackaton.snapspot.mypage.service.MypageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/mypage") | ||
public class MypageController { | ||
final private MypageService mypageService; | ||
|
||
@GetMapping("/{userId}") | ||
public ResponseEntity<List<MypageDto.MySptDto>> readAllMySpot(@PathVariable Long userId){ | ||
return ResponseEntity.ok(mypageService.readAllMySpot(userId)); | ||
} | ||
|
||
|
||
@GetMapping("/{userId}/profile") | ||
public ResponseEntity<MypageDto.MyProfile> readMyProfile(@PathVariable Long userId){ | ||
return ResponseEntity.ok(mypageService.readMyProfile(userId)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/umc/hackaton/snapspot/mypage/converter/MypageConverter.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,31 @@ | ||
package com.umc.hackaton.snapspot.mypage.converter; | ||
|
||
import com.umc.hackaton.snapspot.mypage.dto.MypageDto; | ||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import com.umc.hackaton.snapspot.user.entity.User; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class MypageConverter { | ||
|
||
public static List<MypageDto.MySptDto> toDtoList(List<Spot> spotList){ | ||
return spotList.stream() | ||
.map(MypageConverter::toMySptDto) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static MypageDto.MySptDto toMySptDto(Spot spot){ | ||
return MypageDto.MySptDto.builder() | ||
.imageUrl(spot.getImgUrl()) | ||
.likeNum(spot.getLikeNum()) | ||
.spotId(spot.getId()) | ||
.build(); | ||
} | ||
public static MypageDto.MyProfile toMyProfileDto(User user){ | ||
return MypageDto.MyProfile.builder() | ||
.imageUrl(user.getProfileImg()) | ||
.nickName(user.getNickname()) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/umc/hackaton/snapspot/mypage/dto/MypageDto.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,21 @@ | ||
package com.umc.hackaton.snapspot.mypage.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class MypageDto { | ||
@Builder | ||
@Getter | ||
public static class MySptDto{ | ||
Long spotId; | ||
String imageUrl; | ||
Long likeNum; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
public static class MyProfile{ | ||
String nickName; | ||
String imageUrl; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/umc/hackaton/snapspot/mypage/service/MypageService.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,33 @@ | ||
package com.umc.hackaton.snapspot.mypage.service; | ||
|
||
import com.umc.hackaton.snapspot.mypage.converter.MypageConverter; | ||
import com.umc.hackaton.snapspot.mypage.dto.MypageDto; | ||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import com.umc.hackaton.snapspot.spot.repository.SpotRepository; | ||
import com.umc.hackaton.snapspot.user.entity.User; | ||
import com.umc.hackaton.snapspot.user.repository.UserRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class MypageService { | ||
|
||
private SpotRepository spotRepository; | ||
private UserRepository userRepository; | ||
|
||
public List<MypageDto.MySptDto> readAllMySpot(Long userId) { | ||
User user = userRepository.findById(userId).orElseThrow(()-> new IllegalArgumentException("존재하지 않는 사용자입니다.")); | ||
List<Spot> spotList = spotRepository.findAllByUser(user); | ||
|
||
return MypageConverter.toDtoList(spotList); | ||
} | ||
|
||
public MypageDto.MyProfile readMyProfile(Long userId) { | ||
User user = userRepository.findById(userId).orElseThrow(()-> new IllegalArgumentException("존재하지 않는 사용자입니다.")); | ||
|
||
return MypageConverter.toMyProfileDto(user); | ||
} | ||
|
||
|
||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/com/umc/hackaton/snapspot/spot/repository/SpotRepository.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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package com.umc.hackaton.snapspot.spot.repository; | ||
|
||
import com.umc.hackaton.snapspot.spot.entity.Spot; | ||
import com.umc.hackaton.snapspot.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface SpotRepository extends JpaRepository<Spot, Long> { | ||
@Override | ||
void delete(Spot entity); | ||
List<Spot> findAllByUser(User user); | ||
} |