-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/album permission #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/main/java/com/example/pventure/domain/album/controller/AlbumController.java
This file contains hidden or 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,89 @@ | ||
| package com.example.pventure.domain.album.controller; | ||
|
|
||
| import com.example.pventure.domain.album.docs.CreateAlbumDocs; | ||
| import com.example.pventure.domain.album.docs.DeleteAlbumDocs; | ||
| import com.example.pventure.domain.album.docs.GetAlbumDocs; | ||
| import com.example.pventure.domain.album.docs.GetAlbumsDocs; | ||
| import com.example.pventure.domain.album.docs.UpdateAlbumDocs; | ||
| import com.example.pventure.domain.album.dto.request.AlbumRequestDto; | ||
| import com.example.pventure.domain.album.dto.response.AlbumResponseDto; | ||
| import com.example.pventure.domain.album.service.AlbumService; | ||
| import com.example.pventure.global.response.CustomResponse; | ||
| import com.example.pventure.global.response.CustomResponseHelper; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
|
|
||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Tag(name = "Album", description = "μ¨λ² κ΄λ ¨ API") | ||
| @RestController | ||
| @RequestMapping("/trips/{tripId}/albums") | ||
| @RequiredArgsConstructor | ||
| public class AlbumController { | ||
|
|
||
| private final AlbumService albumService; | ||
|
|
||
| @CreateAlbumDocs | ||
| @PostMapping | ||
| public ResponseEntity<CustomResponse<AlbumResponseDto>> createAlbum( | ||
| @RequestParam Long userId, | ||
| @PathVariable Long tripId, | ||
| @Valid @RequestBody AlbumRequestDto requestDto | ||
| ) { | ||
| return CustomResponseHelper.created(albumService.createAlbum(userId, tripId, requestDto)); | ||
| } | ||
|
|
||
| @GetAlbumsDocs | ||
| @GetMapping | ||
| public ResponseEntity<CustomResponse<List<AlbumResponseDto>>> getAlbums( | ||
| @RequestParam Long userId, | ||
| @PathVariable Long tripId | ||
| ){ | ||
| return CustomResponseHelper.ok(albumService.getAlbums(userId, tripId)); | ||
| } | ||
|
|
||
| @GetAlbumDocs | ||
| @GetMapping("/{albumId}") | ||
| public ResponseEntity<CustomResponse<AlbumResponseDto>> getAlbum( | ||
| @RequestParam Long userId, | ||
| @PathVariable Long tripId, | ||
| @PathVariable Long albumId | ||
| ){ | ||
| return CustomResponseHelper.ok(albumService.getAlbum(userId, tripId, albumId)); | ||
| } | ||
|
|
||
| @UpdateAlbumDocs | ||
| @PutMapping("/{albumId}") | ||
| public ResponseEntity<CustomResponse<AlbumResponseDto>> updateAlbum( | ||
| @RequestParam Long userId, | ||
| @PathVariable Long tripId, | ||
| @PathVariable Long albumId, | ||
| @Valid @RequestBody AlbumRequestDto requestDto | ||
| ) { | ||
| return CustomResponseHelper.ok(albumService.updateAlbum(userId, tripId, albumId, requestDto)); | ||
| } | ||
|
|
||
| @DeleteAlbumDocs | ||
| @DeleteMapping("/{albumId}") | ||
| public ResponseEntity<Void> deleteAlbum( | ||
| @RequestParam Long userId, | ||
| @PathVariable Long tripId, | ||
| @PathVariable Long albumId | ||
| ) { | ||
| albumService.deleteAlbum(userId, tripId, albumId); | ||
| return CustomResponseHelper.noContent(); | ||
| } | ||
| } | ||
1 change: 0 additions & 1 deletion
1
src/main/java/com/example/pventure/domain/album/controller/README.md
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/pventure/domain/album/docs/AlbumSwaggerDocs.java
This file contains hidden or 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.example.pventure.domain.album.docs; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class AlbumSwaggerDocs { | ||
|
|
||
| // --- Create --- | ||
| public static final String CREATE_ALBUM_SUMMARY = "μ¨λ² μμ±"; | ||
| public static final String CREATE_ALBUM_DESCRIPTION = "μ¬μ©μ ID, μ¬ν ID, μ¨λ² μ 보λ₯Ό μ λ ₯νμ¬ μλ‘μ΄ μ¬ν μ¨λ²μ μμ±ν©λλ€."; | ||
|
|
||
| // --- Get Albums --- | ||
| public static final String GET_ALBUMS_SUMMARY = "μ¨λ² λͺ©λ‘ μ‘°ν"; | ||
| public static final String GET_ALBUMS_DESCRIPTION = "μ¬μ©μ IDμ μ¬ν IDλ‘ νΉμ μ¬νμ μν λͺ¨λ μ¨λ² λͺ©λ‘μ μ‘°νν©λλ€."; | ||
|
|
||
| // --- Get Album --- | ||
| public static final String GET_ALBUM_SUMMARY = "μ¨λ² μμΈ μ‘°ν"; | ||
| public static final String GET_ALBUM_DESCRIPTION = "μ¬μ©μ ID, μ¬ν ID, μ¨λ² IDλ‘ νΉμ μ¨λ²μ μμΈ μ 보λ₯Ό μ‘°νν©λλ€."; | ||
|
|
||
| // --- Update Album --- | ||
| public static final String UPDATE_ALBUM_SUMMARY = "μ¨λ² μ 보 μμ "; | ||
| public static final String UPDATE_ALBUM_DESCRIPTION = "μ¬μ©μ ID, μ¬ν ID, μ¨λ² IDλ₯Ό ν΅ν΄ μ¨λ² μ 보λ₯Ό μμ ν©λλ€."; | ||
|
|
||
| // --- Delete Album --- | ||
| public static final String DELETE_ALBUM_SUMMARY = "μ¨λ² μμ "; | ||
| public static final String DELETE_ALBUM_DESCRIPTION = "μ¬μ©μ ID, μ¬ν ID, μ¨λ² IDλ₯Ό ν΅ν΄ νΉμ μ¨λ²μ μμ ν©λλ€."; | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/pventure/domain/album/docs/CreateAlbumDocs.java
This file contains hidden or 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.example.pventure.domain.album.docs; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import java.lang.annotation.*; | ||
|
|
||
| @Documented | ||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Operation( | ||
| summary = AlbumSwaggerDocs.CREATE_ALBUM_SUMMARY, | ||
| description = AlbumSwaggerDocs.CREATE_ALBUM_DESCRIPTION | ||
| ) | ||
| @ApiResponse(responseCode = "201", description = "μμ± μ±κ³΅", useReturnTypeSchema = true) | ||
| @ApiResponse(responseCode = "400", description = "μλͺ»λ μμ²") | ||
| @ApiResponse(responseCode = "403", description = "νΈμ§ κΆν μμ") | ||
| @ApiResponse(responseCode = "404", description = "μ¬μ©μ λλ μ¬ν μμ") | ||
| public @interface CreateAlbumDocs {} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/pventure/domain/album/docs/DeleteAlbumDocs.java
This file contains hidden or 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.example.pventure.domain.album.docs; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Documented | ||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Operation( | ||
| summary = AlbumSwaggerDocs.DELETE_ALBUM_SUMMARY, | ||
| description = AlbumSwaggerDocs.DELETE_ALBUM_DESCRIPTION | ||
| ) | ||
| @ApiResponse(responseCode = "204", description = "μμ μ±κ³΅") | ||
| @ApiResponse(responseCode = "403", description = "νΈμ§ κΆν μμ") | ||
| @ApiResponse(responseCode = "404", description = "μ¬μ©μ λλ μ¬ν λλ μ¨λ² μμ") | ||
| public @interface DeleteAlbumDocs {} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/pventure/domain/album/docs/GetAlbumDocs.java
This file contains hidden or 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.example.pventure.domain.album.docs; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Documented | ||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Operation( | ||
| summary = AlbumSwaggerDocs.GET_ALBUM_SUMMARY, | ||
| description = AlbumSwaggerDocs.GET_ALBUM_DESCRIPTION | ||
| ) | ||
| @ApiResponse(responseCode = "200", description = "μ‘°ν μ±κ³΅", useReturnTypeSchema = true) | ||
| @ApiResponse(responseCode = "403", description = "보기 κΆν μμ") | ||
| @ApiResponse(responseCode = "404", description = "μ¬μ©μ λλ μ¬ν λλ μ¨λ² μμ") | ||
| public @interface GetAlbumDocs {} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/pventure/domain/album/docs/GetAlbumsDocs.java
This file contains hidden or 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.example.pventure.domain.album.docs; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Documented | ||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Operation( | ||
| summary = AlbumSwaggerDocs.GET_ALBUMS_SUMMARY, | ||
| description = AlbumSwaggerDocs.GET_ALBUMS_DESCRIPTION | ||
| ) | ||
| @ApiResponse(responseCode = "200", description = "μ‘°ν μ±κ³΅", useReturnTypeSchema = true) | ||
| @ApiResponse(responseCode = "403", description = "보기 κΆν μμ") | ||
| @ApiResponse(responseCode = "404", description = "μ¬μ©μ λλ μ¬ν μμ") | ||
| public @interface GetAlbumsDocs {} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/example/pventure/domain/album/docs/UpdateAlbumDocs.java
This file contains hidden or 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,22 @@ | ||
| package com.example.pventure.domain.album.docs; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Documented | ||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Operation( | ||
| summary = AlbumSwaggerDocs.UPDATE_ALBUM_SUMMARY, | ||
| description = AlbumSwaggerDocs.UPDATE_ALBUM_DESCRIPTION | ||
| ) | ||
| @ApiResponse(responseCode = "200", description = "μμ μ±κ³΅", useReturnTypeSchema = true) | ||
| @ApiResponse(responseCode = "400", description = "μλͺ»λ μμ²") | ||
| @ApiResponse(responseCode = "403", description = "νΈμ§ κΆν μμ") | ||
| @ApiResponse(responseCode = "404", description = "μ¬μ©μ λλ μ¬ν λλ μ¨λ² μμ") | ||
| public @interface UpdateAlbumDocs {} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/example/pventure/domain/album/dto/query/AlbumWithPhotoCountQDto.java
This file contains hidden or 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.example.pventure.domain.album.dto.query; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class AlbumWithPhotoCountQDto { | ||
|
|
||
| private final Long id; | ||
|
|
||
| private final String title; | ||
|
|
||
| private final Long photoCount; | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/pventure/domain/album/dto/request/AlbumRequestDto.java
This file contains hidden or 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,29 @@ | ||
| package com.example.pventure.domain.album.dto.request; | ||
|
|
||
| import com.example.pventure.domain.album.entity.Album; | ||
| import com.example.pventure.domain.trip.entity.Trip; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Schema(description = "μ¨λ² μμ±/μμ μμ² DTO") | ||
| public class AlbumRequestDto { | ||
|
|
||
| @Schema(description = "μ¨λ² μ΄λ¦", example = "1μΌμ°¨ μ¨λ²") | ||
| @NotBlank(message = "μ¨λ² μ΄λ¦μ μ λ ₯ν΄μ£ΌμΈμ.") | ||
| private String title; | ||
|
|
||
| public Album toEntity(Trip trip) { | ||
| return Album.builder() | ||
| .trip(trip) | ||
| .title(title) | ||
| .build(); | ||
| } | ||
| } |
1 change: 0 additions & 1 deletion
1
src/main/java/com/example/pventure/domain/album/dto/request/README.md
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/main/java/com/example/pventure/domain/album/dto/response/AlbumResponseDto.java
This file contains hidden or 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.example.pventure.domain.album.dto.response; | ||
|
|
||
| import com.example.pventure.domain.album.dto.query.AlbumWithPhotoCountQDto; | ||
| import com.example.pventure.domain.album.entity.Album; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Schema(description = "μ¨λ² μλ΅ DTO") | ||
| public class AlbumResponseDto { | ||
|
|
||
| @Schema(description = "μ¨λ² ID", example = "1") | ||
| private Long id; | ||
|
|
||
| @Schema(description = "μ¨λ² μ λͺ©", example = "1μΌμ°¨ μ¨λ²") | ||
| private String title; | ||
|
|
||
| @Schema(description = "μ¬μ§ κ°μ", example = "10") | ||
| private Long photoCount; | ||
|
|
||
| public static AlbumResponseDto from(Album album, Long photoCount) { | ||
| return AlbumResponseDto.builder() | ||
| .id(album.getId()) | ||
| .title(album.getTitle()) | ||
| .photoCount(photoCount) | ||
| .build(); | ||
| } | ||
|
|
||
| public static AlbumResponseDto from(AlbumWithPhotoCountQDto dto) { | ||
| return AlbumResponseDto.builder() | ||
| .id(dto.getId()) | ||
| .title(dto.getTitle()) | ||
| .photoCount(dto.getPhotoCount()) | ||
| .build(); | ||
| } | ||
| } |
1 change: 0 additions & 1 deletion
1
src/main/java/com/example/pventure/domain/album/dto/response/README.md
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
6 changes: 5 additions & 1 deletion
6
src/main/java/com/example/pventure/domain/album/repository/AlbumRepository.java
This file contains hidden or 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,7 +1,11 @@ | ||
| package com.example.pventure.domain.album.repository; | ||
|
|
||
| import com.example.pventure.domain.album.entity.Album; | ||
| import com.example.pventure.domain.trip.entity.Trip; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface AlbumRepository extends JpaRepository<Album, Long> { | ||
| public interface AlbumRepository extends JpaRepository<Album, Long>, AlbumRepositoryCustom { | ||
|
|
||
| Optional<Album> findByIdAndTrip(Long id, Trip trip); | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/pventure/domain/album/repository/AlbumRepositoryCustom.java
This file contains hidden or 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.example.pventure.domain.album.repository; | ||
|
|
||
| import com.example.pventure.domain.album.dto.query.AlbumWithPhotoCountQDto; | ||
| import java.util.List; | ||
|
|
||
| public interface AlbumRepositoryCustom { | ||
|
|
||
| List<AlbumWithPhotoCountQDto> findAllByTripWithPhotoCount(Long tripId); | ||
|
|
||
| AlbumWithPhotoCountQDto findByIdAndTripWithPhotoCount(Long albumId, Long tripId); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.