Skip to content
Snippets Groups Projects
Commit d3f8695f authored by Seb Barnard's avatar Seb Barnard :speech_balloon:
Browse files

Added tag saving and linking

parent 9c884938
No related branches found
No related tags found
3 merge requests!56tags will be saved to userFavTags table (needs user ID of current logged in user),!22Branch Update,!20Develop
package com.example.clientproject.data.misc;
public class ShopTagLinkTable {
private int shopId;
private int tagId;
public ShopTagLinkTable(int shopId, int tagId){
this.shopId = shopId;
this.tagId = tagId;
}
}
......@@ -23,6 +23,13 @@ public class Tags {
private long tagId;
private String tagName;
/**
*
*/
public Tags(String tagName){
this.tagName = tagName;
}
@ManyToMany(mappedBy="shopTags")
private List<Shops> relatedShops;
......
package com.example.clientproject.data.tags;
import com.example.clientproject.data.shops.Shops;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
......@@ -21,4 +23,7 @@ public interface TagsRepo extends JpaRepository<Tags, Long> {
* @return - the object
*/
Tags save(Tags tags);
@Query("select t.tagId from Tags t where t.tagId = (select max(t.tagId) from Tags t)")
int findMostRecent();
}
......@@ -13,7 +13,7 @@ public class BusinessRegisterDTO {
String business_register_name;
String business_register_desc;
//String businessCategory;
//ArrayList<String> businessTags;
ArrayList<String> businessTags;
//String instagram;
//String facebook;
//String twitter;
......@@ -26,7 +26,7 @@ public class BusinessRegisterDTO {
brf.getBusiness_register_name(),
brf.getBusiness_register_desc(),
//brf.getBusinessCategory(),
//brf.getBusinessTags(),
brf.getBusinessTags(),
//brf.getInstagram(),
//brf.getFacebook(),
//brf.getTwitter(),
......
......@@ -2,15 +2,27 @@ package com.example.clientproject.services;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.tags.TagsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.util.List;
@Service
public class BusinessRegisterSaver {
@Autowired
ShopsRepo shopsRepo;
@Autowired
TagsRepo tagsRepo;
@Autowired
JdbcTemplate jdbc;
public void save(BusinessRegisterDTO business){
Shops shop = new Shops(business.getBusiness_register_name(),
......@@ -22,6 +34,26 @@ public class BusinessRegisterSaver {
false);
shopsRepo.save(shop);
List<Tags> tagsList = tagsRepo.findAll();
for(String t: business.getBusinessTags()){
if(tagsList.contains(new Tags(t))){
// Link shop to tag
continue;
}
//long id = 0;
Tags tag = new Tags(t);
tagsRepo.save(tag);
String query = "INSERT INTO Shop_Tag_Links (Shop_Id, Tag_Id) VALUES ("+ shop.getShopId() +
","+tag.getTagId() + ")";
jdbc.execute(query);
}
System.out.println(shop.getShopId());
System.out.println(tagsRepo.findAll());
System.out.println(shopsRepo.findByShopName(business.getBusiness_register_name()));
}
......
This diff is collapsed.
......@@ -72,7 +72,7 @@ def namePopulator(amount, userType):
# print(current_user_id)
# print(current_user_id+amount)
stringInsert = str(current_user_id) + ',' + '1' + ',' + str(userType)
insertArray.append(createInsert(stringInsert, "UserPermissions", "User_ID, Shop_ID, Admin_Type_Id"))
insertArray.append(createInsert(stringInsert, "User_Permissions", "User_ID, Shop_ID, Admin_Type_Id"))
current_user_id = current_user_id + 1
return insertArray
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment