Skip to content

Commit

Permalink
feat : starpage create, layout, view, startype controller dev (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingLeeSeungHoon committed Apr 24, 2024
1 parent 881672b commit 8e04904
Show file tree
Hide file tree
Showing 27 changed files with 533 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class VotePost extends StarPagePost {
@Enumerated(value = EnumType.STRING)
private VoteStatus voteStatus;

// @Column(name = "time_to_live")
private int timeToLive;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.neo.needeachother.starpage.application;

import com.neo.needeachother.starpage.application.dto.CreatedStarPageResult;
import com.neo.needeachother.starpage.domain.SNSLine;
import com.neo.needeachother.starpage.domain.StarPage;
import com.neo.needeachother.starpage.domain.domainservice.StarPageIdGenerateService;
Expand All @@ -22,11 +23,21 @@ public class CreateStarPageService {
private final ApplicationEventPublisher eventPublisher;

@Transactional
public void createStarPage(String starNickName, String email, Set<String> starTypeSet,
List<SNSLine> snsLines, String starPageIntroduce){
public CreatedStarPageResult createStarPage(String starNickName, String email, Set<String> starTypeSet,
List<SNSLine> snsLines, String starPageIntroduce){
// 스타페이지 생성
StarPage createdStarPage = StarPage.create(idGenerateService.getNextId(), starNickName, email,
starTypeSet, snsLines, starPageIntroduce);

// 영속화
starPageRepository.save(createdStarPage);

// 생성 이벤트 발행 (기본 카테고리 자동 생성)
eventPublisher.publishEvent(new StarPageCreatedEvent(createdStarPage.getStarPageId()));

// 결과 값 생성
return CreatedStarPageResult.builder()
.createdStarPageId(createdStarPage.getStarPageId().getValue())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.neo.needeachother.starpage.application;

import com.neo.needeachother.category.domain.CategoryId;
import com.neo.needeachother.starpage.application.dto.StarPageLayoutResult;
import com.neo.needeachother.starpage.application.mapper.StarPageLayoutResultMapper;
import com.neo.needeachother.starpage.domain.*;
import com.neo.needeachother.starpage.domain.domainservice.CategoryVerifyForLayoutService;
import com.neo.needeachother.starpage.domain.repository.StarPageRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.neo.needeachother.starpage.application.StarPageServiceHelper.*;

@Service
Expand All @@ -16,10 +20,17 @@ public class LayoutManagementService {

private final StarPageRepository starPageRepository;
private final CategoryVerifyForLayoutService categoryVerifyForLayoutService;
private final StarPageLayoutResultMapper starPageLayoutResultMapper;

@Transactional
public void appendLayoutInStarPage(StarPageId id, String email, CategoryId categoryId){
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
foundStarPage.appendCategoricalLayoutLine(NEOMember.of(email), categoryVerifyForLayoutService, categoryId, false);
public List<StarPageLayoutResult> appendLayoutInStarPage(String starPageId, String email, String categoryId) {
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));

foundStarPage.appendCategoricalLayoutLine(NEOMember.of(email), categoryVerifyForLayoutService, CategoryId.of(categoryId), false);

return foundStarPage.getLayoutLines().stream()
.map(starPageLayoutResultMapper::map)
.toList();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ public class ModifyStarPageInformationService {
private final StarPageRepository starPageRepository;

@Transactional
public void modifyProfileImage(StarPageId id, String email, Image modifyingImage) {
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
foundStarPage.changeProfileImage(NEOMember.of(email), modifyingImage);
public void modifyProfileImage(String starPageId, String email, String modifyingImage) {
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
foundStarPage.changeProfileImage(NEOMember.of(email), Image.of(modifyingImage));
}

@Transactional
public void modifyTopRepresentativeImage(StarPageId id, String email, Image modifyingImage){
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
foundStarPage.changeTopRepresentativeImage(NEOMember.of(email), modifyingImage);
public void modifyTopRepresentativeImage(String starPageId, String email, String modifyingImage){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
foundStarPage.changeTopRepresentativeImage(NEOMember.of(email), Image.of(modifyingImage));
}

@Transactional
public void modifyStarNickName(StarPageId id, String email, String modifyingNickName){
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
public void modifyStarNickName(String starPageId, String email, String modifyingNickName){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
foundStarPage.changeStarNickName(email, modifyingNickName);
}

@Transactional
public void modifyStarIntroduction(StarPageId id, String email, String modifyingIntroduce){
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
public void modifyStarIntroduction(String starPageId, String email, String modifyingIntroduce){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
foundStarPage.changeStarPageIntroduction(NEOMember.of(email), StarPageIntroduction.of(modifyingIntroduce));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.neo.needeachother.starpage.application;

import com.neo.needeachother.starpage.application.dto.ModifiedStarTypeResult;
import com.neo.needeachother.starpage.domain.StarPage;
import com.neo.needeachother.starpage.domain.StarPageId;
import com.neo.needeachother.starpage.domain.StarType;
Expand All @@ -8,6 +9,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.stream.Collectors;

import static com.neo.needeachother.starpage.application.StarPageServiceHelper.*;

@Service
Expand All @@ -17,15 +20,35 @@ public class StarTypeService {
private final StarPageRepository starPageRepository;

@Transactional
public void addStarType(StarPageId id, String email, String starTypeName){
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
public ModifiedStarTypeResult addStarType(String starPageId, String email, String starTypeName) {
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));

// can trigger illegalStatementException in StarType.valueOf
foundStarPage.registerNewStarType(email, StarType.valueOf(starTypeName));

return ModifiedStarTypeResult.builder()
.starPageId(starPageId)
.modifiedStarTypes(foundStarPage.getInformation().getHost().getStarTypes()
.stream()
.map(Enum::name)
.collect(Collectors.toList())
)
.build();
}

public void removeStarType(StarPageId id, String email, String starTypeName){
StarPage foundStarPage = findExistingStarPage(starPageRepository, id);
@Transactional
public ModifiedStarTypeResult removeStarType(String starPageId, String email, String starTypeName) {
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
// can trigger illegalStatementException in StarType.valueOf
foundStarPage.removeStarType(email, StarType.valueOf(starTypeName));

return ModifiedStarTypeResult.builder()
.starPageId(starPageId)
.modifiedStarTypes(foundStarPage.getInformation().getHost().getStarTypes()
.stream()
.map(Enum::name)
.collect(Collectors.toList())
)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.neo.needeachother.starpage.application.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
@Builder
public class CreatedStarPageResult {
private String createdStarPageId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.neo.needeachother.starpage.application.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

import java.util.List;

@Getter
@ToString
@Builder
public class ModifiedStarTypeResult {
private String starPageId;
private List<String> modifiedStarTypes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.neo.needeachother.starpage.application.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
@Builder
public class StarPageLayoutResult {
private Long layoutId;
private String layoutTitle;
private String layoutType;
private String categoryId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.neo.needeachother.starpage.application.mapper;

import com.neo.needeachother.starpage.application.dto.StarPageLayoutResult;
import com.neo.needeachother.starpage.domain.CategoricalLayoutLine;
import com.neo.needeachother.starpage.domain.StarPageLayoutLine;
import org.springframework.stereotype.Component;

@Component
public class StarPageLayoutResultMapper implements Mapper<StarPageLayoutLine, StarPageLayoutResult> {

@Override
public StarPageLayoutResult map(StarPageLayoutLine input) {
StarPageLayoutResult.StarPageLayoutResultBuilder builder = StarPageLayoutResult.builder()
.layoutId(input.getLayoutId())
.layoutTitle(input.getLayoutTitle().getValue())
.layoutType(input.getType().name());

if (input instanceof CategoricalLayoutLine) {
builder.categoryId(((CategoricalLayoutLine) input).getCategoryId().getValue());
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ public static Image ofDefaultTopRepresentativeImage() {
return new Image("Default Profile Image Link");
}

public static Image of(String url){
return new Image(url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ public static SNSLine of(SNSType type, String url){
return new SNSLine(type, url);
}

public static SNSLine of(String typeName, String url) {
return new SNSLine(SNSType.valueOf(typeName), url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ public List<LayoutHeadLine> getLayoutHeadLines(StarPageRepository starPageReposi
.toList();
}

public void getTopView(){

}

// 도메인 : 스타페이지로 하여금 통합 카테고리를 생성할 수 있다. (팩토리)
public Category createCommonTypeCategory(CreateCategoryFromStarPageService createCategoryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public class StarPageId implements Serializable {
@Column(name = "star_page_id")
String value;

public static StarPageId of(String value){
return new StarPageId(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.neo.needeachother.starpage.domain.dto.*;
import com.neo.needeachother.starpage.domain.repository.StarPageRepositoryCustom;
import com.querydsl.core.group.GroupBy;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.neo.needeachother.starpage.presentation;

import com.neo.needeachother.starpage.application.CreateStarPageService;
import com.neo.needeachother.starpage.application.dto.CreatedStarPageResult;
import com.neo.needeachother.starpage.domain.SNSLine;
import com.neo.needeachother.starpage.presentation.dto.CreateStarPageRequest;
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;

import java.net.URI;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/starpage")
public class StarPageCreateController {

private final CreateStarPageService createStarPageService;

@PostMapping
public ResponseEntity<CreatedStarPageResult> demandCreateNewStarPage(@RequestBody CreateStarPageRequest createStarPageRequest) {

CreatedStarPageResult createdStarPageResult = createStarPageService.createStarPage(
createStarPageRequest.getStarNickName(),
createStarPageRequest.getEmail(),
createStarPageRequest.getStarTypeSet(),
createStarPageRequest.getSnsProfiles().stream()
.map(snsProfile -> SNSLine.of(snsProfile.getSnsTypeName(), snsProfile.getUrl()))
.toList(),
createStarPageRequest.getStarPageIntroduce()
);

return ResponseEntity.created(URI.create("/api/v1/starpage/" + createdStarPageResult.getCreatedStarPageId()))
.body(createdStarPageResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.neo.needeachother.starpage.presentation;

import com.neo.needeachother.starpage.application.LayoutManagementService;
import com.neo.needeachother.starpage.application.dto.StarPageLayoutResult;
import com.neo.needeachother.starpage.presentation.dto.AddCategoricalLayoutRequest;
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;

import java.net.URI;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/starpage")
public class StarPageLayoutController {

private final LayoutManagementService layoutManagementService;

@PostMapping("/layout")
public ResponseEntity demandAddLayout(@RequestBody AddCategoricalLayoutRequest addCategoricalLayoutRequest){
List<StarPageLayoutResult> result = layoutManagementService.appendLayoutInStarPage(
addCategoricalLayoutRequest.getStarPageId(),
addCategoricalLayoutRequest.getEmail(),
addCategoricalLayoutRequest.getCategoryId()
);

Long appendedLayoutId = result.get(result.size() - 1).getLayoutId();
return ResponseEntity.created(URI.create("/api/v1/starpage/layout?id=" + appendedLayoutId))
.body(result);
}
}
Loading

0 comments on commit 8e04904

Please sign in to comment.