Skip to content

Commit

Permalink
Merge pull request #9 from BbeumbungE/feat/BACK-123
Browse files Browse the repository at this point in the history
Feat: Point 도메인 추가
  • Loading branch information
ah9mon authored Sep 5, 2023
2 parents d6f545a + d6121ea commit 799071d
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.siliconvalley.domain.canvas.domain;

import com.siliconvalley.domain.item.subject.domain.Subject;
import com.siliconvalley.domain.post.domain.Post;
import com.siliconvalley.domain.profile.domain.Profile;
import com.siliconvalley.domain.subject.domain.Subject;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.siliconvalley.domain.item.item.domain.Item;
import com.siliconvalley.domain.item.avatar.dto.AvatarItemResponse;
import com.siliconvalley.domain.item.item.exception.ItemNotFoundException;
import com.siliconvalley.global.common.dto.Page.PageResponse;
import com.siliconvalley.global.common.dto.page.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.siliconvalley.domain.item.myitem.domain.MyItem;
import com.siliconvalley.domain.item.myitem.dto.MyAvatarItemResponse;
import com.siliconvalley.domain.item.myitem.dto.MySubjectItemResponse;
import com.siliconvalley.global.common.dto.Page.PageResponse;
import com.siliconvalley.global.common.dto.page.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.siliconvalley.domain.item.item.dao.ItemRepository;
import com.siliconvalley.domain.item.item.domain.Item;
import com.siliconvalley.domain.item.subject.dto.SubjectItemResponse;
import com.siliconvalley.global.common.dto.Page.PageResponse;
import com.siliconvalley.global.common.dto.page.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Member {
@Column(name = "create_at", nullable = false, updatable = false)
private LocalDateTime createAt;

@OneToMany(mappedBy = "member")
@OneToMany(mappedBy = "member", orphanRemoval = true)
private List<Profile> profileList = new ArrayList<>();

@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.siliconvalley.domain.point.application;

import com.siliconvalley.domain.point.domain.Point;
import com.siliconvalley.domain.point.dto.PointResponse;
import com.siliconvalley.domain.profile.dao.ProfileFindDao;
import com.siliconvalley.domain.profile.domain.Profile;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class PointManagementService {

private final ProfileFindDao profileFindDao;

public PointResponse getPoint(Long profileId) {
Profile profile = profileFindDao.findById(profileId);
return new PointResponse(profile.getPoint());
}

public void updatePoint(Long profileId, Long newPointValue) {
Profile profile = profileFindDao.findById(profileId);
Point point = profile.getPoint();
point.updatePoint(newPointValue);
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/siliconvalley/domain/point/domain/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.siliconvalley.domain.point.domain;

import com.siliconvalley.domain.profile.domain.Profile;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Table(name = "point")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Point {

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

@Column(name = "point")
private Long point;

@OneToOne
@JoinColumn(name = "profile_id")
private Profile profile;

@Builder
public Point(Long point, Profile profile) {
this.point = point;
this.profile = profile;
}

public void setProfile(Profile profile) {
this.profile = profile;
}

public void updatePoint(Long newPointValue) {
if (newPointValue != null) {
this.point = newPointValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.siliconvalley.domain.point.dto;

import com.siliconvalley.domain.point.domain.Point;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PointResponse {

private Long id;
private Long point;

public PointResponse(Point point) {
this.id = point.getId();
this.point = point.getPoint();
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/siliconvalley/domain/profile/api/ProfileApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.siliconvalley.domain.item.myitem.application.MyItemCreateService;
import com.siliconvalley.domain.item.myitem.dao.MyItemFindDao;
import com.siliconvalley.domain.point.application.PointManagementService;
import com.siliconvalley.domain.profile.application.ProfileManagementService;
import com.siliconvalley.domain.profile.dao.ProfileFindDao;
import com.siliconvalley.domain.profile.dto.ProfileCreateOrUpdate;
Expand All @@ -25,6 +26,7 @@ public class ProfileApi {
private final ProfileManagementService profileManagementService;
private final MyItemFindDao myItemFindDao;
private final MyItemCreateService myItemCreateService;
private final PointManagementService pointManagementService;

@PostMapping
public Response createProfile(
Expand Down Expand Up @@ -74,4 +76,20 @@ public Response purchaseSubjectItem(
) {
return Response.of(CommonCode.SUCCESS_CREATE, myItemCreateService.createMyItem(profileId, itemId, category));
}

@GetMapping("/{profileId}/points")
public Response getPoint(
@PathVariable(name = "profileId") Long profileId
) {
return Response.of(CommonCode.GOOD_REQUEST, pointManagementService.getPoint(profileId));
}

@PatchMapping("/{profileId}/points/{newPointValue}")
public Response updatePoint(
@PathVariable(name = "profileId") Long profileId,
@PathVariable(name = "newPointValue") Long newPointValue
) {
pointManagementService.updatePoint(profileId, newPointValue);
return Response.of(CommonCode.SUCCESS_UPDATE);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.siliconvalley.domain.profile.application;

import com.siliconvalley.domain.member.dao.MemberFindDao;
import com.siliconvalley.domain.member.domain.Member;
import com.siliconvalley.domain.profile.dao.ProfileFindDao;
import com.siliconvalley.domain.profile.dao.ProfileRepository;
import com.siliconvalley.domain.profile.domain.Profile;
Expand All @@ -22,7 +21,9 @@ public class ProfileManagementService {
private final ProfileFindDao profileFindDao;

public Profile createProfile(final String memberId, final ProfileCreateOrUpdate dto) {
return profileRepository.save(dto.toEntity(memberFindDao.findById(memberId)));
Profile profile = dto.toEntity(memberFindDao.findById(memberId));
profile.setPoint(profile.buildPoint());
return profileRepository.save(profile);
}

public ProfileResponse updateProfile(final Long profileId, final ProfileCreateOrUpdate dto) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/siliconvalley/domain/profile/domain/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.siliconvalley.domain.canvas.domain.Canvas;
import com.siliconvalley.domain.member.domain.Member;
import com.siliconvalley.domain.point.domain.Point;
import com.siliconvalley.domain.post.domain.Post;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -39,6 +40,9 @@ public class Profile {
@OneToMany(mappedBy = "profile", orphanRemoval = true, fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private List<Post> postList = new ArrayList<>();

@OneToOne(mappedBy = "profile", orphanRemoval = true, fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private Point point;

@Builder
public Profile(String profileName, String profileImage,Member member) {
this.profileName = profileName;
Expand All @@ -54,6 +58,17 @@ public void addPost(Post post){
this.postList.add(post);
}

public void setPoint(Point point) {
this.point = point;
point.setProfile(this);
}

public Point buildPoint() {
return Point.builder()
.point(0L)
.build();
}

public void updateProfile(
final String profileName,
final String profileImage) {
Expand Down
28 changes: 0 additions & 28 deletions src/main/java/com/siliconvalley/domain/subject/domain/Subject.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
public enum CommonCode implements ResponseCode{
GOOD_REQUEST(200, "올바른 요청입니다.", HttpStatus.OK),
SUCCESS_CREATE(201, "생성 성공했습니다.", HttpStatus.CREATED),
SUCCESS_UPDATE(204, "수정 완료했습니다.", HttpStatus.NO_CONTENT),
SUCCESS_DELETE(204, "삭제 완료했습니다.", HttpStatus.NO_CONTENT),
VALIDATION_FAIL(400, "입력값 검증이 실패하였습니다.", HttpStatus.BAD_REQUEST),
BAD_REQUEST(400, "잘못된 요청입니다.", HttpStatus.BAD_REQUEST),
ILLEGAL_REQUEST(422, "잘못된 데이터가 포함된 요청입니다.", HttpStatus.UNPROCESSABLE_ENTITY);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/siliconvalley/global/common/dto/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,19 @@ public static <T> Response<T> of(ResponseCode responseCode, T content) {

return response;
}

public static <T> Response<T> of(ResponseCode responseCode) {
Response<T> response = new Response<>();

Status status = new Status();
status.setCode(responseCode.getCode());
status.setMessage(responseCode.getMessage());
status.setHttpStatus(responseCode.getHttpStatus());

response.setStatus(status);
response.setContent(null);

return response;
}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.siliconvalley.global.common.dto.Page;
package com.siliconvalley.global.common.dto.page;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.siliconvalley.global.common.dto.Page;
package com.siliconvalley.global.common.dto.page;

import lombok.Getter;
import org.springframework.data.domain.Page;
Expand Down

0 comments on commit 799071d

Please sign in to comment.