Skip to content

Commit

Permalink
Merge pull request #6 from kkijuk/feature/2
Browse files Browse the repository at this point in the history
[넬리] 마스터 자기소개서 CRUD
  • Loading branch information
nanna29 authored Jul 21, 2024
2 parents 1711658 + acd2069 commit 1a5f3df
Show file tree
Hide file tree
Showing 35 changed files with 737 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @tape4
16 changes: 13 additions & 3 deletions .github/workflows/CICD_DEVELOP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- develop
- example

env:
DOCKERHUB_REPOSITORY: umc-develop-server
Expand All @@ -25,6 +26,13 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Setup MySQL
uses: mirromutth/[email protected]
with:
mysql database: 'kkijuk'
mysql user: 'test'
mysql password: 'testPW'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

Expand All @@ -34,9 +42,10 @@ jobs:

- name: Generate application.properties
run: |
touch ./src/main/resources/application.properties
echo ${{ secrets.PROPERTIES }} >> ./src/main/resources/application.properties
echo commit.hash=${{ steps.slug.outputs.sha7 }} >> ./src/main/resources/application.properties
echo commit.hash=${{ steps.slug.outputs.sha7 }} >> ./src/main/resources/application-prod.properties
echo ${{ secrets.DATASOURCE_DB_URL }} >> ./src/main/resources/application-prod.properties
echo ${{ secrets.DATASOURCE_DB_USERNAME }} >> ./src/main/resources/application-prod.properties
echo ${{ secrets.DATASOURCE_DB_PASSWORD }} >> ./src/main/resources/application-prod.properties
- name: Build with Gradle Wrapper
run: ./gradlew build
Expand Down Expand Up @@ -105,6 +114,7 @@ jobs:
# echo "No images found in repository $DOCKERHUB_REPOSITORY"
# fi
#

CD_Deploy:
name: CD_Deploy
needs: CD_Delivery_to_DockerHub
Expand Down
38 changes: 27 additions & 11 deletions .github/workflows/CI_MVP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ name: CI FOR MVP
on:
push:
branches:
- mvp/apply
- mvp/member
- mvp/career
- mvp/portfolio

- mvp/apply
- mvp/member
- mvp/career
- mvp/portfolio

jobs:
CI:
Expand All @@ -26,18 +25,35 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Setup MySQL
uses: mirromutth/[email protected]
with:
mysql database: 'kkijuk'
mysql user: 'test'
mysql password: 'testPW'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Get short SHA
id: slug
run: echo "sha7=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT

- name: Generate application.properties
run: |
touch ./src/main/resources/application.properties
echo ${{ secrets.PROPERTIES }} >> ./src/main/resources/application.properties
echo commit.hash=${{ steps.slug.outputs.sha7 }} >> ./src/main/resources/application.properties
# - name: Generate application.properties
# run: |
# echo commit.hash=${{ steps.slug.outputs.sha7 }} >> ./src/main/resources/application-prod.properties
# echo ${{ secrets.DATASOURCE_DB_URL }} >> ./src/main/resources/application-prod.properties
# echo ${{ secrets.DATASOURCE_DB_USERNAME }} >> ./src/main/resources/application-prod.properties
# echo ${{ secrets.DATASOURCE_DB_PASSWORD }} >> ./src/main/resources/application.properties

# touch ./src/main/resources/application.properties
# touch ./src/test/resources/application.properties
# echo ${{ secrets.PROPERTIES }} >> ./src/main/resources/application.properties
# echo ${{ secrets.PROPERTIES }} >> ./src/test/resources/application.properties
#
# echo ${{ secrets.DB_PROPERTIES }} >> ./src/main/resources/application.properties
# echo ${{ secrets.TEST_DB_PROPERTIES }} >> ./src/test/resources/application.properties


- name: Build with Gradle Wrapper
run: ./gradlew build
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ out/
### VS Code ###
.vscode/

### application.properties ###
/src/main/resources/application.properties
application.properties
application-prod.properties
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
ENTRYPOINT ["java", "-jar", "/app.jar", "--spring.profiles.active=prod "]
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'


implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.32'
implementation 'org.springframework.boot:spring-boot-starter-validation'
}

