Skip to content

Commit

Permalink
Merge pull request #2 from Sam3Star/gayeong
Browse files Browse the repository at this point in the history
feat: set structure
  • Loading branch information
GayeongKimm authored Jun 24, 2024
2 parents 82ae70c + 2cc3041 commit 917524e
Show file tree
Hide file tree
Showing 18 changed files with 316 additions and 5 deletions.
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'org.springframework.boot' version '3.0.4'
id 'io.spring.dependency-management' version '1.1.3'
}

group = 'kr.hs.dgsw'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
sourceCompatibility = '17'
}

configurations {
Expand All @@ -31,6 +29,11 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
implementation 'org.springframework.boot:spring-boot-starter-validation'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class ClockServerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kr.hs.dgsw.clock_server.domain.routine.entity;

import jakarta.persistence.*;
import kr.hs.dgsw.clock_server.global.common.entity.BaseTimeEntity;
import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum;
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table(name = "tbl_routine")
@Getter
@DynamicUpdate
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RoutineEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "routine_id", nullable = false)
private Long routineId;

@Column(name = "routine_name", nullable = false)
private String name;

@Column(name = "importance", nullable = false)
private ImportanceEnum importanceEnum;

@Column(name = "color", nullable = false)
private ColorEnum colorEnum;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kr.hs.dgsw.clock_server.domain.routine.mapper;

import kr.hs.dgsw.clock_server.domain.routine.entity.RoutineEntity;
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.RoutineDto;
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq;
import kr.hs.dgsw.clock_server.global.anotation.Mapper;
import lombok.RequiredArgsConstructor;

@Mapper
@RequiredArgsConstructor
public class RoutineMapper {
public RoutineDto mapToDomain(RoutineEntity routineEntity){
return RoutineDto.builder()
.routineId(routineEntity.getRoutineId())
.name(routineEntity.getName())
.importanceEnum(routineEntity.getImportanceEnum())
.colorEnum(routineEntity.getColorEnum())
.build();
}

public RoutineEntity mapToEntity(RoutineDto routineDto){
return RoutineEntity.builder()
.routineId(routineDto.getRoutineId())
.name(routineDto.getName())
.importanceEnum(routineDto.getImportanceEnum())
.colorEnum(routineDto.getColorEnum())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kr.hs.dgsw.clock_server.domain.routine.presentation.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq;
import kr.hs.dgsw.clock_server.domain.routine.service.RoutineService;
import kr.hs.dgsw.clock_server.global.reponse.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "routine", description = "routine Api")
@RestController
@RequiredArgsConstructor
@RequestMapping("/routine")
public class RoutineController {
private final RoutineService routineService;

@PostMapping()
@Operation(summary = "generate routine", description = "generate routine")
public Response generate(
@RequestBody RoutineGenerateReq req
){
routineService.generate(req);
return Response.of(HttpStatus.OK, "생성성공");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kr.hs.dgsw.clock_server.domain.routine.presentation.dto;

import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum;
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum;
import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class RoutineDto {
private Long routineId;
private String name;
private ImportanceEnum importanceEnum;
private ColorEnum colorEnum;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req;

import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum;
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class RoutineGenerateReq{
String name;
ImportanceEnum importanceEnum;
ColorEnum colorEnum;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.hs.dgsw.clock_server.domain.routine.repository;

import kr.hs.dgsw.clock_server.domain.routine.entity.RoutineEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface RoutineRepository extends JpaRepository<RoutineEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.hs.dgsw.clock_server.domain.routine.service;

import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq;

public interface RoutineService {
void generate(RoutineGenerateReq req);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kr.hs.dgsw.clock_server.domain.routine.service;

import kr.hs.dgsw.clock_server.domain.routine.entity.RoutineEntity;
import kr.hs.dgsw.clock_server.domain.routine.mapper.RoutineMapper;
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq;
import kr.hs.dgsw.clock_server.domain.routine.repository.RoutineRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class RoutineServiceImpl implements RoutineService{
private final RoutineRepository routineRepository;
private final RoutineMapper routineMapper;

@Override
@Transactional(rollbackFor = Exception.class)
public void generate(RoutineGenerateReq req){
routineRepository.save(RoutineEntity.builder()
.name(req.getName())
.importanceEnum(req.getImportanceEnum())
.colorEnum(req.getColorEnum())
.build());
}
}
15 changes: 15 additions & 0 deletions src/main/java/kr/hs/dgsw/clock_server/global/anotation/Mapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kr.hs.dgsw.clock_server.global.anotation;

import org.springframework.stereotype.Component;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Component
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Mapper {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kr.hs.dgsw.clock_server.global.common.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@SuperBuilder
@MappedSuperclass
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {
@CreatedDate
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
protected LocalDateTime createdDate;

@LastModifiedDate
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
protected LocalDateTime modifiedDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kr.hs.dgsw.clock_server.global.common.enums;

public enum ColorEnum {
green,
red,
orange,
yellow,
blue,
pink
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.hs.dgsw.clock_server.global.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum ImportanceEnum {
veryImportant,
important,
soso,
baggy,
less
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kr.hs.dgsw.clock_server.global.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
SecurityScheme securityScheme = new SecurityScheme()
.name("Authorization")
.type(SecurityScheme.Type.HTTP)
.in(SecurityScheme.In.HEADER)
.bearerFormat("JWT")
.scheme("bearer");
OpenAPI openAPI = new OpenAPI().addSecurityItem(new SecurityRequirement().addList("JWT Token"))
.components(new Components())
.info(apiInfo());
openAPI.getComponents().addSecuritySchemes("JWT Token", securityScheme);
return openAPI;
}

private Info apiInfo() {
return new Info()
.title("Java.")
.description("Java API")
.version("0.0.1");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.hs.dgsw.clock_server.global.reponse;

import org.springframework.http.HttpStatus;

public record Response(int status, String message) {
public static Response of(HttpStatus status, String message) {
return new Response(status.value(), message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kr.hs.dgsw.clock_server.global.reponse;

import org.springframework.http.HttpStatus;

public record ResponseData<T>(
int status,
String message,
T data
) {
public static <T> ResponseData<T> of(HttpStatus status, String message, T data) {
return new ResponseData<>(status.value(), message, data);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ spring:
hibernate:
format_sql: true
show_sql: true

server:
port: 8080

0 comments on commit 917524e

Please sign in to comment.