-
Notifications
You must be signed in to change notification settings - Fork 0
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
[MS-202] Feat: Create Banner API #108
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/modutaxi/api/domain/banner/controller/GetBannerController.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,29 @@ | ||
package com.modutaxi.api.domain.banner.controller; | ||
|
||
|
||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponseList; | ||
import com.modutaxi.api.domain.banner.service.GetBannerService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/banners") | ||
@Tag(name = "배너") | ||
public class GetBannerController { | ||
|
||
private final GetBannerService getBannerService; | ||
|
||
@Operation(summary = "배너 리스트 조회", | ||
description = "actibe상태의 배너 리스트를 조회합니다." | ||
) | ||
@GetMapping | ||
public ResponseEntity<BannerResponseList> getBannerList() { | ||
return ResponseEntity.ok(getBannerService.getBannerList()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/modutaxi/api/domain/banner/controller/RegisterBannerController.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.modutaxi.api.domain.banner.controller; | ||
|
||
import com.modutaxi.api.common.auth.CurrentMember; | ||
import com.modutaxi.api.domain.banner.dto.BannerRequestDto; | ||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponse; | ||
import com.modutaxi.api.domain.banner.service.RegisterBannerService; | ||
import com.modutaxi.api.domain.member.entity.Member; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/banners") | ||
@Tag(name = "배너") | ||
public class RegisterBannerController { | ||
private final RegisterBannerService registerBannerService; | ||
|
||
@Operation(summary = "배너 생성", description = "배너를 생성합니다. imageUrl, linkUrl을 넣어주세요. 초기 Active 값은 false입니다.") | ||
@PostMapping | ||
public ResponseEntity<BannerResponse> registerBanner( | ||
@Valid @RequestBody BannerRequestDto.CreateBannerRequest createBannerRequest) { | ||
return ResponseEntity.ok(registerBannerService.createBanner(createBannerRequest)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/modutaxi/api/domain/banner/dto/BannerRequestDto.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.modutaxi.api.domain.banner.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
public class BannerRequestDto { | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@ToString | ||
public static class CreateBannerRequest { | ||
@Schema(example = "String", description = "배너 이미지 url") | ||
private String imageUrl; | ||
@Schema(example = "String", description = "배너 링크 url") | ||
private String linkUrl; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/modutaxi/api/domain/banner/dto/BannerResponseDto.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,36 @@ | ||
package com.modutaxi.api.domain.banner.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
public class BannerResponseDto { | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@ToString | ||
public static class BannerResponse { | ||
@Schema(example = "1", description = "배너 id") | ||
private Long id; | ||
@Schema(example = "String", description = "배너 이미지 url") | ||
private String imageUrl; | ||
@Schema(example = "String", description = "배너 링크 url") | ||
private String linkUrl; | ||
@Schema(example = "false", description = "배너 활성화 여부") | ||
private boolean active; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@ToString | ||
public static class BannerResponseList { | ||
@Schema(description = "배너 리스트") | ||
List<BannerResponse> BannerResponseList; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/modutaxi/api/domain/banner/entity/Banner.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,36 @@ | ||
package com.modutaxi.api.domain.banner.entity; | ||
|
||
import com.modutaxi.api.common.entity.BaseTime; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.springframework.lang.Nullable; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@ToString | ||
public class Banner extends BaseTime { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotNull | ||
private String imageUrl; | ||
|
||
@Nullable | ||
private String linkUrl; | ||
|
||
@Builder.Default | ||
private boolean active = false; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/modutaxi/api/domain/banner/mapper/BannerMapper.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,36 @@ | ||
package com.modutaxi.api.domain.banner.mapper; | ||
|
||
import com.modutaxi.api.domain.banner.dto.BannerRequestDto.CreateBannerRequest; | ||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponse; | ||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponseList; | ||
import com.modutaxi.api.domain.banner.entity.Banner; | ||
import java.util.List; | ||
|
||
|
||
public class BannerMapper { | ||
|
||
public static Banner toEntity(CreateBannerRequest createBannerRequest) { | ||
return Banner.builder() | ||
.imageUrl(createBannerRequest.getImageUrl()) | ||
.linkUrl(createBannerRequest.getLinkUrl()) | ||
.build(); | ||
} | ||
|
||
|
||
public static BannerResponse toDto(Banner banner){ | ||
return BannerResponse.builder() | ||
.id(banner.getId()) | ||
.imageUrl(banner.getImageUrl()) | ||
.linkUrl(banner.getLinkUrl()) | ||
.active(banner.isActive()) | ||
.build(); | ||
} | ||
|
||
|
||
public static BannerResponseList toDtoList(List<BannerResponse> bannerResponses){ | ||
return BannerResponseList.builder() | ||
.BannerResponseList(bannerResponses) | ||
.build(); | ||
} | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
src/main/java/com/modutaxi/api/domain/banner/repository/BannerRepository.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,9 @@ | ||
package com.modutaxi.api.domain.banner.repository; | ||
|
||
import com.modutaxi.api.domain.banner.entity.Banner; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface BannerRepository extends JpaRepository<Banner, Long> { | ||
List<Banner> findAllByActiveTrue(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/modutaxi/api/domain/banner/service/GetBannerService.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.modutaxi.api.domain.banner.service; | ||
|
||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponse; | ||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponseList; | ||
import com.modutaxi.api.domain.banner.entity.Banner; | ||
import com.modutaxi.api.domain.banner.mapper.BannerMapper; | ||
import com.modutaxi.api.domain.banner.repository.BannerRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GetBannerService { | ||
|
||
private final BannerRepository bannerRepository; | ||
|
||
public BannerResponseList getBannerList() { | ||
|
||
List<Banner> banners = bannerRepository.findAllByActiveTrue(); | ||
|
||
List<BannerResponse> bannerResponses = | ||
banners.stream().map(BannerMapper::toDto).toList(); | ||
|
||
return BannerMapper.toDtoList(bannerResponses); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/modutaxi/api/domain/banner/service/RegisterBannerService.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.modutaxi.api.domain.banner.service; | ||
|
||
import com.modutaxi.api.domain.banner.dto.BannerRequestDto.CreateBannerRequest; | ||
import com.modutaxi.api.domain.banner.dto.BannerResponseDto.BannerResponse; | ||
import com.modutaxi.api.domain.banner.mapper.BannerMapper; | ||
import com.modutaxi.api.domain.banner.repository.BannerRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class RegisterBannerService { | ||
|
||
private final BannerRepository bannerRepository; | ||
@Transactional | ||
public BannerResponse createBanner(CreateBannerRequest createBannerRequest) { | ||
return BannerMapper.toDto(bannerRepository.save(BannerMapper.toEntity(createBannerRequest))); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오타있습니다!