tasks.named('test') {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/umc/kkijuk/server/common/LoginUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package umc.kkijuk.server.common;

public class LoginUser {
private static final LoginUser LOGIN_USER = new LoginUser(0L);

public LoginUser(Long id) {
}

public static LoginUser get() {
return LOGIN_USER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package umc.kkijuk.server.common.converter;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.AttributeConverter;

import java.io.IOException;
import java.util.List;

public class StringListToStringConverter implements AttributeConverter<List<String>, String> {
private static final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);

@Override
public String convertToDatabaseColumn(List<String> attribute) {
try {
return mapper.writeValueAsString(attribute);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException();
}
}

@Override
public List<String> convertToEntityAttribute(String dbData) {
TypeReference<List<String>> typeReference = new TypeReference<List<String>>() {};
try {
return mapper.readValue(dbData, typeReference);
} catch (IOException e) {
throw new IllegalArgumentException();
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/umc/kkijuk/server/introduce/common/BaseResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package umc.kkijuk.server.introduce.common;

import lombok.Getter;

@Getter
public class BaseResponse<T> {

private final int status;
private String message;
private T data;

// Response constructor that includes status, message, and data
public BaseResponse(int status, String message, T data) {
this.status = status;
this.message = message;
this.data = data;
}

// Response constructor that includes status and message only
public BaseResponse(int status, String message) {
this.status = status;
this.message = message;
}

// Response constructor that includes status and data only
public BaseResponse(int status, T data) {
this.status = status;
this.data = data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package umc.kkijuk.server.introduce.controller;

public class IntroduceController {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package umc.kkijuk.server.introduce.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import umc.kkijuk.server.introduce.common.BaseResponse;
import umc.kkijuk.server.introduce.domain.MasterIntroduce;
import umc.kkijuk.server.introduce.dto.MasterIntroduceReqDto;
import umc.kkijuk.server.introduce.dto.MasterIntroduceResDto;
import umc.kkijuk.server.introduce.response.BaseErrorResponse;
import umc.kkijuk.server.introduce.response.BaseException;
import umc.kkijuk.server.introduce.service.MasterIntroduceService;

import java.util.List;

@Tag(name = "master", description = "마스터 자기소개서 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/history/intro/master")
public class MasterIntroduceController {
private final MasterIntroduceService masterIntroduceService;

@PostMapping
public ResponseEntity<Object> save(@RequestBody MasterIntroduceReqDto masterIntroduceReqDto){
try {
MasterIntroduceResDto masterIntroduceResDto = masterIntroduceService.saveMasterIntro(masterIntroduceReqDto);
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 생성 완료", masterIntroduceResDto));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@GetMapping
public ResponseEntity<Object> get(){
try {
List<MasterIntroduce> masterIntroduce = masterIntroduceService.getMasterIntro();
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 조회 완료", masterIntroduce));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@PatchMapping
public ResponseEntity<Object> update(Long id, @RequestBody MasterIntroduceReqDto masterIntroduceReqDto){
try {
MasterIntroduceResDto masterIntroduceResDto = masterIntroduceService.updateMasterIntro(id, masterIntroduceReqDto);
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 수정 완료", masterIntroduceResDto));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/umc/kkijuk/server/introduce/domain/Introduce.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package umc.kkijuk.server.introduce.domain;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

@Entity
@Table(name="introduce")
@Getter
public class Introduce {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package umc.kkijuk.server.introduce.domain;

import org.springframework.data.jpa.repository.JpaRepository;

public interface IntroduceRepository extends JpaRepository<Introduce, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package umc.kkijuk.server.introduce.domain;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedDate;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Entity
@Table(name = "master_introduce")
@Getter
@NoArgsConstructor
public class MasterIntroduce {

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

@Size(max = 24)
private String oneLiner;

private String subTitle;
private String content;

@CreationTimestamp
private LocalDateTime created_at;

@UpdateTimestamp
private LocalDateTime updated_at;

@Builder
public MasterIntroduce(String oneLiner, String subTitle, String content) {
this.oneLiner = oneLiner;
this.subTitle = subTitle;
this.content = content;
}

public String getUpdated_at() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return updated_at != null ? updated_at.format(formatter) : null;
}

public void update(String oneLiner, String subTitle, String content) {
this.oneLiner = oneLiner;
this.subTitle = subTitle;
this.content = content;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package umc.kkijuk.server.introduce.domain;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MasterIntroduceRepository extends JpaRepository<MasterIntroduce, Long> {
}
Loading

0 comments on commit 1a5f3df

Please sign in to comment.