Skip to content

Commit

Permalink
fix (#4) : 인증된 회원 시험 정보 및 캘린더 정보 리셋
Browse files Browse the repository at this point in the history
  • Loading branch information
daehwan2yo committed Apr 11, 2022
1 parent 5446337 commit 51eb8bf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.springframework.http.HttpStatus.*;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -33,4 +34,10 @@ ResponseEntity<Void> getValidationNickname(@RequestParam("value") String nicknam
ResponseEntity<String> get(@LoginAccount Account account) {
return ResponseEntity.ok(account.getEmail() + " : " + account.getProvider());
}

@DeleteMapping("/me")
ResponseEntity<Void> reset(@LoginAccount Account account) {
accountService.reset(account);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface AccountService {
Account findAccount(Long userId);

boolean isValidNickname(String nickname);

void reset(Account account);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.transaction.annotation.Transactional;

import com.codingwasabi.howtodo.web.account.entity.Account;
import com.codingwasabi.howtodo.web.calendar.CalendarRepository;
import com.codingwasabi.howtodo.web.dailyplan.DailyPlanRepository;
import com.codingwasabi.howtodo.web.dailyplan.entity.DailyPlan;

import lombok.RequiredArgsConstructor;

Expand All @@ -12,6 +15,7 @@
@RequiredArgsConstructor
public class AccountServiceImpl implements AccountService {
private final AccountRepository accountRepository;
private final CalendarRepository calendarRepository;

@Override
public Account findAccount(Long accountId) {
Expand All @@ -24,4 +28,9 @@ public Account findAccount(Long accountId) {
public boolean isValidNickname(String nickname) {
return !accountRepository.existsByNickname(nickname);
}

@Override
public void reset(Account account) {
calendarRepository.deleteByAccount(account);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@

public interface CalendarRepository extends JpaRepository<Calendar, Long> {
Optional<Calendar> findByAccount(Account account);

void deleteByAccount(Account account);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class DailyPlan {
@ManyToOne(fetch = FetchType.LAZY)
private Account account;

@OneToMany(mappedBy = "dailyPlan", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "dailyPlan", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ToDo> toDos = new ArrayList<>();

@OneToMany(mappedBy = "dailyPlan", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "dailyPlan", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> comments = new ArrayList<>();

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDate;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand All @@ -28,7 +29,7 @@ public class ToDo {

private double hour;

@OneToOne(fetch = FetchType.LAZY)
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true, cascade = CascadeType.REMOVE)
private Exam exam;

@Setter
Expand Down

0 comments on commit 51eb8bf

Please sign in to comment.