Skip to content

Commit

Permalink
🔀 :: feat/campaign merge
Browse files Browse the repository at this point in the history
Feat/campaign
  • Loading branch information
lgwk42 authored Jul 17, 2024
2 parents d9199f1 + 4a570d8 commit 4f055a4
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
implementation 'org.seleniumhq.selenium:selenium-java:4.1.2'
}

tasks.named('test') {
Expand Down
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);
}

}
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));
}

}
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();
}

}
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
) {
}
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;

}
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> {
}
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
);
}

}
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public class SecurityConfig {
private final JwtAuthenticationFilter jwtAuthenticationFilter;
private final JwtExceptionFilter jwtExceptionFilter;

private static final String USER = "ROLE_USER";
private static final String TEACHER = "ROLE_TEACHER";
private static final String ADMIN = "ROLE_ADMIN";

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
Expand Down

0 comments on commit 4f055a4

Please sign in to comment.