Skip to content

Commit

Permalink
Merge pull request #26 from Timetris-Trendithon/userQuit
Browse files Browse the repository at this point in the history
โœจFeat: ํšŒ์› ํƒˆํ‡ด API
  • Loading branch information
jiinkyung authored Feb 21, 2024
2 parents 23841d2 + 760cc3f commit 7cddd26
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@AllArgsConstructor
Expand All @@ -18,10 +21,18 @@ public class Category {
private long id;
private String name;
private String colorCode;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId")
private User user;

@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Do> doList = new ArrayList<>();

@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Plan> planList = new ArrayList<>();


public Category(CategoryCreateDTO categoryCreateDTO, User user){
this.name = categoryCreateDTO.getName();
this.colorCode = categoryCreateDTO.getColorCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ public class Plan {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

private String title;

private LocalTime startTime;

private LocalTime endTime;

private boolean status;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "categoryId")
private Category category;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userDateId")
private UserDate userDate;
@OneToMany(mappedBy = "plan", cascade = CascadeType.ALL)

@OneToMany(mappedBy = "plan", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Cycle> cycle;

public Plan(PlanCreateDTO planCreateDTO, UserDate userDate){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;


@Entity
@Getter
Expand All @@ -17,13 +20,24 @@ public class UserDate {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "dateId")
private Date date;

@OneToMany(mappedBy = "userDate", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Do> doList = new ArrayList<>();

@OneToMany(mappedBy = "userDate", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Plan> planList = new ArrayList<>();

@OneToMany(mappedBy = "userDate", cascade = CascadeType.ALL, orphanRemoval = true)
private List<See> seeList = new ArrayList<>();

public UserDate(UserDateCreateDTO userDateCreateDTO){
this.user = userDateCreateDTO.getUser();
this.date = userDateCreateDTO.getDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public ApiResponse<MyPageResponse.getMyPageDTO> updateName(@RequestBody UpdateNa
return ApiResponse.success(SuccessStatus.OK, myPageDTO);

}

@PostMapping
@Operation(summary = "ํšŒ์› ํƒˆํ‡ด API")
public ApiResponse<?> userOutService(HttpServletRequest request) {
Long userId = tokenProvider.getUserId(request);
myPageService.deleteUser(userId);
return ApiResponse.success(SuccessStatus.DELETE_USER_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.trendithon.timetris.domain.member.domain;

import com.trendithon.timetris.domain.mainpage.domain.Category;
import com.trendithon.timetris.domain.mainpage.domain.UserDate;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@Builder
Expand Down Expand Up @@ -31,6 +36,12 @@ public class User {

private String refreshToken;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Category> categories = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserDate> userDateList = new ArrayList<>();

public void changeNickname(String nickname) {
this.nickname = nickname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.trendithon.timetris.domain.member.dto.MyPageResponse;
import com.trendithon.timetris.domain.member.dto.UpdateNameRequest;
import com.trendithon.timetris.domain.member.repository.UserRepository;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -41,5 +39,10 @@ public MyPageResponse.getMyPageDTO updateName(Long userId, UpdateNameRequest nam
.build();

}
@Transactional
public void deleteUser(Long userId) {
userRepository.deleteById(userId);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum SuccessStatus {
/**
* 200 OK
*/
OK(HttpStatus.OK, "COMMON200", "์„ฑ๊ณต์ž…๋‹ˆ๋‹ค.");
OK(HttpStatus.OK, "COMMON200", "์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
DELETE_USER_SUCCESS(HttpStatus.OK, "USER200", "์œ ์ € ํƒˆํ‡ด ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค.");

private final HttpStatus httpStatus;
private final String code;
Expand Down

0 comments on commit 7cddd26

Please sign in to comment.