-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#20] feature : 구독 생성
- Loading branch information
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
UserService/src/main/java/com/submarket/userservice/controller/SubController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.submarket.userservice.controller; | ||
|
||
import com.submarket.userservice.dto.SubDto; | ||
import com.submarket.userservice.jpa.entity.SubEntity; | ||
import com.submarket.userservice.mapper.SubMapper; | ||
import com.submarket.userservice.service.impl.SubService; | ||
import com.submarket.userservice.vo.RequestSub; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
@RestController | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class SubController { | ||
private final SubService subService; | ||
|
||
@PostMapping("/sub") | ||
public ResponseEntity<String> createNewSub(@RequestBody RequestSub requestSub) { | ||
log.info(this.getClass().getName() + ".createNewSub Start!"); | ||
|
||
SubDto subDto = new SubDto(); | ||
subDto.setItemSeq(requestSub.getItemSeq()); | ||
|
||
int res = subService.createNewSub(subDto); | ||
|
||
if (res != 1) { | ||
return ResponseEntity.status(500).body("오류"); | ||
} | ||
|
||
log.info(this.getClass().getName() + ".createNewSub End! "); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED).body("구독 성공"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
UserService/src/main/java/com/submarket/userservice/mapper/SubMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.submarket.userservice.mapper; | ||
|
||
import com.submarket.userservice.dto.SubDto; | ||
import com.submarket.userservice.jpa.entity.SubEntity; | ||
import com.submarket.userservice.vo.ResponseSub; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface SubMapper { | ||
SubMapper INSTANCE = Mappers.getMapper(SubMapper.class); | ||
|
||
SubEntity subDtoToSubEntity(SubDto subDto); | ||
|
||
@Mapping(target = "user", ignore = true) // Entity 를 DTO 에 담을 때 user 정보 무시 | ||
SubDto subEntityToSubDto(SubEntity subEntity); | ||
|
||
ResponseSub responseSubToSubDto(SubDto subDto); | ||
} |
10 changes: 10 additions & 0 deletions
10
UserService/src/main/java/com/submarket/userservice/service/ISubService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.submarket.userservice.service; | ||
|
||
import com.submarket.userservice.dto.SubDto; | ||
import com.submarket.userservice.jpa.entity.SubEntity; | ||
|
||
import java.util.List; | ||
|
||
public interface ISubService { | ||
int createNewSub(SubDto subDto); | ||
} |
50 changes: 50 additions & 0 deletions
50
UserService/src/main/java/com/submarket/userservice/service/impl/SubService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.submarket.userservice.service.impl; | ||
|
||
import com.submarket.userservice.dto.SubDto; | ||
import com.submarket.userservice.jpa.SubRepository; | ||
import com.submarket.userservice.jpa.UserRepository; | ||
import com.submarket.userservice.jpa.entity.SubEntity; | ||
import com.submarket.userservice.jpa.entity.UserEntity; | ||
import com.submarket.userservice.mapper.SubMapper; | ||
import com.submarket.userservice.service.ISubService; | ||
import com.submarket.userservice.util.DateUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.persistence.EntityNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service(value = "SubService") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class SubService implements ISubService { | ||
private final SubRepository subRepository; | ||
private final UserRepository userRepository; | ||
private final UserService userService; | ||
|
||
/** ------------------------- 구독 생성 ------------------------------*/ | ||
@Override | ||
public int createNewSub(SubDto subDto) { | ||
log.info(this.getClass().getName() + "createNewSub Start!"); | ||
|
||
int res = 0; | ||
subDto.setUser(userRepository.findByUserId("dataofsg02")); // 수정 필요 | ||
subDto.setSubDate(DateUtil.getDateTime("dd")); | ||
subDto.setSubCount(1); | ||
log.info("itemSeq : " + subDto.getItemSeq()); | ||
|
||
SubEntity subEntity = SubMapper.INSTANCE.subDtoToSubEntity(subDto); | ||
|
||
log.info("subEntity (itemSeq) : " + subEntity.getItemSeq()); | ||
subRepository.save(subEntity); | ||
|
||
res = 1; | ||
|
||
log.info(this.getClass().getName() + "createNewSub End"); | ||
|
||
return res; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
UserService/src/main/java/com/submarket/userservice/vo/RequestSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.submarket.userservice.vo; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class RequestSub { | ||
|
||
private int itemSeq; | ||
|
||
private int subSeq; | ||
|
||
private int userSeq; | ||
} |
17 changes: 17 additions & 0 deletions
17
UserService/src/main/java/com/submarket/userservice/vo/ResponseSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.submarket.userservice.vo; | ||
|
||
import com.submarket.userservice.jpa.entity.UserEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ResponseSub { | ||
private Integer subSeq; | ||
private int itemSeq; | ||
private String subDate; | ||
private int subCount; | ||
private UserEntity user; | ||
} |