-
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.
Feat/campaign
- Loading branch information
Showing
10 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
...ain/java/com/project/pieceserver/domain/campaign/application/service/CampaignService.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,28 @@ | ||
package com.project.pieceserver.domain.campaign.application.service; | ||
|
||
import com.project.pieceserver.domain.campaign.client.dto.Campaign; | ||
import com.project.pieceserver.domain.campaign.domain.repository.jpa.CampaignRepository; | ||
import com.project.pieceserver.domain.campaign.domain.repository.query.CampaignQueryRepository; | ||
import com.project.pieceserver.global.common.dto.request.PageRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CampaignService { | ||
|
||
private final CampaignRepository campaignRepository; | ||
private final CampaignQueryRepository campaignQueryRepository; | ||
private final Campaign campaignDTO; | ||
|
||
public void save(Campaign campaign) { | ||
campaignRepository.save(campaignDTO.toEntity(campaign)); | ||
} | ||
|
||
public List<Campaign> CampaignList(PageRequest pageRequest) { | ||
return campaignQueryRepository.campaignList(pageRequest); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/project/pieceserver/domain/campaign/client/api/CampaignController.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.project.pieceserver.domain.campaign.client.api; | ||
|
||
import com.project.pieceserver.domain.campaign.client.dto.Campaign; | ||
import com.project.pieceserver.domain.campaign.client.dto.request.CampaignRegisterRequest; | ||
import com.project.pieceserver.domain.campaign.usecase.CampaignUseCase; | ||
import com.project.pieceserver.global.common.dto.request.PageRequest; | ||
import com.project.pieceserver.global.common.dto.response.BaseResponse; | ||
import com.project.pieceserver.global.common.dto.response.BaseResponseData; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
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; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/campaign") | ||
@RequiredArgsConstructor | ||
@Tag(name = "캠페인 API") | ||
public class CampaignController { | ||
|
||
private final CampaignUseCase campaignUseCase; | ||
|
||
@PostMapping("") | ||
public BaseResponse registerCampaign(@RequestBody CampaignRegisterRequest campaignRegisterRequest) { | ||
campaignUseCase.registerCampaign(campaignRegisterRequest); | ||
return BaseResponse.ok("등록되었습니다."); | ||
} | ||
|
||
@GetMapping("") | ||
public BaseResponseData<List<Campaign>> campaignList(@ModelAttribute PageRequest pageRequest){ | ||
return BaseResponseData.ok( | ||
"캠페인 리스트를 성공적으로 불러왔습니다.", | ||
campaignUseCase.campaignList(pageRequest)); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/project/pieceserver/domain/campaign/client/dto/Campaign.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.project.pieceserver.domain.campaign.client.dto; | ||
|
||
import com.project.pieceserver.domain.campaign.domain.entity.CampaignEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@Component | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Campaign { | ||
|
||
private Long idx; | ||
private String title; | ||
private String description; | ||
private String imageUrl; | ||
|
||
public CampaignEntity toEntity(Campaign campaign) { | ||
return CampaignEntity.builder() | ||
.idx(campaign.getIdx()) | ||
.title(campaign.getTitle()) | ||
.description(campaign.getDescription()) | ||
.imageUrl(campaign.getImageUrl()) | ||
.build(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...a/com/project/pieceserver/domain/campaign/client/dto/request/CampaignRegisterRequest.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,8 @@ | ||
package com.project.pieceserver.domain.campaign.client.dto.request; | ||
|
||
public record CampaignRegisterRequest( | ||
String title, | ||
String description, | ||
String imageUrl | ||
) { | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/project/pieceserver/domain/campaign/domain/entity/CampaignEntity.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,34 @@ | ||
package com.project.pieceserver.domain.campaign.domain.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Entity | ||
@Getter | ||
@SuperBuilder | ||
@Table(name = "tb_campaign") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CampaignEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long idx; | ||
|
||
@Column(nullable = false) | ||
private String title; | ||
|
||
@Column(nullable = false) | ||
private String description; | ||
|
||
@Column(nullable = false) | ||
private String imageUrl; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ava/com/project/pieceserver/domain/campaign/domain/repository/jpa/CampaignRepository.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,7 @@ | ||
package com.project.pieceserver.domain.campaign.domain.repository.jpa; | ||
|
||
import com.project.pieceserver.domain.campaign.domain.entity.CampaignEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CampaignRepository extends JpaRepository<CampaignEntity, Long> { | ||
} |
40 changes: 40 additions & 0 deletions
40
.../project/pieceserver/domain/campaign/domain/repository/query/CampaignQueryRepository.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.project.pieceserver.domain.campaign.domain.repository.query; | ||
|
||
import com.project.pieceserver.domain.campaign.client.dto.Campaign; | ||
import com.project.pieceserver.global.common.dto.request.PageRequest; | ||
import com.querydsl.core.types.ConstructorExpression; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.project.pieceserver.domain.campaign.domain.entity.QCampaignEntity.campaignEntity; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CampaignQueryRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public List<Campaign> campaignList(PageRequest request){ | ||
return jpaQueryFactory | ||
.select(campaignConstructorExpression()) | ||
.from(campaignEntity) | ||
.offset((long) (request.getPage() - 1) * request.getSize()) | ||
.limit(request.getSize()) | ||
.orderBy(campaignEntity.idx.asc()) | ||
.fetch(); | ||
} | ||
|
||
private ConstructorExpression<Campaign> campaignConstructorExpression(){ | ||
return Projections.constructor(Campaign.class, | ||
campaignEntity.idx, | ||
campaignEntity.title, | ||
campaignEntity.description, | ||
campaignEntity.imageUrl | ||
); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/project/pieceserver/domain/campaign/usecase/CampaignUseCase.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,30 @@ | ||
package com.project.pieceserver.domain.campaign.usecase; | ||
|
||
import com.project.pieceserver.domain.campaign.application.service.CampaignService; | ||
import com.project.pieceserver.domain.campaign.client.dto.Campaign; | ||
import com.project.pieceserver.domain.campaign.client.dto.request.CampaignRegisterRequest; | ||
import com.project.pieceserver.global.common.dto.request.PageRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CampaignUseCase { | ||
|
||
private final CampaignService campaignService; | ||
|
||
public void registerCampaign(CampaignRegisterRequest campaignRegisterRequest) { | ||
campaignService.save(Campaign.builder() | ||
.title(campaignRegisterRequest.title()) | ||
.description(campaignRegisterRequest.description()) | ||
.imageUrl(campaignRegisterRequest.imageUrl()) | ||
.build()); | ||
} | ||
|
||
public List<Campaign> campaignList(PageRequest pageRequest) { | ||
return campaignService.CampaignList(pageRequest); | ||
} | ||
|
||
} |
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