Skip to content
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

Refactor/gabang2/code refactoring #155

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public String createForm(Model model){
public String createChallenge(ChallengeRequestDTO challengeRequestDTO,
@RequestPart(value = "file", required = false) MultipartFile file){

if(!file.isEmpty()){
challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image"));
}
challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image"));

challengeService.createChallenge(challengeRequestDTO);
return "redirect:/backoffice/challenge";
Expand Down Expand Up @@ -104,9 +102,8 @@ public String editLevel(@PathVariable("challengeId") Long challengeId,
ChallengeEditDTO challengeEditDTO,
@RequestPart("file") MultipartFile file) {
// 이미지 업로드
if (!file.isEmpty()) {
challengeEditDTO.setImage(imageService.updateImage(file, "level", "badge"));
}
challengeEditDTO.setImage(imageService.updateImage(file, "level", "badge"));

// 레벨 수정
challengeService.editChallenge(challengeId, challengeEditDTO);
return "redirect:/backoffice/challenge";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public String feed(Model model) {
@GetMapping("/{feedId}/delete")
public String feedDelete(@PathVariable("feedId") Long feedId) {
Feed feed = feedService.verifiedFeed(feedId);
feedService.deleteFeedHard(feedId);
if (feed.getFulfillYn()) {
memberService.minusMemberExp(feed.getMember(), feed.getChallenge().getChallengeLevel().getExp());
}
feedService.deleteFeedHard(feed);
memberService.setMemberExpAndLevel(feed.getMember());
return "redirect:/backoffice/feed";
}

Expand All @@ -47,11 +45,10 @@ public String feedFullfill(@PathVariable("feedId") Long feedId) {

if (feedService.verifiedFeed(feedId).getFulfillYn()) {
feedService.patchFeedFulfill(feedId, false);
memberService.minusMemberExp(feed.getMember(), feed.getChallenge().getChallengeLevel().getExp());
} else {
feedService.patchFeedFulfill(feedId, true);
memberService.plusMemberExp(feed.getMember(), feed.getChallenge().getChallengeLevel().getExp());
}
memberService.setMemberExpAndLevel(feed.getMember());
return "redirect:/backoffice/feed";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ public String editLevel(@PathVariable("levelId") Long levelId,
LevelEditDto levelEditDto,
@RequestPart("file") MultipartFile file) {
// 이미지 업로드
if (!file.isEmpty()) {
levelEditDto.setBadge(imageService.updateImage(file, "level", "badge"));
}
levelEditDto.setBadge(imageService.updateImage(file, "level", "badge"));

// 레벨 수정
levelService.editLevel(levelId, levelEditDto);
return "redirect:/backoffice/level";
Expand Down Expand Up @@ -110,9 +109,7 @@ public String levelCreate(Model model) {
public String levelCreate(LevelRequestDto levelRequestDto,
@RequestPart("file") MultipartFile file) {
// 이미지 업로드
if (!file.isEmpty()) {
levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge"));
}
levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge"));

// 레벨 생성
Level level = levelService.createLevel(levelRequestDto);
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/dopamine/backend/backoffice/form/LevelForm.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public class ChallengeController {
@PostMapping(value = "/challenges", consumes={MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public void createChallenge(@Valid @RequestPart(value = "request") ChallengeRequestDTO challengeRequestDTO,
@RequestPart(value = "image", required = false) MultipartFile file){
if(file != null){
challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image"));
}
challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image"));

challengeService.createChallenge(challengeRequestDTO);
}
Expand Down Expand Up @@ -74,9 +72,8 @@ public ChallengeResponseDTO getChallenge(@PathVariable("challengeId") Long chall
@PutMapping(value = "/challenges/{challengeId}", consumes={MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public void editChallenge(@PathVariable Long challengeId, @RequestPart(value = "request") ChallengeEditDTO challengeEditDTO,
@RequestPart(value = "image", required = false) MultipartFile file){
if(file != null){
challengeEditDTO.setImage(imageService.updateImage(file, "challenge", "image"));
}

challengeEditDTO.setImage(imageService.updateImage(file, "challenge", "image"));

challengeService.editChallenge(challengeId, challengeEditDTO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Challenge(String title, String subtitle, String image, String challengeGu
this.challengeLevel = challengeLevel;
}

public void changeChallenge(ChallengeEditDTO challengeEditDTO){
public void changeChallenge(ChallengeEditDTO challengeEditDTO) {
this.title = challengeEditDTO.getTitle();
this.subtitle = challengeEditDTO.getSubtitle();
this.image = challengeEditDTO.getImage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dopamine.backend.domain.feed.controller;

import dopamine.backend.domain.feed.entity.Feed;
import dopamine.backend.domain.feed.request.FeedEditDTO;
import dopamine.backend.domain.feed.request.FeedRequestDTO;
import dopamine.backend.domain.feed.response.FeedResponseDTO;
import dopamine.backend.domain.feed.response.FeedYearResponseDto;
import dopamine.backend.domain.feed.service.FeedService;
import dopamine.backend.domain.member.entity.Member;
import dopamine.backend.domain.member.service.MemberService;
import dopamine.backend.global.exception.BusinessLogicException;
import dopamine.backend.global.exception.ExceptionCode;
import dopamine.backend.global.jwt.service.JwtService;
Expand All @@ -30,6 +32,7 @@ public class FeedController {
private final FeedService feedService;
private final ImageService imageService;
private final JwtService jwtService;
private final MemberService memberService;

/**
* 피드 조회
Expand Down Expand Up @@ -217,6 +220,8 @@ public void deleteFeed(@PathVariable Long feedId) {
*/
@DeleteMapping("/feeds/{feedId}/hard")
public void deleteFeedHard(@PathVariable Long feedId) {
feedService.deleteFeedHard(feedId);
Feed feed = feedService.verifiedFeed(feedId);
feedService.deleteFeedHard(feed);
memberService.setMemberExpAndLevel(feed.getMember());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Optional;

public interface FeedRepository extends JpaRepository<Feed, Long> {
List<Feed> findFeedByMemberAndDelYn(Member member, Boolean delYn);
List<Feed> findFeedByMemberAndDelYnAndFulfillYn(Member member, Boolean delYn, Boolean fulfillYn);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FulfillYn도 고려해야하네요
수정해주셔서 감사합니다

public List<Feed> findFeedByMemberAndDelYnAndCreatedDateBetweenOrderByCreatedDate(Member member, Boolean delYn, LocalDateTime startDate, LocalDateTime finishDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public void postFeed(Member member, FeedRequestDTO feedRequestDTO) {
feed.setChallenge(challenge);
feed.setMember(member);
setCertification(member, challenge);
int exp = feed.getChallenge().getChallengeLevel().getExp();
memberService.plusMemberExp(member, exp);
memberService.setMemberExpAndLevel(member);
feedRepository.save(feed);
}

Expand Down Expand Up @@ -141,14 +140,10 @@ public void deleteFeed(Long feedId) {

/**
* 피드 완전 삭제 (DB)
*
* @param feedId
* @param feed
*/
public void deleteFeedHard(Long feedId) {
Feed feed = verifiedFeed(feedId);

public void deleteFeedHard(Feed feed) {
feed.deleteFromChallenge();

feedRepository.delete(feed);
}

Expand Down Expand Up @@ -272,7 +267,7 @@ public List<FeedYearResponseDto> feedListByMemberAndYear(Member member, List<Str
*/
public void patchFeedFulfill(Long feedId, Boolean value) {
Feed feed = verifiedFeed(feedId);

feed.setFulfillYn(value);
memberService.setMemberExpAndLevel(feed.getMember());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public LevelResponseDto createLevel(
@RequestPart(value = "badge", required = false) MultipartFile file) {

// 이미지 업로드
if (file != null) {
levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge"));
}
levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge"));

// 레벨 생성
Level level = levelService.createLevel(levelRequestDto);
Expand Down Expand Up @@ -64,9 +62,7 @@ public LevelResponseDto editLevel(
@RequestPart(value = "badge", required = false) MultipartFile file) {

// 이미지 업로드
if (file != null) {
levelEditDto.setBadge(imageService.updateImage(file, "level", "badge"));
}
levelEditDto.setBadge(imageService.updateImage(file, "level", "badge"));

return levelService.editLevel(levelId, levelEditDto);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dopamine/backend/domain/level/entity/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ public void changeLevel(int levelNum, String name, String badge, int exp) {
this.exp = (exp != 0) ? exp : this.exp;
}

public void changeLevelNum(int levelNum) {
this.levelNum = (levelNum != 0) ? levelNum : this.levelNum;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public void run(String... args) throws Exception {
return levelService.createLevel(
LevelRequestDto
.builder()
.name("새싹지키미")
.badge("/url/testurl")
.name("새싹지킴이")
.exp(0)
.build()
);
Expand Down
Loading