-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PLADI-ALM/feat/PDS-35-upload-file
[PDS-35] 아카이빙 자료 업로드 API 기능구현
- Loading branch information
Showing
22 changed files
with
569 additions
and
44 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.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,54 @@ | ||
package com.example.PLADIALMArchiving.archiving.controller; | ||
|
||
import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq; | ||
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq; | ||
import com.example.PLADIALMArchiving.archiving.service.ArchivingService; | ||
import com.example.PLADIALMArchiving.global.resolver.Account; | ||
import com.example.PLADIALMArchiving.global.response.ResponseCustom; | ||
import com.example.PLADIALMArchiving.user.entity.User; | ||
import io.swagger.annotations.Api; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Api(tags = "아카이빙 API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/archives") | ||
public class ArchivingController { | ||
|
||
private final ArchivingService archivingService; | ||
|
||
/** | ||
* 프로젝트를 추가한다. | ||
*/ | ||
@PostMapping("/projects/register") | ||
public ResponseCustom<?> registerProject(@RequestBody RegisterProjectReq registerProjectReq) { | ||
archivingService.registerProject(registerProjectReq); | ||
return ResponseCustom.OK(); | ||
} | ||
|
||
/** | ||
* 자료를 업로드한다. | ||
*/ | ||
@PostMapping("/projects/{projectId}/upload") | ||
public ResponseCustom<?> uploadMaterial( | ||
@RequestBody UploadMaterialReq uploadMaterialReq, | ||
@PathVariable Long projectId, | ||
@Account User user | ||
) | ||
{ | ||
archivingService.uploadMaterial(uploadMaterialReq, projectId, user); | ||
return ResponseCustom.OK(); | ||
} | ||
/** | ||
* 자료목록을 조회 및 검색한다. | ||
*/ | ||
|
||
/** | ||
* 자료를 삭제한다. | ||
*/ | ||
|
||
/** | ||
* 자료를 다운로드한다. | ||
*/ | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/RegisterProjectReq.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,8 @@ | ||
package com.example.PLADIALMArchiving.archiving.dto.request; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class RegisterProjectReq { | ||
private String name; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/UploadMaterialReq.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.example.PLADIALMArchiving.archiving.dto.request; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class UploadMaterialReq { | ||
private String fileKey; | ||
private String name; | ||
private String extension; | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/example/PLADIALMArchiving/archiving/entity/Material.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,60 @@ | ||
package com.example.PLADIALMArchiving.archiving.entity; | ||
|
||
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq; | ||
import com.example.PLADIALMArchiving.global.entity.BaseEntity; | ||
import com.example.PLADIALMArchiving.user.entity.User; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
import org.hibernate.annotations.Where; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@DynamicInsert | ||
@DynamicUpdate | ||
@Where(clause = "is_enable = true") | ||
public class Material extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long materialId; | ||
|
||
private String name; | ||
|
||
private String extension; | ||
|
||
private String fileKey; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(nullable = false, name = "project_id") | ||
private Project project; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(nullable = false, name = "user_id") | ||
private User user; | ||
|
||
@Builder | ||
public Material(String name, String extension, String fileKey, Project project, User user) { | ||
this.name = name; | ||
this.extension = extension; | ||
this.fileKey = fileKey; | ||
this.project = project; | ||
this.user = user; | ||
} | ||
|
||
public static Material toEntity(UploadMaterialReq uploadMaterialReq, Project project, User user) { | ||
return Material.builder() | ||
.name(uploadMaterialReq.getName()) | ||
.extension(uploadMaterialReq.getExtension()) | ||
.fileKey(uploadMaterialReq.getFileKey()) | ||
.project(project) | ||
.user(user) | ||
.build(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/example/PLADIALMArchiving/archiving/entity/Project.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,44 @@ | ||
package com.example.PLADIALMArchiving.archiving.entity; | ||
|
||
import com.example.PLADIALMArchiving.global.entity.BaseEntity; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
import org.hibernate.annotations.Where; | ||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@DynamicInsert | ||
@DynamicUpdate | ||
@Where(clause = "is_enable = true") | ||
public class Project extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long projectId; | ||
|
||
@NotNull | ||
@Size(max = 50) | ||
private String name; | ||
|
||
@OneToMany(mappedBy = "project", fetch = FetchType.LAZY) | ||
private List<Material> materialList = new ArrayList<>(); | ||
|
||
public static Project toEntity(String name) { | ||
return Project.builder().name(name).build(); | ||
} | ||
|
||
@Builder | ||
public Project(String name) { | ||
this.name = name; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.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,9 @@ | ||
package com.example.PLADIALMArchiving.archiving.repository; | ||
|
||
import com.example.PLADIALMArchiving.archiving.entity.Material; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MaterialRepository extends JpaRepository<Material, Long> { | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/PLADIALMArchiving/archiving/repository/ProjectRepository.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.example.PLADIALMArchiving.archiving.repository; | ||
|
||
import com.example.PLADIALMArchiving.archiving.entity.Project; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface ProjectRepository extends JpaRepository<Project, Long> { | ||
|
||
Optional<Project> findByName(String name); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.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.example.PLADIALMArchiving.archiving.service; | ||
|
||
import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq; | ||
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq; | ||
import com.example.PLADIALMArchiving.archiving.entity.Material; | ||
import com.example.PLADIALMArchiving.archiving.entity.Project; | ||
import com.example.PLADIALMArchiving.archiving.repository.MaterialRepository; | ||
import com.example.PLADIALMArchiving.archiving.repository.ProjectRepository; | ||
import com.example.PLADIALMArchiving.global.exception.BaseException; | ||
import com.example.PLADIALMArchiving.global.exception.BaseResponseCode; | ||
import com.example.PLADIALMArchiving.user.entity.User; | ||
import com.example.PLADIALMArchiving.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.io.InputStream; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ArchivingService { | ||
|
||
private final UserRepository userRepository; | ||
private final ProjectRepository projectRepository; | ||
private final MaterialRepository materialRepository; | ||
|
||
|
||
@Transactional | ||
public void registerProject(RegisterProjectReq registerProjectReq) { | ||
boolean present = projectRepository.findByName(registerProjectReq.getName()).isPresent(); | ||
if(present) throw new BaseException(BaseResponseCode.ALREADY_REGISTERED_PROJECT); | ||
projectRepository.save(Project.toEntity(registerProjectReq.getName())); | ||
} | ||
|
||
@Transactional | ||
public void uploadMaterial(UploadMaterialReq uploadMaterialReq, Long projectId, User user) { | ||
Project project = projectRepository.findById(projectId).orElseThrow(() -> new BaseException(BaseResponseCode.PROJECT_NOT_FOUND)); | ||
materialRepository.save(Material.toEntity(uploadMaterialReq, project, user)); | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/java/com/example/PLADIALMArchiving/global/BaseEntity.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/PLADIALMArchiving/global/Constants.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,19 @@ | ||
package com.example.PLADIALMArchiving.global; | ||
|
||
public class Constants { | ||
public static final String TIME_PATTERN = "HH:mm"; | ||
public static final String DATE_PATTERN = "yyyy-MM-dd"; | ||
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm"; | ||
|
||
public static class Booking{ | ||
public static final String BOOKED_TIMES = "bookedTimes"; | ||
} | ||
|
||
public static class JWT{ | ||
public static final String AUTHORIZATION_HEADER = "Authorization"; | ||
public static final String BEARER_PREFIX = "Bearer "; | ||
public static final String CLAIM_NAME = "userIdx"; | ||
public static final String LOGOUT = "logout"; | ||
public static final String SIGNOUT = "signout"; | ||
} | ||
} |
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
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
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
Oops, something went wrong.