Skip to content

Commit

Permalink
Merge pull request #41 from Transmatter/development
Browse files Browse the repository at this point in the history
progress 2 backup
  • Loading branch information
oat431 authored Sep 9, 2022
2 parents 6c8fd12 + de6287c commit c741972
Show file tree
Hide file tree
Showing 38 changed files with 739 additions and 263 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM openjdk:17-alpine
RUN addgroup -S spring && adduser -S spring -G spring
RUN mkdir logs
VOLUME /logs
RUN apk add tzdata
EXPOSE 8080 8443

ENV JAVA_PROFILE dev-release
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java" , "-Dspring.profiles.active=${JAVA_PROFILE}",\
"-cp","app:app/lib/*","transmatter.platform.administration.AdministrationApplication"]
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: 1590
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 9000:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: 1590
63 changes: 38 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -86,15 +86,14 @@
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-mongodb</artifactId>
<version>3.7.4</version>
<version>4.2.1</version>
</dependency>

<dependency>
<groupId>com.mysema.querydsl</groupId>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.7.4</version>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand All @@ -105,16 +104,46 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.9.1</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.0.7</version>
</dependency>

</dependencies>
<repositories>
<repository>
Expand Down Expand Up @@ -145,26 +174,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@EnableAspectJAutoProxy
public class AdministrationApplication {

public static void main(String[] args) {
Expand All @@ -18,7 +20,7 @@ public WebMvcConfigurer corsConfigurer(){
@Override
public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000","http://localhost:3300","http://localhost:5500")
.allowedOrigins("http://localhost:3300","http://52.230.104.188")
.exposedHeaders("x-total-count");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,33 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import transmatter.platform.administration.content.entity.Content;
import transmatter.platform.administration.content.entity.ContentType;

import java.util.List;

public interface ContentDao {
Content getContent(String id);
Page<Content> getAllContents(PageRequest page);
List<Content> getAllContents();
void deleteContent(String id);
// News updateContent(News news);
Page<Content> searchContent(String title, PageRequest page);
Page<Content> getBySource(String source, PageRequest page);
Page<Content> getBySourceAndType(String source, String type, PageRequest page);
// progress 1
Content getContent(String id); // both admin and vi
Page<Content> getAllContents(PageRequest page); // both admin and vi
List<Content> getAllContents(); // both admin and vi
void deleteContent(String id); // only admin
Page<Content> searchContent(String title, PageRequest page); // both admin and vi
Page<Content> getBySource(String source, PageRequest page); // both admin and vi
Page<Content> getBySourceAndType(String source, String type, PageRequest page); // both admin and vi

Page<Content> getAllEmptyAltNews(PageRequest page);
// progress 2
Content updateContent(Content news); // only admin
Page<Content> getAllEmptyAltNews(PageRequest page); // only admin
Page<Content> getContentByDate(String start, String end, PageRequest page); // only admin
Page<Content> getContentType(ContentType type, PageRequest page); // only admin
Page<Content> searchContentSpecInSrcAndCate(String title, String source, String category, PageRequest page); // only admin
Page<Content> searchContentSpecInSrc(String title, String source, PageRequest page); // only admin

Page<Content> getAllApproveContent(PageRequest page); // only vi
Page<Content> getApproveContentBySource(String source, PageRequest page); // only vi
Page<Content> getApproveContentByDate(String start, String end, PageRequest page); // only vi
Page<Content> searchOnlyApproveContent(String title, PageRequest page); // only vi
Page<Content> getOnlyApproveContentBySource(String source,String type, PageRequest page); // only vi
Page<Content> searchApproveContentSpecInSrcAndCate(String title, String source, String category, PageRequest page); // only vi
Page<Content> searchApproveContentSpecInSrc(String title, String source, PageRequest page); // only vi
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Repository;
import transmatter.platform.administration.content.entity.Content;
import transmatter.platform.administration.content.entity.ContentStatus;
import transmatter.platform.administration.content.entity.ContentType;
import transmatter.platform.administration.content.repository.ContentRepository;

import java.util.List;
Expand All @@ -15,6 +17,7 @@ public class ContentDaoImpl implements ContentDao {
@Autowired
ContentRepository contentRepository;

// =================== progress 1 ======================== //
@Override
public Content getContent(String id) {
return contentRepository.findById(id).orElse(null);
Expand All @@ -35,11 +38,6 @@ public void deleteContent(String id) {
contentRepository.deleteById(id);
}

// @Override
// public News updateContent(News news) {
// return newsRepository.save(news);
// }

@Override
public Page<Content> searchContent(String title, PageRequest page) {
return contentRepository.findByTitleContaining(title,page);
Expand All @@ -52,11 +50,74 @@ public Page<Content> getBySource(String source, PageRequest page) {

@Override
public Page<Content> getBySourceAndType(String source, String type, PageRequest page) {
return contentRepository.findBySourceAndType(source,type,page);
return contentRepository.findBySourceAndCategory(source,type,page);
}

// =========================== progress 2 admin part ========================= //

@Override
public Content updateContent(Content news) {
return contentRepository.save(news);
}

@Override
public Page<Content> getAllEmptyAltNews(PageRequest page) {
return contentRepository.findByImages_AltIsNull(page);
return contentRepository.findByApproveStatus(ContentStatus.NOT_APPROVE,page);
}

@Override
public Page<Content> getContentByDate(String start, String end, PageRequest page) {
return contentRepository.findByPublicDateBetween(start,end,page);
}

@Override
public Page<Content> getContentType(ContentType type, PageRequest page) {
return contentRepository.findByType(type,page);
}

@Override
public Page<Content> searchContentSpecInSrcAndCate(String title, String source, String category, PageRequest page) {
return contentRepository.findByTitleContainingAndSourceAndCategory(title,source,category,page);
}

@Override
public Page<Content> searchContentSpecInSrc(String title, String source, PageRequest page) {
return contentRepository.findByTitleContainingAndSource(title,source,page);
}

// ========================== progress 2 vi part =================================== //
@Override
public Page<Content> getAllApproveContent(PageRequest page) {
return contentRepository.findByApproveStatus(ContentStatus.APPROVE,page);
}

@Override
public Page<Content> getApproveContentByDate(String start, String end, PageRequest page) {
return contentRepository.findByApprovedDateBetween(start,end,page);
}

@Override
public Page<Content> searchOnlyApproveContent(String title, PageRequest page) {
return contentRepository.findByTitleContainingAndApproveStatus(title,ContentStatus.APPROVE,page);
}

@Override
public Page<Content> getOnlyApproveContentBySource(String source, String type, PageRequest page) {
return contentRepository.findBySourceAndCategoryAndApproveStatus(source,type,ContentStatus.APPROVE, page);
}

@Override
public Page<Content> searchApproveContentSpecInSrcAndCate(String title, String source, String category, PageRequest page) {
return contentRepository.findByTitleContainingAndSourceAndCategoryAndApproveStatus(title,source,category,ContentStatus.APPROVE,page);
}

@Override
public Page<Content> searchApproveContentSpecInSrc(String title, String source, PageRequest page) {
return contentRepository.findByTitleContainingAndSourceAndApproveStatus(title,source,ContentStatus.APPROVE,page);
}

@Override
public Page<Content> getApproveContentBySource(String source, PageRequest page) {
return contentRepository.findBySourceAndApproveStatus(source,ContentStatus.APPROVE, page);
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
package transmatter.platform.administration.content.entity;

import com.mysema.query.annotations.QueryEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.lang.Nullable;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@QueryEntity
@Document
public class Content {
@Id
String id;

String source;
String author;
String public_date;
String publicDate;
String title;
String content;
String type;
String category;
List<Image> images;
List<Comment> comment;

@Builder.Default
ContentStatus approveStatus = ContentStatus.NA;

@Builder.Default
ContentType type = ContentType.NA;

@Nullable
String approvedDate;

@Nullable
String approvedBy;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package transmatter.platform.administration.content.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ContentRequest {
String title;
String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package transmatter.platform.administration.content.entity;

public enum ContentStatus {
NA("ไม่"),APPROVE("รองรับ"),NOT_APPROVE("ไม่รองรับ");

String thaiName;
ContentStatus(String thaiName){
this.thaiName = thaiName;
}

public String getThaiName() {
return thaiName;
}
}
Loading

0 comments on commit c741972

Please sign in to comment.