-
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.
Merge pull request #102 from SWM-Flash/integration
Integration
- Loading branch information
Showing
46 changed files
with
713 additions
and
105 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/com/first/flash/climbing/favorite/application/MemberFavoriteGymService.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,40 @@ | ||
package com.first.flash.climbing.favorite.application; | ||
|
||
import com.first.flash.climbing.favorite.application.dto.MemberFavoriteGymResponseDto; | ||
import com.first.flash.climbing.favorite.domain.MemberFavoriteGym; | ||
import com.first.flash.climbing.favorite.domain.MemberFavoriteGymRepository; | ||
import com.first.flash.climbing.gym.domian.ClimbingGymIdConfirmRequestedEvent; | ||
import com.first.flash.global.event.Events; | ||
import com.first.flash.global.util.AuthUtil; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemberFavoriteGymService { | ||
|
||
private final MemberFavoriteGymRepository memberFavoriteGymRepository; | ||
|
||
public MemberFavoriteGymResponseDto toggleMemberFavoriteGym(final Long gymId) { | ||
Events.raise(ClimbingGymIdConfirmRequestedEvent.of(gymId)); | ||
UUID memberId = AuthUtil.getId(); | ||
Optional<MemberFavoriteGym> favoriteGym = memberFavoriteGymRepository.findByMemberIdAndGymId(memberId, gymId); | ||
|
||
if (favoriteGym.isPresent()) { | ||
memberFavoriteGymRepository.delete(favoriteGym.get()); | ||
} else { | ||
MemberFavoriteGym memberFavoriteGym = MemberFavoriteGym.createDefault(memberId, gymId); | ||
memberFavoriteGymRepository.save(memberFavoriteGym); | ||
} | ||
return MemberFavoriteGymResponseDto.toDtoByStatus(favoriteGym.isPresent()); | ||
} | ||
|
||
public List<Long> findFavoriteGymIdsByMemberId(final UUID memberId) { | ||
return memberFavoriteGymRepository.findByMemberId(memberId).stream() | ||
.map(MemberFavoriteGym::getGymId) | ||
.toList(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../java/com/first/flash/climbing/favorite/application/dto/MemberFavoriteGymResponseDto.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,11 @@ | ||
package com.first.flash.climbing.favorite.application.dto; | ||
|
||
public record MemberFavoriteGymResponseDto(String message) { | ||
|
||
public static MemberFavoriteGymResponseDto toDtoByStatus(final boolean present) { | ||
if (present) { | ||
return new MemberFavoriteGymResponseDto("즐겨찾기에서 제거되었습니다."); | ||
} | ||
return new MemberFavoriteGymResponseDto("즐겨찾기에 추가되었습니다."); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/first/flash/climbing/favorite/domain/MemberFavoriteGym.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.first.flash.climbing.favorite.domain; | ||
|
||
import com.first.flash.global.domain.BaseEntity; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import java.util.UUID; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
@ToString | ||
public class MemberFavoriteGym extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private UUID memberId; | ||
private Long gymId; | ||
|
||
protected MemberFavoriteGym(final UUID memberId, final Long gymId) { | ||
this.memberId = memberId; | ||
this.gymId = gymId; | ||
} | ||
|
||
public static MemberFavoriteGym createDefault(final UUID memberId, final Long gymId) { | ||
return new MemberFavoriteGym(memberId, gymId); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/first/flash/climbing/favorite/domain/MemberFavoriteGymRepository.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.first.flash.climbing.favorite.domain; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface MemberFavoriteGymRepository { | ||
|
||
MemberFavoriteGym save(final MemberFavoriteGym memberFavoriteGym); | ||
|
||
Optional<MemberFavoriteGym> findById(final Long id); | ||
|
||
List<MemberFavoriteGym> findByMemberId(final UUID memberId); | ||
|
||
Optional<MemberFavoriteGym> findByMemberIdAndGymId(final UUID memberId, final Long gymId); | ||
|
||
void delete(final MemberFavoriteGym memberFavoriteGym); | ||
} |
20 changes: 20 additions & 0 deletions
20
...java/com/first/flash/climbing/favorite/infrastructure/MemberFavoriteGymJpaRepository.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,20 @@ | ||
package com.first.flash.climbing.favorite.infrastructure; | ||
|
||
import com.first.flash.climbing.favorite.domain.MemberFavoriteGym; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberFavoriteGymJpaRepository extends JpaRepository<MemberFavoriteGym, Long> { | ||
|
||
MemberFavoriteGym save(final MemberFavoriteGym memberFavoriteGym); | ||
|
||
Optional<MemberFavoriteGym> findById(final Long id); | ||
|
||
List<MemberFavoriteGym> findByMemberId(final UUID memberId); | ||
|
||
Optional<MemberFavoriteGym> findByMemberIdAndGymId(final UUID memberId, final Long gymId); | ||
|
||
void delete(final MemberFavoriteGym memberFavoriteGym); | ||
} |
42 changes: 42 additions & 0 deletions
42
...ava/com/first/flash/climbing/favorite/infrastructure/MemberFavoriteGymRepositoryImpl.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,42 @@ | ||
package com.first.flash.climbing.favorite.infrastructure; | ||
|
||
import com.first.flash.climbing.favorite.domain.MemberFavoriteGym; | ||
import com.first.flash.climbing.favorite.domain.MemberFavoriteGymRepository; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class MemberFavoriteGymRepositoryImpl implements MemberFavoriteGymRepository { | ||
|
||
private final MemberFavoriteGymJpaRepository memberFavoriteGymJpaRepository; | ||
|
||
@Override | ||
public MemberFavoriteGym save(final MemberFavoriteGym memberFavoriteGym) { | ||
return memberFavoriteGymJpaRepository.save(memberFavoriteGym); | ||
} | ||
|
||
@Override | ||
public Optional<MemberFavoriteGym> findById(final Long id) { | ||
return memberFavoriteGymJpaRepository.findById(id); | ||
} | ||
|
||
@Override | ||
public List<MemberFavoriteGym> findByMemberId(final UUID memberId) { | ||
return memberFavoriteGymJpaRepository.findByMemberId(memberId); | ||
} | ||
|
||
@Override | ||
public Optional<MemberFavoriteGym> findByMemberIdAndGymId(final UUID memberId, | ||
final Long gymId) { | ||
return memberFavoriteGymJpaRepository.findByMemberIdAndGymId(memberId, gymId); | ||
} | ||
|
||
@Override | ||
public void delete(final MemberFavoriteGym memberFavoriteGym) { | ||
memberFavoriteGymJpaRepository.delete(memberFavoriteGym); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/first/flash/climbing/favorite/ui/MemberFavoriteGymController.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,38 @@ | ||
package com.first.flash.climbing.favorite.ui; | ||
|
||
import com.first.flash.climbing.favorite.application.MemberFavoriteGymService; | ||
import com.first.flash.climbing.favorite.application.dto.MemberFavoriteGymResponseDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "favorite", description = "즐겨찾기 API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class MemberFavoriteGymController { | ||
|
||
private final MemberFavoriteGymService memberFavoriteGymService; | ||
|
||
@Operation(summary = "클라이밍장 즐겨찾기 생성/삭제", description = "클라이밍장 id로 즐겨찾기 토글") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "즐겨찾기 생성 및 삭제", | ||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MemberFavoriteGymResponseDto.class))), | ||
@ApiResponse(responseCode = "400", description = "유효하지 않은 요청 형식", | ||
content = @Content(mediaType = "application/json")) | ||
}) | ||
@PutMapping("/favorites/{gymId}") | ||
public ResponseEntity<MemberFavoriteGymResponseDto> toggleMemberFavoriteGym( | ||
@PathVariable final Long gymId) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(memberFavoriteGymService.toggleMemberFavoriteGym(gymId)); | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/first/flash/climbing/gym/application/dto/ClimbingGymDetailResponseDto.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,10 +1,11 @@ | ||
package com.first.flash.climbing.gym.application.dto; | ||
|
||
import com.first.flash.climbing.gym.infrastructure.dto.SectorInfoResponseDto; | ||
import java.util.List; | ||
|
||
public record ClimbingGymDetailResponseDto(String gymName, String mapImageUrl, | ||
String calendarImageUrl, | ||
List<String> difficulties, | ||
List<String> sectors) { | ||
List<SectorInfoResponseDto> sectors) { | ||
|
||
} |
10 changes: 0 additions & 10 deletions
10
src/main/java/com/first/flash/climbing/gym/application/dto/ClimbingGymResponseDto.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